1
|
package eu.dnetlib.data.hadoop.action;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
import org.springframework.beans.factory.annotation.Required;
|
9
|
|
10
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
11
|
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException;
|
12
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
13
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
14
|
import eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions;
|
15
|
|
16
|
public class ImportEprHdfsAction extends AbstractHadoopAction {
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(ImportEprHdfsAction.class); // NOPMD by marko on 11/24/08 5:02 PM
|
19
|
|
20
|
private SequenceFileFeeder sequenceFileFeeder;
|
21
|
|
22
|
@Override
|
23
|
public void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws HadoopServiceException {
|
24
|
|
25
|
final String epr = DnetXsltFunctions.decodeBase64(job.getParameters().get("input_epr"));
|
26
|
final ClusterName clusterName = ClusterName.valueOf(job.getParameters().get("cluster"));
|
27
|
final String path = job.getParameters().get("path");
|
28
|
|
29
|
log.info(String.format("Starting import in hdfs sequence file '%s', cluster '%s', epr '%s...", path, clusterName.toString(),
|
30
|
StringUtils.substring(epr, 0, 20)));
|
31
|
try {
|
32
|
Integer count = getSequenceFileFeeder().feed(epr, clusterName, path);
|
33
|
if (count != null) {
|
34
|
log.info("Import completed successfully");
|
35
|
job.getParameters().put("count", String.valueOf(count));
|
36
|
}
|
37
|
|
38
|
handler.done(job);
|
39
|
} catch (IOException e) {
|
40
|
throw new HadoopServiceException("Import failed", e);
|
41
|
}
|
42
|
}
|
43
|
|
44
|
public SequenceFileFeeder getSequenceFileFeeder() {
|
45
|
return sequenceFileFeeder;
|
46
|
}
|
47
|
|
48
|
@Required
|
49
|
public void setSequenceFileFeeder(final SequenceFileFeeder sequenceFileFeeder) {
|
50
|
this.sequenceFileFeeder = sequenceFileFeeder;
|
51
|
}
|
52
|
|
53
|
}
|