List of usage examples for org.apache.hadoop.yarn.api.records ApplicationReport getApplicationId
@Public @Stable public abstract ApplicationId getApplicationId();
ApplicationId
of the application. From source file:org.apache.slider.client.SliderClient.java
License:Apache License
/** * Convert the instance details of an application to a string * @param name instance name//from w ww . j a v a2s . c o m * @param report the application report * @param verbose verbose output * @return a string */ String instanceDetailsToString(String name, ApplicationReport report, boolean verbose) { // format strings String staticf = "%-30s"; String reportedf = staticf + " %10s %-40s"; String livef = reportedf + " %s"; StringBuilder builder = new StringBuilder(200); if (report == null) { builder.append(String.format(staticf, name)); } else { // there's a report to look at String appId = report.getApplicationId().toString(); String state = report.getYarnApplicationState().toString(); if (report.getYarnApplicationState() == YarnApplicationState.RUNNING) { // running: there's a URL builder.append(String.format(livef, name, state, appId, report.getTrackingUrl())); } else { builder.append(String.format(reportedf, name, state, appId)); } if (verbose) { builder.append('\n'); builder.append(SliderUtils.appReportToString(report, "\n ")); } } builder.append('\n'); return builder.toString(); }
From source file:org.apache.slider.client.SliderClient.java
License:Apache License
private void actionDiagnosticIntelligent(ActionDiagnosticArgs diagnosticArgs) throws YarnException, IOException, URISyntaxException { // not using member variable clustername because we want to place // application name after --application option and member variable // cluster name has to be put behind action String clusterName = diagnosticArgs.name; if (SliderUtils.isUnset(clusterName)) { throw new BadCommandArgumentsException("application name must be provided with --name option"); }/*from ww w. ja v a 2s . co m*/ try { SliderUtils.validateClientConfigFile(); log.info("Slider-client.xml is accessible"); } catch (IOException e) { // we are catching exceptions here because those are indication of // validation result, and we need to print them here log.error("validation of slider-client.xml fails because: " + e.toString(), e); return; } SliderClusterOperations clusterOperations = createClusterOperations(clusterName); // cluster not found exceptions will be thrown upstream ClusterDescription clusterDescription = clusterOperations.getClusterDescription(); log.info("Slider AppMaster is accessible"); if (clusterDescription.state == ClusterDescription.STATE_LIVE) { AggregateConf instanceDefinition = clusterOperations.getInstanceDefinition(); String imagePath = instanceDefinition.getInternalOperations() .get(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH); // if null, that means slider uploaded the agent tarball for the user // and we need to use where slider has put if (imagePath == null) { ApplicationReport appReport = findInstance(clusterName); Path path1 = sliderFileSystem.getTempPathForCluster(clusterName); Path subPath = new Path(path1, appReport.getApplicationId().toString() + "/agent"); imagePath = subPath.toString(); } try { SliderUtils.validateHDFSFile(sliderFileSystem, imagePath + "/" + AGENT_TAR); log.info("Slider agent package is properly installed"); } catch (FileNotFoundException e) { log.error("can not find agent package: " + e.toString()); return; } catch (IOException e) { log.error("can not open agent package: " + e.toString()); return; } String pkgTarballPath = instanceDefinition.getAppConfOperations().getGlobalOptions() .getMandatoryOption(AgentKeys.APP_DEF); try { SliderUtils.validateHDFSFile(sliderFileSystem, pkgTarballPath); log.info("Application package is properly installed"); } catch (FileNotFoundException e) { log.error("can not find application package: {}", e); return; } catch (IOException e) { log.error("can not open application package: {} ", e); return; } } }
From source file:org.apache.slider.client.SliderClient.java
License:Apache License
private void actionDiagnosticSlider(ActionDiagnosticArgs diagnosticArgs) throws YarnException, IOException { // not using member variable clustername because we want to place // application name after --application option and member variable // cluster name has to be put behind action String clusterName = diagnosticArgs.name; if (SliderUtils.isUnset(clusterName)) { throw new BadCommandArgumentsException("application name must be provided with --name option"); }/* ww w . j a va 2 s . co m*/ SliderClusterOperations clusterOperations; AggregateConf instanceDefinition = null; try { clusterOperations = createClusterOperations(clusterName); instanceDefinition = clusterOperations.getInstanceDefinition(); } catch (YarnException e) { log.error("Exception happened when retrieving instance definition from YARN: " + e.toString()); throw e; } catch (IOException e) { log.error("Network problem happened when retrieving instance definition from YARN: " + e.toString()); throw e; } String imagePath = instanceDefinition.getInternalOperations() .get(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH); // if null, it will be uploaded by Slider and thus at slider's path if (imagePath == null) { ApplicationReport appReport = findInstance(clusterName); Path path1 = sliderFileSystem.getTempPathForCluster(clusterName); Path subPath = new Path(path1, appReport.getApplicationId().toString() + "/agent"); imagePath = subPath.toString(); } log.info("The path of slider agent tarball on HDFS is: " + imagePath); }
From source file:org.apache.slider.client.SliderYarnClientImpl.java
License:Apache License
/** * Force kill a yarn application by ID. No niceities here *///w ww. java2 s.com public void emergencyForceKill(String applicationId) throws YarnException, IOException { if ("all".equals(applicationId)) { // user wants all instances killed String user = getUsername(); log.info("Killing all applications belonging to {}", user); Collection<ApplicationReport> instances = listInstances(user); for (ApplicationReport instance : instances) { if (isApplicationLive(instance)) { ApplicationId appId = instance.getApplicationId(); log.info("Killing Application {}", appId); killRunningApplication(appId, "forced kill"); } } } else { ApplicationId appId = ConverterUtils.toApplicationId(applicationId); log.info("Killing Application {}", applicationId); killRunningApplication(appId, "forced kill"); } }
From source file:org.apache.slider.client.SliderYarnClientImpl.java
License:Apache License
/** * Find an app in the instance list in the desired state * @param instances instance list// w w w .java 2 s .com * @param appname application name * @param desiredState yarn state desired * @return the match or null for none */ public ApplicationReport findAppInInstanceList(List<ApplicationReport> instances, String appname, YarnApplicationState desiredState) { ApplicationReport found = null; ApplicationReport foundAndLive = null; log.debug("Searching {} records for instance name {} in state '{}'", instances.size(), appname, desiredState); for (ApplicationReport app : instances) { if (app.getName().equals(appname)) { YarnApplicationState appstate = app.getYarnApplicationState(); log.debug("app ID {} is in state {}", app.getApplicationId(), appstate); if (appstate.equals(desiredState)) { log.debug("match"); return app; } } } // nothing found in desired state log.debug("No match"); return null; }
From source file:org.apache.slider.common.tools.SliderUtils.java
License:Apache License
/** * convert an AM report to a string for diagnostics * @param report the report//ww w .j ava2 s. 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() + " URL" + report.getOriginalTrackingUrl(); }
From source file:org.apache.slider.core.launch.LaunchedApplication.java
License:Apache License
public LaunchedApplication(SliderYarnClientImpl yarnClient, ApplicationReport report) { this.yarnClient = yarnClient; this.applicationId = report.getApplicationId(); }
From source file:org.apache.slider.core.launch.SerializedApplicationReport.java
License:Apache License
public SerializedApplicationReport(ApplicationReport report) { this.applicationId = report.getApplicationId().toString(); this.applicationAttemptId = report.getCurrentApplicationAttemptId().toString(); this.name = report.getName(); this.applicationType = report.getApplicationType(); this.user = report.getUser(); this.queue = report.getQueue(); this.host = report.getHost(); this.rpcPort = report.getRpcPort(); this.state = report.getYarnApplicationState().toString(); this.diagnostics = report.getDiagnostics(); this.startTime = report.getStartTime(); this.finishTime = report.getFinishTime(); this.finalStatus = report.getFinalApplicationStatus().toString(); this.progress = report.getProgress(); }
From source file:org.apache.slider.server.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 o m*/ * @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 Slider-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 SliderClusterProtocol 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.elasticsearch.hadoop.yarn.cli.YarnBootstrap.java
License:Apache License
private void stop() { ClientRpc client = new ClientRpc(getConf()); client.start();//from w w w .j ava2 s . c o m try { List<ApplicationReport> esApps = client.listEsClustersAlive(); for (ApplicationReport report : esApps) { System.out.println( String.format("Stopping Elasticsearch-YARN Cluster with id %s", report.getApplicationId())); } List<ApplicationReport> apps = client.killEsApps(); for (ApplicationReport report : apps) { System.out.println( String.format("Stopped Elasticsearch-YARN cluster with id %s", report.getApplicationId())); } } finally { client.close(); } }