Search in sources :

Example 41 with TimelineEvent

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent in project hadoop by apache.

the class TimelineEntityReader method readEvents.

/**
   * Read events from the entity table or the application table. The column name
   * is of the form "eventId=timestamp=infoKey" where "infoKey" may be omitted
   * if there is no info associated with the event.
   *
   * @param <T> Describes the type of column prefix.
   * @param entity entity to fill.
   * @param result HBase Result.
   * @param prefix column prefix.
   * @throws IOException if any problem is encountered while reading result.
   */
protected static <T> void readEvents(TimelineEntity entity, Result result, ColumnPrefix<T> prefix) throws IOException {
    Map<String, TimelineEvent> eventsMap = new HashMap<>();
    Map<EventColumnName, Object> eventsResult = prefix.readResults(result, new EventColumnNameConverter());
    for (Map.Entry<EventColumnName, Object> eventResult : eventsResult.entrySet()) {
        EventColumnName eventColumnName = eventResult.getKey();
        String key = eventColumnName.getId() + Long.toString(eventColumnName.getTimestamp());
        // Retrieve previously seen event to add to it
        TimelineEvent event = eventsMap.get(key);
        if (event == null) {
            // First time we're seeing this event, add it to the eventsMap
            event = new TimelineEvent();
            event.setId(eventColumnName.getId());
            event.setTimestamp(eventColumnName.getTimestamp());
            eventsMap.put(key, event);
        }
        if (eventColumnName.getInfoKey() != null) {
            event.addInfo(eventColumnName.getInfoKey(), eventResult.getValue());
        }
    }
    Set<TimelineEvent> eventsSet = new HashSet<>(eventsMap.values());
    entity.addEvents(eventsSet);
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent) HashMap(java.util.HashMap) EventColumnNameConverter(org.apache.hadoop.yarn.server.timelineservice.storage.common.EventColumnNameConverter) EventColumnName(org.apache.hadoop.yarn.server.timelineservice.storage.common.EventColumnName) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashSet(java.util.HashSet)

Example 42 with TimelineEvent

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent in project hadoop by apache.

the class NMTimelinePublisher method publishContainerFinishedEvent.

@SuppressWarnings("unchecked")
private void publishContainerFinishedEvent(ContainerStatus containerStatus, long timeStamp) {
    ContainerId containerId = containerStatus.getContainerId();
    TimelineEntity entity = createContainerEntity(containerId);
    Map<String, Object> entityInfo = new HashMap<String, Object>();
    entityInfo.put(ContainerMetricsConstants.DIAGNOSTICS_INFO, containerStatus.getDiagnostics());
    entityInfo.put(ContainerMetricsConstants.EXIT_STATUS_INFO, containerStatus.getExitStatus());
    entityInfo.put(ContainerMetricsConstants.STATE_INFO, ContainerState.COMPLETE.toString());
    entityInfo.put(ContainerMetricsConstants.CONTAINER_FINISHED_TIME, timeStamp);
    entity.setInfo(entityInfo);
    TimelineEvent tEvent = new TimelineEvent();
    tEvent.setId(ContainerMetricsConstants.FINISHED_EVENT_TYPE);
    tEvent.setTimestamp(timeStamp);
    entity.addEvent(tEvent);
    dispatcher.getEventHandler().handle(new TimelinePublishEvent(entity, containerId.getApplicationAttemptId().getApplicationId()));
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)

Example 43 with TimelineEvent

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent in project hadoop by apache.

the class NMTimelinePublisher method publishContainerLocalizationEvent.

private void publishContainerLocalizationEvent(ContainerLocalizationEvent event, String eventType) {
    Container container = event.getContainer();
    ContainerId containerId = container.getContainerId();
    TimelineEntity entity = createContainerEntity(containerId);
    TimelineEvent tEvent = new TimelineEvent();
    tEvent.setId(eventType);
    tEvent.setTimestamp(event.getTimestamp());
    entity.addEvent(tEvent);
    ApplicationId appId = container.getContainerId().getApplicationAttemptId().getApplicationId();
    try {
        // no need to put it as part of publisher as timeline client already has
        // Queuing concept
        TimelineV2Client timelineClient = getTimelineClient(appId);
        if (timelineClient != null) {
            timelineClient.putEntitiesAsync(entity);
        } else {
            LOG.error("Seems like client has been removed before the event could be" + " published for " + container.getContainerId());
        }
    } catch (IOException | YarnException e) {
        LOG.error("Failed to publish Container metrics for container " + container.getContainerId(), e);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) TimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client) IOException(java.io.IOException) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 44 with TimelineEvent

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent in project hadoop by apache.

the class TimelineServiceV2Publisher method appAttemptRegistered.

@SuppressWarnings("unchecked")
@Override
public void appAttemptRegistered(RMAppAttempt appAttempt, long registeredTime) {
    TimelineEntity entity = createAppAttemptEntity(appAttempt.getAppAttemptId());
    entity.setCreatedTime(registeredTime);
    TimelineEvent tEvent = new TimelineEvent();
    tEvent.setId(AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE);
    tEvent.setTimestamp(registeredTime);
    entity.addEvent(tEvent);
    Map<String, Object> entityInfo = new HashMap<String, Object>();
    entityInfo.put(AppAttemptMetricsConstants.TRACKING_URL_INFO, appAttempt.getTrackingUrl());
    entityInfo.put(AppAttemptMetricsConstants.ORIGINAL_TRACKING_URL_INFO, appAttempt.getOriginalTrackingUrl());
    entityInfo.put(AppAttemptMetricsConstants.HOST_INFO, appAttempt.getHost());
    entityInfo.put(AppAttemptMetricsConstants.RPC_PORT_INFO, appAttempt.getRpcPort());
    if (appAttempt.getMasterContainer() != null) {
        entityInfo.put(AppAttemptMetricsConstants.MASTER_CONTAINER_INFO, appAttempt.getMasterContainer().getId().toString());
    }
    entity.setInfo(entityInfo);
    getDispatcher().getEventHandler().handle(new TimelineV2PublishEvent(SystemMetricsEventType.PUBLISH_ENTITY, entity, appAttempt.getAppAttemptId().getApplicationId()));
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent) HashMap(java.util.HashMap) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)

Example 45 with TimelineEvent

use of org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent in project hadoop by apache.

the class TimelineServiceV2Publisher method containerFinished.

@SuppressWarnings("unchecked")
@Override
public void containerFinished(RMContainer container, long finishedTime) {
    if (publishContainerEvents) {
        TimelineEntity entity = createContainerEntity(container.getContainerId());
        TimelineEvent tEvent = new TimelineEvent();
        tEvent.setId(ContainerMetricsConstants.FINISHED_IN_RM_EVENT_TYPE);
        tEvent.setTimestamp(finishedTime);
        entity.addEvent(tEvent);
        Map<String, Object> entityInfo = new HashMap<String, Object>();
        entityInfo.put(ContainerMetricsConstants.DIAGNOSTICS_INFO, container.getDiagnosticsInfo());
        entityInfo.put(ContainerMetricsConstants.EXIT_STATUS_INFO, container.getContainerExitStatus());
        entityInfo.put(ContainerMetricsConstants.STATE_INFO, container.getContainerState().toString());
        entityInfo.put(ContainerMetricsConstants.CONTAINER_FINISHED_TIME, finishedTime);
        entity.setInfo(entityInfo);
        getDispatcher().getEventHandler().handle(new TimelineV2PublishEvent(SystemMetricsEventType.PUBLISH_ENTITY, entity, container.getContainerId().getApplicationAttemptId().getApplicationId()));
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent) HashMap(java.util.HashMap) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)

Aggregations

TimelineEvent (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent)56 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)26 HashMap (java.util.HashMap)24 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)12 HashSet (java.util.HashSet)11 ApplicationEntity (org.apache.hadoop.yarn.api.records.timelineservice.ApplicationEntity)7 TimelineEntities (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities)7 Map (java.util.Map)5 Configuration (org.apache.hadoop.conf.Configuration)5 NavigableMap (java.util.NavigableMap)4 Set (java.util.Set)4 EventColumnName (org.apache.hadoop.yarn.server.timelineservice.storage.common.EventColumnName)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)3 TimelineDataToRetrieve (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve)3 TimelineReaderContext (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext)3 EventColumnNameConverter (org.apache.hadoop.yarn.server.timelineservice.storage.common.EventColumnNameConverter)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2