use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerReservedEvent in project hadoop by apache.
the class SchedulerApplicationAttempt method commonReserve.
private boolean commonReserve(SchedulerNode node, SchedulerRequestKey schedulerKey, RMContainer rmContainer, Resource reservedResource) {
try {
rmContainer.handle(new RMContainerReservedEvent(rmContainer.getContainerId(), reservedResource, node.getNodeID(), schedulerKey));
} catch (InvalidStateTransitionException e) {
// false indicate it fails
return false;
}
Map<NodeId, RMContainer> reservedContainers = this.reservedContainers.get(schedulerKey);
if (reservedContainers == null) {
reservedContainers = new HashMap<NodeId, RMContainer>();
this.reservedContainers.put(schedulerKey, reservedContainers);
}
reservedContainers.put(node.getNodeID(), rmContainer);
if (LOG.isDebugEnabled()) {
LOG.debug("Application attempt " + getApplicationAttemptId() + " reserved container " + rmContainer + " on node " + node + ". This attempt currently has " + reservedContainers.size() + " reserved containers at priority " + schedulerKey.getPriority() + "; currentReservation " + reservedResource);
}
return true;
}
use of org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerReservedEvent in project hadoop by apache.
the class FiCaSchedulerApp method moveReservation.
/**
* Move reservation from one node to another
* Comparing to unreserve container on source node and reserve a new
* container on target node. This method will not create new RMContainer
* instance. And this operation is atomic.
*
* @param reservedContainer to be moved reserved container
* @param sourceNode source node
* @param targetNode target node
*
* @return succeeded or not
*/
public boolean moveReservation(RMContainer reservedContainer, FiCaSchedulerNode sourceNode, FiCaSchedulerNode targetNode) {
try {
writeLock.lock();
if (!sourceNode.getPartition().equals(targetNode.getPartition())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Failed to move reservation, two nodes are in different partition");
}
return false;
}
// Update reserved container to node map
Map<NodeId, RMContainer> map = reservedContainers.get(reservedContainer.getReservedSchedulerKey());
if (null == map) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot find reserved container map.");
}
return false;
}
// Check if reserved container changed
if (sourceNode.getReservedContainer() != reservedContainer) {
if (LOG.isDebugEnabled()) {
LOG.debug("To-be-moved container already updated.");
}
return false;
}
// reservation happens transactional
synchronized (targetNode) {
if (targetNode.getReservedContainer() != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Target node is already occupied before moving");
}
}
try {
targetNode.reserveResource(this, reservedContainer.getReservedSchedulerKey(), reservedContainer);
} catch (IllegalStateException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Reserve on target node failed, e=", e);
}
return false;
}
// Set source node's reserved container to null
sourceNode.setReservedContainer(null);
map.remove(sourceNode.getNodeID());
// Update reserved container
reservedContainer.handle(new RMContainerReservedEvent(reservedContainer.getContainerId(), reservedContainer.getReservedResource(), targetNode.getNodeID(), reservedContainer.getReservedSchedulerKey()));
// Add to target node
map.put(targetNode.getNodeID(), reservedContainer);
return true;
}
} finally {
writeLock.unlock();
}
}
Aggregations