Search in sources :

Example 51 with ContainerRequest

use of org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest in project apex-core by apache.

the class ResourceRequestHandler method createContainerRequest.

/**
   * Setup the request(s) that will be sent to the RM for the container ask.
   */
public ContainerRequest createContainerRequest(ContainerStartRequest csr, boolean first) {
    int priority = csr.container.getResourceRequestPriority();
    // check for node locality constraint
    String[] nodes = null;
    String[] racks = null;
    String host = getHost(csr, first);
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(csr.container.getRequiredMemoryMB());
    capability.setVirtualCores(csr.container.getRequiredVCores());
    if (host == INVALID_HOST) {
        return null;
    }
    if (host != null) {
        nodes = new String[] { host };
        /*
       * if(this.nodeToRack.get(host) != null){ racks = new String[] { this.nodeToRack.get(host) }; }
       */
        return new ContainerRequest(capability, nodes, racks, Priority.newInstance(priority), false);
    }
    // For now, only memory is supported so we set memory requirements
    return new ContainerRequest(capability, nodes, racks, Priority.newInstance(priority));
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) ContainerRequest(org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest)

Example 52 with ContainerRequest

use of org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest in project asterixdb by apache.

the class AsterixApplicationMaster method requestResources.

/**
     * @param c
     *            The cluster exception to attempt to alocate with the RM
     * @throws YarnException
     */
private void requestResources(Cluster c) throws YarnException, UnknownHostException {
    //set memory
    if (c.getCcContainerMem() != null) {
        ccMem = Integer.parseInt(c.getCcContainerMem());
    } else {
        ccMem = CC_MEMORY_MBS_DEFAULT;
    }
    if (c.getNcContainerMem() != null) {
        ncMem = Integer.parseInt(c.getNcContainerMem());
    } else {
        ncMem = CC_MEMORY_MBS_DEFAULT;
    }
    //request CC
    int numNodes = 0;
    ContainerRequest ccAsk = hostToRequest(cC.getClusterIp(), true);
    resourceManager.addContainerRequest(ccAsk);
    LOG.info("Asked for CC: " + Arrays.toString(ccAsk.getNodes().toArray()));
    numNodes++;
    //now we wait to be given the CC before starting the NCs...
    //we will wait a minute.
    int deathClock = 60;
    while (ccUp.get() == false && deathClock > 0) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            LOG.debug(ex);
        }
        --deathClock;
    }
    if (deathClock == 0 && ccUp.get() == false) {
        throw new YarnException("Couldn't allocate container for CC. Abort!");
    }
    LOG.info("Waiting for CC process to start");
    // is there a good way to do this? maybe try opening a socket to it...
    try {
        Thread.sleep(10000);
    } catch (InterruptedException ex) {
        LOG.debug(ex);
    }
    //request NCs
    for (Node n : c.getNode()) {
        resourceManager.addContainerRequest(hostToRequest(n.getClusterIp(), false));
        LOG.info("Asked for NC: " + n.getClusterIp());
        numNodes++;
        synchronized (pendingNCs) {
            pendingNCs.add(n);
        }
    }
    LOG.info("Requested all NCs and CCs. Wait for things to settle!");
    numRequestedContainers.set(numNodes);
    numTotalContainers = numNodes;
    doneAllocating = true;
}
Also used : Node(org.apache.asterix.event.schema.yarnCluster.Node) MasterNode(org.apache.asterix.event.schema.yarnCluster.MasterNode) ContainerRequest(org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

ContainerRequest (org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest)52 Test (org.junit.Test)26 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)15 Configuration (org.apache.hadoop.conf.Configuration)14 Resource (org.apache.hadoop.yarn.api.records.Resource)14 Container (org.apache.hadoop.yarn.api.records.Container)12 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)9 IOException (java.io.IOException)8 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)8 Priority (org.apache.hadoop.yarn.api.records.Priority)8 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)7 UpdatedContainer (org.apache.hadoop.yarn.api.records.UpdatedContainer)6 ArrayList (java.util.ArrayList)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)5 ContainerStartRequest (com.datatorrent.stram.StreamingContainerAgent.ContainerStartRequest)4 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 MutablePair (org.apache.commons.lang3.tuple.MutablePair)4 Credentials (org.apache.hadoop.security.Credentials)4 ApplicationMasterProtocol (org.apache.hadoop.yarn.api.ApplicationMasterProtocol)4