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.springframework.cloud.dataflow.yarn.buildtests.AbstractCliBootYarnClusterTests.java
License:Apache License
protected ApplicationInfo waitState(ApplicationId applicationId, long timeout, TimeUnit unit, YarnApplicationState... applicationStates) throws Exception { YarnApplicationState state = null;//from w ww . jav a 2s .c o m ApplicationReport report = null; long end = System.currentTimeMillis() + unit.toMillis(timeout); // break label for inner loop done: do { report = findApplicationReport(getYarnClient(), applicationId); if (report == null) { break; } state = report.getYarnApplicationState(); for (YarnApplicationState stateCheck : applicationStates) { if (state.equals(stateCheck)) { break done; } } Thread.sleep(1000); } while (System.currentTimeMillis() < end); return new ApplicationInfo(applicationId, report); }
From source file:org.springframework.cloud.deployer.spi.yarn.YarnCloudAppServiceApplication.java
License:Apache License
public Collection<CloudAppInstanceInfo> getSubmittedApplications(String yarnApplicationId) { List<CloudAppInstanceInfo> appIds = new ArrayList<CloudAppInstanceInfo>(); for (ApplicationReport report : yarnClient.listApplications("DATAFLOW")) { if (report.getApplicationId().toString().equals(yarnApplicationId)) { appIds.add(new CloudAppInstanceInfo(report.getApplicationId().toString(), report.getName(), report.getYarnApplicationState().toString(), report.getOriginalTrackingUrl())); }/* w ww . java2s. c om*/ } return appIds; }
From source file:org.springframework.yarn.boot.app.AbstractApplicationTests.java
License:Apache License
protected YarnApplicationState findState(YarnClient client, ApplicationId applicationId) { YarnApplicationState state = null;/*ww w . j a v a 2 s .c o m*/ for (ApplicationReport report : client.listApplications()) { if (report.getApplicationId().equals(applicationId)) { state = report.getYarnApplicationState(); break; } } return state; }
From source file:org.springframework.yarn.boot.app.YarnKillApplication.java
License:Apache License
public String run(String... args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(); builder.web(false);/* ww w .j a va 2s .c o m*/ builder.sources(YarnKillApplication.class, OperationProperties.class); SpringYarnBootUtils.addSources(builder, sources.toArray(new Object[0])); SpringYarnBootUtils.addProfiles(builder, profiles.toArray(new String[0])); if (StringUtils.hasText(applicationBaseDir)) { appProperties.setProperty("spring.yarn.applicationDir", applicationBaseDir + applicationVersion + "/"); } SpringYarnBootUtils.addApplicationListener(builder, appProperties); SpringApplicationTemplate template = new SpringApplicationTemplate(builder); return template.execute(new SpringApplicationCallback<String>() { @Override public String runWithSpringApplication(ApplicationContext context) throws Exception { YarnClient client = context.getBean(YarnClient.class); OperationProperties operationProperties = context.getBean(OperationProperties.class); ApplicationId applicationId = ConverterUtils .toApplicationId(operationProperties.getApplicationId()); ApplicationReport report = client.getApplicationReport(applicationId); if (report.getYarnApplicationState() == YarnApplicationState.FINISHED || report.getYarnApplicationState() == YarnApplicationState.KILLED || report.getYarnApplicationState() == YarnApplicationState.FAILED) { return "Application " + applicationId + " is not running"; } else { client.killApplication(applicationId); return "Kill request for " + applicationId + " sent"; } } }, args); }
From source file:org.springframework.yarn.client.CommandLineClientRunner.java
License:Apache License
/** * Gets the application report table.//from ww w . java2s . c om * * @param applications the applications * @return the application report table */ private static Table getApplicationReportTable(List<ApplicationReport> applications) { Table table = new Table(); table.addHeader(1, new TableHeader("Id")).addHeader(2, new TableHeader("User")) .addHeader(3, new TableHeader("Name")).addHeader(4, new TableHeader("Queue")) .addHeader(5, new TableHeader("StartTime")).addHeader(6, new TableHeader("FinishTime")) .addHeader(7, new TableHeader("State")).addHeader(8, new TableHeader("FinalStatus")); for (ApplicationReport a : applications) { final TableRow row = new TableRow(); row.addValue(1, a.getApplicationId().toString()).addValue(2, a.getUser()).addValue(3, a.getName()) .addValue(4, a.getQueue()) .addValue(5, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(a.getStartTime()))) .addValue(6, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) .format(new Date(a.getFinishTime()))) .addValue(7, a.getYarnApplicationState().toString()) .addValue(8, a.getFinalApplicationStatus().toString()); table.getRows().add(row); } return table; }
From source file:org.springframework.yarn.test.junit.AbstractYarnClusterTests.java
License:Apache License
/** * Finds the current application state./*from ww w . ja v a 2s. c om*/ * * @param client the Yarn client * @param applicationId Yarn app application id * @return Current application state or <code>NULL</code> if not found */ private YarnApplicationState findState(YarnClient client, ApplicationId applicationId) { YarnApplicationState state = null; for (ApplicationReport report : client.listApplications()) { if (report.getApplicationId().equals(applicationId)) { state = report.getYarnApplicationState(); break; } } return state; }
From source file:org.springframework.yarn.test.YarnClusterTests.java
License:Apache License
private YarnApplicationState findState(YarnClient client, ApplicationId applicationId) { YarnApplicationState state = null;//from w w w. j av a 2 s. c om for (ApplicationReport report : client.listApplications()) { if (report.getApplicationId().equals(applicationId)) { state = report.getYarnApplicationState(); break; } } return state; }
From source file:org.starschema.hadoop.yarn.applications.distributedshell.Client.java
License:Apache License
/** * Monitor the submitted application for completion. * Kill application if time expires. /*w w w. j ava2 s .c o m*/ * @param appId Application Id of application to be monitored * @return true if application completed successfully * @throws YarnException * @throws IOException */ private boolean monitorApplication(ApplicationId appId) throws YarnException, IOException { while (true) { // Check app status every 1 second. try { Thread.sleep(1000); } catch (InterruptedException e) { LOG.debug("Thread sleep in monitoring loop interrupted"); } // Get application report for the appId we are interested in ApplicationReport report = yarnClient.getApplicationReport(appId); LOG.info("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()); 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 (System.currentTimeMillis() > (clientStartTime + clientTimeout)) { // LOG.info("Reached client specified timeout for application. Killing application"); // forceKillApplication(appId); // return false; // } } }
From source file:proxyyarn.ProxyYarn.java
License:Apache License
private boolean monitorApplication(YarnClient yarnClient, ApplicationId appId) throws YarnException, IOException { long clientStartTime = System.currentTimeMillis(); while (true) { // Check app status every 1 second. try {//from w w w. ja v a 2 s. co m Thread.sleep(1000); } catch (InterruptedException e) { log.debug("Thread sleep in monitoring loop interrupted"); } // Get application report for the appId we are interested in ApplicationReport report = yarnClient.getApplicationReport(appId); log.info("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()); 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 (System.currentTimeMillis() > (clientStartTime + clientTimeout)) { log.info("Reached client specified timeout for application. Killing application"); forceKillApplication(yarnClient, appId); return false; } } }
From source file:tachyon.yarn.Client.java
License:Apache License
/** * Monitors the submitted application for completion. * * @return true if application completed successfully * @throws YarnException if errors occur when obtaining application report from ResourceManager * @throws IOException if errors occur when obtaining application report from ResourceManager */// w ww . ja v a 2s . c om private boolean monitorApplication() throws YarnException, IOException { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); while (true) { // Check app status every 10 second. CommonUtils.sleepMs(10 * Constants.SECOND_MS); Date date = new Date(); String timeDateStr = dateFormat.format(date); // Get application report for the appId we are interested in ApplicationReport report = mYarnClient.getApplicationReport(mAppId); System.out.println(timeDateStr + " Got application report from ASM for appId=" + mAppId.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()); YarnApplicationState state = report.getYarnApplicationState(); FinalApplicationStatus dsStatus = report.getFinalApplicationStatus(); if (YarnApplicationState.FINISHED == state) { if (FinalApplicationStatus.SUCCEEDED == dsStatus) { System.out.println("Application has completed successfully. Breaking monitoring loop"); return true; } System.out.println("Application did finished unsuccessfully. YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop"); return false; } if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) { System.out.println("Application did not finish. YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop"); return false; } } }