コード例 #1
0
        /// <summary>Abort the application and wait for it to finish.</summary>
        /// <param name="t">the exception that signalled the problem</param>
        /// <exception cref="System.IO.IOException">A wrapper around the exception that was passed in
        ///     </exception>
        internal virtual void Abort(Exception t)
        {
            Log.Info("Aborting because of " + StringUtils.StringifyException(t));
            try
            {
                downlink.Abort();
                downlink.Flush();
            }
            catch (IOException)
            {
            }
            // IGNORE cleanup problems
            try
            {
                handler.WaitForFinish();
            }
            catch
            {
                process.Destroy();
            }
            IOException wrapper = new IOException("pipe child exception");

            Sharpen.Extensions.InitCause(wrapper, t);
            throw wrapper;
        }
コード例 #2
0
 /// <summary>Method used to terminate the node health monitoring service.</summary>
 protected override void ServiceStop()
 {
     if (!ShouldRun(conf))
     {
         return;
     }
     if (nodeHealthScriptScheduler != null)
     {
         nodeHealthScriptScheduler.Cancel();
     }
     if (shexec != null)
     {
         SystemProcess p = shexec.GetProcess();
         if (p != null)
         {
             p.Destroy();
         }
     }
 }
コード例 #3
0
            public override void Run()
            {
                SystemProcess p = shell.GetProcess();

                try
                {
                    p.ExitValue();
                }
                catch (Exception)
                {
                    //Process has not terminated.
                    //So check if it has completed
                    //if not just destroy it.
                    if (p != null && !shell.completed.Get())
                    {
                        shell.SetTimedOut();
                        p.Destroy();
                    }
                }
            }
コード例 #4
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public virtual void LaunchAM(ApplicationAttemptId attemptId)
        {
            Credentials credentials = new Credentials();

            Org.Apache.Hadoop.Security.Token.Token <AMRMTokenIdentifier> token = rmClient.GetAMRMToken
                                                                                     (attemptId.GetApplicationId());
            // Service will be empty but that's okay, we are just passing down only
            // AMRMToken down to the real AM which eventually sets the correct
            // service-address.
            credentials.AddToken(token.GetService(), token);
            FilePath tokenFile = FilePath.CreateTempFile("unmanagedAMRMToken", string.Empty,
                                                         new FilePath(Runtime.GetProperty("user.dir")));

            try
            {
                FileUtil.Chmod(tokenFile.GetAbsolutePath(), "600");
            }
            catch (Exception ex)
            {
                throw new RuntimeException(ex);
            }
            tokenFile.DeleteOnExit();
            DataOutputStream os = new DataOutputStream(new FileOutputStream(tokenFile, true));

            credentials.WriteTokenStorageToStream(os);
            os.Close();
            IDictionary <string, string> env = Sharpen.Runtime.GetEnv();
            AList <string> envAMList         = new AList <string>();
            bool           setClasspath      = false;

            foreach (KeyValuePair <string, string> entry in env)
            {
                string key   = entry.Key;
                string value = entry.Value;
                if (key.Equals("CLASSPATH"))
                {
                    setClasspath = true;
                    if (classpath != null)
                    {
                        value = value + FilePath.pathSeparator + classpath;
                    }
                }
                envAMList.AddItem(key + "=" + value);
            }
            if (!setClasspath && classpath != null)
            {
                envAMList.AddItem("CLASSPATH=" + classpath);
            }
            ContainerId containerId = ContainerId.NewContainerId(attemptId, 0);
            string      hostname    = Sharpen.Runtime.GetLocalHost().GetHostName();

            envAMList.AddItem(ApplicationConstants.Environment.ContainerId.ToString() + "=" +
                              containerId);
            envAMList.AddItem(ApplicationConstants.Environment.NmHost.ToString() + "=" + hostname
                              );
            envAMList.AddItem(ApplicationConstants.Environment.NmHttpPort.ToString() + "=0");
            envAMList.AddItem(ApplicationConstants.Environment.NmPort.ToString() + "=0");
            envAMList.AddItem(ApplicationConstants.Environment.LocalDirs.ToString() + "= /tmp"
                              );
            envAMList.AddItem(ApplicationConstants.AppSubmitTimeEnv + "=" + Runtime.CurrentTimeMillis
                                  ());
            envAMList.AddItem(ApplicationConstants.ContainerTokenFileEnvName + "=" + tokenFile
                              .GetAbsolutePath());
            string[]      envAM  = new string[envAMList.Count];
            SystemProcess amProc = Runtime.GetRuntime().Exec(amCmd, Sharpen.Collections.ToArray
                                                                 (envAMList, envAM));
            BufferedReader errReader = new BufferedReader(new InputStreamReader(amProc.GetErrorStream
                                                                                    (), Sharpen.Extensions.GetEncoding("UTF-8")));
            BufferedReader inReader = new BufferedReader(new InputStreamReader(amProc.GetInputStream
                                                                                   (), Sharpen.Extensions.GetEncoding("UTF-8")));

            // read error and input streams as this would free up the buffers
            // free the error stream buffer
            Sharpen.Thread errThread = new _Thread_244(errReader);
            Sharpen.Thread outThread = new _Thread_258(inReader);
            try
            {
                errThread.Start();
                outThread.Start();
            }
            catch (InvalidOperationException)
            {
            }
            // wait for the process to finish and check the exit code
            try
            {
                int exitCode = amProc.WaitFor();
                Log.Info("AM process exited with value: " + exitCode);
            }
            catch (Exception e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
            }
            finally
            {
                amCompleted = true;
            }
            try
            {
                // make sure that the error thread exits
                // on Windows these threads sometimes get stuck and hang the execution
                // timeout and join later after destroying the process.
                errThread.Join();
                outThread.Join();
                errReader.Close();
                inReader.Close();
            }
            catch (Exception ie)
            {
                Log.Info("ShellExecutor: Interrupted while reading the error/out stream", ie);
            }
            catch (IOException ioe)
            {
                Log.Warn("Error while closing the error/out stream", ioe);
            }
            amProc.Destroy();
        }