Revision 58415
Added by Antonis Lempesis about 4 years ago
UsageStatsWrapper.java | ||
---|---|---|
1 |
package eu.dnetlib.iis.core.workflows.usage_stats; |
|
2 |
|
|
3 |
import eu.dnetlib.iis.core.java.PortBindings; |
|
4 |
import eu.dnetlib.iis.core.java.Process; |
|
5 |
import eu.dnetlib.iis.core.java.porttype.PortType; |
|
6 |
import eu.dnetlib.usagestats.export.UsageStatsExporter; |
|
7 |
import org.apache.hadoop.conf.Configuration; |
|
8 |
import org.apache.log4j.Logger; |
|
9 |
import java.util.HashMap; |
|
10 |
import java.util.Map; |
|
11 |
import java.util.Properties; |
|
12 |
|
|
13 |
public class UsageStatsWrapper implements Process { |
|
14 |
private Logger log = Logger.getLogger(this.getClass()); |
|
15 |
private UsageStatsExporter usageStatsExporter; |
|
16 |
|
|
17 |
@Override |
|
18 |
public void run(PortBindings portBindings, Configuration context, Map<String, String> parameters) throws Exception { |
|
19 |
|
|
20 |
Properties properties = new Properties(); |
|
21 |
|
|
22 |
for (String key:parameters.keySet()) { |
|
23 |
properties.setProperty(key, parameters.get(key)); |
|
24 |
} |
|
25 |
usageStatsExporter = new UsageStatsExporter(properties); |
|
26 |
|
|
27 |
// usageStatsExporter.setUsername(parameters.get("piwik_username")); |
|
28 |
// usageStatsExporter.setPassword(parameters.get("piwik_pass")); |
|
29 |
// usageStatsExporter.setHttpProtocol(parameters.get("piwik_httpProtocol")); |
|
30 |
// usageStatsExporter.setPiwikUrl(parameters.get("piwik_url")); |
|
31 |
// usageStatsExporter.setSiteId(parameters.get("piwik_siteId")); |
|
32 |
// usageStatsExporter.setStartDate(parameters.get("piwik_startDate")); |
|
33 |
// usageStatsExporter.setStartDate(parameters.get("piwik_startDate")); |
|
34 |
// usageStatsExporter.setFinalDate(parameters.get("piwik_finalDate")); |
|
35 |
// usageStatsExporter.setLogsPath(parameters.get("piwik_logsPath")); |
|
36 |
// usageStatsExporter.setFilterOffset(parameters.get("piwik_filterOffset")); |
|
37 |
// //usageStatsExporter.setDbSchema(parameters.get("piwik_schema")); |
|
38 |
// usageStatsExporter.setDbUrl(parameters.get("Stats_db_Url")); |
|
39 |
// usageStatsExporter.setDbUsername(parameters.get("Stats_db_User")); |
|
40 |
// usageStatsExporter.setDbPassword(parameters.get("Stats_db_Pass")); |
|
41 |
// usageStatsExporter.setTokenAuth(parameters.get("token_auth")); |
|
42 |
|
|
43 |
|
|
44 |
// log.info("Parameters: " + usageStatsExporter.getDbUrl() + usageStatsExporter.getUsername() + usageStatsExporter.getDbPassword()); |
|
45 |
// log.info("Parameters: " + usageStatsExporter.getDbSchema() + usageStatsExporter.getLogsPath()); |
|
46 |
|
|
47 |
for (Map.Entry<String, String> e : parameters.entrySet()) { |
|
48 |
log.info(e.getKey() + ":" + e.getValue()); |
|
49 |
} |
|
50 |
|
|
51 |
try { |
|
52 |
usageStatsExporter.export(); |
|
53 |
log.info("Usage Stats Exported!..."); |
|
54 |
} catch (Exception e){ |
|
55 |
log.error("Usage Stats Export failed: ", e); |
|
56 |
throw new Exception("Usage Stats Export failed: " + e.toString(), e); |
|
57 |
} |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
@Override |
|
63 |
public Map<String, PortType> getInputPorts() { |
|
64 |
return createInputPorts(); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public Map<String, PortType> getOutputPorts() { |
|
70 |
return createOutputPorts(); |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
private static HashMap<String, PortType> createInputPorts() { |
|
75 |
HashMap<String, PortType> inputPorts = new HashMap<String, PortType>(); |
|
76 |
|
|
77 |
return inputPorts; |
|
78 |
} |
|
79 |
|
|
80 |
private static HashMap<String, PortType> createOutputPorts() { |
|
81 |
HashMap<String, PortType> outputPorts = new HashMap<String, PortType>(); |
|
82 |
|
|
83 |
return outputPorts; |
|
84 |
} |
|
85 |
} |
Also available in: Unified diff
a ton of fixes. Close to running smoothly in all cases