Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.URISyntaxException"/>
        internal static LocalResource CreateZipFile(FileContext files, Path p, int len, Random
                                                    r, LocalResourceVisibility vis)
        {
            byte[] bytes = new byte[len];
            r.NextBytes(bytes);
            FilePath archiveFile = new FilePath(p.ToUri().GetPath() + ".ZIP");

            archiveFile.CreateNewFile();
            ZipOutputStream @out = new ZipOutputStream(new FileOutputStream(archiveFile));

            @out.PutNextEntry(new ZipEntry(p.GetName()));
            @out.Write(bytes);
            @out.CloseEntry();
            @out.Close();
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(new Path(p.ToString() + ".ZIP")
                                                              ));
            ret.SetSize(len);
            ret.SetType(LocalResourceType.Archive);
            ret.SetVisibility(vis);
            ret.SetTimestamp(files.GetFileStatus(new Path(p.ToString() + ".ZIP")).GetModificationTime
                                 ());
            return(ret);
        }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public static void StartContainer(NodeManager nm, ContainerId cId, FileContext localFS
                                          , FilePath scriptFileDir, FilePath processStartFile)
        {
            FilePath scriptFile = CreateUnhaltingScriptFile(cId, scriptFileDir, processStartFile
                                                            );
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            NodeId nodeId = BuilderUtils.NewNodeId(Sharpen.Extensions.GetAddressByName("localhost"
                                                                                       ).ToString(), 12345);
            URL localResourceUri = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new
                                                                                           Path(scriptFile.GetAbsolutePath())));
            LocalResource localResource = recordFactory.NewRecordInstance <LocalResource>();

            localResource.SetResource(localResourceUri);
            localResource.SetSize(-1);
            localResource.SetVisibility(LocalResourceVisibility.Application);
            localResource.SetType(LocalResourceType.File);
            localResource.SetTimestamp(scriptFile.LastModified());
            string destinationFile = "dest_file";
            IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource
                                                                                 >();

            localResources[destinationFile] = localResource;
            containerLaunchContext.SetLocalResources(localResources);
            IList <string> commands = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile));

            containerLaunchContext.SetCommands(commands);
            IPEndPoint containerManagerBindAddress = NetUtils.CreateSocketAddrForHost("127.0.0.1"
                                                                                      , 12345);
            UserGroupInformation currentUser = UserGroupInformation.CreateRemoteUser(cId.ToString
                                                                                         ());

            Org.Apache.Hadoop.Security.Token.Token <NMTokenIdentifier> nmToken = ConverterUtils
                                                                                 .ConvertFromYarn(nm.GetNMContext().GetNMTokenSecretManager().CreateNMToken(cId.GetApplicationAttemptId
                                                                                                                                                                (), nodeId, user), containerManagerBindAddress);
            currentUser.AddToken(nmToken);
            ContainerManagementProtocol containerManager = currentUser.DoAs(new _PrivilegedAction_229
                                                                                ());
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , TestContainerManager.CreateContainerToken(cId, 0, nodeId, user, nm.GetNMContext
                                                                                                                                ().GetContainerTokenSecretManager()));
            IList <StartContainerRequest> list = new AList <StartContainerRequest>();

            list.AddItem(scRequest);
            StartContainersRequest allRequests = StartContainersRequest.NewInstance(list);

            containerManager.StartContainers(allRequests);
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(cId);
            GetContainerStatusesRequest request = GetContainerStatusesRequest.NewInstance(containerIds
                                                                                          );
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(request).
                                              GetContainerStatuses()[0];

            NUnit.Framework.Assert.AreEqual(ContainerState.Running, containerStatus.GetState(
                                                ));
        }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        internal static LocalResource CreateFile(FileContext files, Path p, int len, Random
                                                 r, LocalResourceVisibility vis)
        {
            CreateFile(files, p, len, r);
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(p));
            ret.SetSize(len);
            ret.SetType(LocalResourceType.File);
            ret.SetVisibility(vis);
            ret.SetTimestamp(files.GetFileStatus(p).GetModificationTime());
            return(ret);
        }
Ejemplo n.º 4
0
        public static LocalResource NewLocalResource(URL url, LocalResourceType type, LocalResourceVisibility
                                                     visibility, long size, long timestamp, bool shouldBeUploadedToSharedCache)
        {
            LocalResource resource = recordFactory.NewRecordInstance <LocalResource>();

            resource.SetResource(url);
            resource.SetType(type);
            resource.SetVisibility(visibility);
            resource.SetSize(size);
            resource.SetTimestamp(timestamp);
            resource.SetShouldBeUploadedToSharedCache(shouldBeUploadedToSharedCache);
            return(resource);
        }
Ejemplo n.º 5
0
        /// <exception cref="System.IO.IOException"/>
        private LocalResource CreateApplicationResource(FileContext fs, Path p, LocalResourceType
                                                        type)
        {
            LocalResource rsrc     = recordFactory.NewRecordInstance <LocalResource>();
            FileStatus    rsrcStat = fs.GetFileStatus(p);

            rsrc.SetResource(ConverterUtils.GetYarnUrlFromPath(fs.GetDefaultFileSystem().ResolvePath
                                                                   (rsrcStat.GetPath())));
            rsrc.SetSize(rsrcStat.GetLen());
            rsrc.SetTimestamp(rsrcStat.GetModificationTime());
            rsrc.SetType(type);
            rsrc.SetVisibility(LocalResourceVisibility.Application);
            return(rsrc);
        }
Ejemplo n.º 6
0
        /// <exception cref="Sharpen.URISyntaxException"/>
        internal static LocalResource GetYarnResource(Path p, long size, long timestamp,
                                                      LocalResourceType type, LocalResourceVisibility state, string pattern)
        {
            LocalResource ret = RecordFactoryProvider.GetRecordFactory(null).NewRecordInstance
                                <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromURI(p.ToUri()));
            ret.SetSize(size);
            ret.SetTimestamp(timestamp);
            ret.SetType(type);
            ret.SetVisibility(state);
            ret.SetPattern(pattern);
            return(ret);
        }
Ejemplo n.º 7
0
        /// <exception cref="System.IO.IOException"/>
        internal static LocalResource CreateJar(FileContext files, Path p, LocalResourceVisibility
                                                vis)
        {
            Log.Info("Create jar file " + p);
            FilePath         jarFile = new FilePath((files.MakeQualified(p)).ToUri());
            FileOutputStream stream  = new FileOutputStream(jarFile);

            Log.Info("Create jar out stream ");
            JarOutputStream @out = new JarOutputStream(stream, new Manifest());

            Log.Info("Done writing jar stream ");
            @out.Close();
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(p));
            FileStatus status = files.GetFileStatus(p);

            ret.SetSize(status.GetLen());
            ret.SetTimestamp(status.GetModificationTime());
            ret.SetType(LocalResourceType.Pattern);
            ret.SetVisibility(vis);
            ret.SetPattern("classes/.*");
            return(ret);
        }
Ejemplo n.º 8
0
        public virtual void TestLocalFilesCleanup()
        {
            // Real del service
            delSrvc = new DeletionService(exec);
            delSrvc.Init(conf);
            containerManager = CreateContainerManager(delSrvc);
            containerManager.Init(conf);
            containerManager.Start();
            // ////// Create the resources for the container
            FilePath dir = new FilePath(tmpDir, "dir");

            dir.Mkdirs();
            FilePath    file       = new FilePath(dir, "file");
            PrintWriter fileWriter = new PrintWriter(file);

            fileWriter.Write("Hello World!");
            fileWriter.Close();
            // ////// Construct the Container-id
            ContainerId   cId   = CreateContainerId(0);
            ApplicationId appId = cId.GetApplicationAttemptId().GetApplicationId();
            // ////// Construct the container-spec.
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            //    containerLaunchContext.resources =
            //        new HashMap<CharSequence, LocalResource>();
            URL resource_alpha = ConverterUtils.GetYarnUrlFromPath(FileContext.GetLocalFSFileContext
                                                                       ().MakeQualified(new Path(file.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(file.LastModified());
            string destinationFile = "dest_file";
            IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource
                                                                                 >();

            localResources[destinationFile] = rsrc_alpha;
            containerLaunchContext.SetLocalResources(localResources);
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , CreateContainerToken(cId, DummyRmIdentifier, 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
                                                           .Complete);
            BaseContainerManagerTest.WaitForApplicationState(containerManager, cId.GetApplicationAttemptId
                                                                 ().GetApplicationId(), ApplicationState.Running);
            // Now ascertain that the resources are localised correctly.
            string   appIDStr       = ConverterUtils.ToString(appId);
            string   containerIDStr = ConverterUtils.ToString(cId);
            FilePath userCacheDir   = new FilePath(localDir, ContainerLocalizer.Usercache);
            FilePath userDir        = new FilePath(userCacheDir, user);
            FilePath appCache       = new FilePath(userDir, ContainerLocalizer.Appcache);
            FilePath appDir         = new FilePath(appCache, appIDStr);
            FilePath containerDir   = new FilePath(appDir, containerIDStr);
            FilePath targetFile     = new FilePath(containerDir, destinationFile);
            FilePath sysDir         = new FilePath(localDir, ResourceLocalizationService.NmPrivateDir
                                                   );
            FilePath appSysDir       = new FilePath(sysDir, appIDStr);
            FilePath containerSysDir = new FilePath(appSysDir, containerIDStr);

            // AppDir should still exist
            NUnit.Framework.Assert.IsTrue("AppDir " + appDir.GetAbsolutePath() + " doesn't exist!!"
                                          , appDir.Exists());
            NUnit.Framework.Assert.IsTrue("AppSysDir " + appSysDir.GetAbsolutePath() + " doesn't exist!!"
                                          , appSysDir.Exists());
            foreach (FilePath f in new FilePath[] { containerDir, containerSysDir })
            {
                NUnit.Framework.Assert.IsFalse(f.GetAbsolutePath() + " exists!!", f.Exists());
            }
            NUnit.Framework.Assert.IsFalse(targetFile.GetAbsolutePath() + " exists!!", targetFile
                                           .Exists());
            // Simulate RM sending an AppFinish event.
            containerManager.Handle(new CMgrCompletedAppsEvent(Arrays.AsList(new ApplicationId
                                                                             [] { appId }), CMgrCompletedAppsEvent.Reason.OnShutdown));
            BaseContainerManagerTest.WaitForApplicationState(containerManager, cId.GetApplicationAttemptId
                                                                 ().GetApplicationId(), ApplicationState.Finished);
            // Now ascertain that the resources are localised correctly.
            foreach (FilePath f_1 in new FilePath[] { appDir, containerDir, appSysDir, containerSysDir })
            {
                // Wait for deletion. Deletion can happen long after AppFinish because of
                // the async DeletionService
                int timeout = 0;
                while (f_1.Exists() && timeout++ < 15)
                {
                    Sharpen.Thread.Sleep(1000);
                }
                NUnit.Framework.Assert.IsFalse(f_1.GetAbsolutePath() + " exists!!", f_1.Exists());
            }
            // Wait for deletion
            int timeout_1 = 0;

            while (targetFile.Exists() && timeout_1++ < 15)
            {
                Sharpen.Thread.Sleep(1000);
            }
            NUnit.Framework.Assert.IsFalse(targetFile.GetAbsolutePath() + " exists!!", targetFile
                                           .Exists());
        }
Ejemplo n.º 9
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void TestContainerLaunchAndExit(int exitCode)
        {
            FilePath    scriptFile       = Shell.AppendScriptExtension(tmpDir, "scriptFile");
            PrintWriter fileWriter       = new PrintWriter(scriptFile);
            FilePath    processStartFile = new FilePath(tmpDir, "start_file.txt").GetAbsoluteFile
                                               ();
            // ////// Construct the Container-id
            ContainerId cId = CreateContainerId(0);

            if (Shell.Windows)
            {
                fileWriter.WriteLine("@echo Hello World!> " + processStartFile);
                fileWriter.WriteLine("@echo " + cId + ">> " + processStartFile);
                if (exitCode != 0)
                {
                    fileWriter.WriteLine("@exit " + exitCode);
                }
            }
            else
            {
                fileWriter.Write("\numask 0");
                // So that start file is readable by the test
                fileWriter.Write("\necho Hello World! > " + processStartFile);
                fileWriter.Write("\necho $$ >> " + processStartFile);
                // Have script throw an exit code at the end
                if (exitCode != 0)
                {
                    fileWriter.Write("\nexit " + exitCode);
                }
            }
            fileWriter.Close();
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            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 = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile));

            containerLaunchContext.SetCommands(commands);
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , CreateContainerToken(cId, DummyRmIdentifier, 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
                                                           .Complete);
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(cId);
            GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.NewInstance(
                containerIds);
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(gcsRequest
                                                                                    ).GetContainerStatuses()[0];

            // Verify exit status matches exit state of script
            NUnit.Framework.Assert.AreEqual(exitCode, containerStatus.GetExitStatus());
        }
Ejemplo n.º 10
0
        public virtual void TestContainerLaunchAndStop()
        {
            containerManager.Start();
            FilePath    scriptFile       = Shell.AppendScriptExtension(tmpDir, "scriptFile");
            PrintWriter fileWriter       = new PrintWriter(scriptFile);
            FilePath    processStartFile = new FilePath(tmpDir, "start_file.txt").GetAbsoluteFile
                                               ();
            // ////// Construct the Container-id
            ContainerId cId = CreateContainerId(0);

            if (Shell.Windows)
            {
                fileWriter.WriteLine("@echo Hello World!> " + processStartFile);
                fileWriter.WriteLine("@echo " + cId + ">> " + processStartFile);
                fileWriter.WriteLine("@ping -n 100 127.0.0.1 >nul");
            }
            else
            {
                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("\nexec sleep 100");
            }
            fileWriter.Close();
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            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 = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile));

            containerLaunchContext.SetCommands(commands);
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , CreateContainerToken(cId, DummyRmIdentifier, context.GetNodeId(), user, context
                                                                                                       .GetContainerTokenSecretManager()));
            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());
            // Now test the stop functionality.
            // Assert that the process is alive
            NUnit.Framework.Assert.IsTrue("Process is not alive!", DefaultContainerExecutor.ContainerIsAlive
                                              (pid));
            // Once more
            NUnit.Framework.Assert.IsTrue("Process is not alive!", DefaultContainerExecutor.ContainerIsAlive
                                              (pid));
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(cId);
            StopContainersRequest stopRequest = StopContainersRequest.NewInstance(containerIds
                                                                                  );

            containerManager.StopContainers(stopRequest);
            BaseContainerManagerTest.WaitForContainerState(containerManager, cId, ContainerState
                                                           .Complete);
            GetContainerStatusesRequest gcsRequest = GetContainerStatusesRequest.NewInstance(
                containerIds);
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(gcsRequest
                                                                                    ).GetContainerStatuses()[0];
            int expectedExitCode = ContainerExitStatus.KilledByAppmaster;

            NUnit.Framework.Assert.AreEqual(expectedExitCode, containerStatus.GetExitStatus()
                                            );
            // Assert that the process is not alive anymore
            NUnit.Framework.Assert.IsFalse("Process is still alive!", DefaultContainerExecutor
                                           .ContainerIsAlive(pid));
        }
Ejemplo n.º 11
0
        public virtual void TestContainerSetup()
        {
            containerManager.Start();
            // ////// Create the resources for the container
            FilePath dir = new FilePath(tmpDir, "dir");

            dir.Mkdirs();
            FilePath    file       = new FilePath(dir, "file");
            PrintWriter fileWriter = new PrintWriter(file);

            fileWriter.Write("Hello World!");
            fileWriter.Close();
            // ////// Construct the Container-id
            ContainerId cId = CreateContainerId(0);
            // ////// Construct the container-spec.
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            URL resource_alpha = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new
                                                                                         Path(file.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(file.LastModified());
            string destinationFile = "dest_file";
            IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource
                                                                                 >();

            localResources[destinationFile] = rsrc_alpha;
            containerLaunchContext.SetLocalResources(localResources);
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , CreateContainerToken(cId, DummyRmIdentifier, 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
                                                           .Complete);
            // Now ascertain that the resources are localised correctly.
            ApplicationId appId          = cId.GetApplicationAttemptId().GetApplicationId();
            string        appIDStr       = ConverterUtils.ToString(appId);
            string        containerIDStr = ConverterUtils.ToString(cId);
            FilePath      userCacheDir   = new FilePath(localDir, ContainerLocalizer.Usercache);
            FilePath      userDir        = new FilePath(userCacheDir, user);
            FilePath      appCache       = new FilePath(userDir, ContainerLocalizer.Appcache);
            FilePath      appDir         = new FilePath(appCache, appIDStr);
            FilePath      containerDir   = new FilePath(appDir, containerIDStr);
            FilePath      targetFile     = new FilePath(containerDir, destinationFile);
            FilePath      sysDir         = new FilePath(localDir, ResourceLocalizationService.NmPrivateDir
                                                        );
            FilePath appSysDir       = new FilePath(sysDir, appIDStr);
            FilePath containerSysDir = new FilePath(appSysDir, containerIDStr);

            foreach (FilePath f in new FilePath[] { localDir, sysDir, userCacheDir, appDir, appSysDir
                                                    , containerDir, containerSysDir })
            {
                NUnit.Framework.Assert.IsTrue(f.GetAbsolutePath() + " doesn't exist!!", f.Exists(
                                                  ));
                NUnit.Framework.Assert.IsTrue(f.GetAbsolutePath() + " is not a directory!!", f.IsDirectory
                                                  ());
            }
            NUnit.Framework.Assert.IsTrue(targetFile.GetAbsolutePath() + " doesn't exist!!",
                                          targetFile.Exists());
            // Now verify the contents of the file
            BufferedReader reader = new BufferedReader(new FileReader(targetFile));

            NUnit.Framework.Assert.AreEqual("Hello World!", reader.ReadLine());
            NUnit.Framework.Assert.AreEqual(null, reader.ReadLine());
        }
Ejemplo n.º 12
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.URISyntaxException"/>
        /// <exception cref="System.Exception"/>
        private void DownloadWithFileType(TestFSDownload.TEST_FILE_TYPE fileType)
        {
            Configuration conf = new Configuration();

            conf.Set(CommonConfigurationKeys.FsPermissionsUmaskKey, "077");
            FileContext files   = FileContext.GetLocalFSFileContext(conf);
            Path        basedir = files.MakeQualified(new Path("target", typeof(TestFSDownload).Name
                                                               ));

            files.Mkdir(basedir, null, true);
            conf.SetStrings(typeof(TestFSDownload).FullName, basedir.ToString());
            Random rand       = new Random();
            long   sharedSeed = rand.NextLong();

            rand.SetSeed(sharedSeed);
            System.Console.Out.WriteLine("SEED: " + sharedSeed);
            IDictionary <LocalResource, Future <Path> > pending = new Dictionary <LocalResource,
                                                                                  Future <Path> >();
            ExecutorService   exec = Executors.NewSingleThreadExecutor();
            LocalDirAllocator dirs = new LocalDirAllocator(typeof(TestFSDownload).FullName);
            int size = rand.Next(512) + 512;
            LocalResourceVisibility vis = LocalResourceVisibility.Private;
            Path          p             = new Path(basedir, string.Empty + 1);
            string        strFileName   = string.Empty;
            LocalResource rsrc          = null;

            switch (fileType)
            {
            case TestFSDownload.TEST_FILE_TYPE.Tar:
            {
                rsrc = CreateTarFile(files, p, size, rand, vis);
                break;
            }

            case TestFSDownload.TEST_FILE_TYPE.Jar:
            {
                rsrc = CreateJarFile(files, p, size, rand, vis);
                rsrc.SetType(LocalResourceType.Pattern);
                break;
            }

            case TestFSDownload.TEST_FILE_TYPE.Zip:
            {
                rsrc        = CreateZipFile(files, p, size, rand, vis);
                strFileName = p.GetName() + ".ZIP";
                break;
            }

            case TestFSDownload.TEST_FILE_TYPE.Tgz:
            {
                rsrc = CreateTgzFile(files, p, size, rand, vis);
                break;
            }
            }
            Path destPath = dirs.GetLocalPathForWrite(basedir.ToString(), size, conf);

            destPath = new Path(destPath, System.Convert.ToString(uniqueNumberGenerator.IncrementAndGet
                                                                      ()));
            FSDownload fsd = new FSDownload(files, UserGroupInformation.GetCurrentUser(), conf
                                            , destPath, rsrc);

            pending[rsrc] = exec.Submit(fsd);
            exec.Shutdown();
            while (!exec.AwaitTermination(1000, TimeUnit.Milliseconds))
            {
            }
            try
            {
                pending[rsrc].Get();
                // see if there was an Exception during download
                FileStatus[] filesstatus = files.GetDefaultFileSystem().ListStatus(basedir);
                foreach (FileStatus filestatus in filesstatus)
                {
                    if (filestatus.IsDirectory())
                    {
                        FileStatus[] childFiles = files.GetDefaultFileSystem().ListStatus(filestatus.GetPath
                                                                                              ());
                        foreach (FileStatus childfile in childFiles)
                        {
                            if (strFileName.EndsWith(".ZIP") && childfile.GetPath().GetName().Equals(strFileName
                                                                                                     ) && !childfile.IsDirectory())
                            {
                                NUnit.Framework.Assert.Fail("Failure...After unzip, there should have been a" + " directory formed with zip file name but found a file. "
                                                            + childfile.GetPath());
                            }
                            if (childfile.GetPath().GetName().StartsWith("tmp"))
                            {
                                NUnit.Framework.Assert.Fail("Tmp File should not have been there " + childfile.GetPath
                                                                ());
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new IOException("Failed exec", e);
            }
        }
Ejemplo n.º 13
0
        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));
        }