當前位置: 首頁>>代碼示例>>Java>>正文


Java UserGroupInformation.setConfiguration方法代碼示例

本文整理匯總了Java中org.apache.hadoop.security.UserGroupInformation.setConfiguration方法的典型用法代碼示例。如果您正苦於以下問題:Java UserGroupInformation.setConfiguration方法的具體用法?Java UserGroupInformation.setConfiguration怎麽用?Java UserGroupInformation.setConfiguration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.security.UserGroupInformation的用法示例。


在下文中一共展示了UserGroupInformation.setConfiguration方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Before
public void setup() {
  LOG.info("---------------------------------");
  LOG.info("Testing QOP:"+ getQOPNames(qop));
  LOG.info("---------------------------------");
  conf = new Configuration();
  // the specific tests for kerberos will enable kerberos.  forcing it
  // for all tests will cause tests to fail if the user has a TGT
  conf.set(HADOOP_SECURITY_AUTHENTICATION, SIMPLE.toString());
  conf.set(HADOOP_RPC_PROTECTION, getQOPNames(qop));
  if (saslPropertiesResolver != null){
    conf.set(CommonConfigurationKeys.HADOOP_SECURITY_SASL_PROPS_RESOLVER_CLASS,
      saslPropertiesResolver);
  }
  UserGroupInformation.setConfiguration(conf);
  enableSecretManager = null;
  forceSecretManager = null;
  clientFallBackToSimpleAllowed = true;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestSaslRPC.java

示例2: RpcProgramMountd

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public RpcProgramMountd(NfsConfiguration config,
    DatagramSocket registrationSocket, boolean allowInsecurePorts)
    throws IOException {
  // Note that RPC cache is not enabled
  super("mountd", "localhost", config.getInt(
      NfsConfigKeys.DFS_NFS_MOUNTD_PORT_KEY,
      NfsConfigKeys.DFS_NFS_MOUNTD_PORT_DEFAULT), PROGRAM, VERSION_1,
      VERSION_3, registrationSocket, allowInsecurePorts);
  exports = new ArrayList<String>();
  exports.add(config.get(NfsConfigKeys.DFS_NFS_EXPORT_POINT_KEY,
      NfsConfigKeys.DFS_NFS_EXPORT_POINT_DEFAULT));
  this.hostsMatcher = NfsExports.getInstance(config);
  this.mounts = Collections.synchronizedList(new ArrayList<MountEntry>());
  UserGroupInformation.setConfiguration(config);
  SecurityUtil.login(config, NfsConfigKeys.DFS_NFS_KEYTAB_FILE_KEY,
      NfsConfigKeys.DFS_NFS_KERBEROS_PRINCIPAL_KEY);
  this.dfsClient = new DFSClient(NameNode.getAddress(config), config);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:RpcProgramMountd.java

示例3: main

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public static void main(String[] args) {
    String rootPath = "hdfs://nameservice1";
    Path p = new Path(rootPath + "/tmp/file.txt");
    Configuration conf = new Configuration();
    conf.addResource("core-site.xml");
    conf.addResource("hdfs-site.xml");
    conf.addResource("yarn-site.xml");
    try {
        // 沒開kerberos,注釋下麵兩行
        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab("[email protected]","E:\\星環\\hdfs.keytab");
        FileSystem fs = p.getFileSystem(conf);
        boolean b = fs.delete(p, true);
        System.out.println(b);
        fs.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Transwarp-DE,項目名稱:Transwarp-Sample-Code,代碼行數:20,代碼來源:Delete.java

示例4: run

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public int run(final String[] argv) throws IOException, InterruptedException {
  int val = -1;
  final Configuration conf = getConf();
  UserGroupInformation.setConfiguration(conf);
  UserGroupInformation ugi = UserGroupInformation.getLoginUser();

  val = ugi.doAs(new PrivilegedExceptionAction<Integer>() {
    public Integer run() throws Exception {
      return runJob(conf, argv);
    }
  });
  
  // print the gridmix summary if the run was successful
  if (val == 0) {
      // print the run summary
      System.out.print("\n\n");
      System.out.println(summarizer.toString());
  }
  
  return val; 
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:Gridmix.java

示例5: init

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Override
public void init(SubsetConfiguration metrics2Properties) {
  properties = metrics2Properties;
  basePath = new Path(properties.getString(BASEPATH_KEY, BASEPATH_DEFAULT));
  source = properties.getString(SOURCE_KEY, SOURCE_DEFAULT);
  ignoreError = properties.getBoolean(IGNORE_ERROR_KEY, false);
  allowAppend = properties.getBoolean(ALLOW_APPEND_KEY, false);

  conf = loadConf();
  UserGroupInformation.setConfiguration(conf);

  // Don't do secure setup if it's not needed.
  if (UserGroupInformation.isSecurityEnabled()) {
    // Validate config so that we don't get an NPE
    checkForProperty(properties, KEYTAB_PROPERTY_KEY);
    checkForProperty(properties, USERNAME_PROPERTY_KEY);


    try {
      // Login as whoever we're supposed to be and let the hostname be pulled
      // from localhost. If security isn't enabled, this does nothing.
      SecurityUtil.login(conf, properties.getString(KEYTAB_PROPERTY_KEY),
          properties.getString(USERNAME_PROPERTY_KEY));
    } catch (IOException ex) {
      throw new MetricsException("Error logging in securely: ["
          + ex.toString() + "]", ex);
    }
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:30,代碼來源:RollingFileSystemSink.java

示例6: cleanUp

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@After
public void cleanUp() throws Exception {
  jetty.stop();

  // resetting hadoop security to simple
  org.apache.hadoop.conf.Configuration conf =
      new org.apache.hadoop.conf.Configuration();
  UserGroupInformation.setConfiguration(conf);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:10,代碼來源:TestWebDelegationToken.java

示例7: setup

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Before
public void setup() throws IOException {
  conf = getConf();
  Logger rootLogger = LogManager.getRootLogger();
  rootLogger.setLevel(Level.DEBUG);
  UserGroupInformation.setConfiguration(conf);
  conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
  conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
  conf.set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName());
  rmAddr = new InetSocketAddress("localhost", 8032);
  Assert.assertTrue(YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS > 1);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:13,代碼來源:TestRMRestart.java

示例8: setUp

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@BeforeClass
public static void setUp() {
  conf = new Configuration();
  SecurityUtil.setAuthenticationMethod(KERBEROS, conf);
  UserGroupInformation.setConfiguration(conf);    
  UserGroupInformation.setLoginUser(
      UserGroupInformation.createUserForTesting(
          "LoginUser", new String[]{"supergroup"}));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:TestWebHdfsTokens.java

示例9: setup

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Before
public void setup() throws UnknownHostException {
  Logger rootLogger = LogManager.getRootLogger();
  rootLogger.setLevel(Level.DEBUG);
  conf = new YarnConfiguration();
  UserGroupInformation.setConfiguration(conf);
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
      YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:TestContainerResourceUsage.java

示例10: testAppSubmissionWithOldDelegationTokenAfterRMRestart

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Test (timeout = 60000)
public void testAppSubmissionWithOldDelegationTokenAfterRMRestart()
    throws Exception {
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  conf.set(YarnConfiguration.RM_ADDRESS, "localhost:8032");
  UserGroupInformation.setConfiguration(conf);
  MemoryRMStateStore memStore = new MemoryRMStateStore();
  memStore.init(conf);

  MockRM rm1 = new TestSecurityMockRM(conf, memStore);
  rm1.start();

  GetDelegationTokenRequest request1 =
      GetDelegationTokenRequest.newInstance("renewer1");
  UserGroupInformation.getCurrentUser().setAuthenticationMethod(
      AuthMethod.KERBEROS);
  GetDelegationTokenResponse response1 =
      rm1.getClientRMService().getDelegationToken(request1);
  Token<RMDelegationTokenIdentifier> token1 =
      ConverterUtils.convertFromYarn(response1.getRMDelegationToken(), rmAddr);

  // start new RM
  MockRM rm2 = new TestSecurityMockRM(conf, memStore);
  rm2.start();

  // submit an app with the old delegation token got from previous RM.
  Credentials ts = new Credentials();
  ts.addToken(token1.getService(), token1);
  RMApp app = rm2.submitApp(200, "name", "user",
      new HashMap<ApplicationAccessType, String>(), false, "default", 1, ts);
  rm2.waitForState(app.getApplicationId(), RMAppState.ACCEPTED);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:TestRMRestart.java

示例11: createSecuredUserDir

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public void createSecuredUserDir(String userName, String keytabdir) {
  try {
    UserGroupInformation.setConfiguration(conf);
    UserGroupInformation.loginUserFromKeytab(getHDFSPrincipal(""),
        keytabdir + File.separator + "hdfs.keytab");
    FileSystem fs = FileSystem.get(conf);
    Path userDir = new Path("/user" + File.separator + userName);
    fs.mkdirs(userDir, new FsPermission(FsAction.ALL, FsPermission.getDefault().getGroupAction(),
        FsPermission.getDefault().getOtherAction()));
    fs.setOwner(userDir, userName, "hadoop");
  } catch (IOException e) {
    e.printStackTrace();
  }

}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:16,代碼來源:HDFSQuasiService.java

示例12: loginKerberosPrincipal

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
private UserGroupInformation loginKerberosPrincipal(String krbKeytab, String krbPrincipal)
    throws Exception {
  Configuration cnf = new Configuration();
  cnf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(cnf);
  UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab);
  return UserGroupInformation.getLoginUser();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:9,代碼來源:TestSecureRPC.java

示例13: getConfiguration

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
/**
 * Creates the hadoop configuration object from the properties specified for tierstore
 * 
 * @return configuration object
 */
public static Configuration getConfiguration(final Properties props) throws IOException {
  Configuration conf = new Configuration();
  String hdfsSiteXMLPath = props.getProperty(CommonConfig.HDFS_SITE_XML_PATH);
  String hadoopSiteXMLPath = props.getProperty(CommonConfig.HADOOP_SITE_XML_PATH);
  if (hdfsSiteXMLPath != null) {
    conf.addResource(Paths.get(hdfsSiteXMLPath).toUri().toURL());
  }
  if (hadoopSiteXMLPath != null) {
    conf.addResource(Paths.get(hadoopSiteXMLPath).toUri().toURL());
  }

  props.entrySet().forEach((PROP) -> {
    conf.set(String.valueOf(PROP.getKey()), String.valueOf(PROP.getValue()));
  });

  // set secured properties
  String userName = props.getProperty(CommonConfig.USER_NAME);
  String keytabPath = props.getProperty(CommonConfig.KEYTAB_PATH);
  if (userName == null || keytabPath == null) {
    if (props.containsKey(ENABLE_KERBEROS_AUTHC)
        && Boolean.parseBoolean(props.getProperty(ENABLE_KERBEROS_AUTHC))) {
      userName = props.getProperty(ResourceConstants.USER_NAME);
      keytabPath = props.getProperty(ResourceConstants.PASSWORD);
    }
  }

  // use the username and keytab
  if (userName != null && keytabPath != null) {
    // set kerberos authentication
    conf.set("hadoop.security.authentication", "kerberos");
    UserGroupInformation.setConfiguration(conf);
    UserGroupInformation.loginUserFromKeytab(userName, keytabPath);
  }
  return conf;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:41,代碼來源:ConfigurationUtils.java

示例14: SchemaFetch

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public SchemaFetch(Configuration conf)
  throws IOException, InterruptedException {
  logger = LoggerFactory.getLogger(getClass());
  this.conf = conf;

  schemaFileWriter = new FileWriter(this.conf.get(Constant.HDFS_SCHEMA_REMOTE_PATH_KEY));
  sampleFileWriter = new FileWriter(this.conf.get(Constant.HDFS_SAMPLE_REMOTE_PATH_KEY));

  // login from kerberos, get the file system
  String principal = this.conf.get(Constant.HDFS_REMOTE_USER_KEY);
  String keyLocation = this.conf.get(Constant.HDFS_REMOTE_KEYTAB_LOCATION_KEY, null);


  if (keyLocation == null) {
    System.out.println("No keytab file location specified, will ignore the kerberos login process");
    fs = FileSystem.get(new Configuration());
  } else {
    try {
      Configuration hdfs_conf = new Configuration();
      hdfs_conf.set("hadoop.security.authentication", "Kerberos");
      hdfs_conf.set("dfs.namenode.kerberos.principal.pattern", "*");
      UserGroupInformation.setConfiguration(hdfs_conf);
      UserGroupInformation.loginUserFromKeytab(principal, keyLocation);
      fs = FileSystem.get(hdfs_conf);
    } catch (IOException e) {
      System.out
          .println("Failed, Try to login through kerberos. Priciple: " + principal + " keytab location : " + keyLocation);
      e.printStackTrace();
      System.out.println("Use default, assume no kerbero needed");
      fs = FileSystem.get(new Configuration());
    }
  }

  // TODO Write to hdfs
  // String sampleDataFolder = "/projects/wherehows/hdfs/sample_data";
  // String cluster = this.conf.get("hdfs.cluster");
  // sampleDataAvroWriter = new AvroWriter(this.fs, sampleDataFolder + "/" + cluster, SampleDataRecord.class);
  // String schemaFolder = this.conf.get("hdfs.schema_location");

  fileAnalyzerFactory = new FileAnalyzerFactory(this.fs);
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:42,代碼來源:SchemaFetch.java

示例15: testDelegationTokenRestoredInDelegationTokenRenewer

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
@Test (timeout = 60000)
public void testDelegationTokenRestoredInDelegationTokenRenewer()
    throws Exception {
  conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 2);
  conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION,
      "kerberos");
  UserGroupInformation.setConfiguration(conf);

  MemoryRMStateStore memStore = new MemoryRMStateStore();
  memStore.init(conf);
  RMState rmState = memStore.getState();

  Map<ApplicationId, ApplicationStateData> rmAppState =
      rmState.getApplicationState();
  MockRM rm1 = new TestSecurityMockRM(conf, memStore);
  rm1.start();

  HashSet<Token<RMDelegationTokenIdentifier>> tokenSet =
      new HashSet<Token<RMDelegationTokenIdentifier>>();

  // create an empty credential
  Credentials ts = new Credentials();

  // create tokens and add into credential
  Text userText1 = new Text("user1");
  RMDelegationTokenIdentifier dtId1 =
      new RMDelegationTokenIdentifier(userText1, new Text("renewer1"),
        userText1);
  Token<RMDelegationTokenIdentifier> token1 =
      new Token<RMDelegationTokenIdentifier>(dtId1,
        rm1.getRMContext().getRMDelegationTokenSecretManager());
  SecurityUtil.setTokenService(token1, rmAddr);
  ts.addToken(userText1, token1);
  tokenSet.add(token1);

  Text userText2 = new Text("user2");
  RMDelegationTokenIdentifier dtId2 =
      new RMDelegationTokenIdentifier(userText2, new Text("renewer2"),
        userText2);
  Token<RMDelegationTokenIdentifier> token2 =
      new Token<RMDelegationTokenIdentifier>(dtId2,
        rm1.getRMContext().getRMDelegationTokenSecretManager());
  SecurityUtil.setTokenService(token2, rmAddr);
  ts.addToken(userText2, token2);
  tokenSet.add(token2);

  // submit an app with customized credential
  RMApp app = rm1.submitApp(200, "name", "user",
      new HashMap<ApplicationAccessType, String>(), false, "default", 1, ts);

  // assert app info is saved
  ApplicationStateData appState = rmAppState.get(app.getApplicationId());
  Assert.assertNotNull(appState);

  // assert delegation tokens exist in rm1 DelegationTokenRenewr
  Assert.assertEquals(tokenSet, rm1.getRMContext()
    .getDelegationTokenRenewer().getDelegationTokens());

  // assert delegation tokens are saved
  DataOutputBuffer dob = new DataOutputBuffer();
  ts.writeTokenStorageToStream(dob);
  ByteBuffer securityTokens =
      ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
  securityTokens.rewind();
  Assert.assertEquals(securityTokens, appState
    .getApplicationSubmissionContext().getAMContainerSpec()
    .getTokens());

  // start new RM
  MockRM rm2 = new TestSecurityMockRM(conf, memStore);
  rm2.start();

  // Need to wait for a while as now token renewal happens on another thread
  // and is asynchronous in nature.
  waitForTokensToBeRenewed(rm2);

  // verify tokens are properly populated back to rm2 DelegationTokenRenewer
  Assert.assertEquals(tokenSet, rm2.getRMContext()
    .getDelegationTokenRenewer().getDelegationTokens());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:81,代碼來源:TestRMRestart.java


注:本文中的org.apache.hadoop.security.UserGroupInformation.setConfiguration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。