1
|
package eu.dnetlib.data.hadoop.action;
|
2
|
|
3
|
import eu.dnetlib.data.hadoop.HadoopServiceCore;
|
4
|
import eu.dnetlib.data.hadoop.config.ClusterName;
|
5
|
import eu.dnetlib.data.hadoop.rmi.HadoopServiceException;
|
6
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
|
7
|
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
|
12
|
/**
|
13
|
* Creates a directory on hdfs, if it does not exists.
|
14
|
* <p/>
|
15
|
* Params - cluster: cluster name, path: directory path to be created, forceDelete: forces the directory to be dropped and recreated.
|
16
|
*
|
17
|
* @author claudio
|
18
|
*/
|
19
|
public class CreateHdfsDirectoryAction extends AbstractHadoopAction {
|
20
|
|
21
|
/**
|
22
|
* logger.
|
23
|
*/
|
24
|
private static final Log log = LogFactory.getLog(CreateHdfsDirectoryAction.class); // NOPMD by marko on 11/24/08 5:02 PM
|
25
|
|
26
|
/**
|
27
|
* The hadoop service core.
|
28
|
*/
|
29
|
@Autowired
|
30
|
private HadoopServiceCore hadoopServiceCore;
|
31
|
|
32
|
@Override
|
33
|
protected void executeAsync(final BlackboardServerHandler handler, final BlackboardJob job) throws HadoopServiceException {
|
34
|
|
35
|
final ClusterName clusterName = ClusterName.valueOf(job.getParameters().get("cluster"));
|
36
|
log.info("create directory request on cluster: " + clusterName.toString());
|
37
|
|
38
|
final boolean forceDelete = isForceDelete(job);
|
39
|
final String path = job.getParameters().get("path");
|
40
|
|
41
|
hadoopServiceCore.createHdfsDir(clusterName, path, forceDelete);
|
42
|
|
43
|
handler.done(job);
|
44
|
}
|
45
|
|
46
|
private boolean isForceDelete(final BlackboardJob job) {
|
47
|
try {
|
48
|
return Boolean.parseBoolean(job.getParameters().get("force"));
|
49
|
} catch (IllegalArgumentException e) {
|
50
|
return false;
|
51
|
}
|
52
|
}
|
53
|
|
54
|
}
|