List of usage examples for org.apache.hadoop.yarn.api ApplicationMasterProtocol allocate
@Public @Stable @AtMostOnce public AllocateResponse allocate(AllocateRequest request) throws YarnException, IOException;
The main interface between an ApplicationMaster
and the ResourceManager
.
From source file:com.datatorrent.stram.StramMiniClusterTest.java
License:Apache License
@Ignore @Test/*from w ww . j av a2 s .com*/ public void testUnmanagedAM() throws Exception { new InlineAM(conf) { @Override @SuppressWarnings("SleepWhileInLoop") public void runAM(ApplicationAttemptId attemptId) throws Exception { LOG.debug("AM running {}", attemptId); //AMRMClient amRmClient = new AMRMClientImpl(attemptId); //amRmClient.init(conf); //amRmClient.start(); YarnClientHelper yarnClient = new YarnClientHelper(conf); ApplicationMasterProtocol resourceManager = yarnClient.connectToRM(); // register with the RM (LAUNCHED -> RUNNING) RegisterApplicationMasterRequest appMasterRequest = Records .newRecord(RegisterApplicationMasterRequest.class); resourceManager.registerApplicationMaster(appMasterRequest); // AM specific logic /* int containerCount = 1; Resource capability = Records.newRecord(Resource.class); capability.setMemory(1500); Priority priority = Records.newRecord(Priority.class); priority.setPriority(10); String[] hosts = {"vm1"}; String[] racks = {"somerack"}; AMRMClient.ContainerRequest req = new AMRMClient.ContainerRequest(capability, hosts, racks, priority, containerCount); amRmClient.addContainerRequest(req); for (int i=0; i<100; i++) { AllocateResponse ar = amRmClient.allocate(0); Thread.sleep(1000); LOG.debug("allocateResponse: {}" , ar); } */ int responseId = 0; AllocateRequest req = Records.newRecord(AllocateRequest.class); req.setResponseId(responseId++); List<ResourceRequest> lr = Lists.newArrayList(); lr.add(setupContainerAskForRM("hdev-vm", 1, 128, 10)); lr.add(setupContainerAskForRM("/default-rack", 1, 128, 10)); lr.add(setupContainerAskForRM("*", 1, 128, 10)); req.setAskList(lr); LOG.info("Requesting: " + req.getAskList()); resourceManager.allocate(req); for (int i = 0; i < 100; i++) { req = Records.newRecord(AllocateRequest.class); req.setResponseId(responseId++); AllocateResponse ar = resourceManager.allocate(req); sleep(1000); LOG.debug("allocateResponse: {}", ar); } // unregister from RM FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class); finishReq.setFinalApplicationStatus(FinalApplicationStatus.SUCCEEDED); finishReq.setDiagnostics("testUnmanagedAM finished"); resourceManager.finishApplicationMaster(finishReq); } private ResourceRequest setupContainerAskForRM(String resourceName, int numContainers, int containerMemory, int priority) { ResourceRequest request = Records.newRecord(ResourceRequest.class); // setup requirements for hosts // whether a particular rack/host is needed // Refer to apis under org.apache.hadoop.net for more // details on how to get figure out rack/host mapping. // using * as any host will do for the distributed shell app request.setResourceName(resourceName); // set no. of containers needed request.setNumContainers(numContainers); // set the priority for the request Priority pri = Records.newRecord(Priority.class); pri.setPriority(priority); request.setPriority(pri); // Set up resource type requirements // For now, only memory is supported so we set memory requirements Resource capability = Records.newRecord(Resource.class); capability.setMemory(containerMemory); request.setCapability(capability); return request; } }.run(); }
From source file:org.springframework.yarn.am.AppmasterRmTemplate.java
License:Apache License
@Override public AllocateResponse allocate(final AllocateRequest request) { return execute(new YarnRpcCallback<AllocateResponse, ApplicationMasterProtocol>() { @Override/* w w w . ja va2 s .c o m*/ public AllocateResponse doInYarn(ApplicationMasterProtocol proxy) throws YarnException, IOException { return proxy.allocate(request); } }); }