Java Code Examples for org.apache.hadoop.yarn.api.records.timeline.TimelineEntity#getEvents()

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelineEntity#getEvents() . 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: TestSystemMetricsPublisher.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishApplicationMetrics() throws Exception {
  for (int i = 1; i <= 2; ++i) {
    ApplicationId appId = ApplicationId.newInstance(0, i);
    RMApp app = createRMApp(appId);
    metricsPublisher.appCreated(app, app.getStartTime());
    metricsPublisher.appFinished(app, RMAppState.FINISHED, app.getFinishTime());
    if (i == 1) {
      metricsPublisher.appACLsUpdated(app, "uers1,user2", 4L);
    } else {
      // in case user doesn't specify the ACLs
      metricsPublisher.appACLsUpdated(app, null, 4L);
    }
    TimelineEntity entity = null;
    do {
      entity =
          store.getEntity(appId.toString(),
              ApplicationMetricsConstants.ENTITY_TYPE,
              EnumSet.allOf(Field.class));
      // ensure three events are both published before leaving the loop
    } while (entity == null || entity.getEvents().size() < 3);
    // verify all the fields
    Assert.assertEquals(ApplicationMetricsConstants.ENTITY_TYPE,
        entity.getEntityType());
    Assert
        .assertEquals(app.getApplicationId().toString(), entity.getEntityId());
    Assert
        .assertEquals(
            app.getName(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.NAME_ENTITY_INFO));
    Assert.assertEquals(app.getQueue(),
        entity.getOtherInfo()
            .get(ApplicationMetricsConstants.QUEUE_ENTITY_INFO));
    Assert
        .assertEquals(
            app.getUser(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.USER_ENTITY_INFO));
    Assert
        .assertEquals(
            app.getApplicationType(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.TYPE_ENTITY_INFO));
    Assert.assertEquals(app.getSubmitTime(),
        entity.getOtherInfo().get(
            ApplicationMetricsConstants.SUBMITTED_TIME_ENTITY_INFO));
    if (i == 1) {
      Assert.assertEquals("uers1,user2",
          entity.getOtherInfo().get(
              ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
    } else {
      Assert.assertEquals(
          "",
          entity.getOtherInfo().get(
              ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
      Assert.assertEquals(
          app.getRMAppMetrics().getMemorySeconds(),
          Long.parseLong(entity.getOtherInfo()
              .get(ApplicationMetricsConstants.APP_MEM_METRICS).toString()));
      Assert.assertEquals(
          app.getRMAppMetrics().getVcoreSeconds(),
          Long.parseLong(entity.getOtherInfo()
              .get(ApplicationMetricsConstants.APP_CPU_METRICS).toString()));
      Assert.assertEquals(
          app.getRMAppMetrics().getGcoreSeconds(),
          Long.parseLong(entity.getOtherInfo()
              .get(ApplicationMetricsConstants.APP_GPU_METRICS).toString()));
    }
    boolean hasCreatedEvent = false;
    boolean hasFinishedEvent = false;
    boolean hasACLsUpdatedEvent = false;
    for (TimelineEvent event : entity.getEvents()) {
      if (event.getEventType().equals(
          ApplicationMetricsConstants.CREATED_EVENT_TYPE)) {
        hasCreatedEvent = true;
        Assert.assertEquals(app.getStartTime(), event.getTimestamp());
      } else if (event.getEventType().equals(
          ApplicationMetricsConstants.FINISHED_EVENT_TYPE)) {
        hasFinishedEvent = true;
        Assert.assertEquals(app.getFinishTime(), event.getTimestamp());
        Assert.assertEquals(
            app.getDiagnostics().toString(),
            event.getEventInfo().get(
                ApplicationMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
        Assert.assertEquals(
            app.getFinalApplicationStatus().toString(),
            event.getEventInfo().get(
                ApplicationMetricsConstants.FINAL_STATUS_EVENT_INFO));
        Assert.assertEquals(YarnApplicationState.FINISHED.toString(), event
            .getEventInfo().get(ApplicationMetricsConstants.STATE_EVENT_INFO));
      } else if (event.getEventType().equals(
          ApplicationMetricsConstants.ACLS_UPDATED_EVENT_TYPE)) {
        hasACLsUpdatedEvent = true;
        Assert.assertEquals(4L, event.getTimestamp());
      }
    }
    Assert.assertTrue(hasCreatedEvent && hasFinishedEvent && hasACLsUpdatedEvent);
  }
}
 
Example 2
Source File: TestSystemMetricsPublisher.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishAppAttemptMetrics() throws Exception {
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
  RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId);
  metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L);
  RMApp app = mock(RMApp.class);
  when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED);
  metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app,
      Integer.MAX_VALUE + 2L);
  TimelineEntity entity = null;
  do {
    entity =
        store.getEntity(appAttemptId.toString(),
            AppAttemptMetricsConstants.ENTITY_TYPE,
            EnumSet.allOf(Field.class));
    // ensure two events are both published before leaving the loop
  } while (entity == null || entity.getEvents().size() < 2);
  // verify all the fields
  Assert.assertEquals(AppAttemptMetricsConstants.ENTITY_TYPE,
      entity.getEntityType());
  Assert.assertEquals(appAttemptId.toString(), entity.getEntityId());
  Assert.assertEquals(
      appAttemptId.getApplicationId().toString(),
      entity.getPrimaryFilters()
          .get(AppAttemptMetricsConstants.PARENT_PRIMARY_FILTER).iterator()
          .next());
  boolean hasRegisteredEvent = false;
  boolean hasFinishedEvent = false;
  for (TimelineEvent event : entity.getEvents()) {
    if (event.getEventType().equals(
        AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE)) {
      hasRegisteredEvent = true;
      Assert.assertEquals(appAttempt.getHost(),
          event.getEventInfo()
              .get(AppAttemptMetricsConstants.HOST_EVENT_INFO));
      Assert
          .assertEquals(appAttempt.getRpcPort(),
              event.getEventInfo().get(
                  AppAttemptMetricsConstants.RPC_PORT_EVENT_INFO));
      Assert.assertEquals(
          appAttempt.getMasterContainer().getId().toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.MASTER_CONTAINER_EVENT_INFO));
    } else if (event.getEventType().equals(
        AppAttemptMetricsConstants.FINISHED_EVENT_TYPE)) {
      hasFinishedEvent = true;
      Assert.assertEquals(appAttempt.getDiagnostics(), event.getEventInfo()
          .get(AppAttemptMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
      Assert.assertEquals(appAttempt.getTrackingUrl(), event.getEventInfo()
          .get(AppAttemptMetricsConstants.TRACKING_URL_EVENT_INFO));
      Assert.assertEquals(
          appAttempt.getOriginalTrackingUrl(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.ORIGINAL_TRACKING_URL_EVENT_INFO));
      Assert.assertEquals(
          FinalApplicationStatus.UNDEFINED.toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.FINAL_STATUS_EVENT_INFO));
      Assert.assertEquals(
          YarnApplicationAttemptState.FINISHED.toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.STATE_EVENT_INFO));
    }
  }
  Assert.assertTrue(hasRegisteredEvent && hasFinishedEvent);
}
 
Example 3
Source File: TestSystemMetricsPublisher.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishContainerMetrics() throws Exception {
  ContainerId containerId =
      ContainerId.newContainerId(ApplicationAttemptId.newInstance(
          ApplicationId.newInstance(0, 1), 1), 1);
  RMContainer container = createRMContainer(containerId);
  metricsPublisher.containerCreated(container, container.getCreationTime());
  metricsPublisher.containerFinished(container, container.getFinishTime());
  TimelineEntity entity = null;
  do {
    entity =
        store.getEntity(containerId.toString(),
            ContainerMetricsConstants.ENTITY_TYPE,
            EnumSet.allOf(Field.class));
    // ensure two events are both published before leaving the loop
  } while (entity == null || entity.getEvents().size() < 2);
  // verify all the fields
  Assert.assertEquals(ContainerMetricsConstants.ENTITY_TYPE,
      entity.getEntityType());
  Assert.assertEquals(containerId.toString(), entity.getEntityId());
  Assert.assertEquals(
      containerId.getApplicationAttemptId().toString(),
      entity.getPrimaryFilters()
          .get(ContainerMetricsConstants.PARENT_PRIMARIY_FILTER).iterator()
          .next());
  Assert.assertEquals(
      container.getAllocatedNode().getHost(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedNode().getPort(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedResource().getMemory(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_MEMORY_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedResource().getVirtualCores(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_VCORE_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedResource().getGpuCores(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_GCORE_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedPriority().getPriority(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_PRIORITY_ENTITY_INFO));
  boolean hasCreatedEvent = false;
  boolean hasFinishedEvent = false;
  for (TimelineEvent event : entity.getEvents()) {
    if (event.getEventType().equals(
        ContainerMetricsConstants.CREATED_EVENT_TYPE)) {
      hasCreatedEvent = true;
      Assert.assertEquals(container.getCreationTime(), event.getTimestamp());
    } else if (event.getEventType().equals(
        ContainerMetricsConstants.FINISHED_EVENT_TYPE)) {
      hasFinishedEvent = true;
      Assert.assertEquals(container.getFinishTime(), event.getTimestamp());
      Assert.assertEquals(
          container.getDiagnosticsInfo(),
          event.getEventInfo().get(
              ContainerMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
      Assert.assertEquals(
          container.getContainerExitStatus(),
          event.getEventInfo().get(
              ContainerMetricsConstants.EXIT_STATUS_EVENT_INFO));
      Assert.assertEquals(container.getContainerState().toString(), event
          .getEventInfo().get(ContainerMetricsConstants.STATE_EVENT_INFO));
    }
  }
  Assert.assertTrue(hasCreatedEvent && hasFinishedEvent);
}
 
Example 4
Source File: MemoryTimelineStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized TimelineEvents getEntityTimelines(String entityType,
    SortedSet<String> entityIds, Long limit, Long windowStart,
    Long windowEnd,
    Set<String> eventTypes) {
  TimelineEvents allEvents = new TimelineEvents();
  if (entityIds == null) {
    return allEvents;
  }
  if (limit == null) {
    limit = DEFAULT_LIMIT;
  }
  if (windowStart == null) {
    windowStart = Long.MIN_VALUE;
  }
  if (windowEnd == null) {
    windowEnd = Long.MAX_VALUE;
  }
  for (String entityId : entityIds) {
    EntityIdentifier entityID = new EntityIdentifier(entityId, entityType);
    TimelineEntity entity = entities.get(entityID);
    if (entity == null) {
      continue;
    }
    EventsOfOneEntity events = new EventsOfOneEntity();
    events.setEntityId(entityId);
    events.setEntityType(entityType);
    for (TimelineEvent event : entity.getEvents()) {
      if (events.getEvents().size() >= limit) {
        break;
      }
      if (event.getTimestamp() <= windowStart) {
        continue;
      }
      if (event.getTimestamp() > windowEnd) {
        continue;
      }
      if (eventTypes != null && !eventTypes.contains(event.getEventType())) {
        continue;
      }
      events.addEvent(event);
    }
    allEvents.addEvent(events);
  }
  return allEvents;
}
 
Example 5
Source File: TestSystemMetricsPublisher.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishApplicationMetrics() throws Exception {
  for (int i = 1; i <= 2; ++i) {
    ApplicationId appId = ApplicationId.newInstance(0, i);
    RMApp app = createRMApp(appId);
    metricsPublisher.appCreated(app, app.getStartTime());
    metricsPublisher.appFinished(app, RMAppState.FINISHED, app.getFinishTime());
    if (i == 1) {
      metricsPublisher.appACLsUpdated(app, "uers1,user2", 4L);
    } else {
      // in case user doesn't specify the ACLs
      metricsPublisher.appACLsUpdated(app, null, 4L);
    }
    TimelineEntity entity = null;
    do {
      entity =
          store.getEntity(appId.toString(),
              ApplicationMetricsConstants.ENTITY_TYPE,
              EnumSet.allOf(Field.class));
      // ensure three events are both published before leaving the loop
    } while (entity == null || entity.getEvents().size() < 3);
    // verify all the fields
    Assert.assertEquals(ApplicationMetricsConstants.ENTITY_TYPE,
        entity.getEntityType());
    Assert
        .assertEquals(app.getApplicationId().toString(), entity.getEntityId());
    Assert
        .assertEquals(
            app.getName(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.NAME_ENTITY_INFO));
    Assert.assertEquals(app.getQueue(),
        entity.getOtherInfo()
            .get(ApplicationMetricsConstants.QUEUE_ENTITY_INFO));
    Assert
        .assertEquals(
            app.getUser(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.USER_ENTITY_INFO));
    Assert
        .assertEquals(
            app.getApplicationType(),
            entity.getOtherInfo().get(
                ApplicationMetricsConstants.TYPE_ENTITY_INFO));
    Assert.assertEquals(app.getSubmitTime(),
        entity.getOtherInfo().get(
            ApplicationMetricsConstants.SUBMITTED_TIME_ENTITY_INFO));
    if (i == 1) {
      Assert.assertEquals("uers1,user2",
          entity.getOtherInfo().get(
              ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
    } else {
      Assert.assertEquals(
          "",
          entity.getOtherInfo().get(
              ApplicationMetricsConstants.APP_VIEW_ACLS_ENTITY_INFO));
      Assert.assertEquals(
          app.getRMAppMetrics().getMemorySeconds(),
          Long.parseLong(entity.getOtherInfo()
              .get(ApplicationMetricsConstants.APP_MEM_METRICS).toString()));
      Assert.assertEquals(
          app.getRMAppMetrics().getVcoreSeconds(),
          Long.parseLong(entity.getOtherInfo()
              .get(ApplicationMetricsConstants.APP_CPU_METRICS).toString()));
    }
    boolean hasCreatedEvent = false;
    boolean hasFinishedEvent = false;
    boolean hasACLsUpdatedEvent = false;
    for (TimelineEvent event : entity.getEvents()) {
      if (event.getEventType().equals(
          ApplicationMetricsConstants.CREATED_EVENT_TYPE)) {
        hasCreatedEvent = true;
        Assert.assertEquals(app.getStartTime(), event.getTimestamp());
      } else if (event.getEventType().equals(
          ApplicationMetricsConstants.FINISHED_EVENT_TYPE)) {
        hasFinishedEvent = true;
        Assert.assertEquals(app.getFinishTime(), event.getTimestamp());
        Assert.assertEquals(
            app.getDiagnostics().toString(),
            event.getEventInfo().get(
                ApplicationMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
        Assert.assertEquals(
            app.getFinalApplicationStatus().toString(),
            event.getEventInfo().get(
                ApplicationMetricsConstants.FINAL_STATUS_EVENT_INFO));
        Assert.assertEquals(YarnApplicationState.FINISHED.toString(), event
            .getEventInfo().get(ApplicationMetricsConstants.STATE_EVENT_INFO));
      } else if (event.getEventType().equals(
          ApplicationMetricsConstants.ACLS_UPDATED_EVENT_TYPE)) {
        hasACLsUpdatedEvent = true;
        Assert.assertEquals(4L, event.getTimestamp());
      }
    }
    Assert.assertTrue(hasCreatedEvent && hasFinishedEvent && hasACLsUpdatedEvent);
  }
}
 
Example 6
Source File: TestSystemMetricsPublisher.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishAppAttemptMetrics() throws Exception {
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
  RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId);
  metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L);
  RMApp app = mock(RMApp.class);
  when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED);
  metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app,
      Integer.MAX_VALUE + 2L);
  TimelineEntity entity = null;
  do {
    entity =
        store.getEntity(appAttemptId.toString(),
            AppAttemptMetricsConstants.ENTITY_TYPE,
            EnumSet.allOf(Field.class));
    // ensure two events are both published before leaving the loop
  } while (entity == null || entity.getEvents().size() < 2);
  // verify all the fields
  Assert.assertEquals(AppAttemptMetricsConstants.ENTITY_TYPE,
      entity.getEntityType());
  Assert.assertEquals(appAttemptId.toString(), entity.getEntityId());
  Assert.assertEquals(
      appAttemptId.getApplicationId().toString(),
      entity.getPrimaryFilters()
          .get(AppAttemptMetricsConstants.PARENT_PRIMARY_FILTER).iterator()
          .next());
  boolean hasRegisteredEvent = false;
  boolean hasFinishedEvent = false;
  for (TimelineEvent event : entity.getEvents()) {
    if (event.getEventType().equals(
        AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE)) {
      hasRegisteredEvent = true;
      Assert.assertEquals(appAttempt.getHost(),
          event.getEventInfo()
              .get(AppAttemptMetricsConstants.HOST_EVENT_INFO));
      Assert
          .assertEquals(appAttempt.getRpcPort(),
              event.getEventInfo().get(
                  AppAttemptMetricsConstants.RPC_PORT_EVENT_INFO));
      Assert.assertEquals(
          appAttempt.getMasterContainer().getId().toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.MASTER_CONTAINER_EVENT_INFO));
    } else if (event.getEventType().equals(
        AppAttemptMetricsConstants.FINISHED_EVENT_TYPE)) {
      hasFinishedEvent = true;
      Assert.assertEquals(appAttempt.getDiagnostics(), event.getEventInfo()
          .get(AppAttemptMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
      Assert.assertEquals(appAttempt.getTrackingUrl(), event.getEventInfo()
          .get(AppAttemptMetricsConstants.TRACKING_URL_EVENT_INFO));
      Assert.assertEquals(
          appAttempt.getOriginalTrackingUrl(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.ORIGINAL_TRACKING_URL_EVENT_INFO));
      Assert.assertEquals(
          FinalApplicationStatus.UNDEFINED.toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.FINAL_STATUS_EVENT_INFO));
      Assert.assertEquals(
          YarnApplicationAttemptState.FINISHED.toString(),
          event.getEventInfo().get(
              AppAttemptMetricsConstants.STATE_EVENT_INFO));
    }
  }
  Assert.assertTrue(hasRegisteredEvent && hasFinishedEvent);
}
 
Example 7
Source File: TestSystemMetricsPublisher.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 10000)
public void testPublishContainerMetrics() throws Exception {
  ContainerId containerId =
      ContainerId.newContainerId(ApplicationAttemptId.newInstance(
          ApplicationId.newInstance(0, 1), 1), 1);
  RMContainer container = createRMContainer(containerId);
  metricsPublisher.containerCreated(container, container.getCreationTime());
  metricsPublisher.containerFinished(container, container.getFinishTime());
  TimelineEntity entity = null;
  do {
    entity =
        store.getEntity(containerId.toString(),
            ContainerMetricsConstants.ENTITY_TYPE,
            EnumSet.allOf(Field.class));
    // ensure two events are both published before leaving the loop
  } while (entity == null || entity.getEvents().size() < 2);
  // verify all the fields
  Assert.assertEquals(ContainerMetricsConstants.ENTITY_TYPE,
      entity.getEntityType());
  Assert.assertEquals(containerId.toString(), entity.getEntityId());
  Assert.assertEquals(
      containerId.getApplicationAttemptId().toString(),
      entity.getPrimaryFilters()
          .get(ContainerMetricsConstants.PARENT_PRIMARIY_FILTER).iterator()
          .next());
  Assert.assertEquals(
      container.getAllocatedNode().getHost(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_HOST_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedNode().getPort(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_PORT_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedResource().getMemory(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_MEMORY_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedResource().getVirtualCores(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_VCORE_ENTITY_INFO));
  Assert.assertEquals(
      container.getAllocatedPriority().getPriority(),
      entity.getOtherInfo().get(
          ContainerMetricsConstants.ALLOCATED_PRIORITY_ENTITY_INFO));
  boolean hasCreatedEvent = false;
  boolean hasFinishedEvent = false;
  for (TimelineEvent event : entity.getEvents()) {
    if (event.getEventType().equals(
        ContainerMetricsConstants.CREATED_EVENT_TYPE)) {
      hasCreatedEvent = true;
      Assert.assertEquals(container.getCreationTime(), event.getTimestamp());
    } else if (event.getEventType().equals(
        ContainerMetricsConstants.FINISHED_EVENT_TYPE)) {
      hasFinishedEvent = true;
      Assert.assertEquals(container.getFinishTime(), event.getTimestamp());
      Assert.assertEquals(
          container.getDiagnosticsInfo(),
          event.getEventInfo().get(
              ContainerMetricsConstants.DIAGNOSTICS_INFO_EVENT_INFO));
      Assert.assertEquals(
          container.getContainerExitStatus(),
          event.getEventInfo().get(
              ContainerMetricsConstants.EXIT_STATUS_EVENT_INFO));
      Assert.assertEquals(container.getContainerState().toString(), event
          .getEventInfo().get(ContainerMetricsConstants.STATE_EVENT_INFO));
    }
  }
  Assert.assertTrue(hasCreatedEvent && hasFinishedEvent);
}
 
Example 8
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 9
Source File: MemoryTimelineStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized TimelineEvents getEntityTimelines(String entityType,
    SortedSet<String> entityIds, Long limit, Long windowStart,
    Long windowEnd,
    Set<String> eventTypes) {
  TimelineEvents allEvents = new TimelineEvents();
  if (entityIds == null) {
    return allEvents;
  }
  if (limit == null) {
    limit = DEFAULT_LIMIT;
  }
  if (windowStart == null) {
    windowStart = Long.MIN_VALUE;
  }
  if (windowEnd == null) {
    windowEnd = Long.MAX_VALUE;
  }
  for (String entityId : entityIds) {
    EntityIdentifier entityID = new EntityIdentifier(entityId, entityType);
    TimelineEntity entity = entities.get(entityID);
    if (entity == null) {
      continue;
    }
    EventsOfOneEntity events = new EventsOfOneEntity();
    events.setEntityId(entityId);
    events.setEntityType(entityType);
    for (TimelineEvent event : entity.getEvents()) {
      if (events.getEvents().size() >= limit) {
        break;
      }
      if (event.getTimestamp() <= windowStart) {
        continue;
      }
      if (event.getTimestamp() > windowEnd) {
        continue;
      }
      if (eventTypes != null && !eventTypes.contains(event.getEventType())) {
        continue;
      }
      events.addEvent(event);
    }
    allEvents.addEvent(events);
  }
  return allEvents;
}