2021-01-28 15:55:22 +01:00
|
|
|
package eu.dnetlib.data.mdstore.manager.utils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import eu.dnetlib.data.mdstore.manager.exceptions.MDStoreManagerException;
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class HdfsClient {
|
|
|
|
|
|
|
|
@Value("${dhp.mdstore-manager.hadoop.cluster}")
|
|
|
|
private String hadoopCluster;
|
|
|
|
|
2021-01-29 15:45:20 +01:00
|
|
|
@Value("${dhp.mdstore-manager.hadoop.user}")
|
|
|
|
private String hadoopUser;
|
|
|
|
|
2021-01-28 15:55:22 +01:00
|
|
|
private static final Log log = LogFactory.getLog(HdfsClient.class);
|
|
|
|
|
|
|
|
public void deletePath(final String path) throws MDStoreManagerException {
|
|
|
|
final Configuration conf = new Configuration();
|
|
|
|
|
2021-01-29 15:45:20 +01:00
|
|
|
System.setProperty("HADOOP_USER_NAME", hadoopUser);
|
|
|
|
|
2021-01-28 15:55:22 +01:00
|
|
|
if (hadoopCluster.equalsIgnoreCase("OCEAN")) {
|
|
|
|
conf.addResource(getClass().getResourceAsStream("/hadoop/OCEAN/core-site.xml"));
|
|
|
|
conf.addResource(getClass().getResourceAsStream("/hadoop/OCEAN/ocean-hadoop-conf.xml"));
|
|
|
|
} else if (hadoopCluster.equalsIgnoreCase("GARR")) {
|
|
|
|
conf.addResource(getClass().getResourceAsStream("/hadoop/GARR/core-site.xml"));
|
|
|
|
conf.addResource(getClass().getResourceAsStream("/hadoop/GARR/garr-hadoop-conf.xml"));
|
|
|
|
} else {
|
|
|
|
log.error("Invalid Haddop Cluster: " + hadoopCluster);
|
|
|
|
throw new MDStoreManagerException("Invalid Haddop Cluster: " + hadoopCluster);
|
|
|
|
}
|
|
|
|
|
|
|
|
try (final FileSystem fs = FileSystem.get(conf)) {
|
|
|
|
fs.delete(new Path(path), true);
|
2021-01-29 15:45:20 +01:00
|
|
|
log.info("HDFS Path deleted: " + path);
|
2021-01-28 15:55:22 +01:00
|
|
|
} catch (IllegalArgumentException | IOException e) {
|
|
|
|
log.error("Eror deleting path: " + path, e);
|
|
|
|
throw new MDStoreManagerException("Eror deleting path: " + path, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getHadoopCluster() {
|
|
|
|
return hadoopCluster;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHadoopCluster(final String hadoopCluster) {
|
|
|
|
this.hadoopCluster = hadoopCluster;
|
|
|
|
}
|
2021-01-29 15:45:20 +01:00
|
|
|
|
|
|
|
public String getHadoopUser() {
|
|
|
|
return hadoopUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setHadoopUser(final String hadoopUser) {
|
|
|
|
this.hadoopUser = hadoopUser;
|
|
|
|
}
|
2021-01-28 15:55:22 +01:00
|
|
|
}
|