1
|
package eu.dnetlib.data.statsmanager;
|
2
|
|
3
|
|
4
|
import org.apache.log4j.Logger;
|
5
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
6
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler;
|
7
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
8
|
|
9
|
import org.springframework.transaction.annotation.Transactional;
|
10
|
|
11
|
import javax.sql.DataSource;
|
12
|
import java.sql.Connection;
|
13
|
|
14
|
public class StatsManager {
|
15
|
|
16
|
private Validator validator;
|
17
|
|
18
|
private ValidationReport validationReport;
|
19
|
|
20
|
private DataSource dataSource;
|
21
|
|
22
|
private CacheController prodCacheController;
|
23
|
private CacheController testCacheController;
|
24
|
|
25
|
private Logger log = Logger.getLogger(this.getClass());
|
26
|
|
27
|
public StatsManager() {
|
28
|
|
29
|
}
|
30
|
|
31
|
|
32
|
public ValidationReport validateDatabase() throws Exception {
|
33
|
|
34
|
|
35
|
this.validationReport = validator.validateDatabase();
|
36
|
return validationReport;
|
37
|
}
|
38
|
|
39
|
|
40
|
@Transactional
|
41
|
public void promoteShadowSchema() throws Exception {
|
42
|
Connection con = dataSource.getConnection();
|
43
|
|
44
|
log.info("Backing up and Replacing public schema with shadow in " + dataSource.getConnection().getMetaData().getURL() + " ...");
|
45
|
con.createStatement().execute("drop schema if exists backup CASCADE ;");
|
46
|
con.createStatement().execute("alter schema public rename to backup ;");
|
47
|
con.createStatement().execute("alter schema shadow rename TO public ;");
|
48
|
log.info("All ops done!");
|
49
|
con.close();
|
50
|
}
|
51
|
|
52
|
public void updateDBPath(String dbUrl) {
|
53
|
}
|
54
|
|
55
|
public void executeCacheAction(BlackboardJob job) throws Exception {
|
56
|
|
57
|
if (job.getAction().equals("refreshCache")) {
|
58
|
|
59
|
executeCommand("refreshAll", job.getParameters().get("cache"));
|
60
|
} else if (job.getAction().equals("refreshCharts")) {
|
61
|
|
62
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
63
|
} else if (job.getAction().equals("refreshNums")) {
|
64
|
|
65
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
66
|
} else if (job.getAction().equals("promoteShadow")) {
|
67
|
|
68
|
executeCommand("promoteAll", job.getParameters().get("cache"));
|
69
|
this.promoteShadowSchema();
|
70
|
|
71
|
} else if (job.getAction().equals("promoteNums")) {
|
72
|
|
73
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
74
|
} else if (job.getAction().equals("promoteCharts")) {
|
75
|
|
76
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
77
|
} else if (job.getAction().equals("promoteCache")) {
|
78
|
|
79
|
executeCommand("promoteAll", job.getParameters().get("cache"));
|
80
|
} else if (job.getAction().equals("restore")) {
|
81
|
|
82
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
83
|
} else if (job.getAction().equals("migrate")) {
|
84
|
|
85
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
86
|
} else if (job.getAction().equals("backup")) {
|
87
|
|
88
|
executeCommand(job.getAction(), job.getParameters().get("cache"));
|
89
|
|
90
|
}
|
91
|
|
92
|
/* else if (job.getAction().equals("updateCacheURL"))
|
93
|
{
|
94
|
log.info("Executing " + job.getAction() + "...");
|
95
|
cacheController.updateCacheURL(job.getParameters().get("cacheURL"));
|
96
|
}*/
|
97
|
|
98
|
else {
|
99
|
log.error("Wrong action given ");
|
100
|
throw new Exception("Wrong action given ");
|
101
|
}
|
102
|
log.info("Done ! ");
|
103
|
}
|
104
|
|
105
|
private void executeCommand(String action, String cache) throws Exception {
|
106
|
|
107
|
|
108
|
log.info("Executing action " + action + " in " + cache + "...");
|
109
|
if (cache == null || cache.contains("test")) {
|
110
|
testCacheController.executeCommand(action);
|
111
|
} else if (cache.contains("beta") || (cache.contains("production"))) {
|
112
|
prodCacheController.executeCommand(action);
|
113
|
} else {
|
114
|
throw new Exception("Wrong cache id");
|
115
|
}
|
116
|
}
|
117
|
|
118
|
public DataSource getDataSource() {
|
119
|
return dataSource;
|
120
|
}
|
121
|
|
122
|
public void setDataSource(DataSource dataSource) {
|
123
|
this.dataSource = dataSource;
|
124
|
}
|
125
|
|
126
|
|
127
|
public Validator getValidator() {
|
128
|
return validator;
|
129
|
}
|
130
|
|
131
|
public void setValidator(Validator validator) {
|
132
|
this.validator = validator;
|
133
|
}
|
134
|
|
135
|
public ValidationReport getValidationReport() {
|
136
|
return validationReport;
|
137
|
}
|
138
|
|
139
|
public void setValidationReport(ValidationReport validationReport) {
|
140
|
this.validationReport = validationReport;
|
141
|
}
|
142
|
|
143
|
public CacheController getProdCacheController() {
|
144
|
return prodCacheController;
|
145
|
}
|
146
|
|
147
|
public void setProdCacheController(CacheController prodCacheController) {
|
148
|
this.prodCacheController = prodCacheController;
|
149
|
}
|
150
|
|
151
|
public CacheController getTestCacheController() {
|
152
|
return testCacheController;
|
153
|
}
|
154
|
|
155
|
public void setTestCacheController(CacheController testCacheController) {
|
156
|
this.testCacheController = testCacheController;
|
157
|
}
|
158
|
}
|