示例#1
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void WriteLaunchEnv(OutputStream @out, IDictionary <string, string>
                                           environment, IDictionary <Path, IList <string> > resources, IList <string> command)
        {
            ContainerLaunch.ShellScriptBuilder sb = ContainerLaunch.ShellScriptBuilder.Create
                                                        ();
            if (environment != null)
            {
                foreach (KeyValuePair <string, string> env in environment)
                {
                    sb.Env(env.Key.ToString(), env.Value.ToString());
                }
            }
            if (resources != null)
            {
                foreach (KeyValuePair <Path, IList <string> > entry in resources)
                {
                    foreach (string linkName in entry.Value)
                    {
                        sb.Symlink(entry.Key, new Path(linkName));
                    }
                }
            }
            sb.Command(command);
            TextWriter pout = null;

            try
            {
                pout = new TextWriter(@out, false, "UTF-8");
                sb.Write(pout);
            }
            finally
            {
                if (@out != null)
                {
                    @out.Close();
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        public override void WriteLaunchEnv(OutputStream @out, IDictionary <string, string
                                                                            > environment, IDictionary <Path, IList <string> > resources, IList <string> command
                                            )
        {
            ContainerLaunch.ShellScriptBuilder sb = ContainerLaunch.ShellScriptBuilder.Create
                                                        ();
            ICollection <string> exclusionSet = new HashSet <string>();

            exclusionSet.AddItem(YarnConfiguration.NmDockerContainerExecutorImageName);
            exclusionSet.AddItem(ApplicationConstants.Environment.HadoopYarnHome.ToString());
            exclusionSet.AddItem(ApplicationConstants.Environment.HadoopCommonHome.ToString()
                                 );
            exclusionSet.AddItem(ApplicationConstants.Environment.HadoopHdfsHome.ToString());
            exclusionSet.AddItem(ApplicationConstants.Environment.HadoopConfDir.ToString());
            exclusionSet.AddItem(ApplicationConstants.Environment.JavaHome.ToString());
            if (environment != null)
            {
                foreach (KeyValuePair <string, string> env in environment)
                {
                    if (!exclusionSet.Contains(env.Key))
                    {
                        sb.Env(env.Key.ToString(), env.Value.ToString());
                    }
                }
            }
            if (resources != null)
            {
                foreach (KeyValuePair <Path, IList <string> > entry in resources)
                {
                    foreach (string linkName in entry.Value)
                    {
                        sb.Symlink(entry.Key, new Path(linkName));
                    }
                }
            }
            sb.Command(command);
            TextWriter            pout = null;
            TextWriter            ps   = null;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            try
            {
                pout = new TextWriter(@out, false, "UTF-8");
                if (Log.IsDebugEnabled())
                {
                    ps = new TextWriter(baos, false, "UTF-8");
                    sb.Write(ps);
                }
                sb.Write(pout);
            }
            finally
            {
                if (@out != null)
                {
                    @out.Close();
                }
                if (ps != null)
                {
                    ps.Close();
                }
            }
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Script: " + baos.ToString("UTF-8"));
            }
        }