public virtual void TestContainerKillOnMemoryOverflow() { if (!ProcfsBasedProcessTree.IsAvailable()) { return; } containerManager.Start(); FilePath scriptFile = new FilePath(tmpDir, "scriptFile.sh"); PrintWriter fileWriter = new PrintWriter(scriptFile); FilePath processStartFile = new FilePath(tmpDir, "start_file.txt").GetAbsoluteFile (); fileWriter.Write("\numask 0"); // So that start file is readable by the // test. fileWriter.Write("\necho Hello World! > " + processStartFile); fileWriter.Write("\necho $$ >> " + processStartFile); fileWriter.Write("\nsleep 15"); fileWriter.Close(); ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext >(); // ////// Construct the Container-id ApplicationId appId = ApplicationId.NewInstance(0, 0); ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1); ContainerId cId = ContainerId.NewContainerId(appAttemptId, 0); int port = 12345; URL resource_alpha = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new Path(scriptFile.GetAbsolutePath()))); LocalResource rsrc_alpha = recordFactory.NewRecordInstance <LocalResource>(); rsrc_alpha.SetResource(resource_alpha); rsrc_alpha.SetSize(-1); rsrc_alpha.SetVisibility(LocalResourceVisibility.Application); rsrc_alpha.SetType(LocalResourceType.File); rsrc_alpha.SetTimestamp(scriptFile.LastModified()); string destinationFile = "dest_file"; IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource >(); localResources[destinationFile] = rsrc_alpha; containerLaunchContext.SetLocalResources(localResources); IList <string> commands = new AList <string>(); commands.AddItem("/bin/bash"); commands.AddItem(scriptFile.GetAbsolutePath()); containerLaunchContext.SetCommands(commands); Resource r = BuilderUtils.NewResource(8 * 1024 * 1024, 1); ContainerTokenIdentifier containerIdentifier = new ContainerTokenIdentifier(cId, context.GetNodeId().ToString(), user, r, Runtime.CurrentTimeMillis() + 120000, 123 , DummyRmIdentifier, Priority.NewInstance(0), 0); Token containerToken = BuilderUtils.NewContainerToken(context.GetNodeId(), containerManager .GetContext().GetContainerTokenSecretManager().CreatePassword(containerIdentifier ), containerIdentifier); StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext , containerToken); IList <StartContainerRequest> list = new AList <StartContainerRequest>(); list.AddItem(scRequest); StartContainersRequest allRequests = StartContainersRequest.NewInstance(list); containerManager.StartContainers(allRequests); int timeoutSecs = 0; while (!processStartFile.Exists() && timeoutSecs++ < 20) { Sharpen.Thread.Sleep(1000); Log.Info("Waiting for process start-file to be created"); } NUnit.Framework.Assert.IsTrue("ProcessStartFile doesn't exist!", processStartFile .Exists()); // Now verify the contents of the file BufferedReader reader = new BufferedReader(new FileReader(processStartFile)); NUnit.Framework.Assert.AreEqual("Hello World!", reader.ReadLine()); // Get the pid of the process string pid = reader.ReadLine().Trim(); // No more lines NUnit.Framework.Assert.AreEqual(null, reader.ReadLine()); BaseContainerManagerTest.WaitForContainerState(containerManager, cId, ContainerState .Complete, 60); IList <ContainerId> containerIds = new AList <ContainerId>(); containerIds.AddItem(cId); GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.NewInstance( containerIds); ContainerStatus containerStatus = containerManager.GetContainerStatuses(gcsRequest ).GetContainerStatuses()[0]; NUnit.Framework.Assert.AreEqual(ContainerExitStatus.KilledExceededVmem, containerStatus .GetExitStatus()); string expectedMsgPattern = "Container \\[pid=" + pid + ",containerID=" + cId + "\\] is running beyond virtual memory limits. Current usage: " + "[0-9.]+ ?[KMGTPE]?B of [0-9.]+ ?[KMGTPE]?B physical memory used; " + "[0-9.]+ ?[KMGTPE]?B of [0-9.]+ ?[KMGTPE]?B virtual memory used. " + "Killing container.\nDump of the process-tree for " + cId + " :\n"; Sharpen.Pattern pat = Sharpen.Pattern.Compile(expectedMsgPattern); NUnit.Framework.Assert.AreEqual("Expected message pattern is: " + expectedMsgPattern + "\n\nObserved message is: " + containerStatus.GetDiagnostics(), true, pat.Matcher (containerStatus.GetDiagnostics()).Find()); // Assert that the process is not alive anymore NUnit.Framework.Assert.IsFalse("Process is still alive!", exec.SignalContainer(user , pid, ContainerExecutor.Signal.Null)); }
public virtual void TestSuccessfulContainerLaunch() { FileContext localFS = FileContext.GetLocalFSFileContext(); localFS.Delete(new Path(localDir.GetAbsolutePath()), true); localFS.Delete(new Path(localLogDir.GetAbsolutePath()), true); localFS.Delete(new Path(remoteLogDir.GetAbsolutePath()), true); localDir.Mkdir(); localLogDir.Mkdir(); remoteLogDir.Mkdir(); YarnConfiguration conf = new YarnConfiguration(); Context context = new _NMContext_84(new NMContainerTokenSecretManager(conf), new NMTokenSecretManagerInNM(), null, null, new NMNullStateStoreService()); conf.Set(YarnConfiguration.NmLocalDirs, localDir.GetAbsolutePath()); conf.Set(YarnConfiguration.NmLogDirs, localLogDir.GetAbsolutePath()); conf.Set(YarnConfiguration.NmRemoteAppLogDir, remoteLogDir.GetAbsolutePath()); ContainerExecutor exec = new DefaultContainerExecutor(); exec.SetConf(conf); DeletionService del = new DeletionService(exec); Dispatcher dispatcher = new AsyncDispatcher(); NodeHealthCheckerService healthChecker = new NodeHealthCheckerService(); healthChecker.Init(conf); LocalDirsHandlerService dirsHandler = healthChecker.GetDiskHandler(); NodeManagerMetrics metrics = NodeManagerMetrics.Create(); NodeStatusUpdater nodeStatusUpdater = new _NodeStatusUpdaterImpl_106(context, dispatcher , healthChecker, metrics); // Don't start any updating thread. DummyContainerManager containerManager = new DummyContainerManager(context, exec, del, nodeStatusUpdater, metrics, new ApplicationACLsManager(conf), dirsHandler); nodeStatusUpdater.Init(conf); ((NodeManager.NMContext)context).SetContainerManager(containerManager); nodeStatusUpdater.Start(); containerManager.Init(conf); containerManager.Start(); ContainerLaunchContext launchContext = recordFactory.NewRecordInstance <ContainerLaunchContext >(); ApplicationId applicationId = ApplicationId.NewInstance(0, 0); ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.NewInstance(applicationId , 0); ContainerId cID = ContainerId.NewContainerId(applicationAttemptId, 0); string user = "******"; StartContainerRequest scRequest = StartContainerRequest.NewInstance(launchContext , TestContainerManager.CreateContainerToken(cID, SimulatedRmIdentifier, context. GetNodeId(), user, context.GetContainerTokenSecretManager())); IList <StartContainerRequest> list = new AList <StartContainerRequest>(); list.AddItem(scRequest); StartContainersRequest allRequests = StartContainersRequest.NewInstance(list); containerManager.StartContainers(allRequests); BaseContainerManagerTest.WaitForContainerState(containerManager, cID, ContainerState .Running); IList <ContainerId> containerIds = new AList <ContainerId>(); containerIds.AddItem(cID); StopContainersRequest stopRequest = StopContainersRequest.NewInstance(containerIds ); containerManager.StopContainers(stopRequest); BaseContainerManagerTest.WaitForContainerState(containerManager, cID, ContainerState .Complete); containerManager.Stop(); }