Java Code Examples for org.apache.hadoop.yarn.util.resource.Resources#greaterThan()
The following examples show how to use
org.apache.hadoop.yarn.util.resource.Resources#greaterThan() .
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: GreedyReservationAgent.java From hadoop with Apache License 2.0 | 6 votes |
private void validateInput(Plan plan, ReservationRequest rr, Resource totalCapacity) throws ContractValidationException { if (rr.getConcurrency() < 1) { throw new ContractValidationException("Gang Size should be >= 1"); } if (rr.getNumContainers() <= 0) { throw new ContractValidationException("Num containers should be >= 0"); } // check that gangSize and numContainers are compatible if (rr.getNumContainers() % rr.getConcurrency() != 0) { throw new ContractValidationException( "Parallelism must be an exact multiple of gang size"); } // check that the largest container request does not exceed // the cluster-wide limit for container sizes if (Resources.greaterThan(plan.getResourceCalculator(), totalCapacity, rr.getCapability(), plan.getMaximumAllocation())) { throw new ContractValidationException("Individual" + " capability requests should not exceed cluster's maxAlloc"); } }
Example 2
Source File: FairScheduler.java From hadoop with Apache License 2.0 | 6 votes |
/** * Check for queues that need tasks preempted, either because they have been * below their guaranteed share for minSharePreemptionTimeout or they have * been below their fair share threshold for the fairSharePreemptionTimeout. If * such queues exist, compute how many tasks of each type need to be preempted * and then select the right ones using preemptTasks. */ protected synchronized void preemptTasksIfNecessary() { if (!shouldAttemptPreemption()) { return; } long curTime = getClock().getTime(); if (curTime - lastPreemptCheckTime < preemptionInterval) { return; } lastPreemptCheckTime = curTime; Resource resToPreempt = Resources.clone(Resources.none()); for (FSLeafQueue sched : queueMgr.getLeafQueues()) { Resources.addTo(resToPreempt, resToPreempt(sched, curTime)); } if (Resources.greaterThan(RESOURCE_CALCULATOR, clusterResource, resToPreempt, Resources.none())) { preemptResources(resToPreempt); } }
Example 3
Source File: GreedyReservationAgent.java From big-c with Apache License 2.0 | 6 votes |
private void validateInput(Plan plan, ReservationRequest rr, Resource totalCapacity) throws ContractValidationException { if (rr.getConcurrency() < 1) { throw new ContractValidationException("Gang Size should be >= 1"); } if (rr.getNumContainers() <= 0) { throw new ContractValidationException("Num containers should be >= 0"); } // check that gangSize and numContainers are compatible if (rr.getNumContainers() % rr.getConcurrency() != 0) { throw new ContractValidationException( "Parallelism must be an exact multiple of gang size"); } // check that the largest container request does not exceed // the cluster-wide limit for container sizes if (Resources.greaterThan(plan.getResourceCalculator(), totalCapacity, rr.getCapability(), plan.getMaximumAllocation())) { throw new ContractValidationException("Individual" + " capability requests should not exceed cluster's maxAlloc"); } }
Example 4
Source File: FairScheduler.java From big-c with Apache License 2.0 | 6 votes |
/** * Check for queues that need tasks preempted, either because they have been * below their guaranteed share for minSharePreemptionTimeout or they have * been below their fair share threshold for the fairSharePreemptionTimeout. If * such queues exist, compute how many tasks of each type need to be preempted * and then select the right ones using preemptTasks. */ protected synchronized void preemptTasksIfNecessary() { if (!shouldAttemptPreemption()) { return; } long curTime = getClock().getTime(); if (curTime - lastPreemptCheckTime < preemptionInterval) { return; } lastPreemptCheckTime = curTime; Resource resToPreempt = Resources.clone(Resources.none()); for (FSLeafQueue sched : queueMgr.getLeafQueues()) { Resources.addTo(resToPreempt, resToPreempt(sched, curTime)); } if (Resources.greaterThan(RESOURCE_CALCULATOR, clusterResource, resToPreempt, Resources.none())) { preemptResources(resToPreempt); } }
Example 5
Source File: CapacitySchedulerPlanFollower.java From big-c with Apache License 2.0 | 5 votes |
@Override protected boolean arePlanResourcesLessThanReservations( Resource clusterResources, Resource planResources, Resource reservedResources) { return Resources.greaterThan(cs.getResourceCalculator(), clusterResources, reservedResources, planResources); }
Example 6
Source File: ProportionalCapacityPreemptionPolicy.java From hadoop with Apache License 2.0 | 5 votes |
public void assignPreemption(float scalingFactor, ResourceCalculator rc, Resource clusterResource) { if (Resources.greaterThan(rc, clusterResource, current, idealAssigned)) { toBePreempted = Resources.multiply( Resources.subtract(current, idealAssigned), scalingFactor); } else { toBePreempted = Resource.newInstance(0, 0, 0); } }
Example 7
Source File: ProportionalCapacityPreemptionPolicy.java From big-c with Apache License 2.0 | 5 votes |
public void assignPreemption(float scalingFactor, ResourceCalculator rc, Resource clusterResource) { if (Resources.greaterThan(rc, clusterResource, current, idealAssigned)) { //to avoid negative memory or cores //we only prempte current.cores > idealAssigned.cores || current.memory > idealAssigned.memory toBePreempted = Resources.multiply( Resources.subtracts(current, idealAssigned), scalingFactor); //we still have resource left LOG.info("assignPreemption queue "+queueName+" toBePreempted "+toBePreempted); } else { toBePreempted = Resource.newInstance(0, 0); } }
Example 8
Source File: CSQueueUtils.java From big-c with Apache License 2.0 | 4 votes |
@Lock(CSQueue.class) public static void updateQueueStatistics( final ResourceCalculator calculator, final CSQueue childQueue, final CSQueue parentQueue, final Resource clusterResource, final Resource minimumAllocation) { Resource queueLimit = Resources.none(); Resource usedResources = childQueue.getUsedResources(); float absoluteUsedCapacity = 0.0f; float usedCapacity = 0.0f; if (Resources.greaterThan( calculator, clusterResource, clusterResource, Resources.none())) { queueLimit = Resources.multiply(clusterResource, childQueue.getAbsoluteCapacity()); //absoluteUsedCapacity = // Resources.divide(calculator, clusterResource, // usedResources, clusterResource); absoluteUsedCapacity = (float) ((usedResources.getVirtualCores()*1.0)/(clusterResource.getVirtualCores()*1.0)); usedCapacity = Resources.equals(queueLimit, Resources.none()) ? 0 : Resources.divide(calculator, clusterResource, usedResources, queueLimit); } childQueue.setUsedCapacity(usedCapacity); childQueue.setAbsoluteUsedCapacity(absoluteUsedCapacity); Resource available = Resources.subtract(queueLimit, usedResources); childQueue.getMetrics().setAvailableResourcesToQueue( Resources.max( calculator, clusterResource, available, Resources.none() ) ); }
Example 9
Source File: FairSchedulerPlanFollower.java From big-c with Apache License 2.0 | 4 votes |
@Override protected boolean arePlanResourcesLessThanReservations(Resource clusterResources, Resource planResources, Resource reservedResources) { return Resources.greaterThan(fs.getResourceCalculator(), clusterResources, reservedResources, planResources); }
Example 10
Source File: ProportionalCapacityPreemptionPolicy.java From hadoop with Apache License 2.0 | 4 votes |
/** * Based a resource preemption target drop reservations of containers and * if necessary select containers for preemption from applications in each * over-capacity queue. It uses {@link #NATURAL_TERMINATION_FACTOR} to * account for containers that will naturally complete. * * @param queues set of leaf queues to preempt from * @param clusterResource total amount of cluster resources * @return a map of applciationID to set of containers to preempt */ private Map<ApplicationAttemptId,Set<RMContainer>> getContainersToPreempt( List<TempQueue> queues, Resource clusterResource) { Map<ApplicationAttemptId,Set<RMContainer>> preemptMap = new HashMap<ApplicationAttemptId,Set<RMContainer>>(); List<RMContainer> skippedAMContainerlist = new ArrayList<RMContainer>(); for (TempQueue qT : queues) { if (qT.preemptionDisabled && qT.leafQueue != null) { if (LOG.isDebugEnabled()) { if (Resources.greaterThan(rc, clusterResource, qT.toBePreempted, Resource.newInstance(0, 0, 0))) { LOG.debug("Tried to preempt the following " + "resources from non-preemptable queue: " + qT.queueName + " - Resources: " + qT.toBePreempted); } } continue; } // we act only if we are violating balance by more than // maxIgnoredOverCapacity if (Resources.greaterThan(rc, clusterResource, qT.current, Resources.multiply(qT.guaranteed, 1.0 + maxIgnoredOverCapacity))) { // we introduce a dampening factor naturalTerminationFactor that // accounts for natural termination of containers Resource resToObtain = Resources.multiply(qT.toBePreempted, naturalTerminationFactor); Resource skippedAMSize = Resource.newInstance(0, 0, 0); // lock the leafqueue while we scan applications and unreserve synchronized (qT.leafQueue) { NavigableSet<FiCaSchedulerApp> ns = (NavigableSet<FiCaSchedulerApp>) qT.leafQueue.getApplications(); Iterator<FiCaSchedulerApp> desc = ns.descendingIterator(); qT.actuallyPreempted = Resources.clone(resToObtain); while (desc.hasNext()) { FiCaSchedulerApp fc = desc.next(); if (Resources.lessThanOrEqual(rc, clusterResource, resToObtain, Resources.none())) { break; } preemptMap.put( fc.getApplicationAttemptId(), preemptFrom(fc, clusterResource, resToObtain, skippedAMContainerlist, skippedAMSize)); } Resource maxAMCapacityForThisQueue = Resources.multiply( Resources.multiply(clusterResource, qT.leafQueue.getAbsoluteCapacity()), qT.leafQueue.getMaxAMResourcePerQueuePercent()); // Can try preempting AMContainers (still saving atmost // maxAMCapacityForThisQueue AMResource's) if more resources are // required to be preempted from this Queue. preemptAMContainers(clusterResource, preemptMap, skippedAMContainerlist, resToObtain, skippedAMSize, maxAMCapacityForThisQueue); } } } return preemptMap; }
Example 11
Source File: ReservationInputValidator.java From big-c with Apache License 2.0 | 4 votes |
private void validateReservationDefinition(ReservationId reservationId, ReservationDefinition contract, Plan plan, String auditConstant) throws YarnException { String message = ""; // check if deadline is in the past if (contract == null) { message = "Missing reservation definition." + " Please try again by specifying a reservation definition."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } if (contract.getDeadline() <= clock.getTime()) { message = "The specified deadline: " + contract.getDeadline() + " is the past. Please try again with deadline in the future."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // Check if at least one RR has been specified ReservationRequests resReqs = contract.getReservationRequests(); if (resReqs == null) { message = "No resources have been specified to reserve." + "Please try again by specifying the resources to reserve."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } List<ReservationRequest> resReq = resReqs.getReservationResources(); if (resReq == null || resReq.isEmpty()) { message = "No resources have been specified to reserve." + " Please try again by specifying the resources to reserve."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // compute minimum duration and max gang size long minDuration = 0; Resource maxGangSize = Resource.newInstance(0, 0); ReservationRequestInterpreter type = contract.getReservationRequests().getInterpreter(); for (ReservationRequest rr : resReq) { if (type == ReservationRequestInterpreter.R_ALL || type == ReservationRequestInterpreter.R_ANY) { minDuration = Math.max(minDuration, rr.getDuration()); } else { minDuration += rr.getDuration(); } maxGangSize = Resources.max(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, Resources.multiply(rr.getCapability(), rr.getConcurrency())); } // verify the allocation is possible (skip for ANY) if (contract.getDeadline() - contract.getArrival() < minDuration && type != ReservationRequestInterpreter.R_ANY) { message = "The time difference (" + (contract.getDeadline() - contract.getArrival()) + ") between arrival (" + contract.getArrival() + ") " + "and deadline (" + contract.getDeadline() + ") must " + " be greater or equal to the minimum resource duration (" + minDuration + ")"; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // check that the largest gang does not exceed the inventory available // capacity (skip for ANY) if (Resources.greaterThan(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, plan.getTotalCapacity()) && type != ReservationRequestInterpreter.R_ANY) { message = "The size of the largest gang in the reservation refinition (" + maxGangSize + ") exceed the capacity available (" + plan.getTotalCapacity() + " )"; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } }
Example 12
Source File: AbstractCSQueue.java From big-c with Apache License 2.0 | 4 votes |
synchronized boolean canAssignToThisQueue(Resource clusterResource, Set<String> nodeLabels, ResourceLimits currentResourceLimits, Resource nowRequired, Resource resourceCouldBeUnreserved) { // Get label of this queue can access, it's (nodeLabel AND queueLabel) Set<String> labelCanAccess; if (null == nodeLabels || nodeLabels.isEmpty()) { labelCanAccess = new HashSet<String>(); // Any queue can always access any node without label labelCanAccess.add(RMNodeLabelsManager.NO_LABEL); } else { labelCanAccess = new HashSet<String>( accessibleLabels.contains(CommonNodeLabelsManager.ANY) ? nodeLabels : Sets.intersection(accessibleLabels, nodeLabels)); } for (String label : labelCanAccess) { // New total resource = used + required Resource newTotalResource = Resources.add(queueUsage.getUsed(label), nowRequired); Resource currentLimitResource = getCurrentLimitResource(label, clusterResource, currentResourceLimits); //current resource is much more than currentlimit if (Resources.greaterThan(resourceCalculator, clusterResource, newTotalResource, currentLimitResource)) { // if reservation continous looking enabled, check to see if could we // potentially use this node instead of a reserved node if the application // has reserved containers. // TODO, now only consider reservation cases when the node has no label if (this.reservationsContinueLooking && label.equals(RMNodeLabelsManager.NO_LABEL) && Resources.greaterThan(resourceCalculator, clusterResource, resourceCouldBeUnreserved, Resources.none())) { // resource-without-reserved = used - reserved Resource newTotalWithoutReservedResource = Resources.subtract(newTotalResource, resourceCouldBeUnreserved); // when total-used-without-reserved-resource < currentLimit, we still // have chance to allocate on this node by unreserving some containers if (Resources.lessThan(resourceCalculator, clusterResource, newTotalWithoutReservedResource, currentLimitResource)) { if (LOG.isDebugEnabled()) { LOG.debug("try to use reserved: " + getQueueName() + " usedResources: " + queueUsage.getUsed() + ", clusterResources: " + clusterResource + ", reservedResources: " + resourceCouldBeUnreserved + ", capacity-without-reserved: " + newTotalWithoutReservedResource + ", maxLimitCapacity: " + currentLimitResource); } currentResourceLimits.setAmountNeededUnreserve(Resources.subtract(newTotalResource, currentLimitResource)); return true; } } if (LOG.isDebugEnabled()) { LOG.debug(getQueueName() + "Check assign to queue, label=" + label + " usedResources: " + queueUsage.getUsed(label) + " clusterResources: " + clusterResource + " currentUsedCapacity " + Resources.divide(resourceCalculator, clusterResource, queueUsage.getUsed(label), labelManager.getResourceByLabel(label, clusterResource)) + " max-capacity: " + queueCapacities.getAbsoluteMaximumCapacity(label) + ")"); } return false; } return true; } // Actually, this will not happen, since labelCanAccess will be always // non-empty return false; }
Example 13
Source File: FairSharePolicy.java From big-c with Apache License 2.0 | 4 votes |
@Override public boolean checkIfUsageOverFairShare(Resource usage, Resource fairShare) { return Resources.greaterThan(RESOURCE_CALCULATOR, null, usage, fairShare); }
Example 14
Source File: ParentQueue.java From big-c with Apache License 2.0 | 4 votes |
@Override public synchronized CSAssignment assignContainers(Resource clusterResource, FiCaSchedulerNode node, ResourceLimits resourceLimits) { CSAssignment assignment = new CSAssignment(Resources.createResource(0, 0), NodeType.NODE_LOCAL); Set<String> nodeLabels = node.getLabels(); // if our queue cannot access this node, just return if (!SchedulerUtils.checkQueueAccessToNode(accessibleLabels, nodeLabels)) { return assignment; } //每次分配一个container 给node节点上的应用,直到不能非配为止 while (canAssign(clusterResource, node)) { if (LOG.isDebugEnabled()) { LOG.info("Trying to assign containers to child-queue of " + getQueueName()); } //LOG.info("cluster resource:"+clusterResource.getMemory()+"node:"+node.getNodeName()+"resource limits:"+resourceLimits.getLimit().getMemory()); // Are we over maximum-capacity for this queue? // This will also consider parent's limits and also continuous reservation // looking,try to allocate at minimumAllocation to see if it's can be allocated if (!super.canAssignToThisQueue(clusterResource, nodeLabels, resourceLimits, minimumAllocation, Resources.createResource(getMetrics() .getReservedMB(), getMetrics().getReservedVirtualCores()))) { LOG.info("over maximum-capacity of this queue "+getQueueName()); break; } // Schedule CSAssignment assignedToChild = assignContainersToChildQueues(clusterResource, node, resourceLimits); assignment.setType(assignedToChild.getType()); // Done if no child-queue assigned anything //if get allocated in child queue if (Resources.greaterThan( resourceCalculator, clusterResource, assignedToChild.getResource(), Resources.none())) { // Track resource utilization for the parent-queue if(assignedToChild.getContainersToResume().size() > 0){ super.allocateResource(clusterResource, assignedToChild.getResource(), nodeLabels,true); }else{ super.allocateResource(clusterResource, assignedToChild.getResource(), nodeLabels,false); } // Track resource utilization in this pass of the scheduler //Resources.addTo(assignment.getResource(), assignedToChild.getResource()); //we need to merge the resumed containers and accumulate the resource assignment.merge(assignedToChild); LOG.info("assignedContainer" + " queue=" + getQueueName() + " usedCapacity=" + getUsedCapacity() + " absoluteUsedCapacity=" + getAbsoluteUsedCapacity() + " used=" + queueUsage.getUsed() + " cluster=" + clusterResource+ " resume size="+assignment.getContainersToResume().size()); } else { break; } if (LOG.isDebugEnabled()) { LOG.info("ParentQ=" + getQueueName() + " assignedSoFarInThisIteration=" + assignment.getResource() + " usedCapacity=" + getUsedCapacity() + " absoluteUsedCapacity=" + getAbsoluteUsedCapacity()); } // Do not assign more than one container if this isn't the root queue // or if we've already assigned an off-switch container why? if (!rootQueue || assignment.getType() == NodeType.OFF_SWITCH) { if (LOG.isDebugEnabled()) { if (rootQueue && assignment.getType() == NodeType.OFF_SWITCH) { LOG.debug("Not assigning more than one off-switch container," + " assignments so far: " + assignment); } } break; } } return assignment; }
Example 15
Source File: ParentQueue.java From hadoop with Apache License 2.0 | 4 votes |
private synchronized CSAssignment assignContainersToChildQueues( Resource cluster, FiCaSchedulerNode node, ResourceLimits limits) { CSAssignment assignment = new CSAssignment(Resources.createResource(0, 0, 0), NodeType.NODE_LOCAL); printChildQueues(); // Try to assign to most 'under-served' sub-queue for (Iterator<CSQueue> iter = childQueues.iterator(); iter.hasNext();) { CSQueue childQueue = iter.next(); if(LOG.isDebugEnabled()) { LOG.debug("Trying to assign to queue: " + childQueue.getQueuePath() + " stats: " + childQueue); } // Get ResourceLimits of child queue before assign containers ResourceLimits childLimits = getResourceLimitsOfChild(childQueue, cluster, limits); assignment = childQueue.assignContainers(cluster, node, childLimits); if(LOG.isDebugEnabled()) { LOG.debug("Assigned to queue: " + childQueue.getQueuePath() + " stats: " + childQueue + " --> " + assignment.getResource() + ", " + assignment.getType()); } // If we do assign, remove the queue and re-insert in-order to re-sort if (Resources.greaterThan( resourceCalculator, cluster, assignment.getResource(), Resources.none())) { // Remove and re-insert to sort iter.remove(); LOG.info("Re-sorting assigned queue: " + childQueue.getQueuePath() + " stats: " + childQueue); childQueues.add(childQueue); if (LOG.isDebugEnabled()) { printChildQueues(); } break; } } return assignment; }
Example 16
Source File: ParentQueue.java From hadoop with Apache License 2.0 | 4 votes |
@Override public synchronized CSAssignment assignContainers(Resource clusterResource, FiCaSchedulerNode node, ResourceLimits resourceLimits) { CSAssignment assignment = new CSAssignment(Resources.createResource(0, 0, 0), NodeType.NODE_LOCAL); Set<String> nodeLabels = node.getLabels(); // if our queue cannot access this node, just return if (!SchedulerUtils.checkQueueAccessToNode(accessibleLabels, nodeLabels)) { return assignment; } while (canAssign(clusterResource, node)) { if (LOG.isDebugEnabled()) { LOG.debug("Trying to assign containers to child-queue of " + getQueueName()); } // Are we over maximum-capacity for this queue? // This will also consider parent's limits and also continuous reservation // looking if (!super.canAssignToThisQueue(clusterResource, nodeLabels, resourceLimits, minimumAllocation, Resources.createResource(getMetrics() .getReservedMB(), getMetrics().getReservedVirtualCores(), getMetrics().getReservedGpuCores()))) { break; } // Schedule CSAssignment assignedToChild = assignContainersToChildQueues(clusterResource, node, resourceLimits); assignment.setType(assignedToChild.getType()); // Done if no child-queue assigned anything if (Resources.greaterThan( resourceCalculator, clusterResource, assignedToChild.getResource(), Resources.none())) { // Track resource utilization for the parent-queue super.allocateResource(clusterResource, assignedToChild.getResource(), nodeLabels); // Track resource utilization in this pass of the scheduler Resources.addTo(assignment.getResource(), assignedToChild.getResource()); LOG.info("assignedContainer" + " queue=" + getQueueName() + " usedCapacity=" + getUsedCapacity() + " absoluteUsedCapacity=" + getAbsoluteUsedCapacity() + " used=" + queueUsage.getUsed() + " cluster=" + clusterResource); } else { break; } if (LOG.isDebugEnabled()) { LOG.debug("ParentQ=" + getQueueName() + " assignedSoFarInThisIteration=" + assignment.getResource() + " usedCapacity=" + getUsedCapacity() + " absoluteUsedCapacity=" + getAbsoluteUsedCapacity()); } // Do not assign more than one container if this isn't the root queue // or if we've already assigned an off-switch container if (!rootQueue || assignment.getType() == NodeType.OFF_SWITCH) { if (LOG.isDebugEnabled()) { if (rootQueue && assignment.getType() == NodeType.OFF_SWITCH) { LOG.debug("Not assigning more than one off-switch container," + " assignments so far: " + assignment); } } break; } } return assignment; }
Example 17
Source File: FairSharePolicy.java From hadoop with Apache License 2.0 | 4 votes |
@Override public boolean checkIfUsageOverFairShare(Resource usage, Resource fairShare) { return Resources.greaterThan(RESOURCE_CALCULATOR, null, usage, fairShare); }
Example 18
Source File: FairSchedulerPlanFollower.java From hadoop with Apache License 2.0 | 4 votes |
@Override protected boolean arePlanResourcesLessThanReservations(Resource clusterResources, Resource planResources, Resource reservedResources) { return Resources.greaterThan(fs.getResourceCalculator(), clusterResources, reservedResources, planResources); }
Example 19
Source File: CapacityScheduler.java From big-c with Apache License 2.0 | 4 votes |
@Override public void suspendContianer(RMContainer cont, Resource toPreempt) { // TODO Auto-generated method stub if (LOG.isDebugEnabled()) { LOG.debug("SUSPEND_CONTAINER: container" + cont.toString()); } LOG.info("capacity scheduler try to preempt "+cont.getContainerId()+" resource: "+toPreempt); if(toPreempt == null){ LOG.info("preempted resource can not be null"); return; } if(!Resources.greaterThan(getResourceCalculator(), clusterResource, toPreempt,Resources.none())){ LOG.info("preempted resource is none"); return; } //set preempted resource cont.addPreemptedResource(toPreempt); //mark this container to be preempted completedContainer(cont, SchedulerUtils.createPreemptedContainerStatus( cont.getContainerId(), SchedulerUtils.PREEMPTED_CONTAINER), RMContainerEventType.SUSPEND); //send this resource update info to NodeManager NodeId nodeId = cont.getContainer().getNodeId(); ContainerId containerId = cont.getContainerId(); //get current resource after preemption Resource currentResource = cont.getCurrentUsedResource(); NodeContainerUpdate nodeContainerUpdate= NodeContainerUpdate.newInstance(containerId, currentResource.getMemory(), currentResource.getVirtualCores(),true,false); LOG.info("get container "+containerId+" to suspend "+" on host "+nodeId.getHost()+" currentresource: "+currentResource); if(nodeContainerUpdateMap.get(nodeId) == null){ ConcurrentLinkedQueue<NodeContainerUpdate> listNodeContainerUpdate = new ConcurrentLinkedQueue<NodeContainerUpdate>(); listNodeContainerUpdate.add(nodeContainerUpdate); nodeContainerUpdateMap.put(nodeId, listNodeContainerUpdate); }else{ nodeContainerUpdateMap.get(nodeId).add(nodeContainerUpdate); } }
Example 20
Source File: ReservationInputValidator.java From hadoop with Apache License 2.0 | 4 votes |
private void validateReservationDefinition(ReservationId reservationId, ReservationDefinition contract, Plan plan, String auditConstant) throws YarnException { String message = ""; // check if deadline is in the past if (contract == null) { message = "Missing reservation definition." + " Please try again by specifying a reservation definition."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } if (contract.getDeadline() <= clock.getTime()) { message = "The specified deadline: " + contract.getDeadline() + " is the past. Please try again with deadline in the future."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // Check if at least one RR has been specified ReservationRequests resReqs = contract.getReservationRequests(); if (resReqs == null) { message = "No resources have been specified to reserve." + "Please try again by specifying the resources to reserve."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } List<ReservationRequest> resReq = resReqs.getReservationResources(); if (resReq == null || resReq.isEmpty()) { message = "No resources have been specified to reserve." + " Please try again by specifying the resources to reserve."; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // compute minimum duration and max gang size long minDuration = 0; Resource maxGangSize = Resource.newInstance(0, 0, 0); ReservationRequestInterpreter type = contract.getReservationRequests().getInterpreter(); for (ReservationRequest rr : resReq) { if (type == ReservationRequestInterpreter.R_ALL || type == ReservationRequestInterpreter.R_ANY) { minDuration = Math.max(minDuration, rr.getDuration()); } else { minDuration += rr.getDuration(); } maxGangSize = Resources.max(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, Resources.multiply(rr.getCapability(), rr.getConcurrency())); } // verify the allocation is possible (skip for ANY) if (contract.getDeadline() - contract.getArrival() < minDuration && type != ReservationRequestInterpreter.R_ANY) { message = "The time difference (" + (contract.getDeadline() - contract.getArrival()) + ") between arrival (" + contract.getArrival() + ") " + "and deadline (" + contract.getDeadline() + ") must " + " be greater or equal to the minimum resource duration (" + minDuration + ")"; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } // check that the largest gang does not exceed the inventory available // capacity (skip for ANY) if (Resources.greaterThan(plan.getResourceCalculator(), plan.getTotalCapacity(), maxGangSize, plan.getTotalCapacity()) && type != ReservationRequestInterpreter.R_ANY) { message = "The size of the largest gang in the reservation refinition (" + maxGangSize + ") exceed the capacity available (" + plan.getTotalCapacity() + " )"; RMAuditLogger.logFailure("UNKNOWN", auditConstant, "validate reservation input definition", "ClientRMService", message); throw RPCUtil.getRemoteException(message); } }