Project

General

Profile

« Previous | Next » 

Revision 32084

Added by Eri Katsari about 10 years ago

View differences:

modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/Query.java
15 15
    //TODO check xml generated by query elements
16 16
    private Logger log = Logger.getLogger(this.getClass());
17 17

  
18
    public Query(){};
19

  
18 20
    public Query(String key, Integer dbResult, int cqlResult, boolean qStatus) {
19 21
        this.name = key;
20 22
        this.dbResult = dbResult;
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/ValidationReport.java
22 22
    private Date validationDate;
23 23
    private Logger log = Logger.getLogger(this.getClass());
24 24

  
25
    ValidationReport() {
25
    public ValidationReport() {
26 26
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
27 27
        this.validationDate = new Date();
28 28
        Queries = new ArrayList<Query>();
......
64 64
                ", validationDate=" + validationDate +
65 65
                '}';
66 66
    }
67

  
68
    public Date getValidationDate() {
69
        return validationDate;
70
    }
71

  
72
    public void setValidationDate(Date validationDate) {
73
        this.validationDate = validationDate;
74
    }
67 75
}
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManager.java
27 27
    private URL refreshShadowCacheURL;
28 28
    private URL promoteShadowCacheURL;
29 29
    private DataSource dataSource;
30
    private ServiceLocator<SearchService> searchServiceServiceLocator;
30
    private ServiceLocator<SearchService> searchServiceLocator;
31 31
    private String portalUser;
32 32
    private Logger log = Logger.getLogger(this.getClass());
33 33

  
......
37 37

  
38 38
        this.validationReport = report;
39 39

  
40
        p.load(validationQueriesFile.getInputStream());
40
        try {
41
            p.loadFromXML(validationQueriesFile.getInputStream());
42
        } catch (Exception e) {
43
            log.error(e.toString());
44
            throw new Exception(e);
41 45

  
46
        }
47

  
48

  
49
        log.info("Loaded props : " + p.entrySet());
50
        //  log.info("Loaded props : " + p.values());
51

  
42 52
        int queryCount = Integer.parseInt(p.getProperty("queries.count"));
53
        log.info("Query  Count: " + queryCount + "\n");
54
        for (int i = 1; i <= queryCount; i++) {
43 55

  
44
        for (int i = 1; i <= queryCount; i++) {
45 56
            String queryType = p.getProperty("queries." + i + ".type");
46 57
            String sql = p.getProperty("queries." + i + ".sql");
47 58
            String cql = p.getProperty("queries." + i + ".cql.query");
48
            String name = p.getProperty("queries." + i + ".cql.name");
59
            String name = p.getProperty("queries." + i + ".name");
49 60

  
50
            log.debug("Query: " + name + "\n" + sql + "\n" + cql + "\n");
61
            log.info("Query: " + name + "\n" + " SQL " + sql + "\n" + "CQL" + cql + "\n");
51 62
            if (queryType.equals("search")) {
52 63
                int sqlResult = executeSQLCountQuery(sql);
53
                int cqlResult = executeCQLCountQuery(cql);
54

  
64
                // int cqlResult = executeCQLCountQuery(cql);
65
                int cqlResult = 0;
55 66
                boolean status = validate(sqlResult, cqlResult);
56 67
                validationReport.addQuery(name, sqlResult, cqlResult, status);
57 68

  
......
64 75
            }
65 76
        }
66 77

  
67
        log.debug("Generated report : " + report.toString());
78
        log.info("Generated report : " + report.toString());
68 79
        return report;
69 80
    }
70 81

  
......
76 87

  
77 88
    @Transactional
78 89
    public void promoteShadowSchema() throws IOException, SQLException {
79
// promote shadow cache entries to  public then switch the schema
90

  
80 91
        promoteShadowCacheURL.openConnection();
81 92

  
82 93
        Connection con = dataSource.getConnection();
......
96 107

  
97 108
    private boolean validate(int sqlResult, int cqlResult) {
98 109

  
99

  
110
        log.info(" Validation input " + sqlResult + " " + cqlResult);
100 111
        if (sqlResult == cqlResult) {
101 112

  
102 113
            return true;
......
141 152
    }
142 153

  
143 154
    private int executeCQLCountQuery(String cql) throws Exception {
144
        try {
145
            SearchService searchService = searchServiceServiceLocator.getService();
146
            SearchResult result = searchService.search(cql, null, "UTF-8", 1, 1);
147
            //   String text, String transformer, String locale, int page, int size)
148
            return result.getTotal();
155
        {
156
            log.info("************** Trying to get SS");
149 157

  
150
        } catch (Exception e) {
151
            log.error("Could not  query the Search Service :" + e);
152
            throw new Exception("Could not  query the Search Service ", e);
158

  
153 159
        }
154 160

  
161
        //  SearchService webService = (SearchService) factory.create();
162

  
163

  
164
//			AASClient aasClient = new AASClient();
165
//			aasClient.setA2Service(webService);
166
//			StaticServiceLocator<eu.dnetlib.api.enabling.A2Service> locator = new StaticServiceLocator<eu.dnetlib.api.enabling.A2Service>();
167
//
168
//			locator.setService(aasClient);
169
//
170
//			((A2WrapperImpl) a2Wrapper).setLocator(locator);
171

  
172
        SearchService searchService = searchServiceLocator.getService();
173

  
174

  
175
        if (searchService == null) {
176
            log.error("Search service null");
177

  
178

  
179
        }
180
        SearchResult result = searchService.search(cql, "results_openaire", "en-gb", 1, 1);
181
        //   String text, String transformer, String locale, int page, int size)
182
        return result.getTotal();
183

  
155 184
    }
156 185

  
157 186

  
......
160 189
        Connection con = null;
161 190
        try {
162 191
            con = dataSource.getConnection();
163
            PreparedStatement st = con.prepareStatement(sql);
164
            ResultSet rs = st.executeQuery();
165
            return getResult(rs);
192
            log.info("Executing Sql query  " + sql);
166 193

  
194
            Statement st = con.createStatement();
195
            if (st.execute(sql)) {
196

  
197
                ResultSet rs = st.getResultSet();
198
                int res = getResult(rs);
199
                st.close();
200
                return res;
201
            } else {
202
                log.error("Fail to execute command  " + sql + "  " + st.getWarnings());
203
                throw new Exception("Fail to execute command " + sql + "  " + st.getWarnings());
204
            }
205

  
206

  
167 207
        } catch (Exception e) {
168
            log.error("Could not execute sql query :" + e);
169
            throw new Exception("Could not execute sql query  : ", e);
208
            log.error("Could not execute sql query  " + sql + " : " + e);
209
            throw new Exception("Could not execute sql query  " + sql + " : ", e);
170 210
        } finally {
171 211
            con.close();
172 212
        }
......
174 214

  
175 215
    private int getResult(ResultSet rs) throws Exception {
176 216
        HashMap<String, Integer> data = new HashMap<String, Integer>();
217
        int res = -1;
177 218
        try {
178 219

  
179 220
            ResultSetMetaData rsmd = rs.getMetaData();
180
            while (rs.next()) {
181
                for (int i = 1; i < rsmd.getColumnCount() - 1; i++) {
182
                    log.debug("Query result : " + rsmd.getColumnName(i) + rs.getInt(i));
183
                    return rs.getInt(i);
184
                }
221
            //for (int i = 1; i < rsmd.getColumnCount() - 1; i++)
222
            if (rs.next()) {
223
                log.info("Query result : " + rsmd.getColumnName(1) + rs.getObject(1));
224
                res = (Integer.valueOf(rs.getString(1)));
225
                rs.close();
185 226
            }
186
            return 0;
227

  
228
            return res;
187 229
        } catch (Exception e) {
188 230
            log.error("Could not process results :" + e);
189 231
            throw new Exception("Could not process results :", e);
......
245 287
        this.dataSource = dataSource;
246 288
    }
247 289

  
248
    public ServiceLocator<SearchService> getSearchServiceServiceLocator() {
249
        return searchServiceServiceLocator;
250
    }
251 290

  
252
    public void setSearchServiceServiceLocator(ServiceLocator<SearchService> searchServiceServiceLocator) {
253
        this.searchServiceServiceLocator = searchServiceServiceLocator;
254
    }
255

  
256 291
    public ValidationReport getValidationReport() {
257 292
        return validationReport;
258 293
    }
......
268 303
    public void setPortalUser(String portalUser) {
269 304
        this.portalUser = portalUser;
270 305
    }
306

  
307
    public ServiceLocator<SearchService> getSearchServiceLocator() {
308
        return searchServiceLocator;
309
    }
310

  
311
    public void setSearchServiceLocator(ServiceLocator<SearchService> searchServiceLocator) {
312
        this.searchServiceLocator = searchServiceLocator;
313
    }
271 314
}
modules/uoa-stats-service/trunk/src/main/java/eu/dnetlib/data/statsmanager/StatsManagerServiceBlackboardHandler.java
14 14
 */
15 15
public class StatsManagerServiceBlackboardHandler extends BlackboardNotificationHandler<BlackboardServerHandler> {
16 16

  
17
	private static Logger logger = Logger.getLogger(StatsManagerServiceBlackboardHandler.class);
18
	private StatsManager statsManager;
17
    private static Logger logger = Logger.getLogger(StatsManagerServiceBlackboardHandler.class);
18
    private StatsManager statsManager;
19 19

  
20
	protected void processJob(BlackboardJob job) {
21
		String action = job.getAction();
20
    protected void processJob(BlackboardJob job) {
21
        //TODO needs this?
22
        super.processJob(job);
22 23

  
23
		logger.info("Got BB message: " + action);
24
        logger.info("Beginning new job...");
25
        logger.info("Id: " + job.getId() +  " Date : " + job.getDate());
26
        String action = job.getAction();
24 27

  
25
		try {
26
			getBlackboardHandler().ongoing(job);
28
        logger.info("Got BB message: " + action);
27 29

  
28
			if (action.equals("validate")) {
29
				ValidationReport report = statsManager.validateDatabase();
30
        try {
31
            getBlackboardHandler().ongoing(job);
30 32

  
33
            if (action.equals("validate")) {
34
                ValidationReport report = statsManager.validateDatabase();
31 35

  
36
                // TODO update job status
32 37

  
33
				// TODO update job status
34 38

  
39
                StringWriter sw = new StringWriter();
40
                JAXBContext.newInstance(ValidationReport.class).createMarshaller().marshal(report, sw);
35 41

  
36
				StringWriter sw = new StringWriter();
37
				JAXBContext.newInstance(ValidationReport.class).createMarshaller().marshal(report, sw);
42
                job.getParameters().put("report", sw.toString());
43
            } else if (action.equals("refreshCache")) {
44
                statsManager.refreshCache();
45
            } else if (action.equals("promoteShadow")) {
46
                statsManager.promoteShadowSchema();
47
            } else {
48
                throw new Exception("Don't know what to do with " + action);
49
            }
38 50

  
39
				job.getParameters().put("report", sw.toString());
40
			} else if (action.equals("refreshCache")) {
41
				statsManager.refreshCache();
42
			} else if (action.equals("promoteShadow")) {
43
				statsManager.promoteShadowSchema();
44
			} else {
45
				throw new Exception("Don't know what to do with " + action);
46
			}
51
            getBlackboardHandler().done(job);
52
        } catch (Exception e) {
53
            getBlackboardHandler().failed(job, e);
47 54

  
48
			getBlackboardHandler().done(job);
49
		} catch (Exception e) {
50
			getBlackboardHandler().failed(job, e);
55
            logger.error("Error processing job", e);
56
        }
57
    }
51 58

  
52
			logger.error("Error processing job", e);
53
		}
54
	}
59
    public StatsManager getStatsManager() {
60
        return statsManager;
61
    }
55 62

  
56
	public StatsManager getStatsManager() {
57
		return statsManager;
58
	}
59

  
60
	public void setStatsManager(StatsManager statsManager) {
61
		this.statsManager = statsManager;
62
	}
63
    public void setStatsManager(StatsManager statsManager) {
64
        this.statsManager = statsManager;
65
    }
63 66
}
modules/uoa-stats-service/trunk/src/main/resources/eu/dnetlib/data/statsmanager/springContext-statsManager.properties
7 7
services.statsManager.db.password = sqoop
8 8
services.statsManager.db.portalUser = dnet
9 9

  
10
services.statsmanager.validationQueriesFile = classpath*:/eu/dnetlib/data/statsmanager/validationQueries.xml
10
services.statsmanager.validationQueriesFile = classpath:/eu/dnetlib/data/statsmanager/validationQueries.xml
11 11
services.statsmanager.refreshShadowCacheURL = https://www.beta.openaire.eu/stats/refreshCache.php
12 12
services.statsmanager.promoteShadowCacheURL = https://www.beta.openaire.eu/stats/promoteCache.php
13
services.statsManager.shadowSearchServiceURL = http://services.openaire.eu:8380/search/
14

  
13
services.statsManager.shadowSearchServiceURL =http://services.openaire.eu:8380/search/services/searchWebService

Also available in: Unified diff