public Text getRMDelegationTokenService() { if (rmDTService == null) { rmDTService = ClientRMProxy.getRMDelegationTokenService(conf); } return rmDTService; }
public Text getRMDelegationTokenService() { if (rmDTService == null) { rmDTService = ClientRMProxy.getRMDelegationTokenService(conf); } return rmDTService; }
/** * Create and add an RM delegation token to the credentials * @param yarnClient Yarn Client * @param credentials to add token to * @return the token which was added * @throws IOException * @throws YarnException */ public static Token<TokenIdentifier> addRMDelegationToken(YarnClient yarnClient, Credentials credentials) throws IOException, YarnException { Configuration conf = yarnClient.getConfig(); Text rmPrincipal = new Text(CredentialUtils.getRMPrincipal(conf)); Text rmDTService = ClientRMProxy.getRMDelegationTokenService(conf); Token<TokenIdentifier> rmDelegationToken = ConverterUtils.convertFromYarn( yarnClient.getRMDelegationToken(rmPrincipal), rmDTService); credentials.addToken(rmDelegationToken.getService(), rmDelegationToken); return rmDelegationToken; }
/** * Create and add an RM delegation token to the credentials * @param yarnClient Yarn Client * @param credentials to add token to * @return the token which was added * @throws IOException * @throws YarnException */ public static Token<TokenIdentifier> addRMDelegationToken(YarnClient yarnClient, Credentials credentials) throws IOException, YarnException { Configuration conf = yarnClient.getConfig(); Text rmPrincipal = new Text(CredentialUtils.getRMPrincipal(conf)); Text rmDTService = ClientRMProxy.getRMDelegationTokenService(conf); Token<TokenIdentifier> rmDelegationToken = ConverterUtils.convertFromYarn( yarnClient.getRMDelegationToken(rmPrincipal), rmDTService); credentials.addToken(rmDelegationToken.getService(), rmDelegationToken); return rmDelegationToken; }
@Test public void testGetRMDelegationTokenService() { String defaultRMAddress = YarnConfiguration.DEFAULT_RM_ADDRESS; YarnConfiguration conf = new YarnConfiguration(); // HA is not enabled Text tokenService = ClientRMProxy.getRMDelegationTokenService(conf); String[] services = tokenService.toString().split(","); assertEquals(1, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } // HA is enabled conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm1"), "0.0.0.0"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm2"), "0.0.0.0"); tokenService = ClientRMProxy.getRMDelegationTokenService(conf); services = tokenService.toString().split(","); assertEquals(2, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } }
@Test public void testGetRMDelegationTokenService() { String defaultRMAddress = YarnConfiguration.DEFAULT_RM_ADDRESS; YarnConfiguration conf = new YarnConfiguration(); // HA is not enabled Text tokenService = ClientRMProxy.getRMDelegationTokenService(conf); String[] services = tokenService.toString().split(","); assertEquals(1, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } // HA is enabled conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm1"), "0.0.0.0"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm2"), "0.0.0.0"); tokenService = ClientRMProxy.getRMDelegationTokenService(conf); services = tokenService.toString().split(","); assertEquals(2, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } }
@Test public void testGetRMDelegationTokenService() { String defaultRMAddress = YarnConfiguration.DEFAULT_RM_ADDRESS; YarnConfiguration conf = new YarnConfiguration(); // HA is not enabled Text tokenService = ClientRMProxy.getRMDelegationTokenService(conf); String[] services = tokenService.toString().split(","); assertEquals(1, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } // HA is enabled conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm1"), "0.0.0.0"); conf.set(HAUtil.addSuffix(YarnConfiguration.RM_HOSTNAME, "rm2"), "0.0.0.0"); tokenService = ClientRMProxy.getRMDelegationTokenService(conf); services = tokenService.toString().split(","); assertEquals(2, services.length); for (String service : services) { assertTrue("Incorrect token service name", service.contains(defaultRMAddress)); } }
/** * Add an RM_DELEGATION_TOKEN to the {@link Credentials} provided. * * @param credentials the credentials object which is updated * @param config launcher AM configuration * @param props properties for getting credential token or certificate * @param context workflow context * @throws Exception thrown if failed */ @Override public void updateCredentials(Credentials credentials, Configuration config, CredentialsProperties props, ActionExecutor.Context context) throws Exception { Text rmDelegationTokenService = ClientRMProxy.getRMDelegationTokenService(config); if (rmDelegationTokenService == null) { throw new CredentialException(ErrorCode.E0512, "Can't create RMDelegationTokenService"); } try (YarnClient yarnClient = Services.get().get(HadoopAccessorService.class) .createYarnClient(context.getWorkflow().getUser(), config)) { org.apache.hadoop.yarn.api.records.Token rmDelegationToken = yarnClient.getRMDelegationToken(new Text(new HadoopTokenHelper().getServerPrincipal(config))); if (rmDelegationToken == null) { throw new CredentialException(ErrorCode.E0512, "Returned token is null"); } Token<TokenIdentifier> rmToken = ConverterUtils.convertFromYarn(rmDelegationToken, rmDelegationTokenService); credentials.addToken(rmDelegationTokenService, rmToken); } catch (Exception e) { XLog.getLog(getClass()).debug("Exception in updateCredentials", e); throw e; } }
/** * Add an RM_DELEGATION_TOKEN to the {@link Credentials} provided. * * @param credentials the credentials object which is updated * @param config launcher AM configuration * @param props properties for getting credential token or certificate * @param context workflow context * @throws Exception thrown if failed */ @Override public void updateCredentials(Credentials credentials, Configuration config, CredentialsProperties props, ActionExecutor.Context context) throws Exception { Text rmDelegationTokenService = ClientRMProxy.getRMDelegationTokenService(config); if (rmDelegationTokenService == null) { throw new CredentialException(ErrorCode.E0512, "Can't create RMDelegationTokenService"); } try (YarnClient yarnClient = Services.get().get(HadoopAccessorService.class) .createYarnClient(context.getWorkflow().getUser(), config)) { org.apache.hadoop.yarn.api.records.Token rmDelegationToken = yarnClient.getRMDelegationToken(new Text(new HadoopTokenHelper().getServerPrincipal(config))); if (rmDelegationToken == null) { throw new CredentialException(ErrorCode.E0512, "Returned token is null"); } Token<TokenIdentifier> rmToken = ConverterUtils.convertFromYarn(rmDelegationToken, rmDelegationTokenService); credentials.addToken(rmDelegationTokenService, rmToken); } catch (Exception e) { XLog.getLog(getClass()).debug("Exception in updateCredentials", e); throw e; } }