1
|
package eu.dnetlib.actionmanager;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
import javax.jws.WebParam;
|
7
|
|
8
|
import eu.dnetlib.data.hadoop.HadoopServiceCore;
|
9
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
10
|
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException;
|
11
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
12
|
import org.apache.hadoop.fs.Path;
|
13
|
import org.springframework.beans.factory.annotation.Required;
|
14
|
|
15
|
import eu.dnetlib.actionmanager.actions.XsltInfoPackageAction;
|
16
|
import eu.dnetlib.actionmanager.common.Agent;
|
17
|
import eu.dnetlib.actionmanager.common.Operation;
|
18
|
import eu.dnetlib.actionmanager.common.Provenance;
|
19
|
import eu.dnetlib.actionmanager.hbase.HBaseActionManagerCore;
|
20
|
import eu.dnetlib.actionmanager.rmi.ActionManagerException;
|
21
|
import eu.dnetlib.actionmanager.rmi.ActionManagerService;
|
22
|
import eu.dnetlib.actionmanager.set.ActionManagerSet;
|
23
|
import eu.dnetlib.enabling.tools.AbstractBaseService;
|
24
|
import eu.dnetlib.enabling.tools.blackboard.NotificationHandler;
|
25
|
|
26
|
public class ActionManagerServiceImpl extends AbstractBaseService implements ActionManagerService {
|
27
|
|
28
|
private HBaseActionManagerCore core;
|
29
|
|
30
|
private NotificationHandler notificationHandler;
|
31
|
|
32
|
@Resource
|
33
|
private HadoopServiceCore hadoopServiceCore;
|
34
|
|
35
|
@Override
|
36
|
public String createSet(@WebParam(name = "set") final ActionManagerSet set) throws ActionManagerException {
|
37
|
try {
|
38
|
final String basePath = core.getBasePathHDFS();
|
39
|
final Path actionSetPath = new Path(basePath + "/" + set.getId());
|
40
|
hadoopServiceCore.createHdfsDir(ClusterName.DM, actionSetPath.toString(), true);
|
41
|
return core.getInformationServiceClient().registerSetProfile(set);
|
42
|
} catch (HadoopServiceException e) {
|
43
|
throw new ActionManagerException(e);
|
44
|
} catch (ISLookUpException e) {
|
45
|
throw new ActionManagerException(e);
|
46
|
}
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public boolean deleteSet(@WebParam(name = "set") final String setId) throws ActionManagerException {
|
51
|
try {
|
52
|
final String basePath = core.getBasePathHDFS();
|
53
|
final Path actionSetPath = new Path(basePath + "/" + setId);
|
54
|
hadoopServiceCore.deleteFromHdfs(ClusterName.DM, actionSetPath.toString());
|
55
|
return core.getInformationServiceClient().deleteSetProfile(setId);
|
56
|
} catch (HadoopServiceException e) {
|
57
|
throw new ActionManagerException(e);
|
58
|
} catch (ISLookUpException e) {
|
59
|
throw new ActionManagerException(e);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public List<ActionManagerSet> ListSets() throws ActionManagerException {
|
65
|
return core.listAvailableSets();
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public String createAction(final String splitRuleId,
|
70
|
final String set,
|
71
|
final Agent agent,
|
72
|
final Operation operation,
|
73
|
final String infoPackage,
|
74
|
final Provenance provenance,
|
75
|
final String trust,
|
76
|
final String nsprefix) throws ActionManagerException {
|
77
|
|
78
|
final XsltInfoPackageAction action = core.applyInfoPackageAction(splitRuleId, set, agent, operation, infoPackage, provenance, trust, nsprefix);
|
79
|
return action.getRowKey();
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public String updateAction(final String actionId,
|
84
|
final String splitRuleId,
|
85
|
final String set,
|
86
|
final Agent agent,
|
87
|
final Operation operation,
|
88
|
final String infoPackage,
|
89
|
final Provenance provenance,
|
90
|
final String trust,
|
91
|
final String nsprefix) throws ActionManagerException {
|
92
|
|
93
|
core.deleteInfoPackageAction(actionId);
|
94
|
|
95
|
final XsltInfoPackageAction action = core.applyInfoPackageAction(splitRuleId, set, agent, operation, infoPackage, provenance, trust, nsprefix);
|
96
|
|
97
|
return action.getRowKey();
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public boolean deleteAction(final String actionId) throws ActionManagerException {
|
102
|
core.deleteInfoPackageAction(actionId);
|
103
|
return true;
|
104
|
}
|
105
|
|
106
|
@Override
|
107
|
public List<String> getActionsByAgent(final String agentId, final int limit) throws ActionManagerException {
|
108
|
return core.getHbaseClient().retrieveActionsByAgent(agentId, limit);
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public void notify(final String subscriptionId, final String topic, final String isId, final String message) {
|
113
|
notificationHandler.notified(subscriptionId, topic, isId, message);
|
114
|
}
|
115
|
|
116
|
public HBaseActionManagerCore getCore() {
|
117
|
return core;
|
118
|
}
|
119
|
|
120
|
public void setCore(final HBaseActionManagerCore core) {
|
121
|
this.core = core;
|
122
|
}
|
123
|
|
124
|
public NotificationHandler getNotificationHandler() {
|
125
|
return notificationHandler;
|
126
|
}
|
127
|
|
128
|
@Required
|
129
|
public void setNotificationHandler(final NotificationHandler notificationHandler) {
|
130
|
this.notificationHandler = notificationHandler;
|
131
|
}
|
132
|
|
133
|
}
|