Revision 33689
Added by Eri Katsari almost 10 years ago
modules/uoa-stats/trunk/migrateCache.php | ||
---|---|---|
15 | 15 |
global $redis_host; |
16 | 16 |
global $redis_port; |
17 | 17 |
global $redis_scheme; |
18 |
global $host; |
|
18 |
global $host; |
|
19 |
global $db_name; |
|
19 | 20 |
|
20 |
global $db_name; |
|
21 |
/*$redis_remote_host='duffy.di.uoa.gr'; |
|
22 | 21 |
|
22 |
//$redis_host='localhost'; |
|
23 |
/*$redis_remote_host='duffy.di.uoa.gr'; |
|
24 |
|
|
23 | 25 |
$redis_remote_port=$redis_port; |
24 | 26 |
$redis_remote_scheme=$redis_scheme; |
25 | 27 |
*/ |
... | ... | |
44 | 46 |
|
45 | 47 |
|
46 | 48 |
} |
47 |
|
|
48 |
public function migrate() |
|
49 |
public function migrate($redis_remote_host,$redis_remote_port) |
|
49 | 50 |
{ |
50 | 51 |
|
51 | 52 |
global $redis_host; |
52 | 53 |
global $redis_port; |
53 | 54 |
global $redis_scheme; |
54 | 55 |
global $host; |
55 |
|
|
56 |
global $redis_remote_host; |
|
57 |
|
|
58 |
//='duffy.di.uoa.gr'; |
|
59 | 56 |
|
60 | 57 |
//$this->cache->migrate( |
61 | 58 |
// $redis_remote_host, # localhost in my example |
... | ... | |
68 | 65 |
//Predis\Client::executeRaw() |
69 | 66 |
|
70 | 67 |
$backupKeys=$this->cache->hkeys('STATS_NUMBERS'); |
68 |
$this->log->info("migrating Stat Numbers from ".$redis_host." to ".$redis_remote_host." on ".$redis_remote_port); |
|
71 | 69 |
|
72 |
$this->log->info("migrating Stat Numbers..."); |
|
73 |
|
|
74 | 70 |
try { |
75 | 71 |
|
76 | 72 |
//todo changed timeout from 0 to -1 |
77 | 73 |
$this->remotecache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_remote_host,"port" => $redis_port,"read_write_timeout" => -1)); |
78 |
$this->log->info("redis host: ".$redis_remote_host." and redis port: ".$redis_port); |
|
74 |
$this->log->info("redis host: ".$redis_remote_host." and redis port: ".$redis_remote_port);
|
|
79 | 75 |
} catch(Exception $e) { |
80 | 76 |
$this->log->error("Error connecting to Redis server: ".$e->getMessage()); |
81 | 77 |
$this->cache = null; |
... | ... | |
121 | 117 |
$this->remotecache->hmset($keys[$x],$values); |
122 | 118 |
|
123 | 119 |
$this->log->info("id : ".$keys[$x]); |
124 |
$this->log->info("query : ".$this->remotecache->hget($keys[$x],"query")); |
|
120 |
//$this->log->info("query : ".$this->remotecache->hget($keys[$x],"query"));
|
|
125 | 121 |
$this->log->info("res: ".$this->remotecache->hget($keys[$x],"results")); |
126 | 122 |
|
127 | 123 |
} |
... | ... | |
148 | 144 |
|
149 | 145 |
} |
150 | 146 |
|
151 |
$rc = new MigrateCache(); |
|
152 |
$rc->migrate(); |
|
147 |
//$rc = new MigrateCache();
|
|
148 |
//$rc->migrate();
|
|
153 | 149 |
?> |
modules/uoa-stats/trunk/refreshNums.php | ||
---|---|---|
13 | 13 |
global $redis_host; |
14 | 14 |
global $redis_port; |
15 | 15 |
global $redis_scheme; |
16 |
global $host; |
|
16 |
global $db_name; |
|
17 |
GLOBAL $username; |
|
18 |
global $password; |
|
19 |
global $host; |
|
17 | 20 |
|
18 |
$this->log = Logger::getLogger(__CLASS__); |
|
19 |
Logger::configure('./js/log4php/log4php.xml'); |
|
20 |
if(class_exists("Predis\Client")){ |
|
21 |
$this->log = Logger::getLogger(__CLASS__); |
|
22 |
Logger::configure('./js/log4php/log4php.xml'); |
|
23 |
|
|
24 |
if(class_exists("Predis\Client")){ |
|
21 | 25 |
|
22 | 26 |
try { |
23 | 27 |
//todo changed timeout from 0 to -1 |
... | ... | |
29 | 33 |
} |
30 | 34 |
} |
31 | 35 |
else{ |
32 |
$this->log->info("cache does not exist"); //predis |
|
33 |
exit;
|
|
36 |
$this->log->info("cache does not exist"); //predis
|
|
37 |
exit; |
|
34 | 38 |
} |
35 | 39 |
//NOW GET DB |
36 | 40 |
try { |
37 |
$str = 'pgsql:host='.$host.';port=5432;dbname=stats;user=sqoop;password=sqoop'; |
|
38 |
$this->db = new PDO($str); |
|
39 |
} catch(Exception $e){ |
|
41 |
$str = 'pgsql:host='.$host.";port=5432;dbname=".$db_name.";user=".$username.";password=".$password; |
|
42 |
|
|
43 |
$this->db = new PDO($str); |
|
44 |
|
|
45 |
//TODO set search path here |
|
46 |
} catch(Exception $e){ |
|
40 | 47 |
$this->log->error('Could not connect to database: ' . $e->getMessage()); |
41 | 48 |
exit; |
42 | 49 |
} |
... | ... | |
56 | 63 |
} |
57 | 64 |
//TODO here store Queries in cache |
58 | 65 |
private function storeQuery($key, $query) { |
59 |
global $redis_host; |
|
60 |
global $redis_port; |
|
61 |
global $redis_scheme; |
|
62 |
|
|
63 | 66 |
$res=$this->doQuery($query); |
64 | 67 |
|
65 |
$this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port)); |
|
68 |
//$this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port));
|
|
66 | 69 |
$this->cache->connect(); //predis |
67 | 70 |
$this->cache->hset('SHADOW_STATS_NUMBERS',$key,$res); |
68 |
|
|
69 |
|
|
70 |
//TODO hset name is STATS_NUMBERS; field name = each key; query=field value |
|
71 |
|
|
72 | 71 |
$this->log->info("Stored query : ".$key." ".$this->cache->hget('SHADOW_STATS_NUMBERS',$key)); |
73 | 72 |
$this->cache->quit(); |
73 |
|
|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
function computeStats() { |
77 | 77 |
|
78 | 78 |
global $redis_host; |
79 |
global $redis_port; |
|
80 |
global $redis_scheme; |
|
81 |
/*OVERALL*/ |
|
82 |
|
|
79 |
/*OVERALL*/ |
|
80 |
|
|
83 | 81 |
/*1*/ |
84 | 82 |
$qpubs = "SELECT count(*) FROM result where type='publication'"; |
85 | 83 |
|
modules/uoa-stats/trunk/cacheController.php | ||
---|---|---|
42 | 42 |
include_once('./backupCache.php'); |
43 | 43 |
include_once('./restoreCache.php'); |
44 | 44 |
include_once('./migrateCache.php'); |
45 |
include_once("./paths.php"); |
|
45 | 46 |
|
46 | 47 |
class CacheController |
47 | 48 |
{ |
48 |
public function __construct($action){ |
|
49 |
public function __construct($action,$args){
|
|
49 | 50 |
$this->log = Logger::getLogger(__CLASS__); |
50 | 51 |
Logger::configure('./js/log4php/log4php.xml'); |
51 | 52 |
$this->log->info("Calling scripts to modify Cache...."); |
... | ... | |
74 | 75 |
{ |
75 | 76 |
$this->backup(); } |
76 | 77 |
else if ($action=='migrate') |
77 |
{$this->migrate(); }
|
|
78 |
{$this->migrate($args);}
|
|
78 | 79 |
else if ($action=='help') |
79 | 80 |
{$this->printHelp();} |
80 | 81 |
else |
... | ... | |
128 | 129 |
$this->log->info("Done!"); |
129 | 130 |
} |
130 | 131 |
|
131 |
public function migrate()
|
|
132 |
public function migrate ($args)
|
|
132 | 133 |
{ |
133 |
$this->log->info("Cache Migration not yet implemented"); |
|
134 |
//$csn = new MigrateCache(); |
|
135 |
//$csn->migrate(); |
|
136 |
//$this->log->info("Done!"); |
|
137 |
echo("Cache Migration not yet implemented <br>"); |
|
134 |
|
|
135 |
//$this->log->info("Cache Migration not yet implemented"); |
|
136 |
|
|
137 |
$this->log->info("*************Migrating Cache to ".$args[0]." on ".$args[1]); |
|
138 |
|
|
139 |
$csn = new MigrateCache(); |
|
140 |
|
|
141 |
global $redis_remote_host; |
|
142 |
global $redis_remote_port; |
|
143 |
global $redis_remote_beta_host ; |
|
144 |
global $redis_remote_beta_port; |
|
145 |
|
|
146 |
if($args[0]=='production') |
|
147 |
{ |
|
148 |
$csn->migrate($redis_remote_host,$redis_remote_port);} |
|
149 |
else if($args[0]=='beta' ) |
|
150 |
{ |
|
151 |
$csn->migrate($redis_remote_beta_host,$redis_remote_beta_port);} |
|
152 |
else{ |
|
153 |
|
|
154 |
$csn->migrate($args[0],$args[1]); |
|
155 |
$this->log->info("Done!"); |
|
156 |
|
|
157 |
//echo("Cache Migration not yet implemented <br>"); |
|
158 |
|
|
138 | 159 |
} |
139 | 160 |
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
140 | 167 |
public function backup() |
141 | 168 |
{ |
142 | 169 |
$this->log->info("Backing Up Cache..."); |
... | ... | |
145 | 172 |
} |
146 | 173 |
|
147 | 174 |
public function restore() |
148 |
{
|
|
175 |
{ |
|
149 | 176 |
$this->log->info("Restoring Cache..."); |
150 | 177 |
$csn = new RestoreCache();$csn->restore(); |
151 | 178 |
$this->log->info("Done!"); |
152 | 179 |
} |
153 | 180 |
|
154 |
|
|
155 | 181 |
public function promoteAll() |
156 | 182 |
{ $this->promoteNums(); |
157 |
$this->promoteCharts(); |
|
183 |
$this->promoteCharts();}
|
|
158 | 184 |
} |
159 | 185 |
|
186 |
if ($_GET) { |
|
187 |
$action = $_GET['action']; |
|
188 |
$args = array( "0"=> $_GET['targetCache'], "1"=> $_GET['port']); |
|
189 |
//$args = array( "0"=> $_GET['targetCache']); |
|
160 | 190 |
|
161 |
|
|
162 | 191 |
} |
192 |
else |
|
193 |
{$action = $argv[1]; |
|
194 |
if(count($argv)>1) |
|
195 |
{$args = array("0"=> $argv[2], "1"=> $argv[3]);}} |
|
163 | 196 |
|
164 |
//if(!empty($_SERVER['argv'][0]) { |
|
165 |
//$action = $_SERVER['argv'][1]; |
|
166 |
|
|
167 |
//} else { |
|
168 |
// $action = $_GET['action']; |
|
169 |
//} |
|
197 |
$rc = new CacheController($action,$args); |
|
170 | 198 |
|
171 |
|
|
172 |
if ($_GET) { |
|
173 |
$action = $_GET['action']; |
|
174 |
} else { |
|
175 |
$action = $argv[1]; |
|
176 |
} |
|
177 |
$rc = new CacheController($action); |
|
178 |
|
|
179 | 199 |
/* |
180 | 200 |
</body> |
181 | 201 |
</html> |
modules/uoa-stats/trunk/paths.php | ||
---|---|---|
5 | 5 |
$help_functions = $head."help_functions.php"; |
6 | 6 |
$model_logger = './js/log4php'; |
7 | 7 |
|
8 |
$redis_host = 'localhost'; |
|
8 |
//$redis_host = 'localhost'; |
|
9 |
$redis_host = 'duffy.di.uoa.gr'; |
|
10 |
|
|
9 | 11 |
$redis_remote_host= 'duffy.di.uoa.gr'; |
12 |
$redis_remote_port= 6379; |
|
13 |
|
|
14 |
$redis_remote_beta_host= 'dl114.madgik.di.uoa.gr'; |
|
15 |
$redis_remote_beta_port= 6379; |
|
16 |
|
|
17 |
|
|
18 |
// for beta.stats.openaire.eu port is 63 |
|
19 |
//$redis_remote_port= 63; |
|
20 |
|
|
10 | 21 |
$redis_port = 6379; |
11 | 22 |
$redis_scheme = 'tcp'; |
12 | 23 |
|
Also available in: Unified diff
finalized migrate option