Java 类org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport 实例源码

项目:AthenaX    文件:Utils.java   
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);
}
项目:hadoop    文件:BuilderUtils.java   
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;
}
项目:hadoop    文件:RMAppAttemptImpl.java   
@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();
  }
}
项目:hadoop    文件:RMAppAttemptMetrics.java   
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);
}
项目:hadoop    文件:TestApplicationACLs.java   
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());
}
项目:hadoop    文件:TestClientRMService.java   
@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);
}
项目:hadoop    文件:TestResourceMgrDelegate.java   
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;
}
项目:aliyun-oss-hadoop-fs    文件:RMAppAttemptImpl.java   
@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();
  }
}
项目:aliyun-oss-hadoop-fs    文件:RMAppAttemptMetrics.java   
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);
}
项目:aliyun-oss-hadoop-fs    文件:SchedulerApplicationAttempt.java   
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);
}
项目:aliyun-oss-hadoop-fs    文件:TestApplicationACLs.java   
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());
}
项目:aliyun-oss-hadoop-fs    文件:TestClientRMService.java   
@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);
}
项目:aliyun-oss-hadoop-fs    文件:TestResourceMgrDelegate.java   
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;
}
项目:big-c    文件:RMAppAttemptImpl.java   
@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();
  }
}
项目:big-c    文件:RMAppAttemptMetrics.java   
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);
}
项目:big-c    文件:TestApplicationACLs.java   
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());
}
项目:big-c    文件:TestClientRMService.java   
@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);
}
项目:big-c    文件:TestResourceMgrDelegate.java   
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;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:RMAppAttemptImpl.java   
@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();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:RMAppAttemptMetrics.java   
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);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestApplicationACLs.java   
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());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestClientRMService.java   
@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);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestResourceMgrDelegate.java   
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;
}
项目:hadoop-plus    文件:TestApplicationACLs.java   
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());
}
项目:hadoop-plus    文件:TestResourceMgrDelegate.java   
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;
}
项目:hadoop-plus    文件:TestTypeConverter.java   
@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());
}
项目:FlexMap    文件:TestResourceMgrDelegate.java   
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;
}
项目:hops    文件:BuilderUtils.java   
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;
 }
项目:hops    文件:RMAppAttemptImpl.java   
@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();
  }
}
项目:hops    文件:RMAppAttemptMetrics.java   
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);
}
项目:hops    文件:SchedulerApplicationAttempt.java   
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);
}
项目:hops    文件:FiCaSchedulerApp.java   
/**
 * 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;
}
项目:hops    文件:TestApplicationACLs.java   
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());
}
项目:hops    文件:TestClientRMService.java   
@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);
}
项目:hops    文件:TestResourceMgrDelegate.java   
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;
}
项目:hadoop-TCP    文件:TestApplicationACLs.java   
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());
}
项目:hadoop-TCP    文件:TestResourceMgrDelegate.java   
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;
}
项目:hadoop-TCP    文件:TestTypeConverter.java   
@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());
}
项目:hardfs    文件:TestApplicationACLs.java   
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());
}
项目:hardfs    文件:TestResourceMgrDelegate.java   
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;
}