List of usage examples for org.apache.hadoop.yarn.api.records FinalApplicationStatus SUCCEEDED
FinalApplicationStatus SUCCEEDED
To view the source code for org.apache.hadoop.yarn.api.records FinalApplicationStatus SUCCEEDED.
Click Source Link
From source file:com.tito.easyyarn.appmaster.ApplicationMaster.java
License:Apache License
@VisibleForTesting protected boolean finish() { // wait for completion. LOG.info("(!done " + (!done)); LOG.info("!hasCompleted()" + (!hasCompleted())); while (!done && !hasCompleted()) { try {/*from w w w . j av a2 s . co m*/ if (currentPhase == null) { if (!pendingPhases.isEmpty()) { currentPhase = pendingPhases.poll(); currentPhase.setPassedArguments(passedArguments); Thread phaseThread = new Thread(currentPhase); phaseThreads.add(phaseThread); LOG.info("Starting First Phase:" + currentPhase.getId()); phaseThread.start(); } else { LOG.error("NO Phases Registered , aborting phase execution"); done = true; } continue; } PhaseStatus currentPhaseStatus = currentPhase.getPhaseStatus(); if (currentPhaseStatus != null && currentPhaseStatus != PhaseStatus.RUNNING && currentPhaseStatus != PhaseStatus.PENDING) { LOG.info("currentPhase.getPhaseStatus()" + currentPhaseStatus); if (currentPhaseStatus == PhaseStatus.SUCCESSED) { LOG.info("Phase Completed successfully : " + currentPhase.getId()); completedPhases.add(currentPhase); // check to see if any pending phases start them if (pendingPhases.isEmpty()) { LOG.info("No More Phases remaining"); done = true; } if (!pendingPhases.isEmpty()) { currentPhase = pendingPhases.poll(); currentPhase.setPassedArguments(passedArguments); Thread phaseThread = new Thread(currentPhase); phaseThreads.add(phaseThread); phaseThread.start(); } } // phase failed else { failedPhases.add(currentPhase); done = true; } } Thread.sleep(1000); } catch (InterruptedException ex) { } } // Join all launched threads // needed for when we time out // and we need to release containers for (Thread phaseThread : phaseThreads) { try { phaseThread.join(10000); } catch (InterruptedException e) { LOG.info("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(); } } // When the application completes, it should stop all running containers LOG.info("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application // signal to the RM LOG.info("Application completed. Signalling finish to RM"); FinalApplicationStatus appStatus; String appMessage = null; boolean success = true; LOG.info("hasCompletedSuccessfully():" + hasCompletedSuccessfully()); LOG.info("completedPhases.size():" + completedPhases.size()); LOG.info("phaseList.size():" + phaseList.size()); LOG.info("+failedPhases.size():" + failedPhases.size()); if (hasCompletedSuccessfully()) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total Phases=" + phaseList.size() + ", completed=" + completedPhases.size() + ", failed=" + failedPhases.size(); success = false; } try { amRMClient.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException ex) { LOG.error("Failed to unregister application", ex); } catch (IOException e) { LOG.error("Failed to unregister application", e); } amRMClient.stop(); return success; }
From source file:com.toy.TOYMaster.java
License:Apache License
void run() throws Exception { LOG.info("============== TOYMaster.run() ================="); final AMRMClientAsync.CallbackHandler allocListener = new RMCallbackHandler(); amRMClient = AMRMClientAsync.createAMRMClientAsync(1000, allocListener); amRMClient.init(configuration);// w w w . ja v a 2 s. c o m amRMClient.start(); nmClientAsync = new NMClientAsyncImpl(nodeManagerListener); nmClientAsync.init(configuration); nmClientAsync.start(); // Register self with ResourceManager this will start heartbeating to the RM RegisterApplicationMasterResponse response = amRMClient.registerApplicationMaster(NetUtils.getHostname(), -1, ""); LOG.info("============== TOYMaster registered ! ================="); for (int i = 0; i < requestedContainers.get(); i++) { amRMClient.addContainerRequest(newTomcatContainer()); } // Ok, just wait for the shutdown order... latch.await(); // Shutdown order received, stop Zookeeper queue consumer if (ordersQueue != null) ordersQueue.close(); // Close Zookeeper connection try { zookeeper.close(); } catch (Exception e) { LOG.error("Error while closing Zookeeper connection", e); } // Clean HDFS clean(); // Let say that everyting is ok amRMClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, "All done", null); // When the application completes, it should stop all running containers LOG.info("Application completed. Stopping running containers"); nmClientAsync.stop(); // bye LOG.info("============== TOYMaster BYE ! ================="); amRMClient.close(); }
From source file:com.yahoo.storm.yarn.MasterServer.java
License:Open Source License
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { LOG.info("Starting the AM!!!!"); Options opts = new Options(); opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used " + "unless for testing purposes"); CommandLine cl = new GnuParser().parse(opts, args); ApplicationAttemptId appAttemptID;// ww w . j a v a2 s. c o m Map<String, String> envs = System.getenv(); if (cl.hasOption("app_attempt_id")) { String appIdStr = cl.getOptionValue("app_attempt_id", ""); appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr); } else if (envs.containsKey(ApplicationConstants.Environment.CONTAINER_ID.name())) { ContainerId containerId = ConverterUtils .toContainerId(envs.get(ApplicationConstants.Environment.CONTAINER_ID.name())); appAttemptID = containerId.getApplicationAttemptId(); LOG.info("appAttemptID from env:" + appAttemptID.toString()); } else { LOG.error("appAttemptID is not specified for storm master"); throw new Exception("appAttemptID is not specified for storm master"); } @SuppressWarnings("rawtypes") Map storm_conf = Config.readStormConfig(null); Util.rmNulls(storm_conf); YarnConfiguration hadoopConf = new YarnConfiguration(); final String host = InetAddress.getLocalHost().getHostName(); storm_conf.put("nimbus.host", host); StormAMRMClient rmClient = new StormAMRMClient(appAttemptID, storm_conf, hadoopConf); rmClient.init(hadoopConf); rmClient.start(); BlockingQueue<Container> launcherQueue = new LinkedBlockingQueue<Container>(); MasterServer server = new MasterServer(storm_conf, rmClient); try { final int port = Utils.getInt(storm_conf.get(Config.MASTER_THRIFT_PORT)); final String target = host + ":" + port; InetSocketAddress addr = NetUtils.createSocketAddr(target); RegisterApplicationMasterResponse resp = rmClient.registerApplicationMaster(addr.getHostName(), port, null); LOG.info("Got a registration response " + resp); LOG.info("Max Capability " + resp.getMaximumResourceCapability()); rmClient.setMaxResource(resp.getMaximumResourceCapability()); LOG.info("Starting HB thread"); server.initAndStartHeartbeat(rmClient, launcherQueue, (Integer) storm_conf.get(Config.MASTER_HEARTBEAT_INTERVAL_MILLIS)); LOG.info("Starting launcher"); initAndStartLauncher(rmClient, launcherQueue); rmClient.startAllSupervisors(); LOG.info("Starting Master Thrift Server"); server.serve(); LOG.info("StormAMRMClient::unregisterApplicationMaster"); rmClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, "AllDone", null); } finally { if (server.isServing()) { LOG.info("Stop Master Thrift Server"); server.stop(); } LOG.info("Stop RM client"); rmClient.stop(); } System.exit(0); }
From source file:com.yahoo.storm.yarn.StormOnYarn.java
License:Open Source License
/** * Wait until the application is successfully launched * @throws YarnException//from w w w . j a v a2 s . com */ public boolean waitUntilLaunched() 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 = _yarn.getApplicationReport(_appId); 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; } //announce application master's host and port if (state == YarnApplicationState.RUNNING) { return true; } } }
From source file:com.zqh.hadoop.moya.core.yarn.ApplicationMaster.java
License:Apache License
private void finish() { // Join all launched threads // needed for when we time out // and we need to release containers for (Thread launchThread : launchThreads) { try {/*w w w . j av a 2s . c o m*/ launchThread.join(10000); } catch (InterruptedException e) { LOG.info("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(); } } // When the application completes, it should stop all running containers LOG.info("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application // signal to the RM LOG.info("Application completed. Signalling finish to RM"); //TODO Remove MOYA NODE try { DeleteGroup.main(new String[] { ZKHosts, "moya" }); } catch (Exception e1) { e1.printStackTrace(); } FinalApplicationStatus appStatus; String appMessage = null; success = true; if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed=" + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed=" + numFailedContainers.get(); success = false; } try { resourceManager.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException ex) { LOG.error("Failed to unregister application", ex); } catch (IOException e) { LOG.error("Failed to unregister application", e); } done = true; resourceManager.stop(); }
From source file:com.zqh.hadoop.moya.core.yarn.Client.java
License:Apache License
/** * Monitor the submitted application for completion. Kill application if * time expires./*from ww w. j av a2 s .co m*/ * * @param appId * Application Id of application to be monitored * @return true if application completed successfully * @throws org.apache.hadoop.yarn.exceptions.YarnException * @throws java.io.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; } } }
From source file:de.huberlin.wbi.hiway.am.HiWay.java
License:Apache License
private void finish() { writeEntryToLog(new JsonReportEntry(getRunId(), null, null, null, null, null, HiwayDBI.KEY_WF_TIME, Long.toString(System.currentTimeMillis() - amRMClient.getStartTime()))); Collection<Data> outputFiles = getOutputFiles(); if (outputFiles.size() > 0) { String outputs = getOutputFiles().toString(); writeEntryToLog(new JsonReportEntry(getRunId(), null, null, null, null, null, HiwayDBI.KEY_WF_OUTPUT, outputs.substring(1, outputs.length() - 1))); }/*ww w . j a v a2s. c o m*/ // Join all launched threads needed for when we time out and we need to release containers for (Thread launchThread : launchThreads) { try { launchThread.join(10000); } catch (InterruptedException e) { System.err.println("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(); System.exit(-1); } } // When the application completes, it should stop all running containers System.out.println("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application signal to the RM System.out.println("Application completed. Signalling finish to RM"); FinalApplicationStatus appStatus; String appMessage = null; success = true; System.out.println("Failed Containers: " + numFailedContainers.get()); System.out.println("Completed Containers: " + numCompletedContainers.get()); int numTotalContainers = scheduler.getNumberOfTotalTasks(); System.out.println("Total Scheduled Containers: " + numTotalContainers); if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed=" + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed=" + numFailedContainers.get() + ", killed=" + numKilledContainers.get(); success = false; } try { statLog.close(); federatedReport.stageOut(); if (summaryPath != null) { String stdout = hdfsApplicationDirectory + "/AppMaster.stdout"; String stderr = hdfsApplicationDirectory + "/AppMaster.stderr"; String statlog = hdfsApplicationDirectory + "/" + appId + ".log"; try (BufferedWriter writer = new BufferedWriter(new FileWriter(summaryPath.toString()))) { Collection<String> output = new ArrayList<>(); for (Data outputFile : getOutputFiles()) { output.add(outputFile.getHdfsPath().toString()); } JSONObject obj = new JSONObject(); try { obj.put("output", output); obj.put("stdout", stdout); obj.put("stderr", stderr); obj.put("statlog", statlog); } catch (JSONException e) { e.printStackTrace(); System.exit(-1); } writer.write(obj.toString()); } new Data("AppMaster.stdout").stageOut(); new Data("AppMaster.stderr").stageOut(); new Data(summaryPath).stageOut(); } } catch (IOException e) { System.err.println("Error when attempting to stage out federated output log."); e.printStackTrace(); System.exit(-1); } try { amRMClient.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException | IOException e) { System.err.println("Failed to unregister application"); e.printStackTrace(); System.exit(-1); } amRMClient.stop(); }
From source file:de.huberlin.wbi.hiway.am.WorkflowDriver.java
License:Apache License
protected void finish() { /* log */ logger.writeEntryToLog(new JsonReportEntry(getRunId(), null, null, null, null, null, HiwayDBI.KEY_WF_TIME, Long.toString(System.currentTimeMillis() - amRMClient.getStartTime()))); // Join all launched threads needed for when we time out and we need to release containers for (Thread launchThread : launchThreads) { try {//from www.j av a 2 s . c om launchThread.join(10000); } catch (InterruptedException e) { Logger.writeToStdout("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(System.out); System.exit(-1); } } // When the application completes, it should stop all running containers Logger.writeToStdout("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application signal to the RM Logger.writeToStdout("Application completed. Signalling finish to RM"); FinalApplicationStatus appStatus; String appMessage = null; success = true; WorkflowDriver.Logger.writeToStdout("Failed Containers: " + logger.numFailedContainers.get()); WorkflowDriver.Logger.writeToStdout("Completed Containers: " + logger.numCompletedContainers.get()); int numTotalContainers = scheduler.getNumberOfTotalTasks(); // WorkflowDriver.writeToStdout("Total Scheduled Containers: " + numTotalContainers); if (logger.getNumFailedContainers().get() == 0 && logger.getNumCompletedContainers().get() == numTotalContainers) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed=" + logger.getNumCompletedContainers().get() + ", allocated=" + logger.getNumAllocatedContainers().get() + ", failed=" + logger.getNumFailedContainers().get() + ", killed=" + logger.getNumKilledContainers().get(); success = false; } Collection<String> output = getOutput(); Collection<Data> outputFiles = getOutputFiles(); if (outputFiles.size() > 0) { String outputs = outputFiles.toString(); logger.writeEntryToLog(new JsonReportEntry(getRunId(), null, null, null, null, null, HiwayDBI.KEY_WF_OUTPUT, outputs.substring(1, outputs.length() - 1))); } try { logger.statLog.close(); logger.federatedReport.stageOut(); if (summaryPath != null) { String stdout = hdfsApplicationDirectory + "/AppMaster.stdout"; String stderr = hdfsApplicationDirectory + "/AppMaster.stderr"; String statlog = hdfsApplicationDirectory + "/" + appId + ".log"; try (BufferedWriter writer = new BufferedWriter(new FileWriter(summaryPath.toString()))) { JSONObject obj = new JSONObject(); try { obj.put("output", output); obj.put("stdout", stdout); obj.put("stderr", stderr); obj.put("statlog", statlog); } catch (JSONException e) { e.printStackTrace(System.out); System.exit(-1); } writer.write(obj.toString()); } new Data("AppMaster.stdout").stageOut(); new Data("AppMaster.stderr").stageOut(); new Data(summaryPath).stageOut(); } } catch (IOException e) { Logger.writeToStdout("Error when attempting to stage out federated output log."); e.printStackTrace(System.out); System.exit(-1); } try { amRMClient.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException | IOException e) { Logger.writeToStdout("Failed to unregister application"); e.printStackTrace(System.out); System.exit(-1); } amRMClient.stop(); if (timelineClient != null) timelineClient.stop(); }
From source file:de.huberlin.wbi.hiway.common.Client.java
License:Apache License
/** * Monitor the submitted application for completion. Kill application if time expires. * // ww w . j a v a 2 s. c o m * @param appId * Application Id of application to be monitored * @return true if application completed successfully */ private boolean monitorApplication(ApplicationId appId) throws YarnException, IOException { while (true) { // Check app status every 1 second. try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Thread sleep in monitoring run interrupted"); } // Get application report for the appId we are interested in ApplicationReport report = yarnClient.getApplicationReport(appId); 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 run"); System.out.println(report.getDiagnostics()); return true; } System.out.println("Application finished unsuccessfully." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring run"); return false; } else if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) { System.out.println("Application did not finish." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring run"); return false; } if (System.currentTimeMillis() > (clientStartTime + clientTimeout)) { System.out.println("Reached client specified timeout for application. Killing application"); forceKillApplication(appId); return false; } } }
From source file:edu.cmu.graphchi.toolkits.collaborative_filtering.yarn.ApplicationMaster.java
License:Apache License
private void finish() { // Join all launched threads // needed for when we time out // and we need to release containers for (Thread launchThread : launchThreads) { try {//w ww . j a v a 2 s. com launchThread.join(10000); } catch (InterruptedException e) { LOG.info("Exception thrown in thread join: " + e.getMessage()); e.printStackTrace(); } } // When the application completes, it should stop all running containers LOG.info("Application completed. Stopping running containers"); nmClientAsync.stop(); // When the application completes, it should send a finish application // signal to the RM LOG.info("Application completed. Signalling finish to RM"); FinalApplicationStatus appStatus; String appMessage = null; success = true; if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) { appStatus = FinalApplicationStatus.SUCCEEDED; } else { appStatus = FinalApplicationStatus.FAILED; appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed=" + numCompletedContainers.get() + ", failed=" + numFailedContainers.get(); success = false; } try { amRMClient.unregisterApplicationMaster(appStatus, appMessage, null); } catch (YarnException ex) { LOG.error("Failed to unregister application", ex); } catch (IOException e) { LOG.error("Failed to unregister application", e); } amRMClient.stop(); }