Exemple #1
0
        internal static void StartupShutdownMessage(Type clazz, string[] args, LogAdapter
                                                    Log)
        {
            string hostname  = NetUtils.GetHostname();
            string classname = clazz.Name;

            Log.Info(ToStartupShutdownString("STARTUP_MSG: ", new string[] { "Starting " + classname
                                                                             , "  host = " + hostname, "  args = " + Arrays.AsList(args), "  version = " + VersionInfo
                                                                             .GetVersion(), "  classpath = " + Runtime.GetProperty("java.class.path"), "  build = "
                                                                             + VersionInfo.GetUrl() + " -r " + VersionInfo.GetRevision() + "; compiled by '"
                                                                             + VersionInfo.GetUser() + "' on " + VersionInfo.GetDate(), "  java = " + Runtime
                                                                             .GetProperty("java.version") }));
            if (SystemUtils.IsOsUnix)
            {
                try
                {
                    SignalLogger.Instance.Register(Log);
                }
                catch (Exception t)
                {
                    Log.Warn("failed to register any UNIX signal loggers: ", t);
                }
            }
            ShutdownHookManager.Get().AddShutdownHook(new _Runnable_673(Log, classname, hostname
                                                                        ), ShutdownHookPriority);
        }
Exemple #2
0
        /// <exception cref="System.Exception"/>
        public virtual void Run(string[] args)
        {
            string usage = "RunJar jarFile [mainClass] args...";

            if (args.Length < 1)
            {
                System.Console.Error.WriteLine(usage);
                System.Environment.Exit(-1);
            }
            int      firstArg = 0;
            string   fileName = args[firstArg++];
            FilePath file     = new FilePath(fileName);

            if (!file.Exists() || !file.IsFile())
            {
                System.Console.Error.WriteLine("Not a valid JAR: " + file.GetCanonicalPath());
                System.Environment.Exit(-1);
            }
            string  mainClassName = null;
            JarFile jarFile;

            try
            {
                jarFile = new JarFile(fileName);
            }
            catch (IOException io)
            {
                throw Extensions.InitCause(new IOException("Error opening job jar: " + fileName
                                                           ), io);
            }
            Manifest manifest = jarFile.GetManifest();

            if (manifest != null)
            {
                mainClassName = manifest.GetMainAttributes().GetValue("Main-Class");
            }
            jarFile.Close();
            if (mainClassName == null)
            {
                if (args.Length < 2)
                {
                    System.Console.Error.WriteLine(usage);
                    System.Environment.Exit(-1);
                }
                mainClassName = args[firstArg++];
            }
            mainClassName = mainClassName.ReplaceAll("/", ".");
            FilePath tmpDir = new FilePath(Runtime.GetProperty("java.io.tmpdir"));

            EnsureDirectory(tmpDir);
            FilePath workDir;

            try
            {
                workDir = FilePath.CreateTempFile("hadoop-unjar", string.Empty, tmpDir);
            }
            catch (IOException ioe)
            {
                // If user has insufficient perms to write to tmpDir, default
                // "Permission denied" message doesn't specify a filename.
                System.Console.Error.WriteLine("Error creating temp dir in java.io.tmpdir " + tmpDir
                                               + " due to " + ioe.Message);
                System.Environment.Exit(-1);
                return;
            }
            if (!workDir.Delete())
            {
                System.Console.Error.WriteLine("Delete failed for " + workDir);
                System.Environment.Exit(-1);
            }
            EnsureDirectory(workDir);
            ShutdownHookManager.Get().AddShutdownHook(new _Runnable_201(workDir), ShutdownHookPriority
                                                      );
            UnJar(file, workDir);
            ClassLoader loader = CreateClassLoader(file, workDir);

            Thread.CurrentThread().SetContextClassLoader(loader);
            Type       mainClass = Runtime.GetType(mainClassName, true, loader);
            MethodInfo main      = mainClass.GetMethod("main", new Type[] { System.Array.CreateInstance
                                                                                (typeof(string), 0).GetType() });

            string[] newArgs = Collections.ToArray(Arrays.AsList(args).SubList(firstArg
                                                                               , args.Length), new string[0]);
            try
            {
                main.Invoke(null, new object[] { newArgs });
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }