Revision 31926
Added by Antonis Lempesis over 9 years ago
modules/uoa-stats-service/trunk/deploy.info | ||
---|---|---|
1 |
{ |
|
2 |
"type_source": "SVN", |
|
3 |
"goal": "package -U -T 4C source:jar", |
|
4 |
"url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-stats-service/trunk", |
|
5 |
"deploy_repository": "dnet4-snapshots", |
|
6 |
"version": "4", |
|
7 |
"mail": "antleb@di.uoa.gr, kiatrop@di.uoa.gr, gkatsari@di.uoa.gr", |
|
8 |
"deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", |
|
9 |
"name": "uoa-stats-service" |
|
10 |
} |
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/ValidationReport.java | ||
---|---|---|
1 |
package eu.dnetlib.data.statsmanager; |
|
2 |
|
|
3 |
import javax.xml.bind.annotation.XmlRootElement; |
|
4 |
|
|
5 |
/** |
|
6 |
* Created by antleb on 10/25/14. |
|
7 |
*/ |
|
8 |
|
|
9 |
@XmlRootElement |
|
10 |
public class ValidationReport { |
|
11 |
|
|
12 |
/* |
|
13 |
DB validation report. Contains: |
|
14 |
- queries: |
|
15 |
- query name |
|
16 |
- db result |
|
17 |
- cql result |
|
18 |
- status (success/fail) |
|
19 |
- metadata: |
|
20 |
- validation date |
|
21 |
- ??? |
|
22 |
*/ |
|
23 |
} |
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManager.java | ||
---|---|---|
1 |
package eu.dnetlib.data.statsmanager; |
|
2 |
|
|
3 |
import eu.dnetlib.api.data.SearchService; |
|
4 |
import eu.dnetlib.common.rmi.UnimplementedException; |
|
5 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
6 |
import org.springframework.core.io.Resource; |
|
7 |
import org.springframework.transaction.annotation.Transactional; |
|
8 |
|
|
9 |
import javax.sql.DataSource; |
|
10 |
import java.io.IOException; |
|
11 |
import java.net.URL; |
|
12 |
import java.sql.Connection; |
|
13 |
import java.sql.SQLException; |
|
14 |
import java.util.Map; |
|
15 |
import java.util.Properties; |
|
16 |
|
|
17 |
/** |
|
18 |
* Created by antleb on 10/25/14. |
|
19 |
*/ |
|
20 |
public class StatsManager { |
|
21 |
|
|
22 |
private ValidationReport validationReport; |
|
23 |
|
|
24 |
private Resource validationQueriesFile; |
|
25 |
private URL refreshShadowCacheURL; |
|
26 |
private URL promoteShadowCacheURL; |
|
27 |
private DataSource dataSource; |
|
28 |
private ServiceLocator<SearchService> searchServiceServiceLocator; |
|
29 |
|
|
30 |
public ValidationReport validateDatabase() throws IOException { |
|
31 |
ValidationReport report = new ValidationReport(); |
|
32 |
Properties p = new Properties(); |
|
33 |
|
|
34 |
this.validationReport = report; |
|
35 |
|
|
36 |
p.load(validationQueriesFile.getInputStream()); |
|
37 |
|
|
38 |
int queryCount = Integer.parseInt(p.getProperty("queries.count")); |
|
39 |
|
|
40 |
for (int i = 1; i <= queryCount; i++) { |
|
41 |
String queryType = p.getProperty("queries." + i + ".type"); |
|
42 |
String sql = p.getProperty("queries." + i + ".sql"); |
|
43 |
String cql = p.getProperty("queries." + i + ".cql.query"); |
|
44 |
|
|
45 |
if (queryType.equals("search")) { |
|
46 |
int sqlResult = executeSQLCountQuery(sql); |
|
47 |
int cqlResult = executeCQLCountQuery(cql); |
|
48 |
|
|
49 |
// TODO compare and update report |
|
50 |
|
|
51 |
} else if (queryType.equals("browse")) { |
|
52 |
Map<String, Integer> sqlResults = executeSQLBrowseQuery(sql); |
|
53 |
Map<String, Integer> cqlResults = executeCQLBrowseQuery(cql, p.getProperty("queries." + i + ".cql.groupBy")); |
|
54 |
|
|
55 |
// TODO compare and update report |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
return report; |
|
60 |
} |
|
61 |
|
|
62 |
public void refreshCache() throws IOException { |
|
63 |
refreshShadowCacheURL.openConnection(); |
|
64 |
} |
|
65 |
|
|
66 |
@Transactional |
|
67 |
public void promoteShadowSchema() throws IOException, SQLException { |
|
68 |
promoteShadowCacheURL.openConnection(); |
|
69 |
|
|
70 |
Connection con = dataSource.getConnection(); |
|
71 |
|
|
72 |
con.createStatement().execute("DROP SCHEMA public CASCADE"); |
|
73 |
con.createStatement().execute("ALTER SCHEMA shadow RENAME TO public"); |
|
74 |
} |
|
75 |
|
|
76 |
private Map<String, Integer> executeCQLBrowseQuery(String cql, String groupBy) { |
|
77 |
// TODO implement me please |
|
78 |
throw new UnimplementedException(); |
|
79 |
} |
|
80 |
|
|
81 |
private Map<String, Integer> executeSQLBrowseQuery(String sql) { |
|
82 |
// TODO implement me please |
|
83 |
throw new UnimplementedException(); |
|
84 |
} |
|
85 |
|
|
86 |
private int executeCQLCountQuery(String cql) { |
|
87 |
// TODO implement me please |
|
88 |
throw new UnimplementedException(); |
|
89 |
} |
|
90 |
|
|
91 |
private int executeSQLCountQuery(String sql) { |
|
92 |
// TODO implement me please |
|
93 |
throw new UnimplementedException(); |
|
94 |
} |
|
95 |
|
|
96 |
public Resource getValidationQueriesFile() { |
|
97 |
return validationQueriesFile; |
|
98 |
} |
|
99 |
|
|
100 |
public void setValidationQueriesFile(Resource validationQueriesFile) { |
|
101 |
this.validationQueriesFile = validationQueriesFile; |
|
102 |
} |
|
103 |
|
|
104 |
public URL getRefreshShadowCacheURL() { |
|
105 |
return refreshShadowCacheURL; |
|
106 |
} |
|
107 |
|
|
108 |
public void setRefreshShadowCacheURL(URL refreshShadowCacheURL) { |
|
109 |
this.refreshShadowCacheURL = refreshShadowCacheURL; |
|
110 |
} |
|
111 |
|
|
112 |
public URL getPromoteShadowCacheURL() { |
|
113 |
return promoteShadowCacheURL; |
|
114 |
} |
|
115 |
|
|
116 |
public void setPromoteShadowCacheURL(URL promoteShadowCacheURL) { |
|
117 |
this.promoteShadowCacheURL = promoteShadowCacheURL; |
|
118 |
} |
|
119 |
|
|
120 |
public DataSource getDataSource() { |
|
121 |
return dataSource; |
|
122 |
} |
|
123 |
|
|
124 |
public void setDataSource(DataSource dataSource) { |
|
125 |
this.dataSource = dataSource; |
|
126 |
} |
|
127 |
|
|
128 |
public ServiceLocator<SearchService> getSearchServiceServiceLocator() { |
|
129 |
return searchServiceServiceLocator; |
|
130 |
} |
|
131 |
|
|
132 |
public void setSearchServiceServiceLocator(ServiceLocator<SearchService> searchServiceServiceLocator) { |
|
133 |
this.searchServiceServiceLocator = searchServiceServiceLocator; |
|
134 |
} |
|
135 |
|
|
136 |
public ValidationReport getValidationReport() { |
|
137 |
return validationReport; |
|
138 |
} |
|
139 |
|
|
140 |
public void setValidationReport(ValidationReport validationReport) { |
|
141 |
this.validationReport = validationReport; |
|
142 |
} |
|
143 |
} |
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManagerServiceImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.data.statsmanager; |
|
2 |
|
|
3 |
import eu.dnetlib.api.DriverService; |
|
4 |
import eu.dnetlib.api.data.StatsManagerService; |
|
5 |
import eu.dnetlib.domain.ActionType; |
|
6 |
import eu.dnetlib.domain.ResourceType; |
|
7 |
import eu.dnetlib.domain.enabling.Notification; |
|
8 |
import gr.uoa.di.driver.app.DriverServiceImpl; |
|
9 |
import gr.uoa.di.driver.enabling.issn.NotificationListener; |
|
10 |
|
|
11 |
/** |
|
12 |
* Created by antleb on 10/25/14. |
|
13 |
*/ |
|
14 |
public class StatsManagerServiceImpl extends DriverServiceImpl implements StatsManagerService { |
|
15 |
|
|
16 |
private StatsManagerServiceBlackboardHandler statsManagerServiceBlackboardHandler; |
|
17 |
|
|
18 |
public void init() { |
|
19 |
super.init(); |
|
20 |
|
|
21 |
this.subscribe( |
|
22 |
ActionType.UPDATE, |
|
23 |
ResourceType.STATSMANAGERSERVICERESOURCETYPE, |
|
24 |
this.getServiceEPR().getParameter("serviceId"), |
|
25 |
"RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_REQUEST", |
|
26 |
new NotificationListener() { |
|
27 |
|
|
28 |
@Override |
|
29 |
public void processNotification(Notification notification) { |
|
30 |
statsManagerServiceBlackboardHandler.notified( |
|
31 |
notification.getSubscriptionId(), |
|
32 |
notification.getTopic(), |
|
33 |
notification.getIsId(), |
|
34 |
notification.getMessage()); |
|
35 |
} |
|
36 |
}); |
|
37 |
} |
|
38 |
|
|
39 |
public StatsManagerServiceBlackboardHandler getStatsManagerServiceBlackboardHandler() { |
|
40 |
return statsManagerServiceBlackboardHandler; |
|
41 |
} |
|
42 |
|
|
43 |
public void setStatsManagerServiceBlackboardHandler(StatsManagerServiceBlackboardHandler statsManagerServiceBlackboardHandler) { |
|
44 |
this.statsManagerServiceBlackboardHandler = statsManagerServiceBlackboardHandler; |
|
45 |
} |
|
46 |
} |
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManagerController.java | ||
---|---|---|
1 |
package eu.dnetlib.data.statsmanager; |
|
2 |
|
|
3 |
|
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.beans.factory.annotation.Required; |
|
6 |
import org.springframework.stereotype.Controller; |
|
7 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
8 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
9 |
|
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
import javax.xml.bind.JAXBContext; |
|
13 |
import javax.xml.bind.JAXBException; |
|
14 |
import javax.xml.bind.Marshaller; |
|
15 |
import java.io.IOException; |
|
16 |
|
|
17 |
/** |
|
18 |
* Created by antleb on 10/25/14. |
|
19 |
*/ |
|
20 |
@Controller |
|
21 |
public class StatsManagerController { |
|
22 |
|
|
23 |
private StatsManager statsManager; |
|
24 |
|
|
25 |
@RequestMapping(value = "/stats", method = RequestMethod.GET) |
|
26 |
public void getReport(HttpServletRequest request, HttpServletResponse response) throws IOException, JAXBException { |
|
27 |
ValidationReport report = statsManager.getValidationReport(); |
|
28 |
|
|
29 |
JAXBContext.newInstance().createMarshaller().marshal(report, response.getWriter()); |
|
30 |
} |
|
31 |
|
|
32 |
public StatsManager getStatsManager() { |
|
33 |
return statsManager; |
|
34 |
} |
|
35 |
|
|
36 |
public void setStatsManager(StatsManager statsManager) { |
|
37 |
this.statsManager = statsManager; |
|
38 |
} |
|
39 |
} |
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManagerServiceBlackboardHandler.java | ||
---|---|---|
1 |
package eu.dnetlib.data.statsmanager; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
import org.apache.log4j.Logger; |
|
7 |
|
|
8 |
/** |
|
9 |
* Created by antleb on 10/25/14. |
|
10 |
*/ |
|
11 |
public class StatsManagerServiceBlackboardHandler extends BlackboardNotificationHandler<BlackboardServerHandler> { |
|
12 |
|
|
13 |
private static Logger logger = Logger.getLogger(StatsManagerServiceBlackboardHandler.class); |
|
14 |
private StatsManager statsManager; |
|
15 |
|
|
16 |
protected void processJob(BlackboardJob job) { |
|
17 |
String action = job.getAction(); |
|
18 |
|
|
19 |
logger.info("Got BB message: " + action); |
|
20 |
|
|
21 |
try { |
|
22 |
getBlackboardHandler().ongoing(job); |
|
23 |
|
|
24 |
if (action.equals("validate")) { |
|
25 |
ValidationReport report = statsManager.validateDatabase(); |
|
26 |
|
|
27 |
// TODO update update job with report |
|
28 |
// TODO update job status |
|
29 |
} else if (action.equals("refreshCache")) { |
|
30 |
statsManager.refreshCache(); |
|
31 |
} else if (action.equals("promoteShadow")) { |
|
32 |
statsManager.promoteShadowSchema(); |
|
33 |
} else { |
|
34 |
throw new Exception("Don't know what to do with " + action); |
|
35 |
} |
|
36 |
|
|
37 |
getBlackboardHandler().done(job); |
|
38 |
} catch (Exception e) { |
|
39 |
getBlackboardHandler().failed(job, e); |
|
40 |
|
|
41 |
logger.error("Error processing job", e); |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
public StatsManager getStatsManager() { |
|
46 |
return statsManager; |
|
47 |
} |
|
48 |
|
|
49 |
public void setStatsManager(StatsManager statsManager) { |
|
50 |
this.statsManager = statsManager; |
|
51 |
} |
|
52 |
} |
modules/uoa-stats-service/trunk/src/main/resources/eu/dnetlib/data/statsmanager/springContext-statsManager.properties | ||
---|---|---|
1 |
services.statsManager.serviceName = uoa-stats-service |
|
2 |
|
|
3 |
services.statsManager.db.driverClassName = org.postgresql.Driver |
|
4 |
services.statsManager.db.url = jdbc:postgresql://stats.openaire.eu:5432/stats |
|
5 |
services.statsManager.db.username = sqoop |
|
6 |
services.statsManager.db.password = sqoop |
|
7 |
|
|
8 |
services.statsmanager.validationQueriesFile = classpath*:/eu/dnetlib/data/statsmanager/validationQueries.xml |
|
9 |
services.statsmanager.refreshShadowCacheURL = https://www.openaire.eu/stats/refreshCache.php |
|
10 |
services.statsmanager.promoteShadowCacheURL = https://www.openaire.eu/stats/promoteCache.php |
|
11 |
services.statsManager.shadowSearchServiceURL = http://IHAVENOIDEA.com |
|
12 |
|
modules/uoa-stats-service/trunk/src/main/resources/uoa-stats-service.properties | ||
---|---|---|
1 |
#Generated by ANT |
|
2 |
name=uoa-stats-service |
|
3 |
version=1.0.0 |
|
4 |
label= |
modules/uoa-stats-service/trunk/svn-commit.tmp | ||
---|---|---|
1 |
Importing stats service |
|
2 |
--This line, and those below, will be ignored-- |
|
3 |
|
|
4 |
A http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-stats-service |
|
5 |
A http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-stats-service/trunk |
Also available in: Unified diff
Initial import