1
|
<?php
|
2
|
require_once('./js/log4php/Logger.php');
|
3
|
include_once('./refreshNums.php');
|
4
|
include_once('./refreshCharts.php');
|
5
|
include_once('./promoteNums.php');
|
6
|
include_once('./promoteCharts.php');
|
7
|
include_once('./backupCache.php');
|
8
|
include_once('./restoreCache.php');
|
9
|
include_once('./migrateCache.php');
|
10
|
include_once("./paths.php");
|
11
|
|
12
|
class CacheController
|
13
|
|
14
|
{
|
15
|
|
16
|
/* TODO Eri: Controller with main actions for
|
17
|
refreshing Redis Cache in the background,
|
18
|
making new content visible on the portal ,
|
19
|
backing up & restoring cache contents,
|
20
|
and migrating data from one redis instance to another.
|
21
|
Linked with uoa-stats-service.
|
22
|
Can be invoked either through htttp calls or command line.
|
23
|
*/
|
24
|
|
25
|
public $log;
|
26
|
public function __construct($action,$args){
|
27
|
$this->log = Logger::getLogger(__CLASS__);
|
28
|
Logger::configure('./js/log4php/log4php.xml');
|
29
|
$this->log->info("Calling scripts to modify Cache....");
|
30
|
$this->log->info("Script Mode:".$action);
|
31
|
|
32
|
if(!$action=='help'){
|
33
|
echo ("Performing Action : ".$action."<br><br>"); }
|
34
|
|
35
|
|
36
|
if ($action=='refreshNums')
|
37
|
{$this->refreshNums();}
|
38
|
else if ($action=='refreshCharts')
|
39
|
{$this->refreshCharts();}
|
40
|
else if ($action=='refreshAll')
|
41
|
{ $this->refreshAll(); }
|
42
|
else if ($action=='promoteNums')
|
43
|
{$this->promoteNums();}
|
44
|
else if ($action=='promoteCharts')
|
45
|
{$this->promoteCharts();}
|
46
|
else if ($action=='promoteAll')
|
47
|
{ $this->promoteAll(); }
|
48
|
else if ($action=='restore')
|
49
|
{ $this->restore(); }
|
50
|
else if ($action=='backup')
|
51
|
{
|
52
|
$this->backup(); }
|
53
|
else if ($action=='migrate')
|
54
|
{$this->migrate($args);}
|
55
|
else if ($action=='help')
|
56
|
{$this->printHelp();}
|
57
|
else
|
58
|
{$this->log->info("Wrong argument given");
|
59
|
$this->printHelp();}
|
60
|
|
61
|
|
62
|
if($action!=='help'){
|
63
|
echo("<br>Action Finished! <br>");
|
64
|
}
|
65
|
|
66
|
|
67
|
}
|
68
|
|
69
|
private function printHelp()
|
70
|
{
|
71
|
$msg="<h1>Cache Controls <br><br> </h1> Availiable options for <b> refresh :</b> <br><br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshNums\"> refreshNums </a> -> Refresh Stats Numbers Only <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshCharts\"> refreshCharts</a> -> Refresh Chart Queries <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshAll\"> refreshAll</a > -> Refresh every entry in the cache.<br> <br>Availiable options for <b>promote</b> :<br> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteNums\"> promoteNums </a> -> Promotes Stats Numbers Only; <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteCharts\"> promoteCharts </a> -> Promote Chart Queries ; <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteAll\"> promoteAll</a> ->Promote every entry in the cache. <br> <br>Availiable options for <b>backup</b> : <br><br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=backup\"> backup </a> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=restore\"> restore </a> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=migrate\"> migrate </a> <br>"; $this->log->info($msg); echo($msg);
|
72
|
}
|
73
|
|
74
|
public function refreshNums(){
|
75
|
$this->log->info("Refreshing Numbers...");
|
76
|
$csn = new ComputeStatsNumbers();
|
77
|
$csn->computeStats();
|
78
|
$this->log->info("Done!");
|
79
|
}
|
80
|
|
81
|
public function refreshCharts()
|
82
|
{
|
83
|
$this->log->info("Refreshing Charts...");
|
84
|
$csn = new RefreshCharts();$csn->refresh();
|
85
|
$this->log->info("Done!");
|
86
|
}
|
87
|
|
88
|
public function refreshAll()
|
89
|
{
|
90
|
$this->refreshNums();
|
91
|
$this->refreshCharts();
|
92
|
}
|
93
|
|
94
|
public function promoteNums(){
|
95
|
$this->log->info(" Promoting Numbers...");
|
96
|
$csn = new PromoteShadowNums();
|
97
|
$csn->replace();
|
98
|
$this->log->info("Done!");
|
99
|
}
|
100
|
|
101
|
public function promoteCharts()
|
102
|
{
|
103
|
$this->log->info("Promoting Charts...");
|
104
|
$csn = new PromoteCharts();$csn->replace();
|
105
|
$this->log->info("Done!");
|
106
|
}
|
107
|
|
108
|
public function migrate ($args)
|
109
|
{
|
110
|
|
111
|
//$this->log->info("Cache Migration not yet implemented");
|
112
|
|
113
|
$this->log->info("*************Migrating Cache to ".$args[0]." on ".$args[1]);
|
114
|
|
115
|
$csn = new MigrateCache();
|
116
|
|
117
|
global $redis_remote_host;
|
118
|
global $redis_remote_port;
|
119
|
global $redis_remote_beta_host ;
|
120
|
global $redis_remote_beta_port;
|
121
|
|
122
|
if($args[0]=='production')
|
123
|
{
|
124
|
$csn->migrate($redis_remote_host,$redis_remote_port);}
|
125
|
else if($args[0]=='beta' )
|
126
|
{
|
127
|
$csn->migrate($redis_remote_beta_host,$redis_remote_beta_port);}
|
128
|
else{
|
129
|
|
130
|
$csn->migrate($args[0],$args[1]);
|
131
|
$this->log->info("Done!");
|
132
|
|
133
|
//echo("Cache Migration not yet implemented <br>");
|
134
|
|
135
|
}
|
136
|
|
137
|
}
|
138
|
|
139
|
|
140
|
|
141
|
|
142
|
|
143
|
public function backup()
|
144
|
{
|
145
|
$this->log->info("Backing Up Cache...");
|
146
|
$csn = new BackupCache();$csn->backup();
|
147
|
$this->log->info("Done!");
|
148
|
}
|
149
|
|
150
|
public function restore()
|
151
|
{
|
152
|
$this->log->info("Restoring Cache...");
|
153
|
$csn = new RestoreCache();$csn->restore();
|
154
|
$this->log->info("Done!");
|
155
|
}
|
156
|
|
157
|
public function promoteAll()
|
158
|
{ $this->promoteNums();
|
159
|
$this->promoteCharts();}
|
160
|
}
|
161
|
|
162
|
if ($_GET) {
|
163
|
$action = $_GET['action'];
|
164
|
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
|
165
|
//$args = array( "0"=> $_GET['targetCache']);
|
166
|
|
167
|
}
|
168
|
else
|
169
|
{
|
170
|
$action = $argv[1];
|
171
|
if(count($argv)>1)
|
172
|
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}
|
173
|
|
174
|
}
|
175
|
|
176
|
$rc = new CacheController($action,$args);
|
177
|
|
178
|
?>
|