本文整理匯總了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.");
}