List of usage examples for org.apache.hadoop.yarn.api.records ApplicationAttemptReport getApplicationAttemptId
@Public @Unstable public abstract ApplicationAttemptId getApplicationAttemptId();
ApplicationAttemptId
of this attempt of the application From source file:UnmanagedAMLauncher.java
License:Apache License
public boolean run() throws IOException, YarnException { LOG.info("Starting Client"); // Connect to ResourceManager rmClient.start();/*from w w w . j a va 2 s.c o m*/ try { // Create launch context for app master LOG.info("Setting up application submission context for ASM"); ApplicationSubmissionContext appContext = rmClient.createApplication() .getApplicationSubmissionContext(); ApplicationId appId = appContext.getApplicationId(); // set the application name appContext.setApplicationName(appName); // Set the priority for the application master Priority pri = Records.newRecord(Priority.class); pri.setPriority(amPriority); appContext.setPriority(pri); // Set the queue to which this application is to be submitted in the RM appContext.setQueue(amQueue); // Set up the container launch context for the application master ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class); appContext.setAMContainerSpec(amContainer); // unmanaged AM appContext.setUnmanagedAM(true); LOG.info("Setting unmanaged AM"); // Submit the application to the applications manager LOG.info("Submitting application to ASM"); rmClient.submitApplication(appContext); ApplicationReport appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED, YarnApplicationState.KILLED, YarnApplicationState.FAILED, YarnApplicationState.FINISHED)); if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) { // Monitor the application attempt to wait for launch state ApplicationAttemptReport attemptReport = monitorCurrentAppAttempt(appId, YarnApplicationAttemptState.LAUNCHED); ApplicationAttemptId attemptId = attemptReport.getApplicationAttemptId(); LOG.info("Launching AM with application attempt id " + attemptId); // launch AM launchAM(attemptId); // Monitor the application for end state appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FAILED, YarnApplicationState.FINISHED)); } YarnApplicationState appState = appReport.getYarnApplicationState(); FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus(); LOG.info("App ended with state: " + appReport.getYarnApplicationState() + " and status: " + appStatus); boolean success; if (YarnApplicationState.FINISHED == appState && FinalApplicationStatus.SUCCEEDED == appStatus) { LOG.info("Application has completed successfully."); success = true; } else { LOG.info("Application did finished unsuccessfully." + " YarnState=" + appState.toString() + ", FinalStatus=" + appStatus.toString()); success = false; } return success; } finally { rmClient.stop(); } }
From source file:io.hops.hopsworks.common.admin.llap.LlapClusterFacade.java
License:Open Source License
public List<String> getLlapHosts() { ArrayList<String> hosts = new ArrayList<>(); if (!isClusterUp() || isClusterStarting()) { return hosts; }/*from w w w .j a v a2 s. co m*/ // The cluster is app, so the appId exists String llapAppID = variablesFacade.getVariableValue(Settings.VARIABLE_LLAP_APP_ID); ApplicationId appId = ApplicationId.fromString(llapAppID); YarnClient yarnClient = yarnClientService.getYarnClientSuper(settings.getConfiguration()).getYarnClient(); try { List<ApplicationAttemptReport> attempts = yarnClient.getApplicationAttempts(appId); ApplicationAttemptReport current = null; for (ApplicationAttemptReport attempt : attempts) { // Only if the app is running the metrics are available if (attempt.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) { current = attempt; break; } } if (current == null) { return hosts; } List<ContainerReport> containerReports = yarnClient.getContainers(current.getApplicationAttemptId()); // For all the new/running containers, which are not the application master, get the host for (ContainerReport containerReport : containerReports) { // Only if the container is running the metrics are available if (containerReport.getContainerState() == ContainerState.RUNNING && !containerReport.getContainerId().equals(current.getAMContainerId())) { hosts.add(containerReport.getAssignedNode().getHost()); } } } catch (IOException | YarnException ex) { logger.log(Level.SEVERE, "Couldn't retrieve the containers for LLAP cluster", ex); } finally { try { yarnClient.close(); } catch (IOException ex) { } } return hosts; }
From source file:org.apache.samza.validation.TestYarnJobValidationTool.java
License:Apache License
@Test public void testValidateRunningAttemptId() throws Exception { ApplicationReport appReport = mock(ApplicationReport.class); when(client.getApplicationReport(appId)).thenReturn(appReport); when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId); ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class); when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING); when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId); when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport); assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId)); when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED); exception.expect(SamzaException.class); tool.validateRunningAttemptId(appId); }