public static void main(String[] args) throws Exception { if (args[0].equals("success")) { ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf, ApplicationMasterProtocol.class); client.registerApplicationMaster(RegisterApplicationMasterRequest .newInstance(NetUtils.getHostname(), -1, "")); Thread.sleep(1000); FinishApplicationMasterResponse resp = client.finishApplicationMaster(FinishApplicationMasterRequest .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null)); assertTrue(resp.getIsUnregistered()); System.exit(0); } else { System.exit(1); } }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { String amrmToken = getAppIdentifier(); Log.info("Finishing application attempt: " + amrmToken); synchronized (applicationContainerIdMap) { // Remove the containers that were being tracked for this application Assert.assertTrue("The application id is NOT registered: " + amrmToken, applicationContainerIdMap.containsKey(amrmToken)); List<ContainerId> ids = applicationContainerIdMap.remove(amrmToken); for (ContainerId c : ids) { allocatedContainerMap.remove(c); } } return FinishApplicationMasterResponse .newInstance(request.getFinalApplicationStatus() == FinalApplicationStatus.SUCCEEDED ? true : false); }
@Test public void testFinishOneApplicationMasterWithSuccess() throws Exception { int testAppId = 1; RegisterApplicationMasterResponse registerResponse = registerApplicationMaster(testAppId); Assert.assertNotNull(registerResponse); Assert.assertEquals(Integer.toString(testAppId), registerResponse.getQueue()); FinishApplicationMasterResponse finshResponse = finishApplicationMaster(testAppId, FinalApplicationStatus.SUCCEEDED); Assert.assertNotNull(finshResponse); Assert.assertEquals(true, finshResponse.getIsUnregistered()); }
@Test public void testFinishOneApplicationMasterWithFailure() throws Exception { int testAppId = 1; RegisterApplicationMasterResponse registerResponse = registerApplicationMaster(testAppId); Assert.assertNotNull(registerResponse); Assert.assertEquals(Integer.toString(testAppId), registerResponse.getQueue()); FinishApplicationMasterResponse finshResponse = finishApplicationMaster(testAppId, FinalApplicationStatus.FAILED); Assert.assertNotNull(finshResponse); Assert.assertEquals(false, finshResponse.getIsUnregistered()); try { // Try to finish an application master that is already finished. finishApplicationMaster(testAppId, FinalApplicationStatus.SUCCEEDED); Assert .fail("The request to finish application master should have failed"); } catch (Throwable ex) { // This is expected. So nothing required here. LOG.info("Finish registration failed as expected because it was not registered"); } }
@Test public void testAllocateRequestWithNullValues() throws Exception { int testAppId = 1; RegisterApplicationMasterResponse registerResponse = registerApplicationMaster(testAppId); Assert.assertNotNull(registerResponse); Assert.assertEquals(Integer.toString(testAppId), registerResponse.getQueue()); AllocateResponse allocateResponse = allocate(testAppId); Assert.assertNotNull(allocateResponse); FinishApplicationMasterResponse finshResponse = finishApplicationMaster(testAppId, FinalApplicationStatus.SUCCEEDED); Assert.assertNotNull(finshResponse); Assert.assertEquals(true, finshResponse.getIsUnregistered()); }
public static void main(String[] args) throws Exception { if (args[0].equals("success")) { ApplicationMasterProtocol client = ClientRMProxy.createRMProxy(conf, ApplicationMasterProtocol.class, true); client.registerApplicationMaster(RegisterApplicationMasterRequest .newInstance(NetUtils.getHostname(), -1, "")); Thread.sleep(1000); FinishApplicationMasterResponse resp = client.finishApplicationMaster(FinishApplicationMasterRequest .newInstance(FinalApplicationStatus.SUCCEEDED, "success", null)); assertTrue(resp.getIsUnregistered()); System.exit(0); } else { System.exit(1); } }
@Override public void unregisterApplicationMaster(FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) throws YarnException, IOException { Preconditions.checkArgument(appStatus != null, "AppStatus should not be null."); FinishApplicationMasterRequest request = FinishApplicationMasterRequest.newInstance(appStatus, appMessage, appTrackingUrl); try { while (true) { FinishApplicationMasterResponse response = rmClient.finishApplicationMaster(request); if (response.getIsUnregistered()) { break; } LOG.info("Waiting for application to be successfully unregistered."); Thread.sleep(100); } } catch (InterruptedException e) { LOG.info("Interrupted while waiting for application" + " to be removed from RMStateStore"); } }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { FinishApplicationMasterRequestProto requestProto = ((FinishApplicationMasterRequestPBImpl) request).getProto(); try { return new FinishApplicationMasterResponsePBImpl( proxy.finishApplicationMaster(null, requestProto)); } catch (ServiceException e) { RPCUtil.unwrapAndThrowException(e); return null; } }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { // TODO Auto-generated method stub return null; }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { resetStartFailoverFlag(true); // make sure failover has been triggered Assert.assertTrue(waittingForFailOver()); return createFakeFinishApplicationMasterResponse(); }
@Test(timeout = 15000) public void testFinishApplicationMasterOnHA() throws YarnException, IOException { FinishApplicationMasterRequest request = FinishApplicationMasterRequest.newInstance( FinalApplicationStatus.SUCCEEDED, "", ""); FinishApplicationMasterResponse response = amClient.finishApplicationMaster(request); Assert.assertEquals(response, this.cluster.createFakeFinishApplicationMasterResponse()); }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { ApplicationMasterFinishRequest finishRequest = new ApplicationMasterFinishRequest( request.getFinalApplicationStatus(), request.getDiagnostics(), request.getTrackingUrl()); ApplicationMasterFinishResponse response = applicationMaster .finishApplicationMaster(finishRequest); return FinishApplicationMasterResponse.newInstance(response .isUnregistered()); }
/** * This is called by the AMs started on this node to unregister from the RM. * This method does the initial authorization and then forwards the request to * the application instance specific intercepter chain. */ @Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { LOG.info("Finishing application master. Tracking Url:" + request.getTrackingUrl()); RequestInterceptorChainWrapper pipeline = authorizeAndGetInterceptorChain(); return pipeline.getRootInterceptor().finishApplicationMaster(request); }
@Override public FinishApplicationMasterResponse finishApplicationMaster( final FinishApplicationMasterRequest request) throws YarnException, IOException { LOG.info("Forwarding finish application request to " + "the real YARN Resource Manager"); return rmClient.finishApplicationMaster(request); }
/** * Unregisters the application master for specified application id * * @param appId * @param status * @return * @throws Exception * @throws YarnException * @throws IOException */ protected FinishApplicationMasterResponse finishApplicationMaster( final int appId, final FinalApplicationStatus status) throws Exception, YarnException, IOException { final ApplicationUserInfo ugi = getApplicationUserInfo(appId); return ugi.getUser().doAs( new PrivilegedExceptionAction<FinishApplicationMasterResponse>() { @Override public FinishApplicationMasterResponse run() throws Exception { final FinishApplicationMasterRequest req = Records.newRecord(FinishApplicationMasterRequest.class); req.setDiagnostics(""); req.setTrackingUrl(""); req.setFinalApplicationStatus(status); FinishApplicationMasterResponse response = getAMRMProxyService().finishApplicationMaster(req); getAMRMProxyService().stopApp( ugi.getAppAttemptId().getApplicationId()); return response; } }); }
@Override public FinishApplicationMasterResponse finishApplicationMaster( FinishApplicationMasterRequest request) throws YarnException, IOException { ApplicationAttemptId applicationAttemptId = authorizeRequest(); AllocateResponse lastResponse = responseMap.get(applicationAttemptId); if (lastResponse == null) { String message = "Application doesn't exist in cache " + applicationAttemptId; LOG.error(message); throw RPCUtil.getRemoteException(message); } // Allow only one thread in AM to do finishApp at a time. synchronized (lastResponse) { this.amLivelinessMonitor.receivedPing(applicationAttemptId); rmContext.getDispatcher().getEventHandler().handle( new RMAppAttemptUnregistrationEvent(applicationAttemptId, request .getTrackingUrl(), request.getFinalApplicationStatus(), request .getDiagnostics())); FinishApplicationMasterResponse response = recordFactory .newRecordInstance(FinishApplicationMasterResponse.class); return response; } }