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
|
public $log;
|
16
|
|
17
|
public function __construct($action,$args){
|
18
|
$this->log = Logger::getLogger(__CLASS__);
|
19
|
Logger::configure('./js/log4php/log4php.xml');
|
20
|
$this->log->info("Calling scripts to modify Cache....");
|
21
|
$this->log->info("Script Mode:".$action);
|
22
|
|
23
|
|
24
|
if(!$action=='help'){
|
25
|
echo ("Performing Action : ".$action."<br><br>"); }
|
26
|
|
27
|
|
28
|
if ($action=='refreshNums')
|
29
|
{$this->refreshNums();}
|
30
|
else if ($action=='refreshCharts')
|
31
|
{$this->refreshCharts();}
|
32
|
else if ($action=='refreshAll')
|
33
|
{ $this->refreshAll(); }
|
34
|
else if ($action=='promoteNums')
|
35
|
{$this->promoteNums();}
|
36
|
else if ($action=='promoteCharts')
|
37
|
{$this->promoteCharts();}
|
38
|
else if ($action=='promoteAll')
|
39
|
{ $this->promoteAll(); }
|
40
|
else if ($action=='restore')
|
41
|
{ $this->restore(); }
|
42
|
else if ($action=='backup')
|
43
|
{
|
44
|
$this->backup(); }
|
45
|
else if ($action=='migrate')
|
46
|
{$this->migrate($args);}
|
47
|
else if ($action=='help')
|
48
|
{$this->printHelp();}
|
49
|
else
|
50
|
{$this->log->info("Wrong argument given");
|
51
|
$this->printHelp();}
|
52
|
|
53
|
|
54
|
if($action!=='help'){
|
55
|
echo("<br>Action Finished! <br>");
|
56
|
}
|
57
|
|
58
|
|
59
|
}
|
60
|
|
61
|
private function printHelp()
|
62
|
{
|
63
|
$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);
|
64
|
}
|
65
|
|
66
|
public function refreshNums(){
|
67
|
$this->log->info("Refreshing Numbers...");
|
68
|
$csn = new ComputeStatsNumbers();
|
69
|
$csn->computeStats();
|
70
|
$this->log->info("Done!");
|
71
|
}
|
72
|
|
73
|
public function refreshCharts()
|
74
|
{
|
75
|
$this->log->info("Refreshing Charts...");
|
76
|
$csn = new RefreshCharts();$csn->refresh();
|
77
|
$this->log->info("Done!");
|
78
|
}
|
79
|
|
80
|
public function refreshAll()
|
81
|
{
|
82
|
$this->refreshNums();
|
83
|
$this->refreshCharts();
|
84
|
}
|
85
|
|
86
|
public function promoteNums(){
|
87
|
$this->log->info(" Promoting Numbers...");
|
88
|
$csn = new PromoteShadowNums();
|
89
|
$csn->replace();
|
90
|
$this->log->info("Done!");
|
91
|
}
|
92
|
|
93
|
public function promoteCharts()
|
94
|
{
|
95
|
$this->log->info("Promoting Charts...");
|
96
|
$csn = new PromoteCharts();$csn->replace();
|
97
|
$this->log->info("Done!");
|
98
|
}
|
99
|
|
100
|
public function migrate ($args)
|
101
|
{
|
102
|
|
103
|
//$this->log->info("Cache Migration not yet implemented");
|
104
|
|
105
|
$this->log->info("*************Migrating Cache to ".$args[0]." on ".$args[1]);
|
106
|
|
107
|
$csn = new MigrateCache();
|
108
|
|
109
|
global $redis_remote_host;
|
110
|
global $redis_remote_port;
|
111
|
global $redis_remote_beta_host ;
|
112
|
global $redis_remote_beta_port;
|
113
|
|
114
|
if($args[0]=='production')
|
115
|
{
|
116
|
$csn->migrate($redis_remote_host,$redis_remote_port);}
|
117
|
else if($args[0]=='beta' )
|
118
|
{
|
119
|
$csn->migrate($redis_remote_beta_host,$redis_remote_beta_port);}
|
120
|
else{
|
121
|
|
122
|
$csn->migrate($args[0],$args[1]);
|
123
|
$this->log->info("Done!");
|
124
|
|
125
|
//echo("Cache Migration not yet implemented <br>");
|
126
|
|
127
|
}
|
128
|
|
129
|
}
|
130
|
|
131
|
|
132
|
|
133
|
|
134
|
|
135
|
public function backup()
|
136
|
{
|
137
|
$this->log->info("Backing Up Cache...");
|
138
|
$csn = new BackupCache();$csn->backup();
|
139
|
$this->log->info("Done!");
|
140
|
}
|
141
|
|
142
|
public function restore()
|
143
|
{
|
144
|
$this->log->info("Restoring Cache...");
|
145
|
$csn = new RestoreCache();$csn->restore();
|
146
|
$this->log->info("Done!");
|
147
|
}
|
148
|
|
149
|
public function promoteAll()
|
150
|
{ $this->promoteNums();
|
151
|
$this->promoteCharts();}
|
152
|
}
|
153
|
|
154
|
if ($_GET) {
|
155
|
$action = $_GET['action'];
|
156
|
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
|
157
|
//$args = array( "0"=> $_GET['targetCache']);
|
158
|
|
159
|
}
|
160
|
else
|
161
|
{
|
162
|
$action = $argv[1];
|
163
|
if(count($argv)>1)
|
164
|
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}
|
165
|
|
166
|
}
|
167
|
|
168
|
$rc = new CacheController($action,$args);
|
169
|
|
170
|
?>
|