Java Code Examples for org.apache.hadoop.yarn.api.records.ContainerReport#newInstance()

The following examples show how to use org.apache.hadoop.yarn.api.records.ContainerReport#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMContainerImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public ContainerReport createContainerReport() {
  this.readLock.lock();
  ContainerReport containerReport = null;
  try {
    containerReport = ContainerReport.newInstance(this.getContainerId(),
        this.getAllocatedResource(), this.getAllocatedNode(),
        this.getAllocatedPriority(), this.getCreationTime(),
        this.getFinishTime(), this.getDiagnosticsInfo(), this.getLogURL(),
        this.getContainerExitStatus(), this.getContainerState(),
        this.getNodeHttpAddress());
  } finally {
    this.readLock.unlock();
  }
  return containerReport;
}
 
Example 2
Source File: ApplicationHistoryManagerImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private ContainerReport convertToContainerReport(
    ContainerHistoryData containerHistory, String user) {
  // If the container has the aggregated log, add the server root url
  String logUrl = WebAppUtils.getAggregatedLogURL(
      serverHttpAddress,
      containerHistory.getAssignedNode().toString(),
      containerHistory.getContainerId().toString(),
      containerHistory.getContainerId().toString(),
      user);
  return ContainerReport.newInstance(containerHistory.getContainerId(),
    containerHistory.getAllocatedResource(),
    containerHistory.getAssignedNode(), containerHistory.getPriority(),
    containerHistory.getStartTime(), containerHistory.getFinishTime(),
    containerHistory.getDiagnosticsInfo(), logUrl,
    containerHistory.getContainerExitStatus(),
    containerHistory.getContainerState(), null);
}
 
Example 3
Source File: RMContainerImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public ContainerReport createContainerReport() {
  this.readLock.lock();
  ContainerReport containerReport = null;
  try {
    containerReport = ContainerReport.newInstance(this.getContainerId(),
        this.getAllocatedResource(), this.getAllocatedNode(),
        this.getAllocatedPriority(), this.getCreationTime(),
        this.getFinishTime(), this.getDiagnosticsInfo(), this.getLogURL(),
        this.getContainerExitStatus(), this.getContainerState(),
        this.getNodeHttpAddress());
  } finally {
    this.readLock.unlock();
  }
  return containerReport;
}
 
Example 4
Source File: ApplicationHistoryManagerImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
private ContainerReport convertToContainerReport(
    ContainerHistoryData containerHistory, String user) {
  // If the container has the aggregated log, add the server root url
  String logUrl = WebAppUtils.getAggregatedLogURL(
      serverHttpAddress,
      containerHistory.getAssignedNode().toString(),
      containerHistory.getContainerId().toString(),
      containerHistory.getContainerId().toString(),
      user);
  return ContainerReport.newInstance(containerHistory.getContainerId(),
    containerHistory.getAllocatedResource(),
    containerHistory.getAssignedNode(), containerHistory.getPriority(),
    containerHistory.getStartTime(), containerHistory.getFinishTime(),
    containerHistory.getDiagnosticsInfo(), logUrl,
    containerHistory.getContainerExitStatus(),
    containerHistory.getContainerState(), null);
}
 
Example 5
Source File: TestYarnCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetContainerReport() throws Exception {
  ApplicationCLI cli = createAndGetAppCLI();
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      applicationId, 1);
  ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
  ContainerReport container = ContainerReport.newInstance(containerId, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234, 5678,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  when(client.getContainerReport(any(ContainerId.class))).thenReturn(
      container);
  int result = cli.run(new String[] { "container", "-status",
      containerId.toString() });
  assertEquals(0, result);
  verify(client).getContainerReport(containerId);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Container Report : ");
  pw.println("\tContainer-Id : container_1234_0005_01_000001");
  pw.println("\tStart-Time : 1234");
  pw.println("\tFinish-Time : 5678");
  pw.println("\tState : COMPLETE");
  pw.println("\tLOG-URL : logURL");
  pw.println("\tHost : host:1234");
  pw.println("\tNodeHttpAddress : http://host:2345");
  pw.println("\tDiagnostics : diagnosticInfo");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
  verify(sysOut, times(1)).println(isA(String.class));
}
 
Example 6
Source File: TestYarnCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetContainerReport() throws Exception {
  ApplicationCLI cli = createAndGetAppCLI();
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      applicationId, 1);
  ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
  ContainerReport container = ContainerReport.newInstance(containerId, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234, 5678,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  when(client.getContainerReport(any(ContainerId.class))).thenReturn(
      container);
  int result = cli.run(new String[] { "container", "-status",
      containerId.toString() });
  assertEquals(0, result);
  verify(client).getContainerReport(containerId);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Container Report : ");
  pw.println("\tContainer-Id : container_1234_0005_01_000001");
  pw.println("\tStart-Time : 1234");
  pw.println("\tFinish-Time : 5678");
  pw.println("\tState : COMPLETE");
  pw.println("\tLOG-URL : logURL");
  pw.println("\tHost : host:1234");
  pw.println("\tNodeHttpAddress : http://host:2345");
  pw.println("\tDiagnostics : diagnosticInfo");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
  verify(sysOut, times(1)).println(isA(String.class));
}
 
Example 7
Source File: ProtocolHATestBase.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public ContainerReport createFakeContainerReport() {
  return ContainerReport.newInstance(createFakeContainerId(), null,
      NodeId.newInstance("localhost", 0), null, 1000l, 1200l, "", "", 0,
      ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("localhost", 0).toString());
}
 
Example 8
Source File: TestAHSClient.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void createAppReports() {
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationReport newApplicationReport =
      ApplicationReport.newInstance(applicationId,
        ApplicationAttemptId.newInstance(applicationId, 1), "user",
        "queue", "appname", "host", 124, null,
        YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN",
        null);
  List<ApplicationReport> applicationReports =
      new ArrayList<ApplicationReport>();
  applicationReports.add(newApplicationReport);
  List<ApplicationAttemptReport> appAttempts =
      new ArrayList<ApplicationAttemptReport>();
  ApplicationAttemptReport attempt =
      ApplicationAttemptReport.newInstance(
        ApplicationAttemptId.newInstance(applicationId, 1),
        "host",
        124,
        "url",
        "oUrl",
        "diagnostics",
        YarnApplicationAttemptState.FINISHED,
        ContainerId.newContainerId(
          newApplicationReport.getCurrentApplicationAttemptId(), 1));
  appAttempts.add(attempt);
  ApplicationAttemptReport attempt1 =
      ApplicationAttemptReport.newInstance(
        ApplicationAttemptId.newInstance(applicationId, 2),
        "host",
        124,
        "url",
        "oUrl",
        "diagnostics",
        YarnApplicationAttemptState.FINISHED,
        ContainerId.newContainerId(
          newApplicationReport.getCurrentApplicationAttemptId(), 2));
  appAttempts.add(attempt1);
  attempts.put(applicationId, appAttempts);

  List<ContainerReport> containerReports = new ArrayList<ContainerReport>();
  ContainerReport container =
      ContainerReport.newInstance(
        ContainerId.newContainerId(attempt.getApplicationAttemptId(), 1),
        null, NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234,
        5678, "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
        "http://" + NodeId.newInstance("host", 2345).toString());
  containerReports.add(container);

  ContainerReport container1 =
      ContainerReport.newInstance(
        ContainerId.newContainerId(attempt.getApplicationAttemptId(), 2),
        null, NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234,
        5678, "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
        "http://" + NodeId.newInstance("host", 2345).toString());
  containerReports.add(container1);
  containers.put(attempt.getApplicationAttemptId(), containerReports);

  ApplicationId applicationId2 = ApplicationId.newInstance(1234, 6);
  ApplicationReport newApplicationReport2 =
      ApplicationReport.newInstance(applicationId2,
        ApplicationAttemptId.newInstance(applicationId2, 2), "user2",
        "queue2", "appname2", "host2", 125, null,
        YarnApplicationState.FINISHED, "diagnostics2", "url2", 2, 2,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.63789f,
        "NON-YARN", null);
  applicationReports.add(newApplicationReport2);

  ApplicationId applicationId3 = ApplicationId.newInstance(1234, 7);
  ApplicationReport newApplicationReport3 =
      ApplicationReport.newInstance(applicationId3,
        ApplicationAttemptId.newInstance(applicationId3, 3), "user3",
        "queue3", "appname3", "host3", 126, null,
        YarnApplicationState.RUNNING, "diagnostics3", "url3", 3, 3,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.73789f,
        "MAPREDUCE", null);
  applicationReports.add(newApplicationReport3);

  ApplicationId applicationId4 = ApplicationId.newInstance(1234, 8);
  ApplicationReport newApplicationReport4 =
      ApplicationReport.newInstance(applicationId4,
        ApplicationAttemptId.newInstance(applicationId4, 4), "user4",
        "queue4", "appname4", "host4", 127, null,
        YarnApplicationState.FAILED, "diagnostics4", "url4", 4, 4,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.83789f,
        "NON-MAPREDUCE", null);
  applicationReports.add(newApplicationReport4);
  reports = applicationReports;
}
 
Example 9
Source File: TestYarnCLI.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetContainers() throws Exception {
  ApplicationCLI cli = createAndGetAppCLI();
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      applicationId, 1);
  ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
  ContainerId containerId1 = ContainerId.newContainerId(attemptId, 2);
  ContainerId containerId2 = ContainerId.newContainerId(attemptId, 3);
  long time1=1234,time2=5678;
  ContainerReport container = ContainerReport.newInstance(containerId, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  ContainerReport container1 = ContainerReport.newInstance(containerId1, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  ContainerReport container2 = ContainerReport.newInstance(containerId2, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1,0,
      "diagnosticInfo", "", 0, ContainerState.RUNNING,
      "http://" + NodeId.newInstance("host", 2345).toString());
  List<ContainerReport> reports = new ArrayList<ContainerReport>();
  reports.add(container);
  reports.add(container1);
  reports.add(container2);
  DateFormat dateFormat=new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
  when(client.getContainers(any(ApplicationAttemptId.class))).thenReturn(
      reports);
  sysOutStream.reset();
  int result = cli.run(new String[] { "container", "-list",
      attemptId.toString() });
  assertEquals(0, result);
  verify(client).getContainers(attemptId);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Total number of containers :3");
  pw.print("                  Container-Id");
  pw.print("\t          Start Time");
  pw.print("\t         Finish Time");
  pw.print("\t               State");
  pw.print("\t                Host");
  pw.print("\t   Node Http Address");
  pw.println("\t                            LOG-URL");
  pw.print(" container_1234_0005_01_000001");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t"+dateFormat.format(new Date(time2)));
  pw.print("\t            COMPLETE");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                             logURL");
  pw.print(" container_1234_0005_01_000002");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t"+dateFormat.format(new Date(time2)));
  pw.print("\t            COMPLETE");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                             logURL");
  pw.print(" container_1234_0005_01_000003");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t                 N/A");
  pw.print("\t             RUNNING");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                                   ");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Log.info("ExpectedOutput");
  Log.info("["+appReportStr+"]");
  Log.info("OutputFrom command");
  String actualOutput = sysOutStream.toString();
  Log.info("["+actualOutput+"]");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
}
 
Example 10
Source File: ApplicationHistoryManagerOnTimelineStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static ContainerReport convertToContainerReport(
    TimelineEntity entity, String serverHttpAddress, String user) {
  int allocatedMem = 0;
  int allocatedVcore = 0;
  String allocatedHost = null;
  int allocatedPort = -1;
  int allocatedPriority = 0;
  long createdTime = 0;
  long finishedTime = 0;
  String diagnosticsInfo = null;
  int exitStatus = ContainerExitStatus.INVALID;
  ContainerState state = null;
  String nodeHttpAddress = null;
  Map<String, Object> entityInfo = entity.getOtherInfo();
  if (entityInfo != null) {
    if (entityInfo
        .containsKey(ContainerMetricsConstants.ALLOCATED_MEMORY_ENTITY_INFO)) {
      allocatedMem = (Integer) entityInfo.get(
              ContainerMetricsConstants.ALLOCATED_MEMORY_ENTITY_INFO);
    }
    if (entityInfo
        .containsKey(ContainerMetricsConstants.ALLOCATED_VCORE_ENTITY_INFO)) {
      allocatedVcore = (Integer) entityInfo.get(
              ContainerMetricsConstants.ALLOCATED_VCORE_ENTITY_INFO);
    }
    if (entityInfo
        .containsKey(ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO)) {
      allocatedHost =
          entityInfo
              .get(ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO)
              .toString();
    }
    if (entityInfo
        .containsKey(ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO)) {
      allocatedPort = (Integer) entityInfo.get(
              ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO);
    }
    if (entityInfo
        .containsKey(ContainerMetricsConstants.ALLOCATED_PRIORITY_ENTITY_INFO)) {
      allocatedPriority = (Integer) entityInfo.get(
              ContainerMetricsConstants.ALLOCATED_PRIORITY_ENTITY_INFO);
    }
    if (entityInfo.containsKey(
        ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_ENTITY_INFO)) {
      nodeHttpAddress =
          (String) entityInfo
            .get(ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_ENTITY_INFO);
    }
  }
  List<TimelineEvent> events = entity.getEvents();
  if (events != null) {
    for (TimelineEvent event : events) {
      if (event.getEventType().equals(
          ContainerMetricsConstants.CREATED_EVENT_TYPE)) {
        createdTime = event.getTimestamp();
      } else if (event.getEventType().equals(
          ContainerMetricsConstants.FINISHED_EVENT_TYPE)) {
        finishedTime = event.getTimestamp();
        Map<String, Object> eventInfo = event.getEventInfo();
        if (eventInfo == null) {
          continue;
        }
        if (eventInfo
            .containsKey(ContainerMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO)) {
          diagnosticsInfo =
              eventInfo.get(
                  ContainerMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO)
                  .toString();
        }
        if (eventInfo
            .containsKey(ContainerMetricsConstants.EXIT_STATUS_EVENT_INFO)) {
          exitStatus = (Integer) eventInfo.get(
                  ContainerMetricsConstants.EXIT_STATUS_EVENT_INFO);
        }
        if (eventInfo
            .containsKey(ContainerMetricsConstants.STATE_EVENT_INFO)) {
          state =
              ContainerState.valueOf(eventInfo.get(
                  ContainerMetricsConstants.STATE_EVENT_INFO).toString());
        }
      }
    }
  }
  NodeId allocatedNode = NodeId.newInstance(allocatedHost, allocatedPort);
  ContainerId containerId =
      ConverterUtils.toContainerId(entity.getEntityId());
  String logUrl = WebAppUtils.getAggregatedLogURL(
      serverHttpAddress,
      allocatedNode.toString(),
      containerId.toString(),
      containerId.toString(),
      user);
  return ContainerReport.newInstance(
      ConverterUtils.toContainerId(entity.getEntityId()),
      Resource.newInstance(allocatedMem, allocatedVcore),
      NodeId.newInstance(allocatedHost, allocatedPort),
      Priority.newInstance(allocatedPriority),
      createdTime, finishedTime, diagnosticsInfo, logUrl, exitStatus, state,
      nodeHttpAddress);
}
 
Example 11
Source File: ProtocolHATestBase.java    From big-c with Apache License 2.0 4 votes vote down vote up
public ContainerReport createFakeContainerReport() {
  return ContainerReport.newInstance(createFakeContainerId(), null,
      NodeId.newInstance("localhost", 0), null, 1000l, 1200l, "", "", 0,
      ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("localhost", 0).toString());
}
 
Example 12
Source File: TestAHSClient.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void createAppReports() {
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationReport newApplicationReport =
      ApplicationReport.newInstance(applicationId,
        ApplicationAttemptId.newInstance(applicationId, 1), "user",
        "queue", "appname", "host", 124, null,
        YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN",
        null);
  List<ApplicationReport> applicationReports =
      new ArrayList<ApplicationReport>();
  applicationReports.add(newApplicationReport);
  List<ApplicationAttemptReport> appAttempts =
      new ArrayList<ApplicationAttemptReport>();
  ApplicationAttemptReport attempt =
      ApplicationAttemptReport.newInstance(
        ApplicationAttemptId.newInstance(applicationId, 1),
        "host",
        124,
        "url",
        "oUrl",
        "diagnostics",
        YarnApplicationAttemptState.FINISHED,
        ContainerId.newContainerId(
          newApplicationReport.getCurrentApplicationAttemptId(), 1));
  appAttempts.add(attempt);
  ApplicationAttemptReport attempt1 =
      ApplicationAttemptReport.newInstance(
        ApplicationAttemptId.newInstance(applicationId, 2),
        "host",
        124,
        "url",
        "oUrl",
        "diagnostics",
        YarnApplicationAttemptState.FINISHED,
        ContainerId.newContainerId(
          newApplicationReport.getCurrentApplicationAttemptId(), 2));
  appAttempts.add(attempt1);
  attempts.put(applicationId, appAttempts);

  List<ContainerReport> containerReports = new ArrayList<ContainerReport>();
  ContainerReport container =
      ContainerReport.newInstance(
        ContainerId.newContainerId(attempt.getApplicationAttemptId(), 1),
        null, NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234,
        5678, "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
        "http://" + NodeId.newInstance("host", 2345).toString());
  containerReports.add(container);

  ContainerReport container1 =
      ContainerReport.newInstance(
        ContainerId.newContainerId(attempt.getApplicationAttemptId(), 2),
        null, NodeId.newInstance("host", 1234), Priority.UNDEFINED, 1234,
        5678, "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
        "http://" + NodeId.newInstance("host", 2345).toString());
  containerReports.add(container1);
  containers.put(attempt.getApplicationAttemptId(), containerReports);

  ApplicationId applicationId2 = ApplicationId.newInstance(1234, 6);
  ApplicationReport newApplicationReport2 =
      ApplicationReport.newInstance(applicationId2,
        ApplicationAttemptId.newInstance(applicationId2, 2), "user2",
        "queue2", "appname2", "host2", 125, null,
        YarnApplicationState.FINISHED, "diagnostics2", "url2", 2, 2,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.63789f,
        "NON-YARN", null);
  applicationReports.add(newApplicationReport2);

  ApplicationId applicationId3 = ApplicationId.newInstance(1234, 7);
  ApplicationReport newApplicationReport3 =
      ApplicationReport.newInstance(applicationId3,
        ApplicationAttemptId.newInstance(applicationId3, 3), "user3",
        "queue3", "appname3", "host3", 126, null,
        YarnApplicationState.RUNNING, "diagnostics3", "url3", 3, 3,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.73789f,
        "MAPREDUCE", null);
  applicationReports.add(newApplicationReport3);

  ApplicationId applicationId4 = ApplicationId.newInstance(1234, 8);
  ApplicationReport newApplicationReport4 =
      ApplicationReport.newInstance(applicationId4,
        ApplicationAttemptId.newInstance(applicationId4, 4), "user4",
        "queue4", "appname4", "host4", 127, null,
        YarnApplicationState.FAILED, "diagnostics4", "url4", 4, 4,
        FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.83789f,
        "NON-MAPREDUCE", null);
  applicationReports.add(newApplicationReport4);
  reports = applicationReports;
}
 
Example 13
Source File: TestYarnCLI.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetContainers() throws Exception {
  ApplicationCLI cli = createAndGetAppCLI();
  ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
      applicationId, 1);
  ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
  ContainerId containerId1 = ContainerId.newContainerId(attemptId, 2);
  ContainerId containerId2 = ContainerId.newContainerId(attemptId, 3);
  long time1=1234,time2=5678;
  ContainerReport container = ContainerReport.newInstance(containerId, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  ContainerReport container1 = ContainerReport.newInstance(containerId1, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1, time2,
      "diagnosticInfo", "logURL", 0, ContainerState.COMPLETE,
      "http://" + NodeId.newInstance("host", 2345).toString());
  ContainerReport container2 = ContainerReport.newInstance(containerId2, null,
      NodeId.newInstance("host", 1234), Priority.UNDEFINED, time1,0,
      "diagnosticInfo", "", 0, ContainerState.RUNNING,
      "http://" + NodeId.newInstance("host", 2345).toString());
  List<ContainerReport> reports = new ArrayList<ContainerReport>();
  reports.add(container);
  reports.add(container1);
  reports.add(container2);
  DateFormat dateFormat=new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
  when(client.getContainers(any(ApplicationAttemptId.class))).thenReturn(
      reports);
  sysOutStream.reset();
  int result = cli.run(new String[] { "container", "-list",
      attemptId.toString() });
  assertEquals(0, result);
  verify(client).getContainers(attemptId);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.println("Total number of containers :3");
  pw.print("                  Container-Id");
  pw.print("\t          Start Time");
  pw.print("\t         Finish Time");
  pw.print("\t               State");
  pw.print("\t                Host");
  pw.print("\t   Node Http Address");
  pw.println("\t                            LOG-URL");
  pw.print(" container_1234_0005_01_000001");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t"+dateFormat.format(new Date(time2)));
  pw.print("\t            COMPLETE");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                             logURL");
  pw.print(" container_1234_0005_01_000002");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t"+dateFormat.format(new Date(time2)));
  pw.print("\t            COMPLETE");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                             logURL");
  pw.print(" container_1234_0005_01_000003");
  pw.print("\t"+dateFormat.format(new Date(time1)));
  pw.print("\t                 N/A");
  pw.print("\t             RUNNING");
  pw.print("\t           host:1234");
  pw.print("\t    http://host:2345");
  pw.println("\t                                   ");
  pw.close();
  String appReportStr = baos.toString("UTF-8");
  Log.info("ExpectedOutput");
  Log.info("["+appReportStr+"]");
  Log.info("OutputFrom command");
  String actualOutput = sysOutStream.toString();
  Log.info("["+actualOutput+"]");
  Assert.assertEquals(appReportStr, sysOutStream.toString());
}