static InstanceInfo extractInstanceInfo(String clusterName, ApplicationReport report) { InstanceMetadata md = getMetadata(report.getApplicationTags()); if (md == null) { return null; } ApplicationResourceUsageReport usage = report.getApplicationResourceUsageReport(); InstanceStatus stat = new InstanceStatus() .allocatedVCores((long) usage.getUsedResources().getVirtualCores()) .allocatedMB((long) usage.getUsedResources().getMemory()) .clusterId(clusterName) .applicationId(report.getApplicationId().toString()) .startedTime(report.getStartTime()) .runningContainers((long) usage.getNumUsedContainers()) .trackingUrl(report.getTrackingUrl()) .state(InstanceStatus.StateEnum.fromValue(report.getYarnApplicationState().toString())); return new InstanceInfo(clusterName, report.getApplicationId(), md, stat); }
public static ApplicationResourceUsageReport newApplicationResourceUsageReport( int numUsedContainers, int numReservedContainers, Resource usedResources, Resource reservedResources, Resource neededResources, long memorySeconds, long vcoreSeconds, long gcoreSeconds) { ApplicationResourceUsageReport report = recordFactory.newRecordInstance(ApplicationResourceUsageReport.class); report.setNumUsedContainers(numUsedContainers); report.setNumReservedContainers(numReservedContainers); report.setUsedResources(usedResources); report.setReservedResources(reservedResources); report.setNeededResources(neededResources); report.setMemorySeconds(memorySeconds); report.setVcoreSeconds(vcoreSeconds); report.setGcoreSeconds(gcoreSeconds); return report; }
@Override public ApplicationResourceUsageReport getApplicationResourceUsageReport() { this.readLock.lock(); try { ApplicationResourceUsageReport report = scheduler.getAppResourceUsageReport(this.getAppAttemptId()); if (report == null) { report = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT; } AggregateAppResourceUsage resUsage = this.attemptMetrics.getAggregateAppResourceUsage(); report.setMemorySeconds(resUsage.getMemorySeconds()); report.setVcoreSeconds(resUsage.getVcoreSeconds()); report.setGcoreSeconds(resUsage.getGcoreSeconds()); return report; } finally { this.readLock.unlock(); } }
public AggregateAppResourceUsage getAggregateAppResourceUsage() { long memorySeconds = finishedMemorySeconds.get(); long vcoreSeconds = finishedVcoreSeconds.get(); long gcoreSeconds = finishedGcoreSeconds.get(); // Only add in the running containers if this is the active attempt. RMAppAttempt currentAttempt = rmContext.getRMApps() .get(attemptId.getApplicationId()).getCurrentAppAttempt(); if (currentAttempt.getAppAttemptId().equals(attemptId)) { ApplicationResourceUsageReport appResUsageReport = rmContext .getScheduler().getAppResourceUsageReport(attemptId); if (appResUsageReport != null) { memorySeconds += appResUsageReport.getMemorySeconds(); vcoreSeconds += appResUsageReport.getVcoreSeconds(); gcoreSeconds += appResUsageReport.getGcoreSeconds(); } } return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds, gcoreSeconds); }
private void verifyEnemyAppReport(ApplicationReport appReport) { Assert.assertEquals("Enemy should not see app host!", UNAVAILABLE, appReport.getHost()); Assert.assertEquals("Enemy should not see app rpc port!", -1, appReport.getRpcPort()); Assert.assertEquals("Enemy should not see app client token!", null, appReport.getClientToAMToken()); Assert.assertEquals("Enemy should not see app diagnostics!", UNAVAILABLE, appReport.getDiagnostics()); Assert.assertEquals("Enemy should not see app tracking url!", UNAVAILABLE, appReport.getTrackingUrl()); Assert.assertEquals("Enemy should not see app original tracking url!", UNAVAILABLE, appReport.getOriginalTrackingUrl()); ApplicationResourceUsageReport usageReport = appReport.getApplicationResourceUsageReport(); Assert.assertEquals("Enemy should not see app used containers", -1, usageReport.getNumUsedContainers()); Assert.assertEquals("Enemy should not see app reserved containers", -1, usageReport.getNumReservedContainers()); Assert.assertEquals("Enemy should not see app used resources", -1, usageReport.getUsedResources().getMemory()); Assert.assertEquals("Enemy should not see app reserved resources", -1, usageReport.getReservedResources().getMemory()); Assert.assertEquals("Enemy should not see app needed resources", -1, usageReport.getNeededResources().getMemory()); }
@Test public void testGetApplicationResourceUsageReportDummy() throws YarnException, IOException { ApplicationAttemptId attemptId = getApplicationAttemptId(1); YarnScheduler yarnScheduler = mockYarnScheduler(); RMContext rmContext = mock(RMContext.class); mockRMContext(yarnScheduler, rmContext); when(rmContext.getDispatcher().getEventHandler()).thenReturn( new EventHandler<Event>() { public void handle(Event event) { } }); ApplicationSubmissionContext asContext = mock(ApplicationSubmissionContext.class); YarnConfiguration config = new YarnConfiguration(); RMAppAttemptImpl rmAppAttemptImpl = new RMAppAttemptImpl(attemptId, rmContext, yarnScheduler, null, asContext, config, false, null); ApplicationResourceUsageReport report = rmAppAttemptImpl .getApplicationResourceUsageReport(); assertEquals(report, RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT); }
private ApplicationReport getApplicationReport( YarnApplicationState yarnApplicationState, FinalApplicationStatus finalApplicationStatus) { ApplicationReport appReport = Mockito.mock(ApplicationReport.class); ApplicationResourceUsageReport appResources = Mockito .mock(ApplicationResourceUsageReport.class); Mockito.when(appReport.getApplicationId()).thenReturn( ApplicationId.newInstance(0, 0)); Mockito.when(appResources.getNeededResources()).thenReturn( Records.newRecord(Resource.class)); Mockito.when(appResources.getReservedResources()).thenReturn( Records.newRecord(Resource.class)); Mockito.when(appResources.getUsedResources()).thenReturn( Records.newRecord(Resource.class)); Mockito.when(appReport.getApplicationResourceUsageReport()).thenReturn( appResources); Mockito.when(appReport.getYarnApplicationState()).thenReturn( yarnApplicationState); Mockito.when(appReport.getFinalApplicationStatus()).thenReturn( finalApplicationStatus); return appReport; }
@Override public ApplicationResourceUsageReport getApplicationResourceUsageReport() { this.readLock.lock(); try { ApplicationResourceUsageReport report = scheduler.getAppResourceUsageReport(this.getAppAttemptId()); if (report == null) { report = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT; } AggregateAppResourceUsage resUsage = this.attemptMetrics.getAggregateAppResourceUsage(); report.setMemorySeconds(resUsage.getMemorySeconds()); report.setVcoreSeconds(resUsage.getVcoreSeconds()); return report; } finally { this.readLock.unlock(); } }
public AggregateAppResourceUsage getAggregateAppResourceUsage() { long memorySeconds = finishedMemorySeconds.get(); long vcoreSeconds = finishedVcoreSeconds.get(); // Only add in the running containers if this is the active attempt. RMAppAttempt currentAttempt = rmContext.getRMApps() .get(attemptId.getApplicationId()).getCurrentAppAttempt(); if (currentAttempt.getAppAttemptId().equals(attemptId)) { ApplicationResourceUsageReport appResUsageReport = rmContext .getScheduler().getAppResourceUsageReport(attemptId); if (appResUsageReport != null) { memorySeconds += appResUsageReport.getMemorySeconds(); vcoreSeconds += appResUsageReport.getVcoreSeconds(); } } return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds); }
public synchronized ApplicationResourceUsageReport getResourceUsageReport() { AggregateAppResourceUsage runningResourceUsage = getRunningAggregateAppResourceUsage(); Resource usedResourceClone = Resources.clone(attemptResourceUsage.getAllUsed()); Resource reservedResourceClone = Resources.clone(attemptResourceUsage.getReserved()); Resource cluster = rmContext.getScheduler().getClusterResource(); ResourceCalculator calc = rmContext.getScheduler().getResourceCalculator(); float queueUsagePerc = calc.divide(cluster, usedResourceClone, Resources .multiply(cluster, queue.getQueueInfo(false, false).getCapacity())) * 100; float clusterUsagePerc = calc.divide(cluster, usedResourceClone, cluster) * 100; return ApplicationResourceUsageReport.newInstance(liveContainers.size(), reservedContainers.size(), usedResourceClone, reservedResourceClone, Resources.add(usedResourceClone, reservedResourceClone), runningResourceUsage.getMemorySeconds(), runningResourceUsage.getVcoreSeconds(), queueUsagePerc, clusterUsagePerc); }
@Test public void testFromYarn() throws Exception { int appStartTime = 612354; YarnApplicationState state = YarnApplicationState.RUNNING; ApplicationId applicationId = ApplicationId.newInstance(0, 0); ApplicationReport applicationReport = Records .newRecord(ApplicationReport.class); applicationReport.setApplicationId(applicationId); applicationReport.setYarnApplicationState(state); applicationReport.setStartTime(appStartTime); applicationReport.setUser("TestTypeConverter-user"); ApplicationResourceUsageReport appUsageRpt = Records .newRecord(ApplicationResourceUsageReport.class); Resource r = Records.newRecord(Resource.class); r.setMemory(2048); appUsageRpt.setNeededResources(r); appUsageRpt.setNumReservedContainers(1); appUsageRpt.setNumUsedContainers(3); appUsageRpt.setReservedResources(r); appUsageRpt.setUsedResources(r); applicationReport.setApplicationResourceUsageReport(appUsageRpt); JobStatus jobStatus = TypeConverter.fromYarn(applicationReport, "dummy-jobfile"); Assert.assertEquals(appStartTime, jobStatus.getStartTime()); Assert.assertEquals(state.toString(), jobStatus.getState().toString()); }
public static ApplicationResourceUsageReport newApplicationResourceUsageReport( int numUsedContainers, int numReservedContainers, Resource usedResources, Resource reservedResources, Resource neededResources, long memorySeconds, long vcoreSeconds, long gpuSeconds, long preemptedMemorySeconds, long preemptedVcoreSeconds, long preemptedGPUSeconds) { ApplicationResourceUsageReport report = recordFactory.newRecordInstance(ApplicationResourceUsageReport.class); report.setNumUsedContainers(numUsedContainers); report.setNumReservedContainers(numReservedContainers); report.setUsedResources(usedResources); report.setReservedResources(reservedResources); report.setNeededResources(neededResources); report.setMemorySeconds(memorySeconds); report.setVcoreSeconds(vcoreSeconds); report.setGPUSeconds(gpuSeconds); report.setPreemptedMemorySeconds(preemptedMemorySeconds); report.setPreemptedVcoreSeconds(preemptedVcoreSeconds); report.setPreemptedGPUSeconds(preemptedGPUSeconds); return report; }
@Override public ApplicationResourceUsageReport getApplicationResourceUsageReport() { this.readLock.lock(); try { ApplicationResourceUsageReport report = scheduler.getAppResourceUsageReport(this.getAppAttemptId()); if (report == null) { report = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT; } AggregateAppResourceUsage resUsage = this.attemptMetrics.getAggregateAppResourceUsage(); report.setMemorySeconds(resUsage.getMemorySeconds()); report.setVcoreSeconds(resUsage.getVcoreSeconds()); report.setGPUSeconds(resUsage.getGPUSeconds()); report.setPreemptedMemorySeconds( this.attemptMetrics.getPreemptedMemory()); report.setPreemptedVcoreSeconds( this.attemptMetrics.getPreemptedVcore()); report.setPreemptedGPUSeconds( this.attemptMetrics.getPreemptedGPU()); return report; } finally { this.readLock.unlock(); } }
public AggregateAppResourceUsage getAggregateAppResourceUsage() { long memorySeconds = finishedMemorySeconds.get(); long vcoreSeconds = finishedVcoreSeconds.get(); long gpuSeconds = finishedGPUSeconds.get(); // Only add in the running containers if this is the active attempt. RMAppAttempt currentAttempt = rmContext.getRMApps() .get(attemptId.getApplicationId()).getCurrentAppAttempt(); if (currentAttempt.getAppAttemptId().equals(attemptId)) { ApplicationResourceUsageReport appResUsageReport = rmContext .getScheduler().getAppResourceUsageReport(attemptId); if (appResUsageReport != null) { memorySeconds += appResUsageReport.getMemorySeconds(); vcoreSeconds += appResUsageReport.getVcoreSeconds(); gpuSeconds += appResUsageReport.getGPUSeconds(); } } return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds, gpuSeconds); }
public synchronized ApplicationResourceUsageReport getResourceUsageReport() { AggregateAppResourceUsage runningResourceUsage = getRunningAggregateAppResourceUsage(); Resource usedResourceClone = Resources.clone(attemptResourceUsage.getAllUsed()); Resource reservedResourceClone = Resources.clone(attemptResourceUsage.getReserved()); Resource cluster = rmContext.getScheduler().getClusterResource(); ResourceCalculator calc = rmContext.getScheduler().getResourceCalculator(); float queueUsagePerc = 0.0f; float clusterUsagePerc = 0.0f; if (!calc.isInvalidDivisor(cluster)) { queueUsagePerc = calc.divide(cluster, usedResourceClone, Resources.multiply(cluster, queue.getQueueInfo(false, false).getCapacity())) * 100; clusterUsagePerc = calc.divide(cluster, usedResourceClone, cluster) * 100; } return ApplicationResourceUsageReport.newInstance(liveContainers.size(), reservedContainers.size(), usedResourceClone, reservedResourceClone, Resources.add(usedResourceClone, reservedResourceClone), runningResourceUsage.getMemorySeconds(), runningResourceUsage.getVcoreSeconds(), runningResourceUsage.getGPUSeconds(), queueUsagePerc, clusterUsagePerc, 0, 0, 0); }
/** * Recalculates the per-app, percent of queue metric, specific to the * Capacity Scheduler. */ @Override public synchronized ApplicationResourceUsageReport getResourceUsageReport() { ApplicationResourceUsageReport report = super.getResourceUsageReport(); Resource cluster = rmContext.getScheduler().getClusterResource(); Resource totalPartitionRes = rmContext.getNodeLabelManager() .getResourceByLabel(getAppAMNodePartitionName(), cluster); ResourceCalculator calc = rmContext.getScheduler().getResourceCalculator(); if (!calc.isInvalidDivisor(totalPartitionRes)) { float queueAbsMaxCapPerPartition = ((AbstractCSQueue)getQueue()).getQueueCapacities() .getAbsoluteCapacity(getAppAMNodePartitionName()); float queueUsagePerc = calc.divide(totalPartitionRes, report.getUsedResources(), Resources.multiply(totalPartitionRes, queueAbsMaxCapPerPartition)) * 100; report.setQueueUsagePercentage(queueUsagePerc); } return report; }
private void verifyEnemyAppReport(ApplicationReport appReport) { Assert.assertEquals("Enemy should not see app host!", UNAVAILABLE, appReport.getHost()); Assert.assertEquals("Enemy should not see app rpc port!", -1, appReport.getRpcPort()); Assert.assertEquals("Enemy should not see app client token!", null, appReport.getClientToAMToken()); Assert.assertEquals("Enemy should not see app diagnostics!", UNAVAILABLE, appReport.getDiagnostics()); Assert.assertEquals("Enemy should not see app tracking url!", UNAVAILABLE, appReport.getTrackingUrl()); Assert.assertEquals("Enemy should not see app original tracking url!", UNAVAILABLE, appReport.getOriginalTrackingUrl()); ApplicationResourceUsageReport usageReport = appReport.getApplicationResourceUsageReport(); Assert.assertEquals("Enemy should not see app used containers", -1, usageReport.getNumUsedContainers()); Assert.assertEquals("Enemy should not see app reserved containers", -1, usageReport.getNumReservedContainers()); Assert.assertEquals("Enemy should not see app used resources", -1, usageReport.getUsedResources().getMemorySize()); Assert.assertEquals("Enemy should not see app reserved resources", -1, usageReport.getReservedResources().getMemorySize()); Assert.assertEquals("Enemy should not see app needed resources", -1, usageReport.getNeededResources().getMemorySize()); }