List of usage examples for org.apache.hadoop.yarn.api.records ApplicationReport getYarnApplicationState
@Public @Stable public abstract YarnApplicationState getYarnApplicationState();
YarnApplicationState
of the application. From source file:org.apache.gobblin.yarn.YarnServiceTest.java
License:Apache License
private void startApp() throws Exception { // submit a dummy app ApplicationSubmissionContext appSubmissionContext = yarnClient.createApplication() .getApplicationSubmissionContext(); this.applicationId = appSubmissionContext.getApplicationId(); ContainerLaunchContext containerLaunchContext = BuilderUtils.newContainerLaunchContext( Collections.emptyMap(), Collections.emptyMap(), Arrays.asList("sleep", "100"), Collections.emptyMap(), null, Collections.emptyMap()); // Setup the application submission context appSubmissionContext.setApplicationName("TestApp"); appSubmissionContext.setResource(Resource.newInstance(128, 1)); appSubmissionContext.setPriority(Priority.newInstance(0)); appSubmissionContext.setAMContainerSpec(containerLaunchContext); this.yarnClient.submitApplication(appSubmissionContext); // wait for application to be accepted int i;//from w ww . j av a2 s . c om RMAppAttempt attempt = null; for (i = 0; i < 120; i++) { ApplicationReport appReport = yarnClient.getApplicationReport(applicationId); if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) { this.applicationAttemptId = appReport.getCurrentApplicationAttemptId(); attempt = yarnCluster.getResourceManager().getRMContext().getRMApps() .get(appReport.getCurrentApplicationAttemptId().getApplicationId()).getCurrentAppAttempt(); break; } Thread.sleep(1000); } Assert.assertTrue(i < 120, "timed out waiting for ACCEPTED state"); // Set the AM-RM token in the UGI for access during testing UserGroupInformation.setLoginUser( UserGroupInformation.createRemoteUser(UserGroupInformation.getCurrentUser().getUserName())); UserGroupInformation.getCurrentUser().addToken(attempt.getAMRMToken()); }
From source file:org.apache.helix.provisioning.yarn.AppLauncher.java
License:Apache License
public HelixConnection pollForConnection() { String prevReport = ""; HelixConnection connection = null;/*from w w w.j av a 2 s .c o m*/ while (true) { try { // Get application report for the appId we are interested in ApplicationReport report = yarnClient.getApplicationReport(_appId); String reportMessage = generateReport(report); if (!reportMessage.equals(prevReport)) { LOG.info(reportMessage); } YarnApplicationState state = report.getYarnApplicationState(); if (YarnApplicationState.RUNNING == state) { if (connection == null) { String hostName = null; int ind = report.getHost().indexOf('/'); if (ind > -1) { hostName = report.getHost().substring(ind + 1); } else { hostName = report.getHost(); } connection = new ZkHelixConnection(hostName + ":2181"); try { connection.connect(); } catch (Exception e) { LOG.warn("AppMaster started but not yet initialized"); connection = null; } } if (connection.isConnected()) { return connection; } } prevReport = reportMessage; Thread.sleep(10000); } catch (Exception e) { LOG.error("Exception while getting info", e); break; } } return null; }
From source file:org.apache.helix.provisioning.yarn.AppLauncher.java
License:Apache License
/** * @return true if successfully completed, it will print status every X seconds *///from www . j a v a 2 s. co m public boolean waitUntilDone() { String prevReport = ""; HelixConnection connection = null; while (true) { try { // Get application report for the appId we are interested in ApplicationReport report = yarnClient.getApplicationReport(_appId); String reportMessage = generateReport(report); if (!reportMessage.equals(prevReport)) { LOG.info(reportMessage); } YarnApplicationState state = report.getYarnApplicationState(); FinalApplicationStatus dsStatus = report.getFinalApplicationStatus(); if (YarnApplicationState.FINISHED == state) { if (FinalApplicationStatus.SUCCEEDED == dsStatus) { LOG.info("Application has completed successfully. Breaking monitoring loop"); return true; } else { LOG.info("Application did finished unsuccessfully." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop"); return false; } } else if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) { LOG.info("Application did not finish." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop"); return false; } if (YarnApplicationState.RUNNING == state) { if (connection == null) { String hostName = null; int ind = report.getHost().indexOf('/'); if (ind > -1) { hostName = report.getHost().substring(ind + 1); } else { hostName = report.getHost(); } connection = new ZkHelixConnection(hostName + ":2181"); try { connection.connect(); } catch (Exception e) { LOG.warn("AppMaster started but not yet initialized"); connection = null; } } if (connection.isConnected()) { AppStatusReportGenerator generator = new AppStatusReportGenerator(); ClusterId clusterId = ClusterId.from(_applicationSpec.getAppName()); String generateReport = generator.generateReport(connection, clusterId); LOG.info(generateReport); } } prevReport = reportMessage; Thread.sleep(10000); } catch (Exception e) { LOG.error("Exception while getting info", e); break; } } return true; }
From source file:org.apache.helix.provisioning.yarn.AppLauncher.java
License:Apache License
/** * TODO: kill the app only in dev mode. In prod, its ok for the app to continue running if the * launcher dies after launching/*from w ww .j a va2 s . c om*/ */ private String generateReport(ApplicationReport report) { return "Got application report from ASM for" + ", appId=" + _appId.getId() + ", clientToAMToken=" + report.getClientToAMToken() + ", appDiagnostics=" + report.getDiagnostics() + ", appMasterHost=" + report.getHost() + ", appQueue=" + report.getQueue() + ", appMasterRpcPort=" + report.getRpcPort() + ", appStartTime=" + report.getStartTime() + ", yarnAppState=" + report.getYarnApplicationState().toString() + ", distributedFinalState=" + report.getFinalApplicationStatus().toString() + ", appTrackingUrl=" + report.getTrackingUrl() + ", appUser=" + report.getUser(); }
From source file:org.apache.hoya.tools.HoyaUtils.java
License:Apache License
public static String appReportToString(ApplicationReport r, String separator) { StringBuilder builder = new StringBuilder(512); builder.append("application ").append(r.getName()).append("/").append(r.getApplicationType()); builder.append(separator).append("state: ").append(r.getYarnApplicationState()); builder.append(separator).append("URL: ").append(r.getTrackingUrl()); builder.append(separator).append("Started ").append(new Date(r.getStartTime()).toGMTString()); long finishTime = r.getFinishTime(); if (finishTime > 0) { builder.append(separator).append("Finished ").append(new Date(finishTime).toGMTString()); }/* www. ja v a 2s. com*/ builder.append(separator).append("RPC :").append(r.getHost()).append(':').append(r.getRpcPort()); String diagnostics = r.getDiagnostics(); if (!diagnostics.isEmpty()) { builder.append(separator).append("Diagnostics :").append(diagnostics); } return builder.toString(); }
From source file:org.apache.hoya.tools.HoyaUtils.java
License:Apache License
public static boolean hasAppFinished(ApplicationReport report) { return report == null || report.getYarnApplicationState().ordinal() >= YarnApplicationState.FINISHED.ordinal(); }
From source file:org.apache.hoya.tools.HoyaUtils.java
License:Apache License
/** * convert an AM report to a string for diagnostics * @param report the report//from ww w . j a v a 2s . c om * @return the string value */ public static String reportToString(ApplicationReport report) { if (report == null) { return "Null application report"; } return "App " + report.getName() + "/" + report.getApplicationType() + "# " + report.getApplicationId() + " user " + report.getUser() + " is in state " + report.getYarnApplicationState() + "RPC: " + report.getHost() + ":" + report.getRpcPort(); }
From source file:org.apache.hoya.yarn.appmaster.rpc.RpcBinder.java
License:Apache License
/** * This loops for a limited period trying to get the Proxy - * by doing so it handles AM failover//from w ww . j a v a 2s . c om * @param conf configuration to patch and use * @param rmClient client of the resource manager * @param application application to work with * @param connectTimeout timeout for the whole proxy operation to timeout * (milliseconds). Use 0 to indicate "do not attempt to wait" -fail fast. * @param rpcTimeout timeout for RPCs to block during communications * @return the proxy * @throws IOException IO problems * @throws YarnException Hoya-generated exceptions related to the binding * failing. This can include the application finishing or timeouts * @throws InterruptedException if a sleep operation waiting for * the cluster to respond is interrupted. */ @SuppressWarnings("NestedAssignment") public static HoyaClusterProtocol getProxy(final Configuration conf, final ApplicationClientProtocol rmClient, ApplicationReport application, final int connectTimeout, final int rpcTimeout) throws IOException, YarnException, InterruptedException { ApplicationId appId; appId = application.getApplicationId(); Duration timeout = new Duration(connectTimeout); timeout.start(); Exception exception = null; YarnApplicationState state = null; while (application != null && (state = application.getYarnApplicationState()).equals(YarnApplicationState.RUNNING)) { try { return getProxy(conf, application, rpcTimeout); } catch (IOException e) { if (connectTimeout <= 0 || timeout.getLimitExceeded()) { throw e; } exception = e; } catch (YarnException e) { if (connectTimeout <= 0 || timeout.getLimitExceeded()) { throw e; } exception = e; } //at this point: app failed to work log.debug("Could not connect to {}. Waiting for getting the latest AM address...", appId); Thread.sleep(1000); //or get the app report application = rmClient.getApplicationReport(GetApplicationReportRequest.newInstance(appId)) .getApplicationReport(); } //get here if the app is no longer running. Raise a specific //exception but init it with the previous failure throw new BadClusterStateException(exception, ErrorStrings.E_FINISHED_APPLICATION, appId, state); }
From source file:org.apache.hoya.yarn.client.HoyaClient.java
License:Apache License
/** * Wait for the launched app to be accepted * @param waittime time in millis/*w w w .ja v a 2s.com*/ * @return exit code * @throws YarnException * @throws IOException */ public int waitForAppAccepted(LaunchedApplication launchedApplication, int waittime) throws YarnException, IOException { assert launchedApplication != null; int exitCode; // wait for the submit state to be reached ApplicationReport report = launchedApplication.monitorAppToState(YarnApplicationState.ACCEPTED, new Duration(Constants.ACCEPT_TIME)); // may have failed, so check that if (HoyaUtils.hasAppFinished(report)) { exitCode = buildExitCode(report); } else { // exit unless there is a wait exitCode = EXIT_SUCCESS; if (waittime != 0) { // waiting for state to change Duration duration = new Duration(waittime * 1000); duration.start(); report = launchedApplication.monitorAppToState(YarnApplicationState.RUNNING, duration); if (report != null && report.getYarnApplicationState() == YarnApplicationState.RUNNING) { exitCode = EXIT_SUCCESS; } else { launchedApplication.kill(""); exitCode = buildExitCode(report); } } } return exitCode; }
From source file:org.apache.hoya.yarn.client.HoyaClient.java
License:Apache License
/** * Build an exit code for an application Id and its report. * If the report parameter is null, the app is killed * @param appId app/*from ww w . j a v a 2s. c o m*/ * @param report report * @return the exit code */ private int buildExitCode(ApplicationReport report) throws IOException, YarnException { if (null == report) { forceKillApplication("Reached client specified timeout for application"); return EXIT_TIMED_OUT; } YarnApplicationState state = report.getYarnApplicationState(); FinalApplicationStatus dsStatus = report.getFinalApplicationStatus(); switch (state) { case FINISHED: if (FinalApplicationStatus.SUCCEEDED == dsStatus) { log.info("Application has completed successfully"); return EXIT_SUCCESS; } else { log.info("Application finished unsuccessfully." + "YarnState = {}, DSFinalStatus = {} Breaking monitoring loop", state, dsStatus); return EXIT_YARN_SERVICE_FINISHED_WITH_ERROR; } case KILLED: log.info("Application did not finish. YarnState={}, DSFinalStatus={}", state, dsStatus); return EXIT_YARN_SERVICE_KILLED; case FAILED: log.info("Application Failed. YarnState={}, DSFinalStatus={}", state, dsStatus); return EXIT_YARN_SERVICE_FAILED; default: //not in any of these states return EXIT_SUCCESS; } }