Browse Source

add

pull/2/head
lgcareer 6 years ago
parent
commit
de5736bec0
  1. 5
      escheduler-common/src/main/java/cn/escheduler/common/Constants.java
  2. 27
      escheduler-common/src/main/java/cn/escheduler/common/utils/HadoopUtils.java

5
escheduler-common/src/main/java/cn/escheduler/common/Constants.java

@ -70,6 +70,11 @@ public final class Constants {
*/ */
public static final String YARN_APPLICATION_STATUS_ADDRESS = "yarn.application.status.address"; public static final String YARN_APPLICATION_STATUS_ADDRESS = "yarn.application.status.address";
/**
* hdfs configuration
* hdfs.root.user
*/
public static final String HDFS_ROOT_USER = "hdfs.root.user";
/** /**
* hdfs configuration * hdfs configuration

27
escheduler-common/src/main/java/cn/escheduler/common/utils/HadoopUtils.java

@ -35,6 +35,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.*; import java.io.*;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -63,6 +66,30 @@ public class HadoopUtils implements Closeable {
return instance; return instance;
} }
/**
* init escheduler root path in hdfs
*/
private void initHdfsPath(){
String hdfsUser = getString(Constants.HDFS_ROOT_USER);
String hdfsPath = getString(Constants.DATA_STORE_2_HDFS_BASEPATH);
Path path = new Path(hdfsPath);
try {
UserGroupInformation ugi = UserGroupInformation.createProxyUser(hdfsUser,UserGroupInformation.getLoginUser());
ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
@Override
public Boolean run() throws Exception {
if(!fs.exists(path)){
return fs.mkdirs(path);
}
return true;
}
});
} catch (Exception e) {
logger.error(e.getMessage(),e);
}
}
/** /**
* init hadoop configuration * init hadoop configuration
*/ */

Loading…
Cancel
Save