Search in sources :

Example 51 with ResourceRequest

use of org.apache.hadoop.yarn.api.records.ResourceRequest in project hadoop by apache.

the class AMRMClientImpl method checkLocalityRelaxationConflict.

/**
   * ContainerRequests with locality relaxation cannot be made at the same
   * priority as ContainerRequests without locality relaxation.
   */
private void checkLocalityRelaxationConflict(Long allocationReqId, Priority priority, Collection<String> locations, boolean relaxLocality) {
    // Locality relaxation will be set to relaxLocality for all implicitly
    // requested racks. Make sure that existing rack requests match this.
    RemoteRequestsTable<T> remoteRequestsTable = getTable(allocationReqId);
    if (remoteRequestsTable != null) {
        @SuppressWarnings("unchecked") List<ResourceRequestInfo> allCapabilityMaps = remoteRequestsTable.getAllResourceRequestInfos(priority, locations);
        for (ResourceRequestInfo reqs : allCapabilityMaps) {
            ResourceRequest remoteRequest = reqs.remoteRequest;
            boolean existingRelaxLocality = remoteRequest.getRelaxLocality();
            if (relaxLocality != existingRelaxLocality) {
                throw new InvalidContainerRequestException("Cannot submit a " + "ContainerRequest asking for location " + remoteRequest.getResourceName() + " with locality relaxation " + relaxLocality + " when it has already been requested" + "with locality relaxation " + existingRelaxLocality);
            }
        }
    }
}
Also used : InvalidContainerRequestException(org.apache.hadoop.yarn.client.api.InvalidContainerRequestException) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Example 52 with ResourceRequest

use of org.apache.hadoop.yarn.api.records.ResourceRequest in project hadoop by apache.

the class OpportunisticContainerContext method matchAllocationToOutstandingRequest.

/**
   * This method matches a returned list of Container Allocations to any
   * outstanding OPPORTUNISTIC ResourceRequest.
   * @param capability Capability
   * @param allocatedContainers Allocated Containers
   */
public void matchAllocationToOutstandingRequest(Resource capability, List<Container> allocatedContainers) {
    for (Container c : allocatedContainers) {
        SchedulerRequestKey schedulerKey = SchedulerRequestKey.extractFrom(c);
        Map<Resource, ResourceRequest> asks = outstandingOpReqs.get(schedulerKey);
        if (asks == null) {
            continue;
        }
        ResourceRequest rr = asks.get(capability);
        if (rr != null) {
            rr.setNumContainers(rr.getNumContainers() - 1);
            if (rr.getNumContainers() == 0) {
                asks.remove(capability);
            }
        }
    }
}
Also used : Container(org.apache.hadoop.yarn.api.records.Container) Resource(org.apache.hadoop.yarn.api.records.Resource) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Example 53 with ResourceRequest

use of org.apache.hadoop.yarn.api.records.ResourceRequest in project hadoop by apache.

the class OpportunisticContainerContext method addToOutstandingReqs.

/**
   * Takes a list of ResourceRequests (asks), extracts the key information viz.
   * (Priority, ResourceName, Capability) and adds to the outstanding
   * OPPORTUNISTIC outstandingOpReqs map. The nested map is required to enforce
   * the current YARN constraint that only a single ResourceRequest can exist at
   * a give Priority and Capability.
   *
   * @param resourceAsks the list with the {@link ResourceRequest}s
   */
public void addToOutstandingReqs(List<ResourceRequest> resourceAsks) {
    for (ResourceRequest request : resourceAsks) {
        SchedulerRequestKey schedulerKey = SchedulerRequestKey.create(request);
        // TODO: Extend for Node/Rack locality. We only handle ANY requests now
        if (!ResourceRequest.isAnyLocation(request.getResourceName())) {
            continue;
        }
        if (request.getNumContainers() == 0) {
            continue;
        }
        Map<Resource, ResourceRequest> reqMap = outstandingOpReqs.get(schedulerKey);
        if (reqMap == null) {
            reqMap = new HashMap<>();
            outstandingOpReqs.put(schedulerKey, reqMap);
        }
        ResourceRequest resourceRequest = reqMap.get(request.getCapability());
        if (resourceRequest == null) {
            resourceRequest = request;
            reqMap.put(request.getCapability(), request);
        } else {
            resourceRequest.setNumContainers(resourceRequest.getNumContainers() + request.getNumContainers());
        }
        if (ResourceRequest.isAnyLocation(request.getResourceName())) {
            LOG.info("# of outstandingOpReqs in ANY (at " + "priority = " + schedulerKey.getPriority() + ", allocationReqId = " + schedulerKey.getAllocationRequestId() + ", with capability = " + request.getCapability() + " ) : " + resourceRequest.getNumContainers());
        }
    }
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Example 54 with ResourceRequest

use of org.apache.hadoop.yarn.api.records.ResourceRequest in project hadoop by apache.

the class BuilderUtils method newResourceRequest.

public static ResourceRequest newResourceRequest(ResourceRequest r) {
    ResourceRequest request = recordFactory.newRecordInstance(ResourceRequest.class);
    request.setPriority(r.getPriority());
    request.setResourceName(r.getResourceName());
    request.setCapability(r.getCapability());
    request.setNumContainers(r.getNumContainers());
    request.setNodeLabelExpression(r.getNodeLabelExpression());
    request.setExecutionTypeRequest(r.getExecutionTypeRequest());
    return request;
}
Also used : ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Example 55 with ResourceRequest

use of org.apache.hadoop.yarn.api.records.ResourceRequest in project hadoop by apache.

the class BaseAMRMProxyTest method createResourceRequests.

protected List<ResourceRequest> createResourceRequests(String[] hosts, int memory, int vCores, int priority, int containers, String labelExpression) throws Exception {
    List<ResourceRequest> reqs = new ArrayList<ResourceRequest>();
    for (String host : hosts) {
        ResourceRequest hostReq = createResourceRequest(host, memory, vCores, priority, containers, labelExpression);
        reqs.add(hostReq);
        ResourceRequest rackReq = createResourceRequest("/default-rack", memory, vCores, priority, containers, labelExpression);
        reqs.add(rackReq);
    }
    ResourceRequest offRackReq = createResourceRequest(ResourceRequest.ANY, memory, vCores, priority, containers, labelExpression);
    reqs.add(offRackReq);
    return reqs;
}
Also used : ArrayList(java.util.ArrayList) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Aggregations

ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)144 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)63 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)61 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)42 Resource (org.apache.hadoop.yarn.api.records.Resource)42 Container (org.apache.hadoop.yarn.api.records.Container)38 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)35 Priority (org.apache.hadoop.yarn.api.records.Priority)28 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)25 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)21 RMNode (org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode)20 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)19 NodeAddedSchedulerEvent (org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.NodeAddedSchedulerEvent)19 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)17 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)17 HashMap (java.util.HashMap)16 AllocateRequest (org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest)15 NodeId (org.apache.hadoop.yarn.api.records.NodeId)14 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)14