Esempio n. 1
0
        /// <exception cref="System.IO.IOException"/>
        private void AddToLocalResources(FileSystem fs, string fileSrcPath, string fileDstPath
                                         , string appId, IDictionary <string, LocalResource> localResources, string resources
                                         )
        {
            string suffix = appName + "/" + appId + "/" + fileDstPath;
            Path   dst    = new Path(fs.GetHomeDirectory(), suffix);

            if (fileSrcPath == null)
            {
                FSDataOutputStream ostream = null;
                try
                {
                    ostream = FileSystem.Create(fs, dst, new FsPermission((short)0x1c8));
                    ostream.WriteUTF(resources);
                }
                finally
                {
                    IOUtils.CloseQuietly(ostream);
                }
            }
            else
            {
                fs.CopyFromLocalFile(new Path(fileSrcPath), dst);
            }
            FileStatus    scFileStatus = fs.GetFileStatus(dst);
            LocalResource scRsrc       = LocalResource.NewInstance(ConverterUtils.GetYarnUrlFromURI
                                                                       (dst.ToUri()), LocalResourceType.File, LocalResourceVisibility.Application, scFileStatus
                                                                   .GetLen(), scFileStatus.GetModificationTime());

            localResources[fileDstPath] = scRsrc;
        }
Esempio n. 2
0
        /// <summary>
        /// To ensure there are not multiple instances of the SCM running on a given
        /// cluster, a global pid file is used.
        /// </summary>
        /// <remarks>
        /// To ensure there are not multiple instances of the SCM running on a given
        /// cluster, a global pid file is used. This file contains the hostname of the
        /// machine that owns the pid file.
        /// </remarks>
        /// <returns>true if the pid file was written, false otherwise</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private bool WriteGlobalCleanerPidFile()
        {
            string root = conf.Get(YarnConfiguration.SharedCacheRoot, YarnConfiguration.DefaultSharedCacheRoot
                                   );
            Path pidPath = new Path(root, GlobalCleanerPid);

            try
            {
                FileSystem fs = FileSystem.Get(this.conf);
                if (fs.Exists(pidPath))
                {
                    return(false);
                }
                FSDataOutputStream os = fs.Create(pidPath, false);
                // write the hostname and the process id in the global cleaner pid file
                string Id = ManagementFactory.GetRuntimeMXBean().GetName();
                os.WriteUTF(Id);
                os.Close();
                // add it to the delete-on-exit to ensure it gets deleted when the JVM
                // exits
                fs.DeleteOnExit(pidPath);
            }
            catch (IOException e)
            {
                throw new YarnException(e);
            }
            Log.Info("Created the global cleaner pid file at " + pidPath.ToString());
            return(true);
        }