當前位置: 首頁>>代碼示例>>Java>>正文


Java ApplicationReport.getYarnApplicationState方法代碼示例

本文整理匯總了Java中org.apache.hadoop.yarn.api.records.ApplicationReport.getYarnApplicationState方法的典型用法代碼示例。如果您正苦於以下問題:Java ApplicationReport.getYarnApplicationState方法的具體用法?Java ApplicationReport.getYarnApplicationState怎麽用?Java ApplicationReport.getYarnApplicationState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.yarn.api.records.ApplicationReport的用法示例。


在下文中一共展示了ApplicationReport.getYarnApplicationState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: submitJob

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
@Override
public JobStatus submitJob(JobID jobId, String jobSubmitDir, Credentials ts)
		throws IOException, InterruptedException {

	addHistoryToken(ts);

	// Construct necessary information to start the MR AM
	ApplicationSubmissionContext appContext = createApplicationSubmissionContext(conf, jobSubmitDir, ts);

	// Submit to ResourceManager
	try {
		ApplicationId applicationId = resMgrDelegate.submitApplication(appContext);

		ApplicationReport appMaster = resMgrDelegate.getApplicationReport(applicationId);
		String diagnostics = (appMaster == null ? "application report is null" : appMaster.getDiagnostics());
		if (appMaster == null || appMaster.getYarnApplicationState() == YarnApplicationState.FAILED
				|| appMaster.getYarnApplicationState() == YarnApplicationState.KILLED) {
			throw new IOException("Failed to run job : " + diagnostics);
		}
		return clientCache.getClient(jobId).getJobStatus(jobId);
	} catch (YarnException e) {
		throw new IOException(e);
	}
}
 
開發者ID:liuhaozzu,項目名稱:big_data,代碼行數:25,代碼來源:YARNRunner.java

示例2: awaitApplication

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
boolean awaitApplication(ApplicationId appId) throws Exception {
  Set<YarnApplicationState> terminated = Sets.newHashSet(
      YarnApplicationState.FAILED,
      YarnApplicationState.FINISHED,
      YarnApplicationState.KILLED);
  while (true) {
    ApplicationReport report = yarnClient.getApplicationReport(appId);
    YarnApplicationState state = report.getYarnApplicationState();
    if (state.equals(YarnApplicationState.RUNNING)) {
      ClusterSpec clusterSpec = Client.getClusterSpec(yarnClient, appId);
      if (isClusterSpecSatisfied(clusterSpec)) {
        System.out.println("ClusterSpec: " + Utils.toJsonString(clusterSpec.getCluster()));
        return true;
      }
    } else if (terminated.contains(state)) {
      return false;
    } else {
      Thread.sleep(1000);
    }
  }
}
 
開發者ID:Intel-bigdata,項目名稱:TensorFlowOnYARN,代碼行數:22,代碼來源:LaunchCluster.java

示例3: AppInfo

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
public AppInfo(ApplicationReport app) {
  appId = app.getApplicationId().toString();
  if (app.getCurrentApplicationAttemptId() != null) {
    currentAppAttemptId = app.getCurrentApplicationAttemptId().toString();
  }
  user = app.getUser();
  queue = app.getQueue();
  name = app.getName();
  type = app.getApplicationType();
  host = app.getHost();
  rpcPort = app.getRpcPort();
  appState = app.getYarnApplicationState();
  diagnosticsInfo = app.getDiagnostics();
  trackingUrl = app.getTrackingUrl();
  originalTrackingUrl = app.getOriginalTrackingUrl();
  submittedTime = app.getStartTime();
  startedTime = app.getStartTime();
  finishedTime = app.getFinishTime();
  elapsedTime = Times.elapsed(startedTime, finishedTime);
  finalAppStatus = app.getFinalApplicationStatus();
  progress = app.getProgress() * 100; // in percent
  if (app.getApplicationTags() != null && !app.getApplicationTags().isEmpty()) {
    this.applicationTags = CSV_JOINER.join(app.getApplicationTags());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:AppInfo.java

示例4: verifyApplicationState

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
private int verifyApplicationState(ApplicationId appId) throws IOException,
    YarnException {
  YarnClient yarnClient = createYarnClient();

  try {
    ApplicationReport appReport = yarnClient.getApplicationReport(appId);
    switch (appReport.getYarnApplicationState()) {
    case NEW:
    case NEW_SAVING:
    case SUBMITTED:
      return -1;
    case ACCEPTED:
    case RUNNING:
    case FAILED:
    case FINISHED:
    case KILLED:
    default:
      break;

    }
  } finally {
    yarnClient.close();
  }
  return 0;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:LogsCLI.java

示例5: killApplication

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
/**
 * Kills the application with the application id as appId
 * 
 * @param applicationId
 * @throws YarnException
 * @throws IOException
 */
private void killApplication(String applicationId) throws YarnException,
    IOException {
  ApplicationId appId = ConverterUtils.toApplicationId(applicationId);
  ApplicationReport  appReport = null;
  try {
    appReport = client.getApplicationReport(appId);
  } catch (ApplicationNotFoundException e) {
    sysout.println("Application with id '" + applicationId +
        "' doesn't exist in RM.");
    throw e;
  }

  if (appReport.getYarnApplicationState() == YarnApplicationState.FINISHED
      || appReport.getYarnApplicationState() == YarnApplicationState.KILLED
      || appReport.getYarnApplicationState() == YarnApplicationState.FAILED) {
    sysout.println("Application " + applicationId + " has already finished ");
  } else {
    sysout.println("Killing application " + applicationId);
    client.killApplication(appId);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:29,代碼來源:ApplicationCLI.java

示例6: waitTillAccepted

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
private void waitTillAccepted(YarnClient rmClient, ApplicationId appId)
  throws Exception {
  try {
    long start = System.currentTimeMillis();
    ApplicationReport report = rmClient.getApplicationReport(appId);
    while (YarnApplicationState.ACCEPTED != report.getYarnApplicationState()) {
      if (System.currentTimeMillis() - start > 20 * 1000) {
        throw new Exception("App '" + appId + 
          "' time out, failed to reach ACCEPTED state");
      }
      Thread.sleep(200);
      report = rmClient.getApplicationReport(appId);
    }
  } catch (Exception ex) {
    throw new Exception(ex);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestYarnClient.java

示例7: poll

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
private ApplicationReport poll() throws IOException, YarnException {
  ApplicationReport report;
  report = yarnClient.getApplicationReport(appId);
  YarnApplicationState appState = report.getYarnApplicationState();
  LOG.debug("Application State: {}", appState);

  switch (appState) {
    case FAILED:
    case FINISHED:
      //TODO: the finished state may be valid in flip-6
    case KILLED:
      throw new IOException("The YARN application unexpectedly switched to state "
          + appState + " during deployment. \n"
          + "Diagnostics from YARN: " + report.getDiagnostics() + "\n"
          + "If log aggregation is enabled on your cluster, use this command to further investigate the issue:\n"
          + "yarn logs -applicationId " + appId);
      //break ..
    case RUNNING:
      LOG.info("YARN application has been deployed successfully.");
      break;
    default:
      if (appState != lastAppState) {
        LOG.info("Deploying cluster, current state " + appState);
      }
      lastAppState = appState;
      if (System.currentTimeMillis() - startTime > DEPLOY_TIMEOUT_MS) {
        throw new RuntimeException(String.format("Deployment took more than %d seconds. "
            + "Please check if the requested resources are available in the YARN cluster", DEPLOY_TIMEOUT_MS));
      }
      return null;
  }
  return report;
}
 
開發者ID:uber,項目名稱:AthenaX,代碼行數:34,代碼來源:AthenaXYarnClusterDescriptor.java

示例8: pollFinishedApplicationState

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
public static YarnApplicationState pollFinishedApplicationState(YarnClient client, ApplicationId appId)
    throws IOException, YarnException, InterruptedException {
  EnumSet<YarnApplicationState> finishedState = EnumSet.of(FINISHED, KILLED, FAILED);

  while (true) {
    ApplicationReport report = client.getApplicationReport(appId);
    YarnApplicationState state = report.getYarnApplicationState();
    if (finishedState.contains(state)) {
      return state;
    } else {
      Thread.sleep(250);
    }
  }
}
 
開發者ID:uber,項目名稱:AthenaX,代碼行數:15,代碼來源:MiniAthenaXCluster.java

示例9: killUnFinishedApplication

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
private void killUnFinishedApplication(ApplicationId appId) throws IOException {
	ApplicationReport application = null;
	try {
		application = resMgrDelegate.getApplicationReport(appId);
	} catch (YarnException e) {
		throw new IOException(e);
	}
	if (application.getYarnApplicationState() == YarnApplicationState.FINISHED
			|| application.getYarnApplicationState() == YarnApplicationState.FAILED
			|| application.getYarnApplicationState() == YarnApplicationState.KILLED) {
		return;
	}
	killApplication(appId);
}
 
開發者ID:liuhaozzu,項目名稱:big_data,代碼行數:15,代碼來源:YARNRunner.java

示例10: getClusterSpec

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
static ClusterSpec getClusterSpec(YarnClient client, ApplicationId appId) throws Exception {
  ClusterSpec clusterSpec = ClusterSpec.empty();
  ApplicationReport report = client.getApplicationReport(appId);
  YarnApplicationState state = report.getYarnApplicationState();
  if (state.equals(YarnApplicationState.RUNNING)) {
    String hostname = report.getHost();
    int port = report.getRpcPort();
    TFApplicationRpc rpc = TFApplicationRpcClient.getInstance(hostname, port);
    String spec = rpc.getClusterSpec();
    if (spec != null) {
      clusterSpec = ClusterSpec.fromJsonString(spec);
    }
  }
  return clusterSpec;
}
 
開發者ID:Intel-bigdata,項目名稱:TensorFlowOnYARN,代碼行數:16,代碼來源:Client.java

示例11: moveApplicationAcrossQueues

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
/**
 * Moves the application with the given ID to the given queue.
 */
private void moveApplicationAcrossQueues(String applicationId, String queue)
    throws YarnException, IOException {
  ApplicationId appId = ConverterUtils.toApplicationId(applicationId);
  ApplicationReport appReport = client.getApplicationReport(appId);
  if (appReport.getYarnApplicationState() == YarnApplicationState.FINISHED
      || appReport.getYarnApplicationState() == YarnApplicationState.KILLED
      || appReport.getYarnApplicationState() == YarnApplicationState.FAILED) {
    sysout.println("Application " + applicationId + " has already finished ");
  } else {
    sysout.println("Moving application " + applicationId + " to queue " + queue);
    client.moveApplicationAcrossQueues(appId, queue);
    sysout.println("Successfully completed move.");
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:ApplicationCLI.java

示例12: submitJob

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
@Override
public JobStatus submitJob(JobID jobId, String jobSubmitDir, Credentials ts)
throws IOException, InterruptedException {
  
  addHistoryToken(ts);
  
  // Construct necessary information to start the MR AM
  ApplicationSubmissionContext appContext =
    createApplicationSubmissionContext(conf, jobSubmitDir, ts);

  // Submit to ResourceManager
  try {
    ApplicationId applicationId =
        resMgrDelegate.submitApplication(appContext);

    ApplicationReport appMaster = resMgrDelegate
        .getApplicationReport(applicationId);
    String diagnostics =
        (appMaster == null ?
            "application report is null" : appMaster.getDiagnostics());
    if (appMaster == null
        || appMaster.getYarnApplicationState() == YarnApplicationState.FAILED
        || appMaster.getYarnApplicationState() == YarnApplicationState.KILLED) {
      throw new IOException("Failed to run job : " +
          diagnostics);
    }
    return clientCache.getClient(jobId).getJobStatus(jobId);
  } catch (YarnException e) {
    throw new IOException(e);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:32,代碼來源:YARNRunner.java

示例13: killUnFinishedApplication

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
private void killUnFinishedApplication(ApplicationId appId)
    throws IOException {
  ApplicationReport application = null;
  try {
    application = resMgrDelegate.getApplicationReport(appId);
  } catch (YarnException e) {
    throw new IOException(e);
  }
  if (application.getYarnApplicationState() == YarnApplicationState.FINISHED
      || application.getYarnApplicationState() == YarnApplicationState.FAILED
      || application.getYarnApplicationState() == YarnApplicationState.KILLED) {
    return;
  }
  killApplication(appId);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:YARNRunner.java

示例14: submitApplication

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
@Override
public ApplicationId
    submitApplication(ApplicationSubmissionContext appContext)
        throws YarnException, IOException {
  ApplicationId applicationId = appContext.getApplicationId();
  if (applicationId == null) {
    throw new ApplicationIdNotProvidedException(
        "ApplicationId is not provided in ApplicationSubmissionContext");
  }
  SubmitApplicationRequest request =
      Records.newRecord(SubmitApplicationRequest.class);
  request.setApplicationSubmissionContext(appContext);

  // Automatically add the timeline DT into the CLC
  // Only when the security and the timeline service are both enabled
  if (isSecurityEnabled() && timelineServiceEnabled) {
    addTimelineDelegationToken(appContext.getAMContainerSpec());
  }

  //TODO: YARN-1763:Handle RM failovers during the submitApplication call.
  rmClient.submitApplication(request);

  int pollCount = 0;
  long startTime = System.currentTimeMillis();
  EnumSet<YarnApplicationState> waitingStates = 
                               EnumSet.of(YarnApplicationState.NEW,
                               YarnApplicationState.NEW_SAVING,
                               YarnApplicationState.SUBMITTED);
  EnumSet<YarnApplicationState> failToSubmitStates = 
                                EnumSet.of(YarnApplicationState.FAILED,
                                YarnApplicationState.KILLED);		
  while (true) {
    try {
      ApplicationReport appReport = getApplicationReport(applicationId);
      YarnApplicationState state = appReport.getYarnApplicationState();
      if (!waitingStates.contains(state)) {
        if(failToSubmitStates.contains(state)) {
          throw new YarnException("Failed to submit " + applicationId + 
              " to YARN : " + appReport.getDiagnostics());
        }
        LOG.info("Submitted application " + applicationId);
        break;
      }

      long elapsedMillis = System.currentTimeMillis() - startTime;
      if (enforceAsyncAPITimeout() &&
          elapsedMillis >= asyncApiPollTimeoutMillis) {
        throw new YarnException("Timed out while waiting for application " +
            applicationId + " to be submitted successfully");
      }

      // Notify the client through the log every 10 poll, in case the client
      // is blocked here too long.
      if (++pollCount % 10 == 0) {
        LOG.info("Application submission is not finished, " +
            "submitted application " + applicationId +
            " is still in " + state);
      }
      try {
        Thread.sleep(submitPollIntervalMillis);
      } catch (InterruptedException ie) {
        LOG.error("Interrupted while waiting for application "
            + applicationId
            + " to be successfully submitted.");
      }
    } catch (ApplicationNotFoundException ex) {
      // FailOver or RM restart happens before RMStateStore saves
      // ApplicationState
      LOG.info("Re-submit application " + applicationId + "with the " +
          "same ApplicationSubmissionContext");
      rmClient.submitApplication(request);
    }
  }

  return applicationId;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:77,代碼來源:YarnClientImpl.java

示例15: startApp

import org.apache.hadoop.yarn.api.records.ApplicationReport; //導入方法依賴的package包/類
@Before
public void startApp() throws Exception {
  // submit new app
  ApplicationSubmissionContext appContext = 
      yarnClient.createApplication().getApplicationSubmissionContext();
  ApplicationId appId = appContext.getApplicationId();
  // set the application name
  appContext.setApplicationName("Test");
  // Set the priority for the application master
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(0);
  appContext.setPriority(pri);
  // Set the queue to which this application is to be submitted in the RM
  appContext.setQueue("default");
  // Set up the container launch context for the application master
  ContainerLaunchContext amContainer =
      BuilderUtils.newContainerLaunchContext(
        Collections.<String, LocalResource> emptyMap(),
        new HashMap<String, String>(), Arrays.asList("sleep", "100"),
        new HashMap<String, ByteBuffer>(), null,
        new HashMap<ApplicationAccessType, String>());
  appContext.setAMContainerSpec(amContainer);
  appContext.setResource(Resource.newInstance(1024, 1, 1));
  // Create the request to send to the applications manager
  SubmitApplicationRequest appRequest = Records
      .newRecord(SubmitApplicationRequest.class);
  appRequest.setApplicationSubmissionContext(appContext);
  // Submit the application to the applications manager
  yarnClient.submitApplication(appContext);

  // wait for app to start
  RMAppAttempt appAttempt = null;
  while (true) {
    ApplicationReport appReport = yarnClient.getApplicationReport(appId);
    if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) {
      attemptId = appReport.getCurrentApplicationAttemptId();
      appAttempt =
          yarnCluster.getResourceManager().getRMContext().getRMApps()
            .get(attemptId.getApplicationId()).getCurrentAppAttempt();
      while (true) {
        if (appAttempt.getAppAttemptState() == RMAppAttemptState.LAUNCHED) {
          break;
        }
      }
      break;
    }
  }
  // Just dig into the ResourceManager and get the AMRMToken just for the sake
  // of testing.
  UserGroupInformation.setLoginUser(UserGroupInformation
    .createRemoteUser(UserGroupInformation.getCurrentUser().getUserName()));

  // emulate RM setup of AMRM token in credentials by adding the token
  // *before* setting the token service
  UserGroupInformation.getCurrentUser().addToken(appAttempt.getAMRMToken());
  appAttempt.getAMRMToken().setService(ClientRMProxy.getAMRMTokenService(conf));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:58,代碼來源:TestAMRMClient.java


注:本文中的org.apache.hadoop.yarn.api.records.ApplicationReport.getYarnApplicationState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。