Java 类org.apache.hadoop.yarn.api.records.YarnApplicationState 实例源码

项目:AthenaX    文件:JobWatcherUtil.java   
static StateView computeState(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) {

    // Instance ID -> JobDefinition ID
    HashMap<UUID, UUID> instanceToJob = new HashMap<>();
    HashMap<UUID, List<InstanceInfo>> jobInstances = new HashMap<>();

    for (Map.Entry<UUID, InstanceInfo> e : instances.entrySet()) {
      YarnApplicationState state = YarnApplicationState.valueOf(e.getValue().status().getState().toString());
      if (!isInstanceAlive(state)) {
        continue;
      }
      UUID jobId = e.getValue().metadata().jobDefinition();
      UUID instanceId = e.getKey();
      instanceToJob.put(instanceId, jobId);
      if (!jobInstances.containsKey(jobId)) {
        jobInstances.put(jobId, new ArrayList<>());
      }
      jobInstances.get(jobId).add(e.getValue());
    }
    jobs.keySet().stream().filter(x -> !jobInstances.containsKey(x))
        .forEach(x -> jobInstances.put(x, Collections.emptyList()));
    return new StateView(jobs, instances, instanceToJob, jobInstances);
  }
项目:TensorFlowOnYARN    文件:LaunchCluster.java   
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);
    }
  }
}
项目:hadoop    文件:AppBlock.java   
private String clarifyAppState(YarnApplicationState state) {
  String ret = state.toString();
  switch (state) {
  case NEW:
    return ret + ": waiting for application to be initialized";
  case NEW_SAVING:
    return ret + ": waiting for application to be persisted in state-store.";
  case SUBMITTED:
    return ret + ": waiting for application to be accepted by scheduler.";
  case ACCEPTED:
    return ret + ": waiting for AM container to be allocated, launched and"
        + " register with RM.";
  case RUNNING:
    return ret + ": AM has registered with RM and started running.";
  default:
    return ret;
  }
}
项目:hadoop    文件:RMWebServices.java   
private static Map<YarnApplicationState, Map<String, Long>> buildScoreboard(
   Set<String> states, Set<String> types) {
  Map<YarnApplicationState, Map<String, Long>> scoreboard
      = new HashMap<YarnApplicationState, Map<String, Long>>();
  // default states will result in enumerating all YarnApplicationStates
  assert !states.isEmpty();
  for (String state : states) {
    Map<String, Long> partScoreboard = new HashMap<String, Long>();
    scoreboard.put(
        YarnApplicationState.valueOf(StringUtils.toUpperCase(state)),
        partScoreboard);
    // types is verified no to be empty
    for (String type : types) {
      partScoreboard.put(type, 0L);
    }
  }
  return scoreboard;
}
项目:hadoop    文件:NavBlock.java   
@Override public void render(Block html) {
  UL<DIV<Hamlet>> mainList = html.
    div("#nav").
      h3("Cluster").
      ul().
        li().a(url("cluster"), "About")._().
        li().a(url("nodes"), "Nodes")._().
        li().a(url("nodelabels"), "Node Labels")._();
  UL<LI<UL<DIV<Hamlet>>>> subAppsList = mainList.
        li().a(url("apps"), "Applications").
          ul();
  subAppsList.li()._();
  for (YarnApplicationState state : YarnApplicationState.values()) {
    subAppsList.
            li().a(url("apps", state.toString()), state.toString())._();
  }
  subAppsList._()._();
  mainList.
        li().a(url("scheduler"), "Scheduler")._()._().
      h3("Tools").
      ul().
        li().a("/conf", "Configuration")._().
        li().a("/logs", "Local logs")._().
        li().a("/stacks", "Server stacks")._().
        li().a("/jmx?qry=Hadoop:*", "Server metrics")._()._()._();
}
项目:hadoop    文件:ApplicationFinishedEvent.java   
public ApplicationFinishedEvent(
    ApplicationId appId,
    String diagnosticsInfo,
    FinalApplicationStatus appStatus,
    YarnApplicationState state,
    ApplicationAttemptId latestAppAttemptId,
    long finishedTime,
    RMAppMetrics appMetrics) {
  super(SystemMetricsEventType.APP_FINISHED, finishedTime);
  this.appId = appId;
  this.diagnosticsInfo = diagnosticsInfo;
  this.appStatus = appStatus;
  this.latestAppAttemptId = latestAppAttemptId;
  this.state = state;
  this.appMetrics=appMetrics;
}
项目:hadoop    文件:RMServerUtils.java   
public static YarnApplicationState createApplicationState(
    RMAppState rmAppState) {
  switch (rmAppState) {
    case NEW:
      return YarnApplicationState.NEW;
    case NEW_SAVING:
      return YarnApplicationState.NEW_SAVING;
    case SUBMITTED:
      return YarnApplicationState.SUBMITTED;
    case ACCEPTED:
      return YarnApplicationState.ACCEPTED;
    case RUNNING:
      return YarnApplicationState.RUNNING;
    case FINISHING:
    case FINISHED:
      return YarnApplicationState.FINISHED;
    case KILLED:
      return YarnApplicationState.KILLED;
    case FAILED:
      return YarnApplicationState.FAILED;
    default:
      throw new YarnRuntimeException("Unknown state passed!");
    }
}
项目:hadoop    文件:TestRMWebServicesApps.java   
@Test
public void testAppsQueryState() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  RMApp app1 = rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps")
      .queryParam("state", YarnApplicationState.ACCEPTED.toString())
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 1, array.length());
  verifyAppInfo(array.getJSONObject(0), app1);
  rm.stop();
}
项目:hadoop    文件:TestRMWebServicesApps.java   
@Test
public void testAppsQueryStatesNone() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps")
      .queryParam("states", YarnApplicationState.RUNNING.toString())
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
  rm.stop();
}
项目:hadoop    文件:TestRMWebServicesApps.java   
@Test
public void testAppsQueryStateNone() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps")
      .queryParam("state", YarnApplicationState.RUNNING.toString())
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
  rm.stop();
}
项目:scheduling-connector-for-hadoop    文件:SlurmApplicationClient.java   
@Override
public ApplicationReport getApplicationReport(ApplicationId applicationId)
    throws IOException {
  List<ApplicationReport> reports = null;
  try {
    reports = getApplications(applicationId.getId());
  } catch (Throwable e) {
    LOG.info("Couldn't get application report for " + applicationId
        + ", might be completed already.");
  }
  if (reports == null || reports.isEmpty()) {
    return ApplicationReport.newInstance(applicationId, null, "", "default",
        "", "", 0, null, YarnApplicationState.FINISHED, "", "", 0, 0,
        FinalApplicationStatus.SUCCEEDED, null, "", 100, null, null);
  }
  return reports.get(0);
}
项目:hadoop    文件:AHSWebServices.java   
private static void
    validateStates(String stateQuery, Set<String> statesQuery) {
  // stateQuery is deprecated.
  if (stateQuery != null && !stateQuery.isEmpty()) {
    statesQuery.add(stateQuery);
  }
  Set<String> appStates = parseQueries(statesQuery, true);
  for (String appState : appStates) {
    switch (YarnApplicationState.valueOf(
        StringUtils.toUpperCase(appState))) {
      case FINISHED:
      case FAILED:
      case KILLED:
        continue;
      default:
        throw new BadRequestException("Invalid application-state " + appState
            + " specified. It should be a final state");
    }
  }
}
项目:hadoop    文件:TestYARNRunner.java   
@Test(timeout=20000)
public void testJobSubmissionFailure() throws Exception {
  when(resourceMgrDelegate.submitApplication(any(ApplicationSubmissionContext.class))).
  thenReturn(appId);
  ApplicationReport report = mock(ApplicationReport.class);
  when(report.getApplicationId()).thenReturn(appId);
  when(report.getDiagnostics()).thenReturn(failString);
  when(report.getYarnApplicationState()).thenReturn(YarnApplicationState.FAILED);
  when(resourceMgrDelegate.getApplicationReport(appId)).thenReturn(report);
  Credentials credentials = new Credentials();
  File jobxml = new File(testWorkDir, "job.xml");
  OutputStream out = new FileOutputStream(jobxml);
  conf.writeXml(out);
  out.close();
  try {
    yarnRunner.submitJob(jobId, testWorkDir.getAbsolutePath().toString(), credentials);
  } catch(IOException io) {
    LOG.info("Logging exception:", io);
    assertTrue(io.getLocalizedMessage().contains(failString));
  }
}
项目:hadoop    文件:TestResourceMgrDelegate.java   
@Test
public void tesAllJobs() throws Exception {
  final ApplicationClientProtocol applicationsManager = Mockito.mock(ApplicationClientProtocol.class);
  GetApplicationsResponse allApplicationsResponse = Records
      .newRecord(GetApplicationsResponse.class);
  List<ApplicationReport> applications = new ArrayList<ApplicationReport>();
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.FAILED));
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.SUCCEEDED));
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.KILLED));
  applications.add(getApplicationReport(YarnApplicationState.FAILED,
      FinalApplicationStatus.FAILED));
  allApplicationsResponse.setApplicationList(applications);
  Mockito.when(
      applicationsManager.getApplications(Mockito
          .any(GetApplicationsRequest.class))).thenReturn(
      allApplicationsResponse);
  ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(
    new YarnConfiguration()) {
    @Override
    protected void serviceStart() throws Exception {
      Assert.assertTrue(this.client instanceof YarnClientImpl);
      ((YarnClientImpl) this.client).setRMClient(applicationsManager);
    }
  };
  JobStatus[] allJobs = resourceMgrDelegate.getAllJobs();

  Assert.assertEquals(State.FAILED, allJobs[0].getState());
  Assert.assertEquals(State.SUCCEEDED, allJobs[1].getState());
  Assert.assertEquals(State.KILLED, allJobs[2].getState());
  Assert.assertEquals(State.FAILED, allJobs[3].getState());
}
项目:hadoop    文件:TestAHSWebApp.java   
@Test
public void testView() throws Exception {
  Injector injector =
      WebAppTests.createMockInjector(ApplicationBaseProtocol.class,
        mockApplicationHistoryClientService(5, 1, 1));
  AHSView ahsViewInstance = injector.getInstance(AHSView.class);

  ahsViewInstance.render();
  WebAppTests.flushOutput(injector);

  ahsViewInstance.set(YarnWebParams.APP_STATE,
    YarnApplicationState.FAILED.toString());
  ahsViewInstance.render();
  WebAppTests.flushOutput(injector);

  ahsViewInstance.set(YarnWebParams.APP_STATE, StringHelper.cjoin(
    YarnApplicationState.FAILED.toString(), YarnApplicationState.KILLED));
  ahsViewInstance.render();
  WebAppTests.flushOutput(injector);
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testAppsQuery() throws Exception {
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .queryParam("state", YarnApplicationState.FINISHED.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 5, array.length());
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testSingleApp() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject app = json.getJSONObject("app");
  assertEquals(appId.toString(), app.getString("appId"));
  assertEquals("test app", app.get("name"));
  assertEquals(round == 0 ? "test diagnostics info" : "",
      app.get("diagnosticsInfo"));
  assertEquals("test queue", app.get("queue"));
  assertEquals("user1", app.get("user"));
  assertEquals("test app type", app.get("type"));
  assertEquals(FinalApplicationStatus.UNDEFINED.toString(),
    app.get("finalAppStatus"));
  assertEquals(YarnApplicationState.FINISHED.toString(), app.get("appState"));
}
项目:hadoop    文件:TypeConverter.java   
public static State fromYarn(YarnApplicationState yarnApplicationState,
    FinalApplicationStatus finalApplicationStatus) {
  switch (yarnApplicationState) {
  case NEW:
  case NEW_SAVING:
  case SUBMITTED:
  case ACCEPTED:
    return State.PREP;
  case RUNNING:
    return State.RUNNING;
  case FINISHED:
    if (finalApplicationStatus == FinalApplicationStatus.SUCCEEDED) {
      return State.SUCCEEDED;
    } else if (finalApplicationStatus == FinalApplicationStatus.KILLED) {
      return State.KILLED;
    }
  case FAILED:
    return State.FAILED;
  case KILLED:
    return State.KILLED;
  }
  throw new YarnRuntimeException("Unrecognized application state: " + yarnApplicationState);
}
项目:hadoop    文件:ApplicationCLI.java   
/**
 * 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);
  }
}
项目:hadoop    文件:TestYarnClient.java   
private List<ApplicationReport> getApplicationReports(
    List<ApplicationReport> applicationReports,
    Set<String> applicationTypes, EnumSet<YarnApplicationState> applicationStates) {

  List<ApplicationReport> appReports = new ArrayList<ApplicationReport>();
  for (ApplicationReport appReport : applicationReports) {
    if (applicationTypes != null && !applicationTypes.isEmpty()) {
      if (!applicationTypes.contains(appReport.getApplicationType())) {
        continue;
      }
    }

    if (applicationStates != null && !applicationStates.isEmpty()) {
      if (!applicationStates.contains(appReport.getYarnApplicationState())) {
        continue;
      }
    }
    appReports.add(appReport);
  }
  return appReports;
}
项目:hadoop    文件:TestYarnClient.java   
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);
  }
}
项目:hadoop    文件:TestLogsCLI.java   
@Test(timeout = 5000l)
public void testFailResultCodes() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.setClass("fs.file.impl", LocalFileSystem.class, FileSystem.class);
  LogCLIHelpers cliHelper = new LogCLIHelpers();
  cliHelper.setConf(conf);
  YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED);
  LogsCLI dumper = new LogsCLIForTest(mockYarnClient);
  dumper.setConf(conf);

  // verify dumping a non-existent application's logs returns a failure code
  int exitCode = dumper.run( new String[] {
      "-applicationId", "application_0_0" } );
  assertTrue("Should return an error code", exitCode != 0);

  // verify dumping a non-existent container log is a failure code 
  exitCode = cliHelper.dumpAContainersLogs("application_0_0", "container_0_0",
      "nonexistentnode:1234", "nobody");
  assertTrue("Should return an error code", exitCode != 0);
}
项目:hadoop    文件:TestResourceMgrDelegate.java   
private ApplicationReport getApplicationReport(
    YarnApplicationState yarnApplicationState,
    FinalApplicationStatus finalApplicationStatus) {
  ApplicationReport appReport = Mockito.mock(ApplicationReport.class);
  ApplicationResourceUsageReport appResources = Mockito
      .mock(ApplicationResourceUsageReport.class);
  Mockito.when(appReport.getApplicationId()).thenReturn(
      ApplicationId.newInstance(0, 0));
  Mockito.when(appResources.getNeededResources()).thenReturn(
      Records.newRecord(Resource.class));
  Mockito.when(appResources.getReservedResources()).thenReturn(
      Records.newRecord(Resource.class));
  Mockito.when(appResources.getUsedResources()).thenReturn(
      Records.newRecord(Resource.class));
  Mockito.when(appReport.getApplicationResourceUsageReport()).thenReturn(
      appResources);
  Mockito.when(appReport.getYarnApplicationState()).thenReturn(
      yarnApplicationState);
  Mockito.when(appReport.getFinalApplicationStatus()).thenReturn(
      finalApplicationStatus);

  return appReport;
}
项目:AthenaX    文件:MiniAthenaXCluster.java   
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);
    }
  }
}
项目:AthenaX    文件:JobDeployerITest.java   
@Test
public void testCreateAthenaXCluster() throws Exception {
  ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
  Configuration flinkConf = new Configuration();
  flinkConf.setString(JobManagerOptions.ADDRESS, "localhost");

  try (MiniAthenaXCluster cluster = new MiniAthenaXCluster(JobDeployerITest.class.getSimpleName())) {
    cluster.start();
    YarnConfiguration conf = cluster.getYarnConfiguration();
    YarnClusterConfiguration clusterConf = cluster.getYarnClusterConf();

    final ApplicationId appId;
    try (YarnClient client = YarnClient.createYarnClient()) {
      client.init(conf);
      client.start();

      JobDeployer deployer = new JobDeployer(clusterConf, client, executor, flinkConf);
      appId = deployer.createApplication();
      InstanceMetadata md = new InstanceMetadata(UUID.randomUUID(), UUID.randomUUID());
      JobConf jobConf = new JobConf(appId, "test", Collections.emptyList(), null, 1, 2048, md);
      deployer.start(JobITestUtil.trivialJobGraph(), jobConf);

      YarnApplicationState state = MiniAthenaXCluster.pollFinishedApplicationState(client, appId);
      assertEquals(FINISHED, state);
    }
  }
}
项目:big_data    文件:YARNRunner.java   
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);
}
项目:TensorFlowOnYARN    文件:Client.java   
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;
}
项目:hadoop    文件:GetApplicationsRequestPBImpl.java   
private void initApplicationStates() {
  if (this.applicationStates != null) {
    return;
  }
  GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
  List<YarnApplicationStateProto> appStatesList =
      p.getApplicationStatesList();
  this.applicationStates = EnumSet.noneOf(YarnApplicationState.class);

  for (YarnApplicationStateProto c : appStatesList) {
    this.applicationStates.add(ProtoUtils.convertFromProtoFormat(c));
  }
}
项目:hadoop    文件:GetApplicationsRequestPBImpl.java   
@Override
public void setApplicationStates(EnumSet<YarnApplicationState> applicationStates) {
  maybeInitBuilder();
  if (applicationStates == null) {
    builder.clearApplicationStates();
  }
  this.applicationStates = applicationStates;
}
项目:hadoop    文件:GetApplicationsRequestPBImpl.java   
@Override
public void setApplicationStates(Set<String> applicationStates) {
  EnumSet<YarnApplicationState> appStates = null;
  for (YarnApplicationState state : YarnApplicationState.values()) {
    if (applicationStates.contains(
        StringUtils.toLowerCase(state.name()))) {
      if (appStates == null) {
        appStates = EnumSet.of(state);
      } else {
        appStates.add(state);
      }
    }
  }
  setApplicationStates(appStates);
}
项目:hadoop    文件:ApplicationReportPBImpl.java   
@Override
public YarnApplicationState getYarnApplicationState() {
  ApplicationReportProtoOrBuilder p = viaProto ? proto : builder;
  if (!p.hasYarnApplicationState()) {
    return null;
  }
  return convertFromProtoFormat(p.getYarnApplicationState());
}
项目:hadoop    文件:ApplicationReportPBImpl.java   
@Override
public void setYarnApplicationState(YarnApplicationState state) {
  maybeInitBuilder();
  if (state == null) {
    builder.clearYarnApplicationState();
    return;
  }
  builder.setYarnApplicationState(convertToProtoFormat(state));
}
项目:hadoop    文件:TestApplicatonReport.java   
protected static ApplicationReport createApplicationReport(
    int appIdInt, int appAttemptIdInt, long timestamp) {
  ApplicationId appId = ApplicationId.newInstance(timestamp, appIdInt);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, appAttemptIdInt);
  ApplicationReport appReport =
      ApplicationReport.newInstance(appId, appAttemptId, "user", "queue",
        "appname", "host", 124, null, YarnApplicationState.FINISHED,
        "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null,
        "N/A", 0.53789f, YarnConfiguration.DEFAULT_APPLICATION_TYPE, null);
  return appReport;
}
项目:hadoop    文件:YARNRunner.java   
@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);
  }
}
项目:hadoop    文件:TestLogsCLI.java   
@Test(timeout = 5000l)
public void testHelpMessage() throws Exception {
  Configuration conf = new YarnConfiguration();
  YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED);
  LogsCLI dumper = new LogsCLIForTest(mockYarnClient);
  dumper.setConf(conf);

  int exitCode = dumper.run(new String[]{});
  assertTrue(exitCode == -1);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Retrieve logs for completed YARN applications.");
  pw.println("usage: yarn logs -applicationId <application ID> [OPTIONS]");
  pw.println();
  pw.println("general options are:");
  pw.println(" -appOwner <Application Owner>   AppOwner (assumed to be current user if");
  pw.println("                                 not specified)");
  pw.println(" -containerId <Container ID>     ContainerId (must be specified if node");
  pw.println("                                 address is specified)");
  pw.println(" -help                           Displays help for all commands.");
  pw.println(" -nodeAddress <Node Address>     NodeAddress in the format nodename:port");
  pw.println("                                 (must be specified if container id is");
  pw.println("                                 specified)");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
}
项目:hadoop    文件:TestAggregatedLogDeletionService.java   
private static GetApplicationReportResponse
    createApplicationReportWithFinishedApplication() {
  ApplicationReport report = mock(ApplicationReport.class);
  when(report.getYarnApplicationState()).thenReturn(
    YarnApplicationState.FINISHED);
  GetApplicationReportResponse response =
      mock(GetApplicationReportResponse.class);
  when(response.getApplicationReport()).thenReturn(report);
  return response;
}
项目:hadoop    文件:TestWebAppProxyServlet.java   
private ApplicationReport getDefaultApplicationReport(ApplicationId appId) {
  ApplicationReport result = new ApplicationReportPBImpl();
  result.setApplicationId(appId);
  result.setOriginalTrackingUrl("localhost:" + originalPort + "/foo/bar");
  result.setYarnApplicationState(YarnApplicationState.RUNNING);
  result.setUser(CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER);
  return result;
}
项目:hadoop    文件:WebServices.java   
protected static Set<String>
    parseQueries(Set<String> queries, boolean isState) {
  Set<String> params = new HashSet<String>();
  if (!queries.isEmpty()) {
    for (String query : queries) {
      if (query != null && !query.trim().isEmpty()) {
        String[] paramStrs = query.split(",");
        for (String paramStr : paramStrs) {
          if (paramStr != null && !paramStr.trim().isEmpty()) {
            if (isState) {
              try {
                // enum string is in the uppercase
                YarnApplicationState.valueOf(
                    StringUtils.toUpperCase(paramStr.trim()));
              } catch (RuntimeException e) {
                YarnApplicationState[] stateArray =
                    YarnApplicationState.values();
                String allAppStates = Arrays.toString(stateArray);
                throw new BadRequestException("Invalid application-state "
                    + paramStr.trim() + " specified. It should be one of "
                    + allAppStates);
              }
            }
            params.add(StringUtils.toLowerCase(paramStr.trim()));
          }
        }
      }
    }
  }
  return params;
}
项目:hadoop    文件:BuilderUtils.java   
public static ApplicationReport newApplicationReport(
    ApplicationId applicationId, ApplicationAttemptId applicationAttemptId,
    String user, String queue, String name, String host, int rpcPort,
    Token clientToAMToken, YarnApplicationState state, String diagnostics,
    String url, long startTime, long finishTime,
    FinalApplicationStatus finalStatus,
    ApplicationResourceUsageReport appResources, String origTrackingUrl,
    float progress, String appType, Token amRmToken, Set<String> tags) {
  ApplicationReport report = recordFactory
      .newRecordInstance(ApplicationReport.class);
  report.setApplicationId(applicationId);
  report.setCurrentApplicationAttemptId(applicationAttemptId);
  report.setUser(user);
  report.setQueue(queue);
  report.setName(name);
  report.setHost(host);
  report.setRpcPort(rpcPort);
  report.setClientToAMToken(clientToAMToken);
  report.setYarnApplicationState(state);
  report.setDiagnostics(diagnostics);
  report.setTrackingUrl(url);
  report.setStartTime(startTime);
  report.setFinishTime(finishTime);
  report.setFinalApplicationStatus(finalStatus);
  report.setApplicationResourceUsageReport(appResources);
  report.setOriginalTrackingUrl(origTrackingUrl);
  report.setProgress(progress);
  report.setApplicationType(appType);
  report.setAMRMToken(amRmToken);
  report.setApplicationTags(tags);
  return report;
}
项目:hadoop    文件:TestRemoteAppChecker.java   
@Test
public void testRunningApp() throws Exception {
  YarnClient client = createCheckerWithMockedClient();
  ApplicationId id = ApplicationId.newInstance(1, 1);

  // create a report and set the state to an active one
  ApplicationReport report = new ApplicationReportPBImpl();
  report.setYarnApplicationState(YarnApplicationState.ACCEPTED);
  doReturn(report).when(client).getApplicationReport(id);

  assertTrue(checker.isApplicationActive(id));
}