Search in sources :

Example 1 with TimelineV2Client

use of org.apache.hadoop.yarn.client.api.TimelineV2Client in project hadoop by apache.

the class TestTimelineServiceClientIntegration method testPutExtendedEntities.

@Test
public void testPutExtendedEntities() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    TimelineV2Client client = TimelineV2Client.createTimelineClient(appId);
    try {
        // set the timeline service address manually
        client.setTimelineServiceAddress(collectorManager.getRestServerBindAddress());
        client.init(conf);
        client.start();
        ClusterEntity cluster = new ClusterEntity();
        cluster.setId(YarnConfiguration.DEFAULT_RM_CLUSTER_ID);
        FlowRunEntity flow = new FlowRunEntity();
        flow.setUser(UserGroupInformation.getCurrentUser().getShortUserName());
        flow.setName("test_flow_name");
        flow.setVersion("test_flow_version");
        flow.setRunId(1L);
        flow.setParent(cluster.getType(), cluster.getId());
        ApplicationEntity app = new ApplicationEntity();
        app.setId(appId.toString());
        flow.addChild(app.getType(), app.getId());
        ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
        ApplicationAttemptEntity appAttempt = new ApplicationAttemptEntity();
        appAttempt.setId(attemptId.toString());
        ContainerId containerId = ContainerId.newContainerId(attemptId, 1);
        ContainerEntity container = new ContainerEntity();
        container.setId(containerId.toString());
        UserEntity user = new UserEntity();
        user.setId(UserGroupInformation.getCurrentUser().getShortUserName());
        QueueEntity queue = new QueueEntity();
        queue.setId("default_queue");
        client.putEntities(cluster, flow, app, appAttempt, container, user, queue);
        client.putEntitiesAsync(cluster, flow, app, appAttempt, container, user, queue);
    } finally {
        client.stop();
    }
}
Also used : ApplicationAttemptEntity(org.apache.hadoop.yarn.api.records.timelineservice.ApplicationAttemptEntity) TimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerEntity(org.apache.hadoop.yarn.api.records.timelineservice.ContainerEntity) ApplicationEntity(org.apache.hadoop.yarn.api.records.timelineservice.ApplicationEntity) FlowRunEntity(org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity) QueueEntity(org.apache.hadoop.yarn.api.records.timelineservice.QueueEntity) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) UserEntity(org.apache.hadoop.yarn.api.records.timelineservice.UserEntity) ClusterEntity(org.apache.hadoop.yarn.api.records.timelineservice.ClusterEntity) Test(org.junit.Test)

Example 2 with TimelineV2Client

use of org.apache.hadoop.yarn.client.api.TimelineV2Client in project hadoop by apache.

the class TestTimelineServiceClientIntegration method testPutEntities.

@Test
public void testPutEntities() throws Exception {
    TimelineV2Client client = TimelineV2Client.createTimelineClient(ApplicationId.newInstance(0, 1));
    try {
        // set the timeline service address manually
        client.setTimelineServiceAddress(collectorManager.getRestServerBindAddress());
        client.init(conf);
        client.start();
        TimelineEntity entity = new TimelineEntity();
        entity.setType("test entity type");
        entity.setId("test entity id");
        TimelineMetric metric = new TimelineMetric(TimelineMetric.Type.TIME_SERIES);
        metric.setId("test metric id");
        metric.addValue(1L, 1.0D);
        metric.addValue(2L, 2.0D);
        entity.addMetric(metric);
        client.putEntities(entity);
        client.putEntitiesAsync(entity);
    } finally {
        client.stop();
    }
}
Also used : TimelineMetric(org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric) TimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) Test(org.junit.Test)

Example 3 with TimelineV2Client

use of org.apache.hadoop.yarn.client.api.TimelineV2Client 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 4 with TimelineV2Client

use of org.apache.hadoop.yarn.client.api.TimelineV2Client in project hadoop by apache.

the class NMTimelinePublisher method createTimelineClient.

public void createTimelineClient(ApplicationId appId) {
    if (!appToClientMap.containsKey(appId)) {
        TimelineV2Client timelineClient = TimelineV2Client.createTimelineClient(appId);
        timelineClient.init(getConfig());
        timelineClient.start();
        appToClientMap.put(appId, timelineClient);
    }
}
Also used : TimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client)

Example 5 with TimelineV2Client

use of org.apache.hadoop.yarn.client.api.TimelineV2Client in project hadoop by apache.

the class NMTimelinePublisher method reportContainerResourceUsage.

public void reportContainerResourceUsage(Container container, Long pmemUsage, Float cpuUsagePercentPerCore) {
    if (pmemUsage != ResourceCalculatorProcessTree.UNAVAILABLE || cpuUsagePercentPerCore != ResourceCalculatorProcessTree.UNAVAILABLE) {
        ContainerEntity entity = createContainerEntity(container.getContainerId());
        long currentTimeMillis = System.currentTimeMillis();
        if (pmemUsage != ResourceCalculatorProcessTree.UNAVAILABLE) {
            TimelineMetric memoryMetric = new TimelineMetric();
            memoryMetric.setId(ContainerMetric.MEMORY.toString());
            memoryMetric.setRealtimeAggregationOp(TimelineMetricOperation.SUM);
            memoryMetric.addValue(currentTimeMillis, pmemUsage);
            entity.addMetric(memoryMetric);
        }
        if (cpuUsagePercentPerCore != ResourceCalculatorProcessTree.UNAVAILABLE) {
            TimelineMetric cpuMetric = new TimelineMetric();
            cpuMetric.setId(ContainerMetric.CPU.toString());
            // TODO: support average
            cpuMetric.setRealtimeAggregationOp(TimelineMetricOperation.SUM);
            cpuMetric.addValue(currentTimeMillis, Math.round(cpuUsagePercentPerCore));
            entity.addMetric(cpuMetric);
        }
        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 container" + " metric could be published for " + container.getContainerId());
            }
        } catch (IOException | YarnException e) {
            LOG.error("Failed to publish Container metrics for container " + container.getContainerId(), e);
        }
    }
}
Also used : TimelineMetric(org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric) ContainerEntity(org.apache.hadoop.yarn.api.records.timelineservice.ContainerEntity) TimelineV2Client(org.apache.hadoop.yarn.client.api.TimelineV2Client) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

TimelineV2Client (org.apache.hadoop.yarn.client.api.TimelineV2Client)5 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 IOException (java.io.IOException)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 ContainerEntity (org.apache.hadoop.yarn.api.records.timelineservice.ContainerEntity)2 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)2 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)1 ApplicationAttemptEntity (org.apache.hadoop.yarn.api.records.timelineservice.ApplicationAttemptEntity)1 ApplicationEntity (org.apache.hadoop.yarn.api.records.timelineservice.ApplicationEntity)1 ClusterEntity (org.apache.hadoop.yarn.api.records.timelineservice.ClusterEntity)1 FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)1 QueueEntity (org.apache.hadoop.yarn.api.records.timelineservice.QueueEntity)1 TimelineEvent (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent)1 UserEntity (org.apache.hadoop.yarn.api.records.timelineservice.UserEntity)1 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)1