org.apache.hadoop.yarn.api.records.timeline.TimelineEvents Java Examples

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelineEvents. 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: TestTimelineWebServices.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEvents() throws Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .path("type_1").path("events")
      .queryParam("entityId", "id_1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelineEvents events = response.getEntity(TimelineEvents.class);
  Assert.assertNotNull(events);
  Assert.assertEquals(1, events.getAllEvents().size());
  TimelineEvents.EventsOfOneEntity partEvents = events.getAllEvents().get(0);
  Assert.assertEquals(2, partEvents.getEvents().size());
  TimelineEvent event1 = partEvents.getEvents().get(0);
  Assert.assertEquals(456l, event1.getTimestamp());
  Assert.assertEquals("end_event", event1.getEventType());
  Assert.assertEquals(1, event1.getEventInfo().size());
  TimelineEvent event2 = partEvents.getEvents().get(1);
  Assert.assertEquals(123l, event2.getTimestamp());
  Assert.assertEquals("start_event", event2.getEventType());
  Assert.assertEquals(0, event2.getEventInfo().size());
}
 
Example #2
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEvents() throws Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .path("type_1").path("events")
      .queryParam("entityId", "id_1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelineEvents events = response.getEntity(TimelineEvents.class);
  Assert.assertNotNull(events);
  Assert.assertEquals(1, events.getAllEvents().size());
  TimelineEvents.EventsOfOneEntity partEvents = events.getAllEvents().get(0);
  Assert.assertEquals(2, partEvents.getEvents().size());
  TimelineEvent event1 = partEvents.getEvents().get(0);
  Assert.assertEquals(456l, event1.getTimestamp());
  Assert.assertEquals("end_event", event1.getEventType());
  Assert.assertEquals(1, event1.getEventInfo().size());
  TimelineEvent event2 = partEvents.getEvents().get(1);
  Assert.assertEquals(123l, event2.getTimestamp());
  Assert.assertEquals("start_event", event2.getEventType());
  Assert.assertEquals(0, event2.getEventInfo().size());
}
 
Example #3
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 #4
Source File: TimelineDataManager.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Get the events whose entities the given user has access to. The meaning of
 * each argument has been documented with
 * {@link TimelineReader#getEntityTimelines}.
 * 
 * @see TimelineReader#getEntityTimelines
 */
public TimelineEvents getEvents(
    String entityType,
    SortedSet<String> entityIds,
    SortedSet<String> eventTypes,
    Long windowStart,
    Long windowEnd,
    Long limit,
    UserGroupInformation callerUGI) throws YarnException, IOException {
  TimelineEvents events = null;
  events = store.getEntityTimelines(
      entityType,
      entityIds,
      limit,
      windowStart,
      windowEnd,
      eventTypes);
  if (events != null) {
    Iterator<TimelineEvents.EventsOfOneEntity> eventsItr =
        events.getAllEvents().iterator();
    while (eventsItr.hasNext()) {
      TimelineEvents.EventsOfOneEntity eventsOfOneEntity = eventsItr.next();
      try {
        TimelineEntity entity = store.getEntity(
            eventsOfOneEntity.getEntityId(),
            eventsOfOneEntity.getEntityType(),
            EnumSet.of(Field.PRIMARY_FILTERS));
        addDefaultDomainIdIfAbsent(entity);
        // check ACLs
        if (!timelineACLsManager.checkAccess(
            callerUGI, ApplicationAccessType.VIEW_APP, entity)) {
          eventsItr.remove();
        }
      } catch (Exception e) {
        LOG.error("Error when verifying access for user " + callerUGI
            + " on the events of the timeline entity "
            + new EntityIdentifier(eventsOfOneEntity.getEntityId(),
                eventsOfOneEntity.getEntityType()), e);
        eventsItr.remove();
      }
    }
  }
  if (events == null) {
    return new TimelineEvents();
  }
  return events;
}
 
Example #5
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;
}
 
Example #6
Source File: TimelineDataManager.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Get the events whose entities the given user has access to. The meaning of
 * each argument has been documented with
 * {@link TimelineReader#getEntityTimelines}.
 * 
 * @see TimelineReader#getEntityTimelines
 */
public TimelineEvents getEvents(
    String entityType,
    SortedSet<String> entityIds,
    SortedSet<String> eventTypes,
    Long windowStart,
    Long windowEnd,
    Long limit,
    UserGroupInformation callerUGI) throws YarnException, IOException {
  TimelineEvents events = null;
  events = store.getEntityTimelines(
      entityType,
      entityIds,
      limit,
      windowStart,
      windowEnd,
      eventTypes);
  if (events != null) {
    Iterator<TimelineEvents.EventsOfOneEntity> eventsItr =
        events.getAllEvents().iterator();
    while (eventsItr.hasNext()) {
      TimelineEvents.EventsOfOneEntity eventsOfOneEntity = eventsItr.next();
      try {
        TimelineEntity entity = store.getEntity(
            eventsOfOneEntity.getEntityId(),
            eventsOfOneEntity.getEntityType(),
            EnumSet.of(Field.PRIMARY_FILTERS));
        addDefaultDomainIdIfAbsent(entity);
        // check ACLs
        if (!timelineACLsManager.checkAccess(
            callerUGI, ApplicationAccessType.VIEW_APP, entity)) {
          eventsItr.remove();
        }
      } catch (Exception e) {
        LOG.error("Error when verifying access for user " + callerUGI
            + " on the events of the timeline entity "
            + new EntityIdentifier(eventsOfOneEntity.getEntityId(),
                eventsOfOneEntity.getEntityType()), e);
        eventsItr.remove();
      }
    }
  }
  if (events == null) {
    return new TimelineEvents();
  }
  return events;
}
 
Example #7
Source File: TimelineReader.java    From ambari-metrics with Apache License 2.0 2 votes vote down vote up
/**
 * This method retrieves the events for a list of entities all of the same
 * entity type. The events for each entity are sorted in order of their
 * timestamps, descending.
 * 
 * @param entityType
 *          The type of entities to retrieve events for.
 * @param entityIds
 *          The entity IDs to retrieve events for.
 * @param limit
 *          A limit on the number of events to return for each entity. If
 *          null, defaults to {@link #DEFAULT_LIMIT} events per entity.
 * @param windowStart
 *          If not null, retrieves only events later than the given time
 *          (exclusive)
 * @param windowEnd
 *          If not null, retrieves only events earlier than the given time
 *          (inclusive)
 * @param eventTypes
 *          Restricts the events returned to the given types. If null, events
 *          of all types will be returned.
 * @return An {@link TimelineEvents} object.
 * @throws IOException
 */
TimelineEvents getEntityTimelines(String entityType,
    SortedSet<String> entityIds, Long limit, Long windowStart,
    Long windowEnd, Set<String> eventTypes) throws IOException;
 
Example #8
Source File: TimelineReader.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * This method retrieves the events for a list of entities all of the same
 * entity type. The events for each entity are sorted in order of their
 * timestamps, descending.
 * 
 * @param entityType
 *          The type of entities to retrieve events for.
 * @param entityIds
 *          The entity IDs to retrieve events for.
 * @param limit
 *          A limit on the number of events to return for each entity. If
 *          null, defaults to {@link #DEFAULT_LIMIT} events per entity.
 * @param windowStart
 *          If not null, retrieves only events later than the given time
 *          (exclusive)
 * @param windowEnd
 *          If not null, retrieves only events earlier than the given time
 *          (inclusive)
 * @param eventTypes
 *          Restricts the events returned to the given types. If null, events
 *          of all types will be returned.
 * @return An {@link TimelineEvents} object.
 * @throws IOException
 */
TimelineEvents getEntityTimelines(String entityType,
    SortedSet<String> entityIds, Long limit, Long windowStart,
    Long windowEnd, Set<String> eventTypes) throws IOException;
 
Example #9
Source File: TimelineReader.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * This method retrieves the events for a list of entities all of the same
 * entity type. The events for each entity are sorted in order of their
 * timestamps, descending.
 * 
 * @param entityType
 *          The type of entities to retrieve events for.
 * @param entityIds
 *          The entity IDs to retrieve events for.
 * @param limit
 *          A limit on the number of events to return for each entity. If
 *          null, defaults to {@link #DEFAULT_LIMIT} events per entity.
 * @param windowStart
 *          If not null, retrieves only events later than the given time
 *          (exclusive)
 * @param windowEnd
 *          If not null, retrieves only events earlier than the given time
 *          (inclusive)
 * @param eventTypes
 *          Restricts the events returned to the given types. If null, events
 *          of all types will be returned.
 * @return An {@link TimelineEvents} object.
 * @throws IOException
 */
TimelineEvents getEntityTimelines(String entityType,
    SortedSet<String> entityIds, Long limit, Long windowStart,
    Long windowEnd, Set<String> eventTypes) throws IOException;