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