本文整理汇总了Java中org.apache.hadoop.security.UserGroupInformation.addCredentials方法的典型用法代码示例。如果您正苦于以下问题:Java UserGroupInformation.addCredentials方法的具体用法?Java UserGroupInformation.addCredentials怎么用?Java UserGroupInformation.addCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.security.UserGroupInformation
的用法示例。
在下文中一共展示了UserGroupInformation.addCredentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.hadoop.security.UserGroupInformation; //导入方法依赖的package包/类
public static void main(String[] argv) {
LOG.info("Starting Parameter Server");
int serverIndex = Integer.valueOf(System.getenv(AngelEnvironment.PARAMETERSERVER_ID.name()));
String appMasterHost = System.getenv(AngelEnvironment.LISTEN_ADDR.name());
int appMasterPort = Integer.valueOf(System.getenv(AngelEnvironment.LISTEN_PORT.name()));
int attemptIndex = Integer.valueOf(System.getenv(AngelEnvironment.PS_ATTEMPT_ID.name()));
Configuration conf = new Configuration();
conf.addResource(AngelConf.ANGEL_JOB_CONF_FILE);
String user = System.getenv(ApplicationConstants.Environment.USER.name());
UserGroupInformation.setConfiguration(conf);
String runningMode = conf.get(AngelConf.ANGEL_RUNNING_MODE,
AngelConf.DEFAULT_ANGEL_RUNNING_MODE);
if(runningMode.equals(RunningMode.ANGEL_PS_WORKER.toString())){
LOG.debug("AngelEnvironment.TASK_NUMBER.name()=" + AngelEnvironment.TASK_NUMBER.name());
conf.set(AngelConf.ANGEL_TASK_ACTUAL_NUM,
System.getenv(AngelEnvironment.TASK_NUMBER.name()));
}
final ParameterServer psServer =
new ParameterServer(serverIndex, attemptIndex, appMasterHost, appMasterPort, conf);
try{
Credentials credentials =
UserGroupInformation.getCurrentUser().getCredentials();
UserGroupInformation psUGI = UserGroupInformation.createRemoteUser(System
.getenv(ApplicationConstants.Environment.USER.toString()));
// Add tokens to new user so that it may execute its task correctly.
psUGI.addCredentials(credentials);
psUGI.doAs(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
psServer.initialize();
psServer.start();
return null;
}
});
} catch (Throwable x) {
LOG.fatal("Start PS failed ", x);
psServer.failed(x.getMessage());
}
LOG.info("Starting Parameter Server successfully.");
}