1 |
33668
|
eri.katsar
|
<?php
|
2 |
37264
|
eri.katsar
|
/*<!--<html>
|
3 |
|
|
<head>
|
4 |
|
|
<title>...</title>
|
5 |
|
|
<style type=”text/css”>
|
6 |
|
|
table {
|
7 |
|
|
margin: 8px;
|
8 |
|
|
}
|
9 |
|
|
h1 {
|
10 |
|
|
text-align: center;
|
11 |
|
|
text-transform: uppercase;
|
12 |
|
|
color: #A7C942;
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
p {
|
18 |
|
|
text-indent: 50px;
|
19 |
|
|
text-align:justify;
|
20 |
|
|
letter-spacing:3px;
|
21 |
|
|
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
|
22 |
|
|
|
23 |
|
|
}
|
24 |
|
|
a {
|
25 |
|
|
text-decoration:none;
|
26 |
|
|
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
</style>
|
33 |
|
|
</head>
|
34 |
|
|
<body>
|
35 |
|
|
-->*/
|
36 |
|
|
//<?php
|
37 |
33214
|
eri.katsar
|
require_once('./js/log4php/Logger.php');
|
38 |
|
|
include_once('./refreshNums.php');
|
39 |
|
|
include_once('./refreshCharts.php');
|
40 |
|
|
include_once('./promoteNums.php');
|
41 |
|
|
include_once('./promoteCharts.php');
|
42 |
|
|
include_once('./backupCache.php');
|
43 |
|
|
include_once('./restoreCache.php');
|
44 |
|
|
include_once('./migrateCache.php');
|
45 |
37264
|
eri.katsar
|
include_once('./cleanCache.php');
|
46 |
33689
|
eri.katsar
|
include_once("./paths.php");
|
47 |
33214
|
eri.katsar
|
|
48 |
|
|
class CacheController
|
49 |
37264
|
eri.katsar
|
{
|
50 |
|
|
public function __construct($action,$args){
|
51 |
33214
|
eri.katsar
|
$this->log = Logger::getLogger(__CLASS__);
|
52 |
37264
|
eri.katsar
|
Logger::configure('./js/log4php/log4php.xml');
|
53 |
|
|
$this->log->info("Calling scripts to modify Cache....");
|
54 |
33214
|
eri.katsar
|
$this->log->info("Script Mode:".$action);
|
55 |
|
|
|
56 |
35680
|
eri.katsar
|
|
57 |
33308
|
eri.katsar
|
if(!$action=='help'){
|
58 |
|
|
echo ("Performing Action : ".$action."<br><br>"); }
|
59 |
|
|
|
60 |
|
|
|
61 |
33214
|
eri.katsar
|
if ($action=='refreshNums')
|
62 |
|
|
{$this->refreshNums();}
|
63 |
|
|
else if ($action=='refreshCharts')
|
64 |
|
|
{$this->refreshCharts();}
|
65 |
|
|
else if ($action=='refreshAll')
|
66 |
|
|
{ $this->refreshAll(); }
|
67 |
|
|
else if ($action=='promoteNums')
|
68 |
|
|
{$this->promoteNums();}
|
69 |
|
|
else if ($action=='promoteCharts')
|
70 |
|
|
{$this->promoteCharts();}
|
71 |
|
|
else if ($action=='promoteAll')
|
72 |
|
|
{ $this->promoteAll(); }
|
73 |
|
|
else if ($action=='restore')
|
74 |
|
|
{ $this->restore(); }
|
75 |
|
|
else if ($action=='backup')
|
76 |
33308
|
eri.katsar
|
{
|
77 |
|
|
$this->backup(); }
|
78 |
33214
|
eri.katsar
|
else if ($action=='migrate')
|
79 |
33689
|
eri.katsar
|
{$this->migrate($args);}
|
80 |
37264
|
eri.katsar
|
else if ($action=='cleanUp')
|
81 |
|
|
{$this->cleanUp();}
|
82 |
33214
|
eri.katsar
|
else if ($action=='help')
|
83 |
|
|
{$this->printHelp();}
|
84 |
|
|
else
|
85 |
|
|
{$this->log->info("Wrong argument given");
|
86 |
33308
|
eri.katsar
|
$this->printHelp();}
|
87 |
33214
|
eri.katsar
|
|
88 |
33668
|
eri.katsar
|
|
89 |
|
|
if($action!=='help'){
|
90 |
|
|
echo("<br>Action Finished! <br>");
|
91 |
33214
|
eri.katsar
|
}
|
92 |
|
|
|
93 |
33668
|
eri.katsar
|
|
94 |
33308
|
eri.katsar
|
}
|
95 |
|
|
|
96 |
33214
|
eri.katsar
|
private function printHelp()
|
97 |
|
|
{
|
98 |
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);
|
99 |
33214
|
eri.katsar
|
}
|
100 |
|
|
|
101 |
|
|
public function refreshNums(){
|
102 |
|
|
$this->log->info("Refreshing Numbers...");
|
103 |
|
|
$csn = new ComputeStatsNumbers();
|
104 |
|
|
$csn->computeStats();
|
105 |
|
|
$this->log->info("Done!");
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
public function refreshCharts()
|
109 |
|
|
{
|
110 |
|
|
$this->log->info("Refreshing Charts...");
|
111 |
|
|
$csn = new RefreshCharts();$csn->refresh();
|
112 |
|
|
$this->log->info("Done!");
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
public function refreshAll()
|
116 |
|
|
{
|
117 |
|
|
$this->refreshNums();
|
118 |
|
|
$this->refreshCharts();
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
public function promoteNums(){
|
122 |
|
|
$this->log->info(" Promoting Numbers...");
|
123 |
|
|
$csn = new PromoteShadowNums();
|
124 |
|
|
$csn->replace();
|
125 |
|
|
$this->log->info("Done!");
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
public function promoteCharts()
|
129 |
|
|
{
|
130 |
|
|
$this->log->info("Promoting Charts...");
|
131 |
|
|
$csn = new PromoteCharts();$csn->replace();
|
132 |
|
|
$this->log->info("Done!");
|
133 |
|
|
}
|
134 |
|
|
|
135 |
37264
|
eri.katsar
|
public function cleanUp()
|
136 |
|
|
{
|
137 |
|
|
$this->log->info("Cleaning Up Cache...");
|
138 |
|
|
$csn = new cleanCache();
|
139 |
|
|
$csn->cleanUp();
|
140 |
|
|
$this->log->info("Done!");
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
|
144 |
33689
|
eri.katsar
|
public function migrate ($args)
|
145 |
33214
|
eri.katsar
|
{
|
146 |
33689
|
eri.katsar
|
|
147 |
|
|
//$this->log->info("Cache Migration not yet implemented");
|
148 |
|
|
|
149 |
|
|
$this->log->info("*************Migrating Cache to ".$args[0]." on ".$args[1]);
|
150 |
|
|
|
151 |
|
|
$csn = new MigrateCache();
|
152 |
|
|
|
153 |
|
|
global $redis_remote_host;
|
154 |
|
|
global $redis_remote_port;
|
155 |
|
|
global $redis_remote_beta_host ;
|
156 |
|
|
global $redis_remote_beta_port;
|
157 |
|
|
|
158 |
|
|
if($args[0]=='production')
|
159 |
|
|
{
|
160 |
|
|
$csn->migrate($redis_remote_host,$redis_remote_port);}
|
161 |
|
|
else if($args[0]=='beta' )
|
162 |
|
|
{
|
163 |
|
|
$csn->migrate($redis_remote_beta_host,$redis_remote_beta_port);}
|
164 |
|
|
else{
|
165 |
|
|
|
166 |
|
|
$csn->migrate($args[0],$args[1]);
|
167 |
|
|
$this->log->info("Done!");
|
168 |
|
|
|
169 |
|
|
//echo("Cache Migration not yet implemented <br>");
|
170 |
|
|
|
171 |
33214
|
eri.katsar
|
}
|
172 |
|
|
|
173 |
33689
|
eri.katsar
|
}
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
33214
|
eri.katsar
|
public function backup()
|
180 |
|
|
{
|
181 |
|
|
$this->log->info("Backing Up Cache...");
|
182 |
|
|
$csn = new BackupCache();$csn->backup();
|
183 |
|
|
$this->log->info("Done!");
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
public function restore()
|
187 |
33689
|
eri.katsar
|
{
|
188 |
33214
|
eri.katsar
|
$this->log->info("Restoring Cache...");
|
189 |
|
|
$csn = new RestoreCache();$csn->restore();
|
190 |
|
|
$this->log->info("Done!");
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
public function promoteAll()
|
194 |
|
|
{ $this->promoteNums();
|
195 |
33689
|
eri.katsar
|
$this->promoteCharts();}
|
196 |
33214
|
eri.katsar
|
}
|
197 |
|
|
|
198 |
33689
|
eri.katsar
|
if ($_GET) {
|
199 |
|
|
$action = $_GET['action'];
|
200 |
|
|
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
|
201 |
|
|
//$args = array( "0"=> $_GET['targetCache']);
|
202 |
33214
|
eri.katsar
|
|
203 |
|
|
}
|
204 |
33689
|
eri.katsar
|
else
|
205 |
37264
|
eri.katsar
|
{$action = $argv[1];
|
206 |
33689
|
eri.katsar
|
if(count($argv)>1)
|
207 |
37264
|
eri.katsar
|
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}}
|
208 |
33214
|
eri.katsar
|
|
209 |
33689
|
eri.katsar
|
$rc = new CacheController($action,$args);
|
210 |
33214
|
eri.katsar
|
|
211 |
37264
|
eri.katsar
|
/*
|
212 |
|
|
</body>
|
213 |
|
|
</html>
|
214 |
|
|
*/
|
215 |
33668
|
eri.katsar
|
?>
|