// This is to test AM Host and rpc port are invalidated after the am attempt // is killed or failed, so that client doesn't get the wrong information. /// <exception cref="System.Exception"/> public virtual void TestInvalidateAMHostPortWhenAMFailedOrKilled() { conf.SetInt(YarnConfiguration.RmAmMaxAttempts, 1); MockRM rm1 = new MockRM(conf); rm1.Start(); // a succeeded app RMApp app1 = rm1.SubmitApp(200); MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm1.GetResourceTrackerService()); nm1.RegisterNode(); MockAM am1 = MockRM.LaunchAndRegisterAM(app1, rm1, nm1); MockRM.FinishAMAndVerifyAppState(app1, rm1, nm1, am1); // a failed app RMApp app2 = rm1.SubmitApp(200); MockAM am2 = MockRM.LaunchAndRegisterAM(app2, rm1, nm1); nm1.NodeHeartbeat(am2.GetApplicationAttemptId(), 1, ContainerState.Complete); am2.WaitForState(RMAppAttemptState.Failed); rm1.WaitForState(app2.GetApplicationId(), RMAppState.Failed); // a killed app RMApp app3 = rm1.SubmitApp(200); MockAM am3 = MockRM.LaunchAndRegisterAM(app3, rm1, nm1); rm1.KillApp(app3.GetApplicationId()); rm1.WaitForState(app3.GetApplicationId(), RMAppState.Killed); rm1.WaitForState(am3.GetApplicationAttemptId(), RMAppAttemptState.Killed); GetApplicationsRequest request1 = GetApplicationsRequest.NewInstance(EnumSet.Of(YarnApplicationState .Finished, YarnApplicationState.Killed, YarnApplicationState.Failed)); GetApplicationsResponse response1 = rm1.GetClientRMService().GetApplications(request1 ); IList <ApplicationReport> appList1 = response1.GetApplicationList(); NUnit.Framework.Assert.AreEqual(3, appList1.Count); foreach (ApplicationReport report in appList1) { // killed/failed apps host and rpc port are invalidated. if (report.GetApplicationId().Equals(app2.GetApplicationId()) || report.GetApplicationId ().Equals(app3.GetApplicationId())) { NUnit.Framework.Assert.AreEqual("N/A", report.GetHost()); NUnit.Framework.Assert.AreEqual(-1, report.GetRpcPort()); } // succeeded app's host and rpc port is not invalidated if (report.GetApplicationId().Equals(app1.GetApplicationId())) { NUnit.Framework.Assert.IsFalse(report.GetHost().Equals("N/A")); NUnit.Framework.Assert.IsTrue(report.GetRpcPort() != -1); } } }
/// <exception cref="System.Exception"/> public virtual void TestUsageWithOneAttemptAndOneContainer() { MockRM rm = new MockRM(conf); rm.Start(); MockNM nm = new MockNM("127.0.0.1:1234", 15120, rm.GetResourceTrackerService()); nm.RegisterNode(); RMApp app0 = rm.SubmitApp(200); RMAppMetrics rmAppMetrics = app0.GetRMAppMetrics(); NUnit.Framework.Assert.IsTrue("Before app submittion, memory seconds should have been 0 but was " + rmAppMetrics.GetMemorySeconds(), rmAppMetrics.GetMemorySeconds() == 0); NUnit.Framework.Assert.IsTrue("Before app submission, vcore seconds should have been 0 but was " + rmAppMetrics.GetVcoreSeconds(), rmAppMetrics.GetVcoreSeconds() == 0); RMAppAttempt attempt0 = app0.GetCurrentAppAttempt(); nm.NodeHeartbeat(true); MockAM am0 = rm.SendAMLaunched(attempt0.GetAppAttemptId()); am0.RegisterAppAttempt(); RMContainer rmContainer = rm.GetResourceScheduler().GetRMContainer(attempt0.GetMasterContainer ().GetId()); // Allow metrics to accumulate. int sleepInterval = 1000; int cumulativeSleepTime = 0; while (rmAppMetrics.GetMemorySeconds() <= 0 && cumulativeSleepTime < 5000) { Sharpen.Thread.Sleep(sleepInterval); cumulativeSleepTime += sleepInterval; } rmAppMetrics = app0.GetRMAppMetrics(); NUnit.Framework.Assert.IsTrue("While app is running, memory seconds should be >0 but is " + rmAppMetrics.GetMemorySeconds(), rmAppMetrics.GetMemorySeconds() > 0); NUnit.Framework.Assert.IsTrue("While app is running, vcore seconds should be >0 but is " + rmAppMetrics.GetVcoreSeconds(), rmAppMetrics.GetVcoreSeconds() > 0); MockRM.FinishAMAndVerifyAppState(app0, rm, nm, am0); AggregateAppResourceUsage ru = CalculateContainerResourceMetrics(rmContainer); rmAppMetrics = app0.GetRMAppMetrics(); NUnit.Framework.Assert.AreEqual("Unexcpected MemorySeconds value", ru.GetMemorySeconds (), rmAppMetrics.GetMemorySeconds()); NUnit.Framework.Assert.AreEqual("Unexpected VcoreSeconds value", ru.GetVcoreSeconds (), rmAppMetrics.GetVcoreSeconds()); rm.Stop(); }
/// <exception cref="System.Exception"/> private void AmRestartTests(bool keepRunningContainers) { MockRM rm = new MockRM(conf); rm.Start(); RMApp app = rm.SubmitApp(200, "name", "user", new Dictionary <ApplicationAccessType , string>(), false, "default", -1, null, "MAPREDUCE", false, keepRunningContainers ); MockNM nm = new MockNM("127.0.0.1:1234", 10240, rm.GetResourceTrackerService()); nm.RegisterNode(); MockAM am0 = MockRM.LaunchAndRegisterAM(app, rm, nm); int NumContainers = 1; // allocate NUM_CONTAINERS containers am0.Allocate("127.0.0.1", 1024, NumContainers, new AList <ContainerId>()); nm.NodeHeartbeat(true); // wait for containers to be allocated. IList <Container> containers = am0.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()).GetAllocatedContainers(); while (containers.Count != NumContainers) { nm.NodeHeartbeat(true); Sharpen.Collections.AddAll(containers, am0.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()).GetAllocatedContainers()); Sharpen.Thread.Sleep(200); } // launch the 2nd container. ContainerId containerId2 = ContainerId.NewContainerId(am0.GetApplicationAttemptId (), 2); nm.NodeHeartbeat(am0.GetApplicationAttemptId(), containerId2.GetContainerId(), ContainerState .Running); rm.WaitForState(nm, containerId2, RMContainerState.Running); // Capture the containers here so the metrics can be calculated after the // app has completed. ICollection <RMContainer> rmContainers = rm.scheduler.GetSchedulerAppInfo(am0.GetApplicationAttemptId ()).GetLiveContainers(); // fail the first app attempt by sending CONTAINER_FINISHED event without // registering. ContainerId amContainerId = app.GetCurrentAppAttempt().GetMasterContainer().GetId (); nm.NodeHeartbeat(am0.GetApplicationAttemptId(), amContainerId.GetContainerId(), ContainerState .Complete); am0.WaitForState(RMAppAttemptState.Failed); long memorySeconds = 0; long vcoreSeconds = 0; // Calculate container usage metrics for first attempt. if (keepRunningContainers) { // Only calculate the usage for the one container that has completed. foreach (RMContainer c in rmContainers) { if (c.GetContainerId().Equals(amContainerId)) { AggregateAppResourceUsage ru = CalculateContainerResourceMetrics(c); memorySeconds += ru.GetMemorySeconds(); vcoreSeconds += ru.GetVcoreSeconds(); } else { // The remaining container should be RUNNING. NUnit.Framework.Assert.IsTrue("After first attempt failed, remaining container " + "should still be running. ", c.GetContainerState().Equals(ContainerState.Running )); } } } else { // If keepRunningContainers is false, all live containers should now // be completed. Calculate the resource usage metrics for all of them. foreach (RMContainer c in rmContainers) { AggregateAppResourceUsage ru = CalculateContainerResourceMetrics(c); memorySeconds += ru.GetMemorySeconds(); vcoreSeconds += ru.GetVcoreSeconds(); } } // wait for app to start a new attempt. rm.WaitForState(app.GetApplicationId(), RMAppState.Accepted); // assert this is a new AM. RMAppAttempt attempt2 = app.GetCurrentAppAttempt(); NUnit.Framework.Assert.IsFalse(attempt2.GetAppAttemptId().Equals(am0.GetApplicationAttemptId ())); // launch the new AM nm.NodeHeartbeat(true); MockAM am1 = rm.SendAMLaunched(attempt2.GetAppAttemptId()); am1.RegisterAppAttempt(); // allocate NUM_CONTAINERS containers am1.Allocate("127.0.0.1", 1024, NumContainers, new AList <ContainerId>()); nm.NodeHeartbeat(true); // wait for containers to be allocated. containers = am1.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()) .GetAllocatedContainers(); while (containers.Count != NumContainers) { nm.NodeHeartbeat(true); Sharpen.Collections.AddAll(containers, am1.Allocate(new AList <ResourceRequest>(), new AList <ContainerId>()).GetAllocatedContainers()); Sharpen.Thread.Sleep(200); } rm.WaitForState(app.GetApplicationId(), RMAppState.Running); // Capture running containers for later use by metrics calculations. rmContainers = rm.scheduler.GetSchedulerAppInfo(attempt2.GetAppAttemptId()).GetLiveContainers (); // complete container by sending the container complete event which has // earlier attempt's attemptId amContainerId = app.GetCurrentAppAttempt().GetMasterContainer().GetId(); nm.NodeHeartbeat(am0.GetApplicationAttemptId(), amContainerId.GetContainerId(), ContainerState .Complete); MockRM.FinishAMAndVerifyAppState(app, rm, nm, am1); // Calculate container usage metrics for second attempt. foreach (RMContainer c_1 in rmContainers) { AggregateAppResourceUsage ru = CalculateContainerResourceMetrics(c_1); memorySeconds += ru.GetMemorySeconds(); vcoreSeconds += ru.GetVcoreSeconds(); } RMAppMetrics rmAppMetrics = app.GetRMAppMetrics(); NUnit.Framework.Assert.AreEqual("Unexcpected MemorySeconds value", memorySeconds, rmAppMetrics.GetMemorySeconds()); NUnit.Framework.Assert.AreEqual("Unexpected VcoreSeconds value", vcoreSeconds, rmAppMetrics .GetVcoreSeconds()); rm.Stop(); return; }