diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AHSClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AHSClient.java index b590a51f108..13918ccda99 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AHSClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AHSClient.java @@ -25,6 +25,7 @@ import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.service.AbstractService; import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport; @@ -33,6 +34,8 @@ import org.apache.hadoop.yarn.api.records.ContainerId; import org.apache.hadoop.yarn.api.records.ContainerReport; import org.apache.hadoop.yarn.client.api.impl.AHSClientImpl; +import org.apache.hadoop.yarn.client.api.impl.AHSv2ClientImpl; +import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException; import org.apache.hadoop.yarn.exceptions.ContainerNotFoundException; import org.apache.hadoop.yarn.exceptions.YarnException; @@ -45,9 +48,11 @@ * Create a new instance of AHSClient. */ @Public - public static AHSClient createAHSClient() { - AHSClient client = new AHSClientImpl(); - return client; + public static AHSClient createAHSClient(Configuration conf) { + if (YarnConfiguration.timelineServiceV2Enabled(conf)) { + return new AHSv2ClientImpl(); + } + return new AHSClientImpl(); } @Private diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AHSv2ClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AHSv2ClientImpl.java new file mode 100644 index 00000000000..6796eab1f32 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/AHSv2ClientImpl.java @@ -0,0 +1,192 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.client.api.impl; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; +import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport; +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.api.records.ApplicationReport; +import org.apache.hadoop.yarn.api.records.ContainerExitStatus; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.ContainerReport; +import org.apache.hadoop.yarn.api.records.ContainerState; +import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.api.records.Priority; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent; +import org.apache.hadoop.yarn.client.api.AHSClient; +import org.apache.hadoop.yarn.client.api.TimelineReaderClient; +import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.server.metrics.ContainerMetricsConstants; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.NavigableSet; + +public class AHSv2ClientImpl extends AHSClient { + private TimelineReaderClient readerClient; + + public AHSv2ClientImpl() { + super(AHSv2ClientImpl.class.getName()); + } + + @Override + public void serviceInit(Configuration conf) { + readerClient = TimelineReaderClientImpl.createTimelineReaderClient(conf); + } + + @Override + public ApplicationReport getApplicationReport(ApplicationId appId) + throws YarnException, IOException { + return null; + } + + @Override + public List getApplications() + throws YarnException, IOException { + return null; + } + + @Override + public ApplicationAttemptReport getApplicationAttemptReport( + ApplicationAttemptId applicationAttemptId) + throws YarnException, IOException { + return null; + } + + @Override + public List getApplicationAttempts( + ApplicationId applicationId) throws YarnException, IOException { + return null; + } + + @Override + public ContainerReport getContainerReport(ContainerId containerId) + throws YarnException, IOException { + ApplicationId appId = containerId.getApplicationAttemptId().getApplicationId(); + TimelineEntity entity = readerClient.getContainerEntity(appId.toString(), containerId.toString()); + return convertToContainerReport(entity); + } + + @Override + public List getContainers( + ApplicationAttemptId applicationAttemptId) + throws YarnException, IOException { + return null; + } + + private static ContainerReport convertToContainerReport( + TimelineEntity entity) { + 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 entityInfo = entity.getInfo(); + if (entityInfo != null) { + if (entityInfo + .containsKey(ContainerMetricsConstants.ALLOCATED_MEMORY_INFO)) { + allocatedMem = (Integer) entityInfo.get( + ContainerMetricsConstants.ALLOCATED_MEMORY_INFO); + } + if (entityInfo + .containsKey(ContainerMetricsConstants.ALLOCATED_VCORE_INFO)) { + allocatedVcore = (Integer) entityInfo.get( + ContainerMetricsConstants.ALLOCATED_VCORE_INFO); + } + if (entityInfo + .containsKey(ContainerMetricsConstants.ALLOCATED_HOST_INFO)) { + allocatedHost = + entityInfo + .get(ContainerMetricsConstants.ALLOCATED_HOST_INFO) + .toString(); + } + if (entityInfo + .containsKey(ContainerMetricsConstants.ALLOCATED_PORT_INFO)) { + allocatedPort = (Integer) entityInfo.get( + ContainerMetricsConstants.ALLOCATED_PORT_INFO); + } + if (entityInfo + .containsKey(ContainerMetricsConstants.ALLOCATED_PRIORITY_INFO)) { + allocatedPriority = (Integer) entityInfo.get( + ContainerMetricsConstants.ALLOCATED_PRIORITY_INFO); + } + if (entityInfo.containsKey( + ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_INFO)) { + nodeHttpAddress = + (String) entityInfo + .get(ContainerMetricsConstants.ALLOCATED_HOST_HTTP_ADDRESS_INFO); + } + } + NavigableSet events = entity.getEvents(); + if (events != null) { + for (TimelineEvent event : events) { + if (event.getId().equals( + ContainerMetricsConstants.CREATED_EVENT_TYPE)) { + createdTime = event.getTimestamp(); + } else if (event.getId().equals( + ContainerMetricsConstants.FINISHED_EVENT_TYPE)) { + finishedTime = event.getTimestamp(); + Map eventInfo = event.getInfo(); + if (eventInfo == null) { + continue; + } + if (eventInfo + .containsKey(ContainerMetricsConstants.DIAGNOSTICS_INFO)) { + diagnosticsInfo = + eventInfo.get( + ContainerMetricsConstants.DIAGNOSTICS_INFO) + .toString(); + } + if (eventInfo + .containsKey(ContainerMetricsConstants.EXIT_STATUS_INFO)) { + exitStatus = (Integer) eventInfo.get( + ContainerMetricsConstants.EXIT_STATUS_INFO); + } + if (eventInfo + .containsKey(ContainerMetricsConstants.STATE_INFO)) { + state = + ContainerState.valueOf(eventInfo.get( + ContainerMetricsConstants.STATE_INFO).toString()); + } + } + } + } + String logUrl = null; + NodeId allocatedNode = null; + if (allocatedHost != null) { + allocatedNode = NodeId.newInstance(allocatedHost, allocatedPort); + } + return ContainerReport.newInstance( + ContainerId.fromString(entity.getId()), + Resource.newInstance(allocatedMem, allocatedVcore), allocatedNode, + Priority.newInstance(allocatedPriority), + createdTime, finishedTime, diagnosticsInfo, logUrl, exitStatus, state, + nodeHttpAddress); + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java index 1ceb46209b1..8c659e192f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/impl/YarnClientImpl.java @@ -154,6 +154,8 @@ protected boolean timelineServiceBestEffort; private boolean loadResourceTypesFromServer; + private boolean timelineV2ServiceEnabled; + private static final String ROOT = "root"; public YarnClientImpl() { @@ -183,15 +185,19 @@ protected void serviceInit(Configuration conf) throws Exception { timelineService = TimelineUtils.buildTimelineTokenService(conf); } + if (YarnConfiguration.timelineServiceV2Enabled(conf)) { + timelineV2ServiceEnabled = true; + } + // The AHSClientService is enabled by default when we start the // TimelineServer which means we are able to get history information // for applications/applicationAttempts/containers by using ahsClient // when the TimelineServer is running. - if (timelineV1ServiceEnabled || conf.getBoolean( + if (timelineV2ServiceEnabled || timelineV1ServiceEnabled || conf.getBoolean( YarnConfiguration.APPLICATION_HISTORY_ENABLED, YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED)) { historyServiceEnabled = true; - historyClient = AHSClient.createAHSClient(); + historyClient = AHSClient.createAHSClient(conf); historyClient.init(conf); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java index f0e3ca2a4cc..9e63bfb71f0 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSClient.java @@ -64,7 +64,7 @@ @Test public void testClientStop() { Configuration conf = new Configuration(); - AHSClient client = AHSClient.createAHSClient(); + AHSClient client = AHSClient.createAHSClient(conf); client.init(conf); client.start(); client.stop(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java new file mode 100644 index 00000000000..eb2e5341c68 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAHSv2ClientImpl.java @@ -0,0 +1,27 @@ +package org.apache.hadoop.yarn.client.api.impl; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.ContainerId; +import org.apache.hadoop.yarn.api.records.ContainerReport; +import org.apache.hadoop.yarn.client.api.AHSClient; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Test; + +public class TestAHSv2ClientImpl { + @Test + public void testGetContainerReport() { + Configuration conf = new YarnConfiguration(); + conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true); + conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 2.0f); + final AHSClient client = new AHSv2ClientImpl(); + client.init(conf); + client.start(); + ContainerId containerId = ContainerId.fromString("container_1533643711195_0001_01_000001"); + try { + ContainerReport report = client.getContainerReport(containerId); + System.out.println(report.toString()); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineReaderClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineReaderClient.java new file mode 100644 index 00000000000..d3212d6a7a9 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineReaderClient.java @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.client.api; + +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType; + +import java.io.IOException; + +public interface TimelineReaderClient { + + TimelineEntity getContainerEntity(String appId, String containerId) throws + IOException; + + TimelineEntity getApplicationEntity(String appId, TimelineEntityType entityType) + throws IOException; +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineReaderClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineReaderClientImpl.java new file mode 100644 index 00000000000..0940401e256 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineReaderClientImpl.java @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.hadoop.yarn.client.api.impl; + +import com.sun.jersey.api.client.config.DefaultClientConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType; +import org.apache.hadoop.yarn.client.api.TimelineReaderClient; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.ClientRequest; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.config.ClientConfig; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.util.timeline.TimelineUtils; +import org.apache.hadoop.yarn.webapp.YarnJacksonJaxbJsonProvider; + +import java.io.IOException; +import java.net.URI; + +import static org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType.YARN_CONTAINER; + +public class TimelineReaderClientImpl implements TimelineReaderClient { + private static final Log LOG = LogFactory.getLog(TimelineReaderClientImpl.class); + + private static final String RESOURCE_URI_STR_V2 = "/ws/v2/timeline/"; + + private Client client; + private volatile String timelineServiceAddress; + private Configuration conf; + + + /** + * Creates an instance of the timeline v.2 client. + * + * @param conf configuration + * @return the created timeline client instance + */ + @InterfaceAudience.Public + public static TimelineReaderClient createTimelineReaderClient(Configuration conf) { + TimelineReaderClient client = new TimelineReaderClientImpl(conf); + return client; + } + + private TimelineReaderClientImpl(Configuration conf) { + this.conf = conf; + ClientConfig cc = new DefaultClientConfig(); + cc.getClasses().add(YarnJacksonJaxbJsonProvider.class); + client = Client.create(cc); + timelineServiceAddress = conf.get(YarnConfiguration.TIMELINE_SERVICE_READER_WEBAPP_ADDRESS, + YarnConfiguration.DEFAULT_TIMELINE_SERVICE_READER_WEBAPP_ADDRESS); + } + + public TimelineEntity getApplicationEntity(String appId, TimelineEntityType entityType) throws IOException { + String url = RESOURCE_URI_STR_V2 + + "apps/" + appId; + if (entityType != null) { + url += "/entities/" + entityType.toString(); + } + url += "?fields=ALL"; + URI uri = TimelineConnector.constructResURI(conf, timelineServiceAddress, url); + ClientResponse response = client.resource(uri).accept("application/json") + .get(ClientResponse.class); + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + TimelineEntity entity = response.getEntity(TimelineEntity.class); + LOG.info("Entity: " + TimelineUtils.dumpTimelineRecordtoJSON(entity)); + return entity; + } + + public TimelineEntity getContainerEntity(String appId, String containerId) throws IOException { + String url = RESOURCE_URI_STR_V2 + + "apps/" + appId; + url += "/entities/" + YARN_CONTAINER.toString(); + url += "/" + containerId; + url += "?fields=ALL"; + URI uri = TimelineConnector.constructResURI(conf, timelineServiceAddress, url); + ClientResponse response = client.resource(uri).accept("application/json") + .get(ClientResponse.class); + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + TimelineEntity entity = response.getEntity(TimelineEntity.class); + LOG.info("Entity: " + TimelineUtils.dumpTimelineRecordtoJSON(entity)); + return entity; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/AppAttemptMetricsConstants.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/AppAttemptMetricsConstants.java similarity index 100% rename from hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/AppAttemptMetricsConstants.java rename to hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/AppAttemptMetricsConstants.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ApplicationMetricsConstants.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ApplicationMetricsConstants.java similarity index 100% rename from hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ApplicationMetricsConstants.java rename to hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ApplicationMetricsConstants.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ContainerMetricsConstants.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ContainerMetricsConstants.java similarity index 100% rename from hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ContainerMetricsConstants.java rename to hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/server/metrics/ContainerMetricsConstants.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineReaderClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineReaderClientImpl.java new file mode 100644 index 00000000000..4dcb3810bd8 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineReaderClientImpl.java @@ -0,0 +1,37 @@ +package org.apache.hadoop.yarn.client.api.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.client.api.TimelineReaderClient; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +public class TestTimelineReaderClientImpl { + private static final Log LOG = + LogFactory.getLog(TestTimelineReaderClientImpl.class); + private TimelineReaderClient client; + private Configuration conf; + + @Before + public void setup() { + conf = new YarnConfiguration(); + conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true); + conf.setFloat(YarnConfiguration.TIMELINE_SERVICE_VERSION, 2.0f); + client = TimelineReaderClientImpl.createTimelineReaderClient(conf); + } + + @Test + public void testGetContainerEntity() { + try { + TimelineEntity entity = client.getContainerEntity("application_1533643711195_0001", "container_1533643711195_0001_01_000001"); + System.out.println("Entity: " + entity.getInfo().size()); + } catch (IOException e) { + LOG.info(e); + } + } +}