Java Code Examples for org.apache.hadoop.yarn.util.Records#newRecord()

The following examples show how to use org.apache.hadoop.yarn.util.Records#newRecord() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestClientServiceDelegate.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private GetCountersResponse getCountersResponseFromHistoryServer() {
  GetCountersResponse countersResponse = Records
      .newRecord(GetCountersResponse.class);
  Counter counter = Records.newRecord(Counter.class);
  CounterGroup counterGroup = Records.newRecord(CounterGroup.class);
  Counters counters = Records.newRecord(Counters.class);
  counter.setDisplayName("dummyCounter");
  counter.setName("dummyCounter");
  counter.setValue(1001);
  counterGroup.setName("dummyCounters");
  counterGroup.setDisplayName("dummyCounters");
  counterGroup.setCounter("dummyCounter", counter);
  counters.setCounterGroup("dummyCounters", counterGroup);
  countersResponse.setCounters(counters);
  return countersResponse;
}
 
Example 2
Source File: YarnClientImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 3
Source File: CancelDelegationTokenResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static CancelDelegationTokenResponse newInstance() {
  CancelDelegationTokenResponse response =
      Records.newRecord(CancelDelegationTokenResponse.class);
  return response;
}
 
Example 4
Source File: ContainerId.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static ContainerId newContainerId(ApplicationAttemptId appAttemptId,
    long containerId) {
  ContainerId id = Records.newRecord(ContainerId.class);
  id.setContainerId(containerId);
  id.setApplicationAttemptId(appAttemptId);
  id.build();
  return id;
}
 
Example 5
Source File: RefreshServiceAclsResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static RefreshServiceAclsResponse newInstance() {
  RefreshServiceAclsResponse response =
      Records.newRecord(RefreshServiceAclsResponse.class);
  return response;
}
 
Example 6
Source File: StartContainerRequest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Public
@Stable
public static StartContainerRequest newInstance(
    ContainerLaunchContext context, Token container) {
  StartContainerRequest request =
      Records.newRecord(StartContainerRequest.class);
  request.setContainerLaunchContext(context);
  request.setContainerToken(container);
  return request;
}
 
Example 7
Source File: GetLabelsToNodesResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static GetLabelsToNodesResponse newInstance(
     Map<String, Set<NodeId>> map) {
GetLabelsToNodesResponse response =
       Records.newRecord(GetLabelsToNodesResponse.class);
   response.setLabelsToNodes(map);
   return response;
 }
 
Example 8
Source File: YarnJobDescriptor.java    From sylph with Apache License 2.0 5 votes vote down vote up
private LocalResource registerLocalResource(FileSystem fs, Path remoteRsrcPath)
        throws IOException
{
    LocalResource localResource = Records.newRecord(LocalResource.class);
    FileStatus jarStat = fs.getFileStatus(remoteRsrcPath);
    localResource.setResource(ConverterUtils.getYarnUrlFromURI(remoteRsrcPath.toUri()));
    localResource.setSize(jarStat.getLen());
    localResource.setTimestamp(jarStat.getModificationTime());
    localResource.setType(LocalResourceType.FILE);
    localResource.setVisibility(LocalResourceVisibility.APPLICATION);
    return localResource;
}
 
Example 9
Source File: ApplicationFinishData.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Public
@Unstable
public static ApplicationFinishData newInstance(ApplicationId applicationId,
    long finishTime, String diagnosticsInfo,
    FinalApplicationStatus finalApplicationStatus,
    YarnApplicationState yarnApplicationState) {
  ApplicationFinishData appFD =
      Records.newRecord(ApplicationFinishData.class);
  appFD.setApplicationId(applicationId);
  appFD.setFinishTime(finishTime);
  appFD.setDiagnosticsInfo(diagnosticsInfo);
  appFD.setFinalApplicationStatus(finalApplicationStatus);
  appFD.setYarnApplicationState(yarnApplicationState);
  return appFD;
}
 
Example 10
Source File: GetApplicationsResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static GetApplicationsResponse newInstance(
    List<ApplicationReport> applications) {
  GetApplicationsResponse response =
      Records.newRecord(GetApplicationsResponse.class);
  response.setApplicationList(applications);
  return response;
}
 
Example 11
Source File: TestYarnClient.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private ApplicationId createApp(YarnClient rmClient, boolean unmanaged) 
  throws Exception {
  YarnClientApplication newApp = rmClient.createApplication();

  ApplicationId appId = newApp.getNewApplicationResponse().getApplicationId();

  // Create launch context for app master
  ApplicationSubmissionContext appContext
    = Records.newRecord(ApplicationSubmissionContext.class);

  // set the application id
  appContext.setApplicationId(appId);

  // set the application name
  appContext.setApplicationName("test");

  // Set the priority for the application master
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(1);
  appContext.setPriority(pri);

  // Set the queue to which this application is to be submitted in the RM
  appContext.setQueue("default");

  // Set up the container launch context for the application master
  ContainerLaunchContext amContainer
    = Records.newRecord(ContainerLaunchContext.class);
  appContext.setAMContainerSpec(amContainer);
  appContext.setResource(Resource.newInstance(1024, 1));
  appContext.setUnmanagedAM(unmanaged);

  // Submit the application to the applications manager
  rmClient.submitApplication(appContext);

  return appId;
}
 
Example 12
Source File: RenewDelegationTokenResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static RenewDelegationTokenResponse newInstance(long expTime) {
  RenewDelegationTokenResponse response =
      Records.newRecord(RenewDelegationTokenResponse.class);
  response.setNextExpirationTime(expTime);
  return response;
}
 
Example 13
Source File: GetClusterMetricsRequest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Public
@Stable
public static GetClusterMetricsRequest newInstance() {
  GetClusterMetricsRequest request =
      Records.newRecord(GetClusterMetricsRequest.class);
  return request;
}
 
Example 14
Source File: GetQueueUserAclsInfoResponse.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static GetQueueUserAclsInfoResponse newInstance(
    List<QueueUserACLInfo> queueUserAclsList) {
  GetQueueUserAclsInfoResponse response =
      Records.newRecord(GetQueueUserAclsInfoResponse.class);
  response.setUserAclsInfoList(queueUserAclsList);
  return response;
}
 
Example 15
Source File: MockJobs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static JobReport newJobReport(JobId id) {
  JobReport report = Records.newRecord(JobReport.class);
  report.setJobId(id);
  report.setSubmitTime(System.currentTimeMillis()-DT);
  report
      .setStartTime(System.currentTimeMillis() - (int) (Math.random() * DT));
  report.setFinishTime(System.currentTimeMillis()
      + (int) (Math.random() * DT) + 1);
  report.setMapProgress((float) Math.random());
  report.setReduceProgress((float) Math.random());
  report.setJobState(JOB_STATES.next());
  return report;
}
 
Example 16
Source File: Token.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Private
@Unstable
public static Token newInstance(byte[] identifier, String kind, byte[] password,
    String service) {
  Token token = Records.newRecord(Token.class);
  token.setIdentifier(ByteBuffer.wrap(identifier));
  token.setKind(kind);
  token.setPassword(ByteBuffer.wrap(password));
  token.setService(service);
  return token;
}
 
Example 17
Source File: TestResourceMgrDelegate.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void tesAllJobs() throws Exception {
  final ApplicationClientProtocol applicationsManager = Mockito.mock(ApplicationClientProtocol.class);
  GetApplicationsResponse allApplicationsResponse = Records
      .newRecord(GetApplicationsResponse.class);
  List<ApplicationReport> applications = new ArrayList<ApplicationReport>();
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.FAILED));
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.SUCCEEDED));
  applications.add(getApplicationReport(YarnApplicationState.FINISHED,
      FinalApplicationStatus.KILLED));
  applications.add(getApplicationReport(YarnApplicationState.FAILED,
      FinalApplicationStatus.FAILED));
  allApplicationsResponse.setApplicationList(applications);
  Mockito.when(
      applicationsManager.getApplications(Mockito
          .any(GetApplicationsRequest.class))).thenReturn(
      allApplicationsResponse);
  ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(
    new YarnConfiguration()) {
    @Override
    protected void serviceStart() throws Exception {
      Assert.assertTrue(this.client instanceof YarnClientImpl);
      ((YarnClientImpl) this.client).setRMClient(applicationsManager);
    }
  };
  JobStatus[] allJobs = resourceMgrDelegate.getAllJobs();

  Assert.assertEquals(State.FAILED, allJobs[0].getState());
  Assert.assertEquals(State.SUCCEEDED, allJobs[1].getState());
  Assert.assertEquals(State.KILLED, allJobs[2].getState());
  Assert.assertEquals(State.FAILED, allJobs[3].getState());
}
 
Example 18
Source File: Resources.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static Resource createResource(int memory, int cores, int gcores) {
  Resource resource = Records.newRecord(Resource.class);
  resource.setMemory(memory);
  resource.setVirtualCores(cores);
  resource.setGpuCores(gcores);
  return resource;
}
 
Example 19
Source File: RefreshNodesRequest.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Public
@Stable
public static RefreshNodesRequest newInstance() {
  RefreshNodesRequest request = Records.newRecord(RefreshNodesRequest.class);
  return request;
}
 
Example 20
Source File: ClusterInfo.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public ClusterInfo() {
  this.maxContainerCapability = Records.newRecord(Resource.class);
}