1 |
33668
|
eri.katsar
|
<?php
|
2 |
33214
|
eri.katsar
|
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 |
33689
|
eri.katsar
|
include_once("./paths.php");
|
11 |
33214
|
eri.katsar
|
|
12 |
|
|
class CacheController
|
13 |
34471
|
eri.katsar
|
|
14 |
|
|
{
|
15 |
35680
|
eri.katsar
|
public $log;
|
16 |
34496
|
eri.katsar
|
|
17 |
34471
|
eri.katsar
|
public function __construct($action,$args){
|
18 |
33214
|
eri.katsar
|
$this->log = Logger::getLogger(__CLASS__);
|
19 |
34471
|
eri.katsar
|
Logger::configure('./js/log4php/log4php.xml');
|
20 |
|
|
$this->log->info("Calling scripts to modify Cache....");
|
21 |
33214
|
eri.katsar
|
$this->log->info("Script Mode:".$action);
|
22 |
|
|
|
23 |
35680
|
eri.katsar
|
|
24 |
33308
|
eri.katsar
|
if(!$action=='help'){
|
25 |
|
|
echo ("Performing Action : ".$action."<br><br>"); }
|
26 |
|
|
|
27 |
|
|
|
28 |
33214
|
eri.katsar
|
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 |
33308
|
eri.katsar
|
{
|
44 |
|
|
$this->backup(); }
|
45 |
33214
|
eri.katsar
|
else if ($action=='migrate')
|
46 |
33689
|
eri.katsar
|
{$this->migrate($args);}
|
47 |
33214
|
eri.katsar
|
else if ($action=='help')
|
48 |
|
|
{$this->printHelp();}
|
49 |
|
|
else
|
50 |
|
|
{$this->log->info("Wrong argument given");
|
51 |
33308
|
eri.katsar
|
$this->printHelp();}
|
52 |
33214
|
eri.katsar
|
|
53 |
33668
|
eri.katsar
|
|
54 |
|
|
if($action!=='help'){
|
55 |
|
|
echo("<br>Action Finished! <br>");
|
56 |
33214
|
eri.katsar
|
}
|
57 |
|
|
|
58 |
33668
|
eri.katsar
|
|
59 |
33308
|
eri.katsar
|
}
|
60 |
|
|
|
61 |
33214
|
eri.katsar
|
private function printHelp()
|
62 |
|
|
{
|
63 |
33308
|
eri.katsar
|
$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 |
33214
|
eri.katsar
|
}
|
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 |
33689
|
eri.katsar
|
public function migrate ($args)
|
101 |
33214
|
eri.katsar
|
{
|
102 |
33689
|
eri.katsar
|
|
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 |
33214
|
eri.katsar
|
}
|
128 |
|
|
|
129 |
33689
|
eri.katsar
|
}
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
33214
|
eri.katsar
|
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 |
33689
|
eri.katsar
|
{
|
144 |
33214
|
eri.katsar
|
$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 |
33689
|
eri.katsar
|
$this->promoteCharts();}
|
152 |
33214
|
eri.katsar
|
}
|
153 |
|
|
|
154 |
33689
|
eri.katsar
|
if ($_GET) {
|
155 |
|
|
$action = $_GET['action'];
|
156 |
|
|
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
|
157 |
|
|
//$args = array( "0"=> $_GET['targetCache']);
|
158 |
33214
|
eri.katsar
|
|
159 |
|
|
}
|
160 |
33689
|
eri.katsar
|
else
|
161 |
34069
|
eri.katsar
|
{
|
162 |
|
|
$action = $argv[1];
|
163 |
33689
|
eri.katsar
|
if(count($argv)>1)
|
164 |
34069
|
eri.katsar
|
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}
|
165 |
33214
|
eri.katsar
|
|
166 |
34069
|
eri.katsar
|
}
|
167 |
|
|
|
168 |
33689
|
eri.katsar
|
$rc = new CacheController($action,$args);
|
169 |
33214
|
eri.katsar
|
|
170 |
33668
|
eri.katsar
|
?>
|