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));
}
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;
}
Aggregations