public ContainerInfo(ContainerReport container) { containerId = container.getContainerId().toString(); if (container.getAllocatedResource() != null) { allocatedMB = container.getAllocatedResource().getMemory(); allocatedVCores = container.getAllocatedResource().getVirtualCores(); allocatedGCores = container.getAllocatedResource().getGpuCores(); } if (container.getAssignedNode() != null) { assignedNodeId = container.getAssignedNode().toString(); } priority = container.getPriority().getPriority(); startedTime = container.getCreationTime(); finishedTime = container.getFinishTime(); elapsedTime = Times.elapsed(startedTime, finishedTime); diagnosticsInfo = container.getDiagnosticsInfo(); logUrl = container.getLogUrl(); containerExitStatus = container.getContainerExitStatus(); containerState = container.getContainerState(); nodeHttpAddress = container.getNodeHttpAddress(); }
@Override public ContainerReport createContainerReport() { this.readLock.lock(); ContainerReport containerReport = null; try { containerReport = ContainerReport.newInstance(this.getContainerId(), this.getAllocatedResource(), this.getAllocatedNode(), this.getAllocatedPriority(), this.getCreationTime(), this.getFinishTime(), this.getDiagnosticsInfo(), this.getLogURL(), this.getContainerExitStatus(), this.getContainerState(), this.getNodeHttpAddress()); } finally { this.readLock.unlock(); } return containerReport; }
private ContainerReport convertToContainerReport( ContainerHistoryData containerHistory, String user) { // If the container has the aggregated log, add the server root url String logUrl = WebAppUtils.getAggregatedLogURL( serverHttpAddress, containerHistory.getAssignedNode().toString(), containerHistory.getContainerId().toString(), containerHistory.getContainerId().toString(), user); return ContainerReport.newInstance(containerHistory.getContainerId(), containerHistory.getAllocatedResource(), containerHistory.getAssignedNode(), containerHistory.getPriority(), containerHistory.getStartTime(), containerHistory.getFinishTime(), containerHistory.getDiagnosticsInfo(), logUrl, containerHistory.getContainerExitStatus(), containerHistory.getContainerState(), null); }
@Override public Map<ContainerId, ContainerReport> getContainers( ApplicationAttemptId appAttemptId) throws IOException { ApplicationReport app = getApplication(appAttemptId.getApplicationId()); Map<ContainerId, ContainerHistoryData> histData = historyStore.getContainers(appAttemptId); HashMap<ContainerId, ContainerReport> containersReport = new HashMap<ContainerId, ContainerReport>(); for (Entry<ContainerId, ContainerHistoryData> entry : histData.entrySet()) { containersReport.put(entry.getKey(), convertToContainerReport(entry.getValue(), app == null ? null : app.getUser())); } return containersReport; }
@Override public ContainerReport getContainer(ContainerId containerId) throws YarnException, IOException { ApplicationReportExt app = getApplication( containerId.getApplicationAttemptId().getApplicationId(), ApplicationReportField.USER_AND_ACLS); checkAccess(app); TimelineEntity entity = timelineDataManager.getEntity( ContainerMetricsConstants.ENTITY_TYPE, containerId.toString(), EnumSet.allOf(Field.class), UserGroupInformation.getLoginUser()); if (entity == null) { throw new ContainerNotFoundException( "The entity for container " + containerId + " doesn't exist in the timeline store"); } else { return convertToContainerReport( entity, serverHttpAddress, app.appReport.getUser()); } }
@Override public Map<ContainerId, ContainerReport> getContainers( ApplicationAttemptId appAttemptId) throws YarnException, IOException { ApplicationReportExt app = getApplication( appAttemptId.getApplicationId(), ApplicationReportField.USER_AND_ACLS); checkAccess(app); TimelineEntities entities = timelineDataManager.getEntities( ContainerMetricsConstants.ENTITY_TYPE, new NameValuePair( ContainerMetricsConstants.PARENT_PRIMARIY_FILTER, appAttemptId.toString()), null, null, null, null, null, Long.MAX_VALUE, EnumSet.allOf(Field.class), UserGroupInformation.getLoginUser()); Map<ContainerId, ContainerReport> containers = new LinkedHashMap<ContainerId, ContainerReport>(); if (entities != null && entities.getEntities() != null) { for (TimelineEntity entity : entities.getEntities()) { ContainerReport container = convertToContainerReport( entity, serverHttpAddress, app.appReport.getUser()); containers.put(container.getContainerId(), container); } } return containers; }
@Test public void testContainerReport() throws IOException, YarnException { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); GetContainerReportRequest request = GetContainerReportRequest.newInstance(containerId); GetContainerReportResponse response = clientService.getContainerReport(request); ContainerReport container = response.getContainerReport(); Assert.assertNotNull(container); Assert.assertEquals(containerId, container.getContainerId()); Assert.assertEquals("http://0.0.0.0:8188/applicationhistory/logs/" + "test host:100/container_0_0001_01_000001/" + "container_0_0001_01_000001/user1", container.getLogUrl()); }
@Test public void testContainers() throws IOException, YarnException { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 2); GetContainersRequest request = GetContainersRequest.newInstance(appAttemptId); GetContainersResponse response = clientService.getContainers(request); List<ContainerReport> containers = response.getContainerList(); Assert.assertNotNull(containers); Assert.assertEquals(containerId, containers.get(0).getContainerId()); Assert.assertEquals(containerId1, containers.get(1).getContainerId()); }
@Override public ContainerReport getContainerReport(ContainerId containerId) throws YarnException, IOException { try { GetContainerReportRequest request = Records .newRecord(GetContainerReportRequest.class); request.setContainerId(containerId); GetContainerReportResponse response = rmClient .getContainerReport(request); return response.getContainerReport(); } catch (YarnException e) { if (!historyServiceEnabled) { // Just throw it as usual if historyService is not enabled. throw e; } // Even if history-service is enabled, treat all exceptions still the same // except the following if (e.getClass() != ApplicationNotFoundException.class && e.getClass() != ContainerNotFoundException.class) { throw e; } return historyClient.getContainerReport(containerId); } }
/** * Lists the containers matching the given application attempts * * @param appAttemptId * @throws YarnException * @throws IOException */ private void listContainers(String appAttemptId) throws YarnException, IOException { PrintWriter writer = new PrintWriter( new OutputStreamWriter(sysout, Charset.forName("UTF-8"))); List<ContainerReport> appsReport = client .getContainers(ConverterUtils.toApplicationAttemptId(appAttemptId)); writer.println("Total number of containers " + ":" + appsReport.size()); writer.printf(CONTAINER_PATTERN, "Container-Id", "Start Time", "Finish Time", "State", "Host", "Node Http Address", "LOG-URL"); for (ContainerReport containerReport : appsReport) { writer.printf( CONTAINER_PATTERN, containerReport.getContainerId(), Times.format(containerReport.getCreationTime()), Times.format(containerReport.getFinishTime()), containerReport.getContainerState(), containerReport .getAssignedNode(), containerReport.getNodeHttpAddress() == null ? "N/A" : containerReport.getNodeHttpAddress(), containerReport.getLogUrl()); } writer.flush(); }
@Test(timeout = 10000) public void testGetContainers() throws YarnException, IOException { Configuration conf = new Configuration(); final AHSClient client = new MockAHSClient(); client.init(conf); client.start(); ApplicationId applicationId = ApplicationId.newInstance(1234, 5); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1); List<ContainerReport> reports = client.getContainers(appAttemptId); Assert.assertNotNull(reports); Assert.assertEquals(reports.get(0).getContainerId(), (ContainerId.newContainerId(appAttemptId, 1))); Assert.assertEquals(reports.get(1).getContainerId(), (ContainerId.newContainerId(appAttemptId, 2))); client.stop(); }
@Test(timeout = 10000) public void testGetContainerReport() throws YarnException, IOException { Configuration conf = new Configuration(); final AHSClient client = new MockAHSClient(); client.init(conf); client.start(); List<ApplicationReport> expectedReports = ((MockAHSClient) client).getReports(); ApplicationId applicationId = ApplicationId.newInstance(1234, 5); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); ContainerReport report = client.getContainerReport(containerId); Assert.assertNotNull(report); Assert.assertEquals(report.getContainerId().toString(), (ContainerId .newContainerId(expectedReports.get(0).getCurrentApplicationAttemptId(), 1)) .toString()); client.stop(); }
private ContainerReport getContainer( ContainerId containerId, HashMap<ApplicationAttemptId, List<ContainerReport>> containersToAppAttemptMapping) throws YarnException, IOException { List<ContainerReport> containersForAppAttempt = containersToAppAttemptMapping.get(containerId .getApplicationAttemptId()); if (containersForAppAttempt == null) { throw new ApplicationNotFoundException(containerId .getApplicationAttemptId().getApplicationId() + " is not found "); } Iterator<ContainerReport> iterator = containersForAppAttempt.iterator(); while (iterator.hasNext()) { ContainerReport next = iterator.next(); if (next.getContainerId().equals(containerId)) { return next; } } throw new ContainerNotFoundException(containerId + " is not found "); }
public ContainerInfo(ContainerReport container) { containerId = container.getContainerId().toString(); if (container.getAllocatedResource() != null) { allocatedMB = container.getAllocatedResource().getMemory(); allocatedVCores = container.getAllocatedResource().getVirtualCores(); } if (container.getAssignedNode() != null) { assignedNodeId = container.getAssignedNode().toString(); } priority = container.getPriority().getPriority(); startedTime = container.getCreationTime(); finishedTime = container.getFinishTime(); elapsedTime = Times.elapsed(startedTime, finishedTime); diagnosticsInfo = container.getDiagnosticsInfo(); logUrl = container.getLogUrl(); containerExitStatus = container.getContainerExitStatus(); containerState = container.getContainerState(); nodeHttpAddress = container.getNodeHttpAddress(); }
@Override public ContainerReport getContainerReport() { if (this.containerReport != null) { return this.containerReport; } GetContainerReportResponseProtoOrBuilder p = viaProto ? proto : builder; if (!p.hasContainerReport()) { return null; } this.containerReport = convertFromProtoFormat(p.getContainerReport()); return this.containerReport; }
@Override public void setContainerReport(ContainerReport containerReport) { maybeInitBuilder(); if (containerReport == null) { builder.clearContainerReport(); } this.containerReport = containerReport; }
@Override public void setContainerList(List<ContainerReport> containers) { maybeInitBuilder(); if (containers == null) { builder.clearContainers(); } this.containerList = containers; }
private void initLocalContainerList() { if (this.containerList != null) { return; } GetContainersResponseProtoOrBuilder p = viaProto ? proto : builder; List<ContainerReportProto> list = p.getContainersList(); containerList = new ArrayList<ContainerReport>(); for (ContainerReportProto c : list) { containerList.add(convertFromProtoFormat(c)); } }
private void addLocalContainersToProto() { maybeInitBuilder(); builder.clearContainers(); if (containerList == null) { return; } Iterable<ContainerReportProto> iterable = new Iterable<ContainerReportProto>() { @Override public Iterator<ContainerReportProto> iterator() { return new Iterator<ContainerReportProto>() { Iterator<ContainerReport> iter = containerList.iterator(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public ContainerReportProto next() { return convertToProtoFormat(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; builder.addAllContainers(iterable); }
private boolean hasAMContainer(ContainerId containerId, Collection<ContainerReport> containers) { for (ContainerReport container : containers) { if (containerId.equals(container.getContainerId())) { return true; } } return false; }