@Override public Boolean get() { return new Boolean(rmAppForCheck.getAppAttempts().size() == 4); } },
private RMAppAttempt getRMAppAttempt() { ApplicationId appId = this.appAttemptId.getApplicationId(); RMAppAttempt attempt = null; RMApp rmApp = rm.getRMContext().getRMApps().get(appId); if (rmApp != null) { attempt = rmApp.getAppAttempts().get(appAttemptId); } return attempt; }
private RMAppAttempt getRMAppAttempt() { ApplicationId appId = this.appAttemptId.getApplicationId(); RMAppAttempt attempt = null; RMApp rmApp = rm.getRMContext().getRMApps().get(appId); if (rmApp != null) { attempt = rmApp.getAppAttempts().get(appAttemptId); } return attempt; }
private RMAppAttempt getRMAppAttempt() { ApplicationId appId = this.appAttemptId.getApplicationId(); RMAppAttempt attempt = null; RMApp rmApp = rm.getRMContext().getRMApps().get(appId); if (rmApp != null) { attempt = rmApp.getAppAttempts().get(appAttemptId); } return attempt; }
@GET @Path(RMWSConsts.APPS_APPID_APPATTEMPTS) @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override public AppAttemptsInfo getAppAttempts(@Context HttpServletRequest hsr, @PathParam(RMWSConsts.APPID) String appId) { initForReadableEndpoints(); ApplicationId id = WebAppUtils.parseApplicationId(recordFactory, appId); RMApp app = rm.getRMContext().getRMApps().get(id); if (app == null) { throw new NotFoundException("app with id: " + appId + " not found"); } AppAttemptsInfo appAttemptsInfo = new AppAttemptsInfo(); for (RMAppAttempt attempt : app.getAppAttempts().values()) { AppAttemptInfo attemptInfo = new AppAttemptInfo(rm, attempt, app.getUser(), hsr.getScheme() + "://"); appAttemptsInfo.add(attemptInfo); } return appAttemptsInfo; }
if (allowAccess) { Map<ApplicationAttemptId, RMAppAttempt> attempts = application .getAppAttempts(); List<ApplicationAttemptReport> listAttempts = new ArrayList<ApplicationAttemptReport>();
public MockAM waitForNewAMToLaunchAndRegister(ApplicationId appId, int attemptSize, MockNM nm) throws Exception { RMApp app = getRMContext().getRMApps().get(appId); Assert.assertNotNull(app); while (app.getAppAttempts().size() != attemptSize) { System.out.println("Application " + appId + " is waiting for AM to restart. Current has " + app.getAppAttempts().size() + " attempts."); Thread.sleep(200); } return launchAndRegisterAM(app, this, nm); }
@GET @Path("/apps/{appid}/appattempts") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AppAttemptsInfo getAppAttempts(@Context HttpServletRequest hsr, @PathParam("appid") String appId) { init(); if (appId == null || appId.isEmpty()) { throw new NotFoundException("appId, " + appId + ", is empty or null"); } ApplicationId id; id = ConverterUtils.toApplicationId(recordFactory, appId); if (id == null) { throw new NotFoundException("appId is null"); } RMApp app = rm.getRMContext().getRMApps().get(id); if (app == null) { throw new NotFoundException("app with id: " + appId + " not found"); } AppAttemptsInfo appAttemptsInfo = new AppAttemptsInfo(); for (RMAppAttempt attempt : app.getAppAttempts().values()) { AppAttemptInfo attemptInfo = new AppAttemptInfo(rm, attempt, app.getUser(), hsr.getScheme() + "://"); appAttemptsInfo.add(attemptInfo); } return appAttemptsInfo; }
public MockAM waitForNewAMToLaunchAndRegister(ApplicationId appId, int attemptSize, MockNM nm) throws Exception { RMApp app = getRMContext().getRMApps().get(appId); Assert.assertNotNull(app); int timeWaiting = 0; while (app.getAppAttempts().size() != attemptSize) { if (timeWaiting >= TIMEOUT_MS_FOR_ATTEMPT) { break; } LOG.info("Application " + appId + " is waiting for AM to restart. Current has " + app.getAppAttempts().size() + " attempts."); Thread.sleep(WAIT_MS_PER_LOOP); timeWaiting += WAIT_MS_PER_LOOP; } return launchAndRegisterAM(app, this, nm); }
private static RMApp createMockAppForRemove(ApplicationId appId, ApplicationAttemptId... attemptIds) { RMApp app = mock(RMApp.class); ApplicationSubmissionContextPBImpl context = new ApplicationSubmissionContextPBImpl(); context.setApplicationId(appId); when(app.getApplicationSubmissionContext()).thenReturn(context); when(app.getUser()).thenReturn("test"); if (attemptIds.length > 0) { HashMap<ApplicationAttemptId, RMAppAttempt> attempts = new HashMap<>(); for (ApplicationAttemptId attemptId : attemptIds) { RMAppAttempt appAttempt = mock(RMAppAttempt.class); when(appAttempt.getAppAttemptId()).thenReturn(attemptId); attempts.put(attemptId, appAttempt); } when(app.getAppAttempts()).thenReturn(attempts); } return app; }
/** * Non-blocking API * ResourceManager services call this to remove an application from the state * store * This does not block the dispatcher threads * There is no notification of completion for this operation. */ @SuppressWarnings("unchecked") public void removeApplication(RMApp app) { ApplicationStateData appState = ApplicationStateData.newInstance( app.getSubmitTime(), app.getStartTime(), app.getApplicationSubmissionContext(), app.getUser()); for(RMAppAttempt appAttempt : app.getAppAttempts().values()) { appState.attempts.put(appAttempt.getAppAttemptId(), null); } dispatcher.getEventHandler().handle(new RMStateStoreRemoveAppEvent(appState)); }
/** * Non-blocking API * ResourceManager services call this to remove an application from the state * store * This does not block the dispatcher threads * There is no notification of completion for this operation. */ @SuppressWarnings("unchecked") public void removeApplication(RMApp app) { ApplicationStateData appState = ApplicationStateData.newInstance( app.getSubmitTime(), app.getStartTime(), app.getApplicationSubmissionContext(), app.getUser()); for(RMAppAttempt appAttempt : app.getAppAttempts().values()) { appState.attempts.put(appAttempt.getAppAttemptId(), null); } dispatcher.getEventHandler().handle(new RMStateStoreRemoveAppEvent(appState)); }
/** * Non-blocking API * ResourceManager services call this to remove an application from the state * store * This does not block the dispatcher threads * There is no notification of completion for this operation. */ @SuppressWarnings("unchecked") public void removeApplication(RMApp app) { ApplicationStateData appState = ApplicationStateData.newInstance(app.getSubmitTime(), app.getStartTime(), app.getApplicationSubmissionContext(), app.getUser(), app.getCallerContext()); for(RMAppAttempt appAttempt : app.getAppAttempts().values()) { appState.attempts.put(appAttempt.getAppAttemptId(), null); } getRMStateStoreEventHandler().handle( new RMStateStoreRemoveAppEvent(appState)); }
private void failOverAndKillApp(ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState initialRMAppState, RMAppAttemptState initialRMAppAttemptState, RMAppState expectedAppStateBeforeKillApp) throws Exception { Assert.assertEquals(initialRMAppState, rm1.getRMContext().getRMApps().get(appId).getState()); Assert.assertEquals(initialRMAppAttemptState, rm1.getRMContext() .getRMApps().get(appId).getAppAttempts().get(appAttemptId).getState()); explicitFailover(); Assert.assertEquals(expectedAppStateBeforeKillApp, rm2.getRMContext().getRMApps().get(appId).getState()); killApplication(rm2, appId, appAttemptId, initialRMAppState); }
private void failOverAndKillApp(ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState initialRMAppState, RMAppAttemptState initialRMAppAttemptState, RMAppState expectedAppStateBeforeKillApp) throws Exception { Assert.assertEquals(initialRMAppState, rm1.getRMContext().getRMApps().get(appId).getState()); Assert.assertEquals(initialRMAppAttemptState, rm1.getRMContext() .getRMApps().get(appId).getAppAttempts().get(appAttemptId).getState()); explicitFailover(); Assert.assertEquals(expectedAppStateBeforeKillApp, rm2.getRMContext().getRMApps().get(appId).getState()); killApplication(rm2, appId, appAttemptId, initialRMAppState); }
private void killApplication(MockRM rm, ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState rmAppState) throws Exception { KillApplicationResponse response = rm.killApp(appId); Assert .assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState)); RMApp loadedApp0 = rm.getRMContext().getRMApps().get(appId); rm.waitForState(appId, RMAppState.KILLED); if (appAttemptId != null) { rm.waitForState(appAttemptId, RMAppAttemptState.KILLED); } // no new attempt is created. Assert.assertEquals(1, loadedApp0.getAppAttempts().size()); } }
private void killApplication(MockRM rm, ApplicationId appId, ApplicationAttemptId appAttemptId, RMAppState rmAppState) throws Exception { KillApplicationResponse response = rm.killApp(appId); Assert .assertTrue(response.getIsKillCompleted() == isFinalState(rmAppState)); RMApp loadedApp0 = rm.getRMContext().getRMApps().get(appId); rm.waitForState(appId, RMAppState.KILLED); if (appAttemptId != null) { rm.waitForState(appAttemptId, RMAppAttemptState.KILLED); } // no new attempt is created. Assert.assertEquals(1, loadedApp0.getAppAttempts().size()); } }
private void testAppAttemptsHelper(String path, RMApp app, String media) throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("apps").path(path).path("appattempts").accept(media) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject jsonAppAttempts = json.getJSONObject("appAttempts"); assertEquals("incorrect number of elements", 1, jsonAppAttempts.length()); JSONArray jsonArray = jsonAppAttempts.getJSONArray("appAttempt"); Collection<RMAppAttempt> attempts = app.getAppAttempts().values(); assertEquals("incorrect number of elements", attempts.size(), jsonArray.length()); // Verify these parallel arrays are the same int i = 0; for (RMAppAttempt attempt : attempts) { verifyAppAttemptsInfo(jsonArray.getJSONObject(i), attempt, app.getUser()); ++i; } }
public void testAppAttemptsHelper(String path, RMApp app, String media) throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("apps").path(path).path("appattempts").accept(media) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject jsonAppAttempts = json.getJSONObject("appAttempts"); assertEquals("incorrect number of elements", 1, jsonAppAttempts.length()); JSONArray jsonArray = jsonAppAttempts.getJSONArray("appAttempt"); Collection<RMAppAttempt> attempts = app.getAppAttempts().values(); assertEquals("incorrect number of elements", attempts.size(), jsonArray.length()); // Verify these parallel arrays are the same int i = 0; for (RMAppAttempt attempt : attempts) { verifyAppAttemptsInfo(jsonArray.getJSONObject(i), attempt, app.getUser()); ++i; } }
@Test(timeout = 100000) public void testMaxAttemptOneMeansOne() throws Exception { getConf().setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1); getConf().setBoolean(YarnConfiguration.RECOVERY_ENABLED, true); getConf().set( YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName()); MockRM rm1 = new MockRM(getConf()); rm1.start(); MockNM nm1 = new MockNM("127.0.0.1:1234", 8000, rm1.getResourceTrackerService()); nm1.registerNode(); RMApp app1 = rm1.submitApp(200); RMAppAttempt attempt1 = app1.getCurrentAppAttempt(); MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1); AbstractYarnScheduler scheduler = (AbstractYarnScheduler) rm1.getResourceScheduler(); ContainerId amContainer = ContainerId.newContainerId(am1.getApplicationAttemptId(), 1); // Preempt the attempt; scheduler.killContainer(scheduler.getRMContainer(amContainer)); rm1.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.FAILED); TestSchedulerUtils.waitSchedulerApplicationAttemptStopped(scheduler, am1.getApplicationAttemptId()); // AM should not be restarted. rm1.waitForState(app1.getApplicationId(), RMAppState.FAILED); Assert.assertEquals(1, app1.getAppAttempts().size()); rm1.stop(); }