public virtual void TestMoveRejectedByScheduler() { failMove = true; // Submit application Application application = new Application("user1", resourceManager); application.Submit(); // Wait for app to be accepted RMApp app = resourceManager.rmContext.GetRMApps()[application.GetApplicationId()]; while (app.GetState() != RMAppState.Accepted) { Sharpen.Thread.Sleep(100); } ClientRMService clientRMService = resourceManager.GetClientRMService(); try { // FIFO scheduler does not support moves clientRMService.MoveApplicationAcrossQueues(MoveApplicationAcrossQueuesRequest.NewInstance (application.GetApplicationId(), "newqueue")); NUnit.Framework.Assert.Fail("Should have hit exception"); } catch (YarnException ex) { NUnit.Framework.Assert.AreEqual("Move not supported", ex.InnerException.Message); } }
/// <exception cref="System.Exception"/> public virtual void TestMoveTooLate() { // Submit application Application application = new Application("user1", resourceManager); ApplicationId appId = application.GetApplicationId(); application.Submit(); ClientRMService clientRMService = resourceManager.GetClientRMService(); // Kill the application clientRMService.ForceKillApplication(KillApplicationRequest.NewInstance(appId)); RMApp rmApp = resourceManager.GetRMContext().GetRMApps()[appId]; // wait until it's dead while (rmApp.GetState() != RMAppState.Killed) { Sharpen.Thread.Sleep(100); } try { clientRMService.MoveApplicationAcrossQueues(MoveApplicationAcrossQueuesRequest.NewInstance (appId, "newqueue")); NUnit.Framework.Assert.Fail("Should have hit exception"); } catch (YarnException ex) { NUnit.Framework.Assert.AreEqual(typeof(YarnException), ex.GetType()); NUnit.Framework.Assert.AreEqual("App in KILLED state cannot be moved.", ex.Message ); } }
public virtual void TestEscapeApplicationSummary() { RMApp app = Org.Mockito.Mockito.Mock <RMAppImpl>(); Org.Mockito.Mockito.When(app.GetApplicationId()).ThenReturn(ApplicationId.NewInstance (100L, 1)); Org.Mockito.Mockito.When(app.GetName()).ThenReturn("Multiline\n\n\r\rAppName"); Org.Mockito.Mockito.When(app.GetUser()).ThenReturn("Multiline\n\n\r\rUserName"); Org.Mockito.Mockito.When(app.GetQueue()).ThenReturn("Multiline\n\n\r\rQueueName"); Org.Mockito.Mockito.When(app.GetState()).ThenReturn(RMAppState.Running); Org.Mockito.Mockito.When(app.GetApplicationType()).ThenReturn("MAPREDUCE"); RMAppMetrics metrics = new RMAppMetrics(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(1234, 56), 10, 1, 16384, 64); Org.Mockito.Mockito.When(app.GetRMAppMetrics()).ThenReturn(metrics); RMAppManager.ApplicationSummary.SummaryBuilder summary = RMAppManager.ApplicationSummary .CreateAppSummary(app); string msg = summary.ToString(); Log.Info("summary: " + msg); NUnit.Framework.Assert.IsFalse(msg.Contains("\n")); NUnit.Framework.Assert.IsFalse(msg.Contains("\r")); string escaped = "\\n\\n\\r\\r"; NUnit.Framework.Assert.IsTrue(msg.Contains("Multiline" + escaped + "AppName")); NUnit.Framework.Assert.IsTrue(msg.Contains("Multiline" + escaped + "UserName")); NUnit.Framework.Assert.IsTrue(msg.Contains("Multiline" + escaped + "QueueName")); NUnit.Framework.Assert.IsTrue(msg.Contains("memorySeconds=16384")); NUnit.Framework.Assert.IsTrue(msg.Contains("vcoreSeconds=64")); NUnit.Framework.Assert.IsTrue(msg.Contains("preemptedAMContainers=1")); NUnit.Framework.Assert.IsTrue(msg.Contains("preemptedNonAMContainers=10")); NUnit.Framework.Assert.IsTrue(msg.Contains("preemptedResources=<memory:1234\\, vCores:56>" )); NUnit.Framework.Assert.IsTrue(msg.Contains("applicationType=MAPREDUCE")); }
/// <exception cref="System.Exception"/> public virtual void WaitForState(ApplicationId appId, RMAppState finalState) { RMApp app = GetRMContext().GetRMApps()[appId]; NUnit.Framework.Assert.IsNotNull("app shouldn't be null", app); int timeoutSecs = 0; while (!finalState.Equals(app.GetState()) && timeoutSecs++ < 40) { System.Console.Out.WriteLine("App : " + appId + " State is : " + app.GetState() + " Waiting for state : " + finalState); Sharpen.Thread.Sleep(2000); } System.Console.Out.WriteLine("App State is : " + app.GetState()); NUnit.Framework.Assert.AreEqual("App state is not correct (timedout)", finalState , app.GetState()); }
protected internal virtual void WriteAuditLog(ApplicationId appId) { RMApp app = rmContext.GetRMApps()[appId]; string operation = "UNKONWN"; bool success = false; switch (app.GetState()) { case RMAppState.Failed: { operation = RMAuditLogger.AuditConstants.FinishFailedApp; break; } case RMAppState.Finished: { operation = RMAuditLogger.AuditConstants.FinishSuccessApp; success = true; break; } case RMAppState.Killed: { operation = RMAuditLogger.AuditConstants.FinishKilledApp; success = true; break; } default: { break; } } if (success) { RMAuditLogger.LogSuccess(app.GetUser(), operation, "RMAppManager", app.GetApplicationId ()); } else { StringBuilder diag = app.GetDiagnostics(); string msg = diag == null ? null : diag.ToString(); RMAuditLogger.LogFailure(app.GetUser(), operation, msg, "RMAppManager", "App failed with state: " + app.GetState(), appId); } }
public virtual void TestAppBlockRenderWithNullCurrentAppAttempt() { ApplicationId AppId = ApplicationId.NewInstance(1234L, 0); Injector injector; // init app RMApp app = Org.Mockito.Mockito.Mock <RMApp>(); Org.Mockito.Mockito.When(app.GetTrackingUrl()).ThenReturn("http://host:123"); Org.Mockito.Mockito.When(app.GetState()).ThenReturn(RMAppState.Failed); Org.Mockito.Mockito.When(app.GetApplicationId()).ThenReturn(AppId); Org.Mockito.Mockito.When(app.GetApplicationType()).ThenReturn("Type"); Org.Mockito.Mockito.When(app.GetUser()).ThenReturn("user"); Org.Mockito.Mockito.When(app.GetName()).ThenReturn("Name"); Org.Mockito.Mockito.When(app.GetQueue()).ThenReturn("queue"); Org.Mockito.Mockito.When(app.GetDiagnostics()).ThenReturn(new StringBuilder()); Org.Mockito.Mockito.When(app.GetFinalApplicationStatus()).ThenReturn(FinalApplicationStatus .Failed); Org.Mockito.Mockito.When(app.GetFinalApplicationStatus()).ThenReturn(FinalApplicationStatus .Failed); Org.Mockito.Mockito.When(app.GetStartTime()).ThenReturn(0L); Org.Mockito.Mockito.When(app.GetFinishTime()).ThenReturn(0L); Org.Mockito.Mockito.When(app.CreateApplicationState()).ThenReturn(YarnApplicationState .Failed); RMAppMetrics appMetrics = new RMAppMetrics(Resource.NewInstance(0, 0), 0, 0, 0, 0 ); Org.Mockito.Mockito.When(app.GetRMAppMetrics()).ThenReturn(appMetrics); // initialize RM Context, and create RMApp, without creating RMAppAttempt RMContext rmContext = TestRMWebApp.MockRMContext(15, 1, 2, 8); rmContext.GetRMApps()[AppId] = app; injector = WebAppTests.CreateMockInjector <RMContext>(rmContext, new _Module_76(rmContext )); AppBlock instance = injector.GetInstance <AppBlock>(); instance.Set(YarnWebParams.ApplicationId, AppId.ToString()); instance.Render(); }
/// <exception cref="System.Exception"/> public virtual void TestKillAppWhenFailOverHappensDuringApplicationKill() { // create a customized ClientRMService // When receives the killApplicationRequest, simply return the response // and make sure the application will not be KILLED State StartRMsWithCustomizedClientRMService(); MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm1.GetResourceTrackerService()); nm1.RegisterNode(); // create app and launch the AM RMApp app0 = rm1.SubmitApp(200); MockAM am0 = LaunchAM(app0, rm1, nm1); // ensure that the app is in running state NUnit.Framework.Assert.AreEqual(app0.GetState(), RMAppState.Running); // kill the app. rm1.KillApp(app0.GetApplicationId()); // failover happens before this application goes to final state. // The RMAppState that will be loaded by the active rm // should be ACCEPTED. FailOverAndKillApp(app0.GetApplicationId(), am0.GetApplicationAttemptId(), RMAppState .Running, RMAppAttemptState.Running, RMAppState.Accepted); }
public virtual void RecoverContainersOnNode(IList <NMContainerStatus> containerReports , RMNode nm) { lock (this) { if (!rmContext.IsWorkPreservingRecoveryEnabled() || containerReports == null || ( containerReports != null && containerReports.IsEmpty())) { return; } foreach (NMContainerStatus container in containerReports) { ApplicationId appId = container.GetContainerId().GetApplicationAttemptId().GetApplicationId (); RMApp rmApp = rmContext.GetRMApps()[appId]; if (rmApp == null) { Log.Error("Skip recovering container " + container + " for unknown application."); KillOrphanContainerOnNode(nm, container); continue; } // Unmanaged AM recovery is addressed in YARN-1815 if (rmApp.GetApplicationSubmissionContext().GetUnmanagedAM()) { Log.Info("Skip recovering container " + container + " for unmanaged AM." + rmApp. GetApplicationId()); KillOrphanContainerOnNode(nm, container); continue; } SchedulerApplication <T> schedulerApp = applications[appId]; if (schedulerApp == null) { Log.Info("Skip recovering container " + container + " for unknown SchedulerApplication. Application current state is " + rmApp.GetState()); KillOrphanContainerOnNode(nm, container); continue; } Log.Info("Recovering container " + container); SchedulerApplicationAttempt schedulerAttempt = schedulerApp.GetCurrentAppAttempt( ); if (!rmApp.GetApplicationSubmissionContext().GetKeepContainersAcrossApplicationAttempts ()) { // Do not recover containers for stopped attempt or previous attempt. if (schedulerAttempt.IsStopped() || !schedulerAttempt.GetApplicationAttemptId().Equals (container.GetContainerId().GetApplicationAttemptId())) { Log.Info("Skip recovering container " + container + " for already stopped attempt." ); KillOrphanContainerOnNode(nm, container); continue; } } // create container RMContainer rmContainer = RecoverAndCreateContainer(container, nm); // recover RMContainer rmContainer.Handle(new RMContainerRecoverEvent(container.GetContainerId(), container )); // recover scheduler node nodes[nm.GetNodeID()].RecoverContainer(rmContainer); // recover queue: update headroom etc. Queue queue = schedulerAttempt.GetQueue(); queue.RecoverContainer(clusterResource, schedulerAttempt, rmContainer); // recover scheduler attempt schedulerAttempt.RecoverContainer(rmContainer); // set master container for the current running AMContainer for this // attempt. RMAppAttempt appAttempt = rmApp.GetCurrentAppAttempt(); if (appAttempt != null) { Container masterContainer = appAttempt.GetMasterContainer(); // Mark current running AMContainer's RMContainer based on the master // container ID stored in AppAttempt. if (masterContainer != null && masterContainer.GetId().Equals(rmContainer.GetContainerId ())) { ((RMContainerImpl)rmContainer).SetAMContainer(true); } } lock (schedulerAttempt) { ICollection <ContainerId> releases = schedulerAttempt.GetPendingRelease(); if (releases.Contains(container.GetContainerId())) { // release the container rmContainer.Handle(new RMContainerFinishedEvent(container.GetContainerId(), SchedulerUtils .CreateAbnormalContainerStatus(container.GetContainerId(), SchedulerUtils.ReleasedContainer ), RMContainerEventType.Released)); releases.Remove(container.GetContainerId()); Log.Info(container.GetContainerId() + " is released by application."); } } } } }
/// <summary>create a summary of the application's runtime.</summary> /// <param name="app"> /// /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Rmapp.RMApp"/> /// whose summary is to be created, cannot /// be <code>null</code>. /// </param> public static RMAppManager.ApplicationSummary.SummaryBuilder CreateAppSummary(RMApp app) { string trackingUrl = "N/A"; string host = "N/A"; RMAppAttempt attempt = app.GetCurrentAppAttempt(); if (attempt != null) { trackingUrl = attempt.GetTrackingUrl(); host = attempt.GetHost(); } RMAppMetrics metrics = app.GetRMAppMetrics(); RMAppManager.ApplicationSummary.SummaryBuilder summary = new RMAppManager.ApplicationSummary.SummaryBuilder ().Add("appId", app.GetApplicationId()).Add("name", app.GetName()).Add("user", app .GetUser()).Add("queue", app.GetQueue()).Add("state", app.GetState()).Add("trackingUrl" , trackingUrl).Add("appMasterHost", host).Add("startTime", app.GetStartTime()).Add ("finishTime", app.GetFinishTime()).Add("finalStatus", app.GetFinalApplicationStatus ()).Add("memorySeconds", metrics.GetMemorySeconds()).Add("vcoreSeconds", metrics .GetVcoreSeconds()).Add("preemptedAMContainers", metrics.GetNumAMContainersPreempted ()).Add("preemptedNonAMContainers", metrics.GetNumNonAMContainersPreempted()).Add ("preemptedResources", metrics.GetResourcePreempted()).Add("applicationType", app .GetApplicationType()); return(summary); }
/// <exception cref="System.Exception"/> public virtual void TestRMAppSubmitDuplicateApplicationId() { ApplicationId appId = MockApps.NewAppID(0); asContext.SetApplicationId(appId); RMApp appOrig = rmContext.GetRMApps()[appId]; NUnit.Framework.Assert.IsTrue("app name matches but shouldn't", "testApp1" != appOrig .GetName()); // our testApp1 should be rejected and original app with same id should be left in place try { appMonitor.SubmitApplication(asContext, "test"); NUnit.Framework.Assert.Fail("Exception is expected when applicationId is duplicate." ); } catch (YarnException e) { NUnit.Framework.Assert.IsTrue("The thrown exception is not the expectd one.", e.Message .Contains("Cannot add a duplicate!")); } // make sure original app didn't get removed RMApp app = rmContext.GetRMApps()[appId]; NUnit.Framework.Assert.IsNotNull("app is null", app); NUnit.Framework.Assert.AreEqual("app id doesn't match", appId, app.GetApplicationId ()); NUnit.Framework.Assert.AreEqual("app state doesn't match", RMAppState.Finished, app .GetState()); }
public virtual void TestRMAppSubmit() { appMonitor.SubmitApplication(asContext, "test"); RMApp app = rmContext.GetRMApps()[appId]; NUnit.Framework.Assert.IsNotNull("app is null", app); NUnit.Framework.Assert.AreEqual("app id doesn't match", appId, app.GetApplicationId ()); NUnit.Framework.Assert.AreEqual("app state doesn't match", RMAppState.New, app.GetState ()); Org.Mockito.Mockito.Verify(metricsPublisher).AppACLsUpdated(Matchers.Any <RMApp>() , Matchers.Any <string>(), Matchers.AnyLong()); // wait for event to be processed int timeoutSecs = 0; while ((GetAppEventType() == RMAppEventType.Kill) && timeoutSecs++ < 20) { Sharpen.Thread.Sleep(1000); } NUnit.Framework.Assert.AreEqual("app event type sent is wrong", RMAppEventType.Start , GetAppEventType()); }