@Override protected void startUp() throws Exception { LOGGER.info("Starting the YarnService"); // Register itself with the EventBus for container-related requests this.eventBus.register(this); this.amrmClientAsync.start(); this.nmClientAsync.start(); // The ApplicationMaster registration response is used to determine the maximum resource capacity of the cluster RegisterApplicationMasterResponse response = this.amrmClientAsync.registerApplicationMaster( GobblinClusterUtils.getHostname(), -1, ""); LOGGER.info("ApplicationMaster registration response: " + response); this.maxResourceCapacity = Optional.of(response.getMaximumResourceCapability()); LOGGER.info("Requesting initial containers"); requestInitialContainers(this.initialContainers); }
jstormMasterContext.maxMemory = response.getMaximumResourceCapability().getMemory(); LOG.info("Max mem capability of resources in this cluster " + jstormMasterContext.maxMemory); jstormMasterContext.maxVcores = response.getMaximumResourceCapability().getVirtualCores(); LOG.info("Max vcores capability of resources in this cluster " + jstormMasterContext.maxVcores); response.getContainersFromPreviousAttempts(); LOG.info(jstormMasterContext.appAttemptID + " received " + previousAMRunningContainers.size() + " previous attempts' running containers on AM registration.");
private void yarnReport() { RegisterApplicationMasterResponse response = yarn.getRegistrationResponse(); LOG.info("YARN queue: " + response.getQueue()); Resource resource = response.getMaximumResourceCapability(); LOG.info("YARN max resource: " + resource.getMemory() + " MB, " + resource.getVirtualCores() + " cores"); EnumSet<SchedulerResourceTypes> types = response .getSchedulerResourceTypes(); StringBuilder buf = new StringBuilder(); String sep = ""; for (SchedulerResourceTypes type : types) { buf.append(sep); buf.append(type.toString()); sep = ", "; } LOG.info("YARN scheduler resource types: " + buf.toString()); }
@Private @Unstable public static RegisterApplicationMasterResponse newInstance( Resource minCapability, Resource maxCapability, Map<ApplicationAccessType, String> acls, ByteBuffer key, List<Container> containersFromPreviousAttempt, String queue, List<NMToken> nmTokensFromPreviousAttempts) { RegisterApplicationMasterResponse response = Records.newRecord(RegisterApplicationMasterResponse.class); response.setMaximumResourceCapability(maxCapability); response.setApplicationACLs(acls); response.setClientToAMTokenMasterKey(key); response.setContainersFromPreviousAttempts(containersFromPreviousAttempt); response.setNMTokensFromPreviousAttempts(nmTokensFromPreviousAttempts); response.setQueue(queue); return response; }
@Override public void start() { try { RegisterApplicationMasterResponse response; synchronized (this) { amRmClient.start(); response = amRmClient.registerApplicationMaster(appHostName, appHostPort, appTrackingUrl); } // upcall to app outside locks getContext().setApplicationRegistrationData( response.getMaximumResourceCapability(), response.getApplicationACLs(), response.getClientToAMTokenMasterKey(), response.getQueue()); delayedContainerManager.start(); } catch (YarnException e) { LOG.error("Yarn Exception while registering", e); throw new TezUncheckedException(e); } catch (IOException e) { LOG.error("IO Exception while registering", e); throw new TezUncheckedException(e); } }
appMasterRpcPort, appMasterTrackingUrl); maximumResourceCapability = amRegistrationData.getMaximumResourceCapability(); amRegistrationData.getClientToAMTokenMasterKey().array()); applicationACLs = amRegistrationData.getApplicationACLs(); liveContainers = amRegistrationData.getContainersFromPreviousAttempts();
"ApplicationMasterService", app.getApplicationId(), applicationAttemptId); response.setMaximumResourceCapability(getScheduler() .getMaximumResourceCapability(app.getQueue())); response.setApplicationACLs(app.getRMAppAttempt(applicationAttemptId) .getSubmissionContext().getAMContainerSpec().getApplicationACLs()); response.setQueue(app.getQueue()); if (UserGroupInformation.isSecurityEnabled()) { LOG.info("Setting client token master key"); response.setClientToAMTokenMasterKey(java.nio.ByteBuffer.wrap( getRmContext().getClientToAMTokenSecretManager() .getMasterKey(applicationAttemptId).getEncoded())); .getTransferredContainers(applicationAttemptId); if (!transferredContainers.isEmpty()) { response.setContainersFromPreviousAttempts(transferredContainers); response.setNMTokensFromPreviousAttempts(nmTokens); LOG.info("Application " + app.getApplicationId() + " retrieved " + transferredContainers.size() + " containers from previous" response.setSchedulerResourceTypes(getScheduler() .getSchedulingResourceTypes()); response.setResourceTypes(ResourceUtils.getResourcesTypeInfo()); if (getRmContext().getYarnConfiguration().getBoolean( YarnConfiguration.RM_RESOURCE_PROFILES_ENABLED, YarnConfiguration.DEFAULT_RM_RESOURCE_PROFILES_ENABLED)) { response.setResourceProfiles( resourceProfilesManager.getResourceProfiles());
.registerApplicationMaster(appMasterHostname, appMasterRpcPort, appMasterTrackingUrl, placementConstraintMap); resourceProfiles = response.getResourceProfiles(); ResourceUtils.reinitializeResources(response.getResourceTypes()); long maxMem = response.getMaximumResourceCapability().getMemorySize(); LOG.info("Max mem capability of resources in this cluster " + maxMem); int maxVCores = response.getMaximumResourceCapability().getVirtualCores(); LOG.info("Max vcores capability of resources in this cluster " + maxVCores); response.getContainersFromPreviousAttempts(); LOG.info(appAttemptID + " received " + previousAMRunningContainers.size() + " previous attempts' running containers on AM registration.");
private void mergeRegisterResponse( RegisterApplicationMasterResponse homeResponse, RegisterApplicationMasterResponse otherResponse) { if (!isNullOrEmpty(otherResponse.getContainersFromPreviousAttempts())) { if (!isNullOrEmpty(homeResponse.getContainersFromPreviousAttempts())) { homeResponse.getContainersFromPreviousAttempts() .addAll(otherResponse.getContainersFromPreviousAttempts()); } else { homeResponse.setContainersFromPreviousAttempts( otherResponse.getContainersFromPreviousAttempts()); } } if (!isNullOrEmpty(otherResponse.getNMTokensFromPreviousAttempts())) { if (!isNullOrEmpty(homeResponse.getNMTokensFromPreviousAttempts())) { homeResponse.getNMTokensFromPreviousAttempts() .addAll(otherResponse.getNMTokensFromPreviousAttempts()); } else { homeResponse.setNMTokensFromPreviousAttempts( otherResponse.getNMTokensFromPreviousAttempts()); } } }
@Override protected void startUp() throws Exception { Preconditions.checkNotNull(trackerAddr, "Tracker address not set."); Preconditions.checkNotNull(trackerUrl, "Tracker URL not set."); amrmClient.start(); String url = String.format("%s:%d", trackerUrl.getHost(), trackerUrl.getPort() == -1 ? trackerUrl.getDefaultPort() : trackerUrl.getPort()); RegisterApplicationMasterResponse response = amrmClient.registerApplicationMaster(trackerAddr.getHostName(), trackerAddr.getPort(), url); maxCapability = response.getMaximumResourceCapability(); minCapability = response.getMinimumResourceCapability(); }
amRegistrationResponse.getQueue(), getApplicationContext().getUser(), homeSubClusterId.getId(), amrmToken, subClusterId.toString()); && response.getContainersFromPreviousAttempts() != null) { cacheAllocatedContainers( response.getContainersFromPreviousAttempts(), subClusterId);
RegisterApplicationMasterResponse registration = entry.getValue(); if (!isNullOrEmpty(registration.getContainersFromPreviousAttempts())) { List<Container> tempContainers = homeResponse.getAllocatedContainers(); if (!isNullOrEmpty(tempContainers)) { tempContainers .addAll(registration.getContainersFromPreviousAttempts()); homeResponse.setAllocatedContainers(tempContainers); } else { homeResponse.setAllocatedContainers( registration.getContainersFromPreviousAttempts()); registration.getContainersFromPreviousAttempts(), entry.getKey()); if (!isNullOrEmpty(registration.getNMTokensFromPreviousAttempts())) { List<NMToken> tempTokens = homeResponse.getNMTokens(); if (!isNullOrEmpty(tempTokens)) { tempTokens.addAll(registration.getNMTokensFromPreviousAttempts()); homeResponse.setNMTokens(tempTokens); } else { homeResponse .setNMTokens(registration.getNMTokensFromPreviousAttempts());
/** * Initializes the list of previous containers as reported by YARN. */ private synchronized void initializeListOfPreviousContainers() { if (this.previousContainers == null) { final List<Container> yarnPrevContainers = this.registration.getRegistration().getContainersFromPreviousAttempts(); // If it's still null, create an empty list to indicate that it's not a restart. if (yarnPrevContainers == null) { this.previousContainers = Collections.unmodifiableSet(new HashSet<Container>()); } else { this.previousContainers = Collections.unmodifiableSet(new HashSet<>(yarnPrevContainers)); } yarnContainerManager.onContainersRecovered(this.previousContainers); } }
RegisterApplicationMasterResponse response = client.registerApplicationMaster(request); Assert.assertNotNull(response.getClientToAMTokenMasterKey()); if (UserGroupInformation.isSecurityEnabled()) { Assert .assertTrue(response.getClientToAMTokenMasterKey().array().length > 0); response.getApplicationACLs().get(ApplicationAccessType.VIEW_APP));
@SuppressWarnings("unchecked") private RegisterApplicationMasterResponse registerApplicationMaster() throws YarnException, IOException { RegisterApplicationMasterRequest request = RegisterApplicationMasterRequest.newInstance(this.appHostName, this.appHostPort, this.appTrackingUrl); if (!this.placementConstraints.isEmpty()) { request.setPlacementConstraints(this.placementConstraints); } RegisterApplicationMasterResponse response = rmClient.registerApplicationMaster(request); synchronized (this) { lastResponseId = 0; if (!response.getNMTokensFromPreviousAttempts().isEmpty()) { populateNMTokens(response.getNMTokensFromPreviousAttempts()); } this.resourceProfilesMap = response.getResourceProfiles(); List<Container> prevContainers = response.getContainersFromPreviousAttempts(); AMRMClientUtils.removeFromOutstandingSchedulingRequests(prevContainers, this.outstandingSchedRequests); } return response; }
ClientToAMTokenIdentifier identifier = new ClientToAMTokenIdentifier(appAttemptID, user); byte[] secret = response.getClientToAMTokenMasterKey().array(); ClientToAMTokenSecretManager secretManager = new ClientToAMTokenSecretManager(appAttemptID, secret); Token<? extends TokenIdentifier> token = new Token<>(identifier, secretManager);
private RegisterApplicationMasterResponse registerApplicationMaster() throws YarnException, IOException { RegisterApplicationMasterRequest request = RegisterApplicationMasterRequest.newInstance(this.appHostName, this.appHostPort, this.appTrackingUrl); RegisterApplicationMasterResponse response = rmClient.registerApplicationMaster(request); synchronized (this) { lastResponseId = 0; if (!response.getNMTokensFromPreviousAttempts().isEmpty()) { populateNMTokens(response.getNMTokensFromPreviousAttempts()); } } return response; }
@Override public RegisterApplicationMasterResponseInfo call() throws Exception { // Create a config loaded with federation on and subclusterId // for each UAM YarnConfiguration config = new YarnConfiguration(getConf()); FederationProxyProviderUtil.updateConfForFederation(config, subClusterId); RegisterApplicationMasterResponse uamResponse = null; Token<AMRMTokenIdentifier> token = null; try { // For appNameSuffix, use subClusterId of the home sub-cluster token = uamPool.launchUAM(subClusterId, config, attemptId.getApplicationId(), amRegistrationResponse.getQueue(), appContext.getUser(), homeSubClusterId.toString(), true, subClusterId); secondaryRelayers.put(subClusterId, uamPool.getAMRMClientRelayer(subClusterId)); uamResponse = uamPool.registerApplicationMaster(subClusterId, registerRequest); } catch (Throwable e) { LOG.error("Failed to register application master: " + subClusterId + " Application: " + attemptId, e); } return new RegisterApplicationMasterResponseInfo(uamResponse, SubClusterId.newInstance(subClusterId), token); } });
@Override public RegisterApplicationMasterResponse registerApplicationMaster( RegisterApplicationMasterRequest request) throws YarnException, IOException { RegisterApplicationMasterResponse resp = factory.newRecordInstance( RegisterApplicationMasterResponse.class); // Dummy Entry to Assert that we get this object back resp.setQueue("dummyQueue"); return resp; }
@Private @Unstable public static RegisterApplicationMasterResponse newInstance( Resource minCapability, Resource maxCapability, Map<ApplicationAccessType, String> acls, ByteBuffer key, List<Container> containersFromPreviousAttempt, String queue, List<NMToken> nmTokensFromPreviousAttempts) { RegisterApplicationMasterResponse response = Records.newRecord(RegisterApplicationMasterResponse.class); response.setMaximumResourceCapability(maxCapability); response.setApplicationACLs(acls); response.setClientToAMTokenMasterKey(key); response.setContainersFromPreviousAttempts(containersFromPreviousAttempt); response.setNMTokensFromPreviousAttempts(nmTokensFromPreviousAttempts); response.setQueue(queue); return response; }