Project

General

Profile

1
<?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

    
119
$this->log->info("Refreshing Charts...");
120
$csn = new RefreshCharts();$csn->refresh();
121
$this->log->info("Done!");}
122

    
123
public function promoteNums(){
124
$this->log->info(" Promoting Numbers..."); 
125
$csn = new PromoteShadowNums();
126
$csn->replace();
127
$this->log->info("Done!");
128
}
129

    
130
public function promoteCharts()
131
{
132
$this->log->info("Promoting Charts...");
133
$csn = new PromoteCharts();$csn->replace();
134
$this->log->info("Done!");
135
}
136

    
137
public function cleanUp()
138
{
139
$this->log->info("Cleaning Up Cache...");
140
$csn = new cleanCache();
141
$csn->cleanUp();
142
$this->log->info("Done!");
143
}
144

    
145

    
146
public function migrate ($args)
147
{ 
148

    
149
//$this->log->info("Cache Migration not yet implemented");
150

    
151
$this->log->info("*************Migrating Cache to ".$args[0]." on  ".$args[1]);
152

    
153
$csn = new MigrateCache();
154

    
155
global $redis_remote_host;
156
global $redis_remote_port;
157
global $redis_remote_beta_host ;
158
global $redis_remote_beta_port;
159

    
160
if($args[0]=='production')
161
{
162
$csn->migrate($redis_remote_host,$redis_remote_port);}
163
else if($args[0]=='beta' )
164
{
165
$csn->migrate($redis_remote_beta_host,$redis_remote_beta_port);}
166
else{
167

    
168
$csn->migrate($args[0],$args[1]);
169
$this->log->info("Done!");
170

    
171
//echo("Cache Migration not yet implemented <br>");
172

    
173
}
174

    
175
}
176

    
177

    
178

    
179

    
180

    
181
public function backup()
182
{  
183
$this->log->info("Backing Up Cache...");
184
$csn = new BackupCache();$csn->backup();
185
$this->log->info("Done!");
186
}
187

    
188
public function restore()
189
{ 
190
$this->log->info("Restoring Cache...");
191
$csn = new RestoreCache();$csn->restore();
192
$this->log->info("Done!");
193
}
194

    
195
public  function promoteAll()
196
{  $this->promoteNums();
197
   $this->promoteCharts();}
198
}
199

    
200
if ($_GET) {
201
$action = $_GET['action'];
202
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']);
203
//$args = array( "0"=> $_GET['targetCache']);
204

    
205
}
206
else
207
{$action = $argv[1];
208
if(count($argv)>1)
209
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}}
210

    
211
$rc = new CacheController($action,$args);
212

    
213
/*
214
</body>
215
</html>
216
*/
217
?>
(4-4/28)