Search in sources :

Example 1 with ResourceInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo in project hadoop by apache.

the class RMWebServices method createReservationSubmissionRequest.

private ReservationSubmissionRequest createReservationSubmissionRequest(ReservationSubmissionRequestInfo resContext) throws IOException {
    // defending against a couple of common submission format problems
    if (resContext == null) {
        throw new BadRequestException("Input ReservationSubmissionContext should not be null");
    }
    ReservationDefinitionInfo resInfo = resContext.getReservationDefinition();
    if (resInfo == null) {
        throw new BadRequestException("Input ReservationDefinition should not be null");
    }
    ReservationRequestsInfo resReqsInfo = resInfo.getReservationRequests();
    if (resReqsInfo == null || resReqsInfo.getReservationRequest() == null || resReqsInfo.getReservationRequest().size() == 0) {
        throw new BadRequestException("The ReservationDefinition should" + " contain at least one ReservationRequest");
    }
    ReservationRequestInterpreter[] values = ReservationRequestInterpreter.values();
    ReservationRequestInterpreter resInt = values[resReqsInfo.getReservationRequestsInterpreter()];
    List<ReservationRequest> list = new ArrayList<ReservationRequest>();
    for (ReservationRequestInfo resReqInfo : resReqsInfo.getReservationRequest()) {
        ResourceInfo rInfo = resReqInfo.getCapability();
        Resource capability = Resource.newInstance(rInfo.getMemorySize(), rInfo.getvCores());
        int numContainers = resReqInfo.getNumContainers();
        int minConcurrency = resReqInfo.getMinConcurrency();
        long duration = resReqInfo.getDuration();
        ReservationRequest rr = ReservationRequest.newInstance(capability, numContainers, minConcurrency, duration);
        list.add(rr);
    }
    ReservationRequests reqs = ReservationRequests.newInstance(list, resInt);
    ReservationDefinition rDef = ReservationDefinition.newInstance(resInfo.getArrival(), resInfo.getDeadline(), reqs, resInfo.getReservationName());
    ReservationId reservationId = ReservationId.parseReservationId(resContext.getReservationId());
    ReservationSubmissionRequest request = ReservationSubmissionRequest.newInstance(rDef, resContext.getQueue(), reservationId);
    return request;
}
Also used : ReservationRequestsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestsInfo) ResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo) LocalResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo) ReservationRequestInterpreter(org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) GetNewReservationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ArrayList(java.util.ArrayList) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) ReservationSubmissionRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest) ReservationRequestInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestInfo) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) ReservationDefinitionInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDefinitionInfo) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException)

Example 2 with ResourceInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo in project hadoop by apache.

the class RMWebServices method createReservationUpdateRequest.

private ReservationUpdateRequest createReservationUpdateRequest(ReservationUpdateRequestInfo resContext) throws IOException {
    // defending against a couple of common submission format problems
    if (resContext == null) {
        throw new BadRequestException("Input ReservationSubmissionContext should not be null");
    }
    ReservationDefinitionInfo resInfo = resContext.getReservationDefinition();
    if (resInfo == null) {
        throw new BadRequestException("Input ReservationDefinition should not be null");
    }
    ReservationRequestsInfo resReqsInfo = resInfo.getReservationRequests();
    if (resReqsInfo == null || resReqsInfo.getReservationRequest() == null || resReqsInfo.getReservationRequest().size() == 0) {
        throw new BadRequestException("The ReservationDefinition should" + " contain at least one ReservationRequest");
    }
    if (resContext.getReservationId() == null) {
        throw new BadRequestException("Update operations must specify an existing ReservaitonId");
    }
    ReservationRequestInterpreter[] values = ReservationRequestInterpreter.values();
    ReservationRequestInterpreter resInt = values[resReqsInfo.getReservationRequestsInterpreter()];
    List<ReservationRequest> list = new ArrayList<ReservationRequest>();
    for (ReservationRequestInfo resReqInfo : resReqsInfo.getReservationRequest()) {
        ResourceInfo rInfo = resReqInfo.getCapability();
        Resource capability = Resource.newInstance(rInfo.getMemorySize(), rInfo.getvCores());
        int numContainers = resReqInfo.getNumContainers();
        int minConcurrency = resReqInfo.getMinConcurrency();
        long duration = resReqInfo.getDuration();
        ReservationRequest rr = ReservationRequest.newInstance(capability, numContainers, minConcurrency, duration);
        list.add(rr);
    }
    ReservationRequests reqs = ReservationRequests.newInstance(list, resInt);
    ReservationDefinition rDef = ReservationDefinition.newInstance(resInfo.getArrival(), resInfo.getDeadline(), reqs, resInfo.getReservationName());
    ReservationUpdateRequest request = ReservationUpdateRequest.newInstance(rDef, ReservationId.parseReservationId(resContext.getReservationId()));
    return request;
}
Also used : ReservationRequestsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestsInfo) ResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo) LocalResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo) ReservationUpdateRequest(org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest) ReservationRequestInterpreter(org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter) ReservationRequest(org.apache.hadoop.yarn.api.records.ReservationRequest) GetNewReservationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest) ReservationDefinition(org.apache.hadoop.yarn.api.records.ReservationDefinition) ArrayList(java.util.ArrayList) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) ReservationRequestInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestInfo) ReservationDefinitionInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDefinitionInfo) ReservationRequests(org.apache.hadoop.yarn.api.records.ReservationRequests) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException)

Example 3 with ResourceInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo in project hadoop by apache.

the class RMWebServices method createNewApplication.

/**
   * Function that actually creates the ApplicationId by calling the
   * ClientRMService
   * 
   * @return returns structure containing the app-id and maximum resource
   *         capabilities
   */
private NewApplication createNewApplication() {
    GetNewApplicationRequest req = recordFactory.newRecordInstance(GetNewApplicationRequest.class);
    GetNewApplicationResponse resp;
    try {
        resp = rm.getClientRMService().getNewApplication(req);
    } catch (YarnException e) {
        String msg = "Unable to create new app from RM web service";
        LOG.error(msg, e);
        throw new YarnRuntimeException(msg, e);
    }
    NewApplication appId = new NewApplication(resp.getApplicationId().toString(), new ResourceInfo(resp.getMaximumResourceCapability()));
    return appId;
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) ResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo) LocalResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo) GetNewApplicationResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse) NewApplication(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NewApplication) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) GetNewApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)

Example 4 with ResourceInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo in project hadoop by apache.

the class TestCapacitySchedulerNodeLabelUpdate method testRequestContainerAfterNodePartitionUpdated.

@Test(timeout = 60000)
public void testRequestContainerAfterNodePartitionUpdated() throws Exception {
    // set node -> label
    mgr.addToCluserNodeLabelsWithDefaultExclusivity(ImmutableSet.of("x", "y", "z"));
    // set mapping:
    // h1 -> x
    // h2 -> y
    mgr.addLabelsToNode(ImmutableMap.of(NodeId.newInstance("h1", 0), toSet("x")));
    mgr.addLabelsToNode(ImmutableMap.of(NodeId.newInstance("h2", 0), toSet("y")));
    // inject node label manager
    MockRM rm = new MockRM(getConfigurationWithQueueLabels(conf)) {

        @Override
        public RMNodeLabelsManager createNodeLabelManager() {
            return mgr;
        }
    };
    rm.getRMContext().setNodeLabelManager(mgr);
    rm.start();
    MockNM nm1 = rm.registerNode("h1:1234", 2048);
    MockNM nm2 = rm.registerNode("h2:1234", 2048);
    MockNM nm3 = rm.registerNode("h3:1234", 2048);
    ContainerId containerId;
    // launch an app to queue a1 (label = x), and check all container will
    // be allocated in h1
    RMApp app1 = rm.submitApp(GB, "app", "user", null, "a");
    MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm3);
    ApplicationResourceUsageReport appResourceUsageReport = rm.getResourceScheduler().getAppResourceUsageReport(am1.getApplicationAttemptId());
    Assert.assertEquals(1024, appResourceUsageReport.getUsedResources().getMemorySize());
    Assert.assertEquals(1, appResourceUsageReport.getUsedResources().getVirtualCores());
    // request a container.
    am1.allocate("*", GB, 1, new ArrayList<ContainerId>(), "x");
    containerId = ContainerId.newContainerId(am1.getApplicationAttemptId(), 2);
    rm.waitForState(nm1, containerId, RMContainerState.ALLOCATED);
    appResourceUsageReport = rm.getResourceScheduler().getAppResourceUsageReport(am1.getApplicationAttemptId());
    Assert.assertEquals(2048, appResourceUsageReport.getUsedResources().getMemorySize());
    Assert.assertEquals(2, appResourceUsageReport.getUsedResources().getVirtualCores());
    LeafQueue queue = (LeafQueue) ((CapacityScheduler) rm.getResourceScheduler()).getQueue("a");
    ArrayList<UserInfo> users = queue.getUsersManager().getUsersInfo();
    for (UserInfo userInfo : users) {
        if (userInfo.getUsername().equals("user")) {
            ResourceInfo resourcesUsed = userInfo.getResourcesUsed();
            Assert.assertEquals(2048, resourcesUsed.getMemorySize());
            Assert.assertEquals(2, resourcesUsed.getvCores());
        }
    }
    rm.stop();
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ResourceInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) ApplicationResourceUsageReport(org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport) MockAM(org.apache.hadoop.yarn.server.resourcemanager.MockAM) MockRM(org.apache.hadoop.yarn.server.resourcemanager.MockRM) Test(org.junit.Test)

Aggregations

ResourceInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo)4 LocalResourceInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LocalResourceInfo)3 ArrayList (java.util.ArrayList)2 GetNewReservationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewReservationRequest)2 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)2 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)2 ReservationRequest (org.apache.hadoop.yarn.api.records.ReservationRequest)2 ReservationRequestInterpreter (org.apache.hadoop.yarn.api.records.ReservationRequestInterpreter)2 ReservationRequests (org.apache.hadoop.yarn.api.records.ReservationRequests)2 Resource (org.apache.hadoop.yarn.api.records.Resource)2 ReservationDefinitionInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationDefinitionInfo)2 ReservationRequestInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestInfo)2 ReservationRequestsInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ReservationRequestsInfo)2 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)2 GetNewApplicationRequest (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest)1 GetNewApplicationResponse (org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse)1 ReservationSubmissionRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest)1 ReservationUpdateRequest (org.apache.hadoop.yarn.api.protocolrecords.ReservationUpdateRequest)1 ApplicationResourceUsageReport (org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1