/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> private RMAppImpl CreateAndPopulateNewRMApp(ApplicationSubmissionContext submissionContext , long submitTime, string user, bool isRecovery) { ApplicationId applicationId = submissionContext.GetApplicationId(); ResourceRequest amReq = ValidateAndCreateResourceRequest(submissionContext, isRecovery ); // Create RMApp RMAppImpl application = new RMAppImpl(applicationId, rmContext, this.conf, submissionContext .GetApplicationName(), user, submissionContext.GetQueue(), submissionContext, this .scheduler, this.masterService, submitTime, submissionContext.GetApplicationType (), submissionContext.GetApplicationTags(), amReq); // Concurrent app submissions with same applicationId will fail here // Concurrent app submissions with different applicationIds will not // influence each other if (rmContext.GetRMApps().PutIfAbsent(applicationId, application) != null) { string message = "Application with id " + applicationId + " is already present! Cannot add a duplicate!"; Log.Warn(message); throw new YarnException(message); } // Inform the ACLs Manager this.applicationACLsManager.AddApplication(applicationId, submissionContext.GetAMContainerSpec ().GetApplicationACLs()); string appViewACLs = submissionContext.GetAMContainerSpec().GetApplicationACLs()[ ApplicationAccessType.ViewApp]; rmContext.GetSystemMetricsPublisher().AppACLsUpdated(application, appViewACLs, Runtime .CurrentTimeMillis()); return(application); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> protected internal override void SubmitApplication(ApplicationSubmissionContext submissionContext , long submitTime, string user) { //Do nothing, just add the application to RMContext RMAppImpl application = new RMAppImpl(submissionContext.GetApplicationId(), this. rmContext, this.conf, submissionContext.GetApplicationName(), user, submissionContext .GetQueue(), submissionContext, this.rmContext.GetScheduler(), this.rmContext.GetApplicationMasterService (), submitTime, submissionContext.GetApplicationType(), submissionContext.GetApplicationTags (), null); this.rmContext.GetRMApps()[submissionContext.GetApplicationId()] = application; }
/// <exception cref="System.Exception"/> protected internal virtual void RecoverApplication(ApplicationStateData appState, RMStateStore.RMState rmState) { ApplicationSubmissionContext appContext = appState.GetApplicationSubmissionContext (); ApplicationId appId = appContext.GetApplicationId(); // create and recover app. RMAppImpl application = CreateAndPopulateNewRMApp(appContext, appState.GetSubmitTime (), appState.GetUser(), true); application.Handle(new RMAppRecoverEvent(appId, rmState)); }
protected internal virtual void CreateApplicationWithAMResource(ApplicationAttemptId attId, string queue, string user, Resource amResource) { RMContext rmContext = resourceManager.GetRMContext(); RMApp rmApp = new RMAppImpl(attId.GetApplicationId(), rmContext, conf, null, null , null, ApplicationSubmissionContext.NewInstance(null, null, null, null, null, false , false, 0, amResource, null), null, null, 0, null, null, null); rmContext.GetRMApps()[attId.GetApplicationId()] = rmApp; AppAddedSchedulerEvent appAddedEvent = new AppAddedSchedulerEvent(attId.GetApplicationId (), queue, user); scheduler.Handle(appAddedEvent); AppAttemptAddedSchedulerEvent attempAddedEvent = new AppAttemptAddedSchedulerEvent (attId, false); scheduler.Handle(attempAddedEvent); }
private RMAppImpl CreateMockRMApp(ApplicationAttemptId attemptId, RMContext context ) { RMAppImpl app = Org.Mockito.Mockito.Mock <RMAppImpl>(); Org.Mockito.Mockito.When(app.GetApplicationId()).ThenReturn(attemptId.GetApplicationId ()); RMAppAttemptImpl attempt = Org.Mockito.Mockito.Mock <RMAppAttemptImpl>(); Org.Mockito.Mockito.When(attempt.GetAppAttemptId()).ThenReturn(attemptId); RMAppAttemptMetrics attemptMetric = Org.Mockito.Mockito.Mock <RMAppAttemptMetrics> (); Org.Mockito.Mockito.When(attempt.GetRMAppAttemptMetrics()).ThenReturn(attemptMetric ); Org.Mockito.Mockito.When(app.GetCurrentAppAttempt()).ThenReturn(attempt); context.GetRMApps().PutIfAbsent(attemptId.GetApplicationId(), app); return(app); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> protected internal virtual void SubmitApplication(ApplicationSubmissionContext submissionContext , long submitTime, string user) { ApplicationId applicationId = submissionContext.GetApplicationId(); RMAppImpl application = CreateAndPopulateNewRMApp(submissionContext, submitTime, user, false); ApplicationId appId = submissionContext.GetApplicationId(); if (UserGroupInformation.IsSecurityEnabled()) { try { this.rmContext.GetDelegationTokenRenewer().AddApplicationAsync(appId, ParseCredentials (submissionContext), submissionContext.GetCancelTokensWhenComplete(), application .GetUser()); } catch (Exception e) { Log.Warn("Unable to parse credentials.", e); // Sending APP_REJECTED is fine, since we assume that the // RMApp is in NEW state and thus we haven't yet informed the // scheduler about the existence of the application System.Diagnostics.Debug.Assert(application.GetState() == RMAppState.New); this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppEvent(applicationId , RMAppEventType.AppRejected, e.Message)); throw RPCUtil.GetRemoteException(e); } } else { // Dispatcher is not yet started at this time, so these START events // enqueued should be guaranteed to be first processed when dispatcher // gets started. this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppEvent(applicationId , RMAppEventType.Start)); } }
/// <exception cref="System.Exception"/> public virtual void TestRMAppAttemptFailuresValidityInterval() { YarnConfiguration conf = new YarnConfiguration(); conf.SetClass(YarnConfiguration.RmScheduler, typeof(CapacityScheduler), typeof(ResourceScheduler )); conf.SetBoolean(YarnConfiguration.RecoveryEnabled, true); conf.SetBoolean(YarnConfiguration.RmWorkPreservingRecoveryEnabled, false); conf.Set(YarnConfiguration.RmStore, typeof(MemoryRMStateStore).FullName); // explicitly set max-am-retry count as 2. conf.SetInt(YarnConfiguration.RmAmMaxAttempts, 2); MemoryRMStateStore memStore = new MemoryRMStateStore(); memStore.Init(conf); MockRM rm1 = new MockRM(conf, memStore); rm1.Start(); MockNM nm1 = new MockNM("127.0.0.1:1234", 8000, rm1.GetResourceTrackerService()); nm1.RegisterNode(); // set window size to a larger number : 20s // we will verify the app should be failed if // two continuous attempts failed in 20s. RMApp app = rm1.SubmitApp(200, 20000); MockAM am = MockRM.LaunchAM(app, rm1, nm1); // Fail current attempt normally nm1.NodeHeartbeat(am.GetApplicationAttemptId(), 1, ContainerState.Complete); am.WaitForState(RMAppAttemptState.Failed); // launch the second attempt rm1.WaitForState(app.GetApplicationId(), RMAppState.Accepted); NUnit.Framework.Assert.AreEqual(2, app.GetAppAttempts().Count); NUnit.Framework.Assert.IsTrue(((RMAppAttemptImpl)app.GetCurrentAppAttempt()).MayBeLastAttempt ()); MockAM am_2 = MockRM.LaunchAndRegisterAM(app, rm1, nm1); am_2.WaitForState(RMAppAttemptState.Running); nm1.NodeHeartbeat(am_2.GetApplicationAttemptId(), 1, ContainerState.Complete); am_2.WaitForState(RMAppAttemptState.Failed); // current app should be failed. rm1.WaitForState(app.GetApplicationId(), RMAppState.Failed); ControlledClock clock = new ControlledClock(new SystemClock()); // set window size to 6s RMAppImpl app1 = (RMAppImpl)rm1.SubmitApp(200, 6000); app1.SetSystemClock(clock); MockAM am1 = MockRM.LaunchAndRegisterAM(app1, rm1, nm1); // Fail attempt1 normally nm1.NodeHeartbeat(am1.GetApplicationAttemptId(), 1, ContainerState.Complete); am1.WaitForState(RMAppAttemptState.Failed); // launch the second attempt rm1.WaitForState(app1.GetApplicationId(), RMAppState.Accepted); NUnit.Framework.Assert.AreEqual(2, app1.GetAppAttempts().Count); RMAppAttempt attempt2 = app1.GetCurrentAppAttempt(); NUnit.Framework.Assert.IsTrue(((RMAppAttemptImpl)attempt2).MayBeLastAttempt()); MockAM am2 = MockRM.LaunchAndRegisterAM(app1, rm1, nm1); am2.WaitForState(RMAppAttemptState.Running); // wait for 6 seconds clock.SetTime(Runtime.CurrentTimeMillis() + 6 * 1000); // Fail attempt2 normally nm1.NodeHeartbeat(am2.GetApplicationAttemptId(), 1, ContainerState.Complete); am2.WaitForState(RMAppAttemptState.Failed); // can launch the third attempt successfully rm1.WaitForState(app1.GetApplicationId(), RMAppState.Accepted); NUnit.Framework.Assert.AreEqual(3, app1.GetAppAttempts().Count); RMAppAttempt attempt3 = app1.GetCurrentAppAttempt(); clock.Reset(); MockAM am3 = MockRM.LaunchAndRegisterAM(app1, rm1, nm1); am3.WaitForState(RMAppAttemptState.Running); // Restart rm. MockRM rm2 = new MockRM(conf, memStore); rm2.Start(); // re-register the NM nm1.SetResourceTrackerService(rm2.GetResourceTrackerService()); NMContainerStatus status = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NMContainerStatus >(); status.SetContainerExitStatus(ContainerExitStatus.KilledByResourcemanager); status.SetContainerId(attempt3.GetMasterContainer().GetId()); status.SetContainerState(ContainerState.Complete); status.SetDiagnostics(string.Empty); nm1.RegisterNode(Sharpen.Collections.SingletonList(status), null); rm2.WaitForState(attempt3.GetAppAttemptId(), RMAppAttemptState.Failed); rm2.WaitForState(app1.GetApplicationId(), RMAppState.Accepted); // Lauch Attempt 4 MockAM am4 = rm2.WaitForNewAMToLaunchAndRegister(app1.GetApplicationId(), 4, nm1); // wait for 6 seconds clock.SetTime(Runtime.CurrentTimeMillis() + 6 * 1000); // Fail attempt4 normally nm1.NodeHeartbeat(am4.GetApplicationAttemptId(), 1, ContainerState.Complete); am4.WaitForState(RMAppAttemptState.Failed); // can launch the 5th attempt successfully rm2.WaitForState(app1.GetApplicationId(), RMAppState.Accepted); MockAM am5 = rm2.WaitForNewAMToLaunchAndRegister(app1.GetApplicationId(), 5, nm1); clock.Reset(); am5.WaitForState(RMAppAttemptState.Running); // Fail attempt5 normally nm1.NodeHeartbeat(am5.GetApplicationAttemptId(), 1, ContainerState.Complete); am5.WaitForState(RMAppAttemptState.Failed); rm2.WaitForState(app1.GetApplicationId(), RMAppState.Failed); rm1.Stop(); rm2.Stop(); }