Java Code Examples for org.apache.hadoop.yarn.api.records.Priority#setPriority()

The following examples show how to use org.apache.hadoop.yarn.api.records.Priority#setPriority() . 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: MockAM.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public ResourceRequest createResourceReq(String resource, int memory, int priority,
    int containers, String labelExpression) throws Exception {
  ResourceRequest req = Records.newRecord(ResourceRequest.class);
  req.setResourceName(resource);
  req.setNumContainers(containers);
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(priority);
  req.setPriority(pri);
  Resource capability = Records.newRecord(Resource.class);
  capability.setMemory(memory);
  req.setCapability(capability);
  if (labelExpression != null) {
   req.setNodeLabelExpression(labelExpression); 
  }
  return req;
}
 
Example 2
Source File: MockAM.java    From big-c with Apache License 2.0 6 votes vote down vote up
public ResourceRequest createResourceReq(String resource, int memory, int priority,
    int containers, String labelExpression) throws Exception {
  ResourceRequest req = Records.newRecord(ResourceRequest.class);
  req.setResourceName(resource);
  req.setNumContainers(containers);
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(priority);
  req.setPriority(pri);
  Resource capability = Records.newRecord(Resource.class);
  capability.setMemory(memory);
  req.setCapability(capability);
  if (labelExpression != null) {
   req.setNodeLabelExpression(labelExpression); 
  }
  return req;
}
 
Example 3
Source File: YarnService.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
private void requestContainer(Optional<String> preferredNode) {
  Priority priority = Records.newRecord(Priority.class);
  priority.setPriority(0);

  Resource capability = Records.newRecord(Resource.class);
  int maxMemoryCapacity = this.maxResourceCapacity.get().getMemory();
  capability.setMemory(this.requestedContainerMemoryMbs <= maxMemoryCapacity ?
      this.requestedContainerMemoryMbs : maxMemoryCapacity);
  int maxCoreCapacity = this.maxResourceCapacity.get().getVirtualCores();
  capability.setVirtualCores(this.requestedContainerCores <= maxCoreCapacity ?
      this.requestedContainerCores : maxCoreCapacity);

  String[] preferredNodes = preferredNode.isPresent() ? new String[] {preferredNode.get()} : null;
  this.amrmClientAsync.addContainerRequest(
      new AMRMClient.ContainerRequest(capability, preferredNodes, null, priority));
}
 
Example 4
Source File: SubQuery.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
public static void allocateContainers(SubQuery subQuery) {
  ExecutionBlock execBlock = subQuery.getBlock();

  //TODO consider disk slot
  int requiredMemoryMBPerTask = 512;

  int numRequest = subQuery.getContext().getResourceAllocator().calculateNumRequestContainers(
      subQuery.getContext().getQueryMasterContext().getWorkerContext(),
      subQuery.schedulerContext.getEstimatedTaskNum(),
      requiredMemoryMBPerTask
  );

  final Resource resource = Records.newRecord(Resource.class);

  resource.setMemory(requiredMemoryMBPerTask);

  LOG.info("Request Container for " + subQuery.getId() + " containers=" + numRequest);

  Priority priority = Records.newRecord(Priority.class);
  priority.setPriority(subQuery.getPriority());
  ContainerAllocationEvent event =
      new ContainerAllocationEvent(ContainerAllocatorEventType.CONTAINER_REQ,
          subQuery.getId(), priority, resource, numRequest,
          subQuery.masterPlan.isLeaf(execBlock), 0.0f);
  subQuery.eventHandler.handle(event);
}
 
Example 5
Source File: AMSimulator.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected ResourceRequest createResourceRequest(
        Resource resource, String host, int priority, int numContainers) {
  ResourceRequest request = recordFactory
      .newRecordInstance(ResourceRequest.class);
  request.setCapability(resource);
  request.setResourceName(host);
  request.setNumContainers(numContainers);
  Priority prio = recordFactory.newRecordInstance(Priority.class);
  prio.setPriority(priority);
  request.setPriority(prio);
  return request;
}
 
Example 6
Source File: AMSimulator.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected ResourceRequest createResourceRequest(
        Resource resource, String host, int priority, int numContainers) {
  ResourceRequest request = recordFactory
      .newRecordInstance(ResourceRequest.class);
  request.setCapability(resource);
  request.setResourceName(host);
  request.setNumContainers(numContainers);
  Priority prio = recordFactory.newRecordInstance(Priority.class);
  prio.setPriority(priority);
  request.setPriority(prio);
  return request;
}
 
Example 7
Source File: TestUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static Priority createMockPriority( int priority) {
//    Priority p = mock(Priority.class);
//    when(p.getPriority()).thenReturn(priority);
    Priority p = recordFactory.newRecordInstance(Priority.class);
    p.setPriority(priority);
    return p;
  }
 
Example 8
Source File: FairSchedulerTestBase.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected ResourceRequest createResourceRequest(
    int memory, int vcores, String host, int priority, int numContainers,
    boolean relaxLocality) {
  ResourceRequest request = recordFactory.newRecordInstance(ResourceRequest.class);
  request.setCapability(BuilderUtils.newResource(memory, vcores));
  request.setResourceName(host);
  request.setNumContainers(numContainers);
  Priority prio = recordFactory.newRecordInstance(Priority.class);
  prio.setPriority(priority);
  request.setPriority(prio);
  request.setRelaxLocality(relaxLocality);
  return request;
}
 
Example 9
Source File: TestFifoScheduler.java    From big-c with Apache License 2.0 5 votes vote down vote up
private ResourceRequest createResourceRequest(int memory, String host,
    int priority, int numContainers) {
  ResourceRequest request = recordFactory
      .newRecordInstance(ResourceRequest.class);
  request.setCapability(Resources.createResource(memory));
  request.setResourceName(host);
  request.setNumContainers(numContainers);
  Priority prio = recordFactory.newRecordInstance(Priority.class);
  prio.setPriority(priority);
  request.setPriority(prio);
  return request;
}
 
Example 10
Source File: TestUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static Priority createMockPriority( int priority) {
//    Priority p = mock(Priority.class);
//    when(p.getPriority()).thenReturn(priority);
    Priority p = recordFactory.newRecordInstance(Priority.class);
    p.setPriority(priority);
    return p;
  }
 
Example 11
Source File: TestFifoScheduler.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private ResourceRequest createResourceRequest(int memory, String host,
    int priority, int numContainers) {
  ResourceRequest request = recordFactory
      .newRecordInstance(ResourceRequest.class);
  request.setCapability(Resources.createResource(memory));
  request.setResourceName(host);
  request.setNumContainers(numContainers);
  Priority prio = recordFactory.newRecordInstance(Priority.class);
  prio.setPriority(priority);
  request.setPriority(prio);
  return request;
}
 
Example 12
Source File: UnmanagedAMLauncher.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public boolean run() throws IOException, YarnException {
  LOG.info("Starting Client");
  
  // Connect to ResourceManager
  rmClient.start();
  try {  
    // Create launch context for app master
    LOG.info("Setting up application submission context for ASM");
    ApplicationSubmissionContext appContext = rmClient.createApplication()
        .getApplicationSubmissionContext();
    ApplicationId appId = appContext.getApplicationId();

    // set the application name
    appContext.setApplicationName(appName);

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

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

    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = Records
        .newRecord(ContainerLaunchContext.class);
    appContext.setAMContainerSpec(amContainer);

    // unmanaged AM
    appContext.setUnmanagedAM(true);
    LOG.info("Setting unmanaged AM");

    // Submit the application to the applications manager
    LOG.info("Submitting application to ASM");
    rmClient.submitApplication(appContext);

    ApplicationReport appReport =
        monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED,
          YarnApplicationState.KILLED, YarnApplicationState.FAILED,
          YarnApplicationState.FINISHED));

    if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) {
      // Monitor the application attempt to wait for launch state
      ApplicationAttemptReport attemptReport =
          monitorCurrentAppAttempt(appId,
            YarnApplicationAttemptState.LAUNCHED);
      ApplicationAttemptId attemptId =
          attemptReport.getApplicationAttemptId();
      LOG.info("Launching AM with application attempt id " + attemptId);
      // launch AM
      launchAM(attemptId);
      // Monitor the application for end state
      appReport =
          monitorApplication(appId, EnumSet.of(YarnApplicationState.KILLED,
            YarnApplicationState.FAILED, YarnApplicationState.FINISHED));
    }

    YarnApplicationState appState = appReport.getYarnApplicationState();
    FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();

    LOG.info("App ended with state: " + appReport.getYarnApplicationState()
        + " and status: " + appStatus);
    
    boolean success;
    if (YarnApplicationState.FINISHED == appState
        && FinalApplicationStatus.SUCCEEDED == appStatus) {
      LOG.info("Application has completed successfully.");
      success = true;
    } else {
      LOG.info("Application did finished unsuccessfully." + " YarnState="
          + appState.toString() + ", FinalStatus=" + appStatus.toString());
      success = false;
    }
    
    return success;
  } finally {
    rmClient.stop();
  }
}
 
Example 13
Source File: TestAMRMClient.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Before
public void startApp() throws Exception {
  // submit new app
  ApplicationSubmissionContext appContext = 
      yarnClient.createApplication().getApplicationSubmissionContext();
  ApplicationId appId = appContext.getApplicationId();
  // set the application name
  appContext.setApplicationName("Test");
  // Set the priority for the application master
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(0);
  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 =
      BuilderUtils.newContainerLaunchContext(
        Collections.<String, LocalResource> emptyMap(),
        new HashMap<String, String>(), Arrays.asList("sleep", "100"),
        new HashMap<String, ByteBuffer>(), null,
        new HashMap<ApplicationAccessType, String>());
  appContext.setAMContainerSpec(amContainer);
  appContext.setResource(Resource.newInstance(1024, 1, 1));
  // Create the request to send to the applications manager
  SubmitApplicationRequest appRequest = Records
      .newRecord(SubmitApplicationRequest.class);
  appRequest.setApplicationSubmissionContext(appContext);
  // Submit the application to the applications manager
  yarnClient.submitApplication(appContext);

  // wait for app to start
  RMAppAttempt appAttempt = null;
  while (true) {
    ApplicationReport appReport = yarnClient.getApplicationReport(appId);
    if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) {
      attemptId = appReport.getCurrentApplicationAttemptId();
      appAttempt =
          yarnCluster.getResourceManager().getRMContext().getRMApps()
            .get(attemptId.getApplicationId()).getCurrentAppAttempt();
      while (true) {
        if (appAttempt.getAppAttemptState() == RMAppAttemptState.LAUNCHED) {
          break;
        }
      }
      break;
    }
  }
  // Just dig into the ResourceManager and get the AMRMToken just for the sake
  // of testing.
  UserGroupInformation.setLoginUser(UserGroupInformation
    .createRemoteUser(UserGroupInformation.getCurrentUser().getUserName()));

  // emulate RM setup of AMRM token in credentials by adding the token
  // *before* setting the token service
  UserGroupInformation.getCurrentUser().addToken(appAttempt.getAMRMToken());
  appAttempt.getAMRMToken().setService(ClientRMProxy.getAMRMTokenService(conf));
}
 
Example 14
Source File: BuilderUtils.java    From big-c with Apache License 2.0 4 votes vote down vote up
public static Priority newPriority(int p) {
  Priority priority = recordFactory.newRecordInstance(Priority.class);
  priority.setPriority(p);
  return priority;
}
 
Example 15
Source File: FSQueue.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public Priority getPriority() {
  Priority p = recordFactory.newRecordInstance(Priority.class);
  p.setPriority(1);
  return p;
}
 
Example 16
Source File: InlineAM.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public boolean run() throws Exception
{
  LOG.info("Starting Client");

  // Connect to ResourceManager
  rmClient.start();
  try {
    // Get a new application id
    YarnClientApplication newApp = rmClient.createApplication();
    ApplicationId appId = newApp.getNewApplicationResponse().getApplicationId();

    // Create launch context for app master
    LOG.info("Setting up application submission context for ASM");
    ApplicationSubmissionContext appContext = Records
        .newRecord(ApplicationSubmissionContext.class);

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

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

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

    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = Records
        .newRecord(ContainerLaunchContext.class);
    appContext.setAMContainerSpec(amContainer);

    // unmanaged AM
    appContext.setUnmanagedAM(true);
    LOG.info("Setting unmanaged AM");

    // Submit the application to the applications manager
    LOG.info("Submitting application to ASM");
    rmClient.submitApplication(appContext);

    // Monitor the application to wait for launch state
    ApplicationReport appReport = monitorApplication(appId,
        EnumSet.of(YarnApplicationState.ACCEPTED));
    ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
    LOG.info("Launching application with id: " + attemptId);

    // launch AM
    runAM(attemptId);

    // Monitor the application for end state
    appReport = monitorApplication(appId, EnumSet.of(
        YarnApplicationState.KILLED, YarnApplicationState.FAILED,
        YarnApplicationState.FINISHED));
    YarnApplicationState appState = appReport.getYarnApplicationState();
    FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();

    LOG.info("App ended with state: " + appReport.getYarnApplicationState()
        + " and status: " + appStatus);

    boolean success;
    if (YarnApplicationState.FINISHED == appState
        && FinalApplicationStatus.SUCCEEDED == appStatus) {
      LOG.info("Application has completed successfully.");
      success = true;
    } else {
      LOG.info("Application did finished unsuccessfully." + " YarnState="
          + appState.toString() + ", FinalStatus=" + appStatus.toString());
      success = false;
    }

    return success;
  } finally {
    rmClient.stop();
  }
}
 
Example 17
Source File: FSQueue.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public Priority getPriority() {
  Priority p = recordFactory.newRecordInstance(Priority.class);
  p.setPriority(1);
  return p;
}
 
Example 18
Source File: ApplicationMaster.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Runs application master.
 *
 * @throws Exception If failed.
 */
public void run() throws Exception {
    // Register with ResourceManager
    rmClient.registerApplicationMaster("", 0, "");

    log.log(Level.INFO, "Application master registered.");

    // Priority for worker containers - priorities are intra-application
    Priority priority = Records.newRecord(Priority.class);
    priority.setPriority(0);

    try {
        // Check ignite cluster.
        while (!nmClient.isInState(Service.STATE.STOPPED)) {
            int runningCnt = containers.size();

            if (runningCnt < props.instances() && checkAvailableResource()) {
                // Resource requirements for worker containers.
                Resource capability = Records.newRecord(Resource.class);

                capability.setMemory((int)props.totalMemoryPerNode());
                capability.setVirtualCores((int)props.cpusPerNode());

                for (int i = 0; i < props.instances() - runningCnt; ++i) {
                    // Make container requests to ResourceManager
                    AMRMClient.ContainerRequest containerAsk =
                        new AMRMClient.ContainerRequest(capability, null, null, priority);

                    rmClient.addContainerRequest(containerAsk);

                    log.log(Level.INFO, "Making request. Memory: {0}, cpu {1}.",
                        new Object[]{props.totalMemoryPerNode(), props.cpusPerNode()});
                }
            }

            TimeUnit.MILLISECONDS.sleep(schedulerTimeout);
        }
    }
    catch (InterruptedException ignored) {
        // Un-register with ResourceManager
        rmClient.unregisterApplicationMaster(FinalApplicationStatus.KILLED, "", "");

        log.log(Level.WARNING, "Application master killed.");
    }
    catch (Exception e) {
        // Un-register with ResourceManager
        rmClient.unregisterApplicationMaster(FinalApplicationStatus.FAILED, "", "");

        log.log(Level.SEVERE, "Application master failed.", e);
    }
}
 
Example 19
Source File: YarnRemoteInterpreterProcess.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
private void setPriority(ApplicationSubmissionContext appContext) {
  Priority pri = Records.newRecord(Priority.class);
  pri.setPriority(1);
  appContext.setPriority(pri);
}
 
Example 20
Source File: BuilderUtils.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public static Priority newPriority(int p) {
  Priority priority = recordFactory.newRecordInstance(Priority.class);
  priority.setPriority(p);
  return priority;
}