Project

General

Profile

1 37810 eri.katsar
<?php
2
/*<!--<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
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
include_once('./cleanCache.php');
46
include_once("./paths.php");
47
48
class CacheController
49
	{
50
           public function __construct($action,$args){
51
	     $this->log = Logger::getLogger(__CLASS__);
52
  Logger::configure('./js/log4php/log4php.xml');
53
$this->log->info("Calling scripts to modify Cache....");
54
	     $this->log->info("Script Mode:".$action);
55
56
57
if(!$action=='help'){
58
echo ("Performing Action :  ".$action."<br><br>"); }
59
60
61
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
{
77
$this->backup(); }
78
else if ($action=='migrate')
79
{$this->migrate($args);}
80
else if ($action=='cleanUp')
81
{$this->cleanUp();}
82
else if ($action=='help')
83
{$this->printHelp();}
84
else
85
{$this->log->info("Wrong argument given");
86
 $this->printHelp();}
87
88
89
if($action!=='help'){
90
echo("<br>Action Finished! <br>");
91
}
92
93
94
}
95
96
private function printHelp()
97
{
98
$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
}
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
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
public function migrate ($args)
145
{
146
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
}
172
173
}
174
175
176
177
178
179
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
{
188
$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
   $this->promoteCharts();}
196
}
197
198
if ($_GET) {
199
$action = $_GET['action'];
200
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
201
//$args = array( "0"=> $_GET['targetCache']);
202
203
}
204
else
205
{$action = $argv[1];
206
if(count($argv)>1)
207
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}}
208
209
$rc = new CacheController($action,$args);
210
211
/*
212
</body>
213
</html>
214
*/
215
?>