Esempio n. 1
0
        static int Main(string[] args)
        {
            Console.WriteLine("{0} starting up in {1}", Environment.CommandLine, Environment.CurrentDirectory);

            bool          waitForDebugger = false;
            List <string> tempArgs        = new List <string>();

            // Record start time so we can report it once logging has been initialized
            DateTime startTime = DateTime.Now.ToLocalTime();

            // Set unhandled exception handler to catch anything thrown from
            // Microsoft.Hpc.Query.GraphManager.dll
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);


            //
            // Add executable name to beginning of args
            // to make graph manager libraries happy
            //
            tempArgs.Add("YarnQueryGraphManager");
            foreach (string arg in args)
            {
                if (String.Compare(arg, "--break", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    waitForDebugger = true;
                }
                else
                {
                    tempArgs.Add(arg);
                }
            }
            args = tempArgs.ToArray();

            if (waitForDebugger)
            {
                DebugHelper.WaitForDebugger();
            }

            /* Yarn removes the need for this
             *
             * //
             * // Create job directory and copy resources
             * //
             * string resources = Environment.GetEnvironmentVariable("XC_RESOURCEFILES");
             * if (ExecutionHelper.InitializeForJobExecution(resources) == false)
             * {
             *  return 1;
             * }
             *
             * //
             * // Set current directory to working directory
             * //
             * Directory.SetCurrentDirectory(ProcessPathHelper.JobPath);
             */
            //
            // Configure tracing
            //
            DebugHelper.InitializeLogging(startTime);

            // Ensure that there is a jvm.dll on the path.
            string pathString = Environment.GetEnvironmentVariable("PATH");
            var    pathDirs   = pathString.Split(';');
            bool   found      = false;

            foreach (var dir in pathDirs)
            {
                string targetFile = Path.Combine(dir, "jvm.dll");
                if (File.Exists(targetFile))
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                string javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
                if (String.IsNullOrEmpty(javaHome))
                {
                    throw new ApplicationException("DryadLINQ requires the JAVA_HOME environment variable to be set or the jvm.dll to be on the path.");
                }
                var jvmPath = ";" + Path.Combine(javaHome, "jre", "bin", "server");
                pathString += jvmPath;
                Environment.SetEnvironmentVariable("PATH", pathString);
            }


            //
            // Run the Graph Manager
            //
            int retCode = 0;

            try
            {
                LinqToDryadJM jm = new LinqToDryadJM();
                retCode = jm.Run(args);
            }
            catch (Exception e)
            {
                retCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);
                if (retCode == 0)
                {
                    DryadLogger.LogCritical(0, e);
                    retCode = unchecked ((int)LinqToDryadException.E_FAIL);
                }
                else
                {
                    DryadLogger.LogCritical(retCode, e);
                }
                System.Threading.Thread.Sleep(10 * 60 * 1000);
            }

            DebugHelper.StopLogging(retCode);

            // NOTE: We don't want to log critical errors twice, so here we're assuming that
            // if the GM exited "gracefully" and returned an error code instead of throwing
            // an exception, that it has already logged the error.
            if (retCode != 0)
            {
                // If the Graph Manager already started executing, we need to exit the process.
                // Exiting the thread (returning from Main) will not necessarily cause the GM's
                // worker threads to exit

                // TODO: Consider deleting temp output stream from DSC
                // requires that we have access to the URI at this point, though
                Environment.Exit(retCode);
            }

            //
            // Cleanup all vertex tasks in case any became
            // unreachable.
            //

            return(retCode);
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            Console.WriteLine("{0} starting up in {1}", Environment.CommandLine, Environment.CurrentDirectory);

            bool waitForDebugger = false;
            List<string> tempArgs = new List<string>();

            // Record start time so we can report it once logging has been initialized
            DateTime startTime = DateTime.Now.ToLocalTime();

            // Set unhandled exception handler to catch anything thrown from
            // Microsoft.Hpc.Query.GraphManager.dll
            AppDomain currentDomain = AppDomain.CurrentDomain;
            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);

            //
            // Add executable name to beginning of args
            // to make graph manager libraries happy
            //
            tempArgs.Add("YarnQueryGraphManager");
            foreach (string arg in args)
            {
                if (String.Compare(arg, "--break", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    waitForDebugger = true;
                }
                else
                {
                    tempArgs.Add(arg);
                }
            }
            args = tempArgs.ToArray();

            if (waitForDebugger)
            {
                DebugHelper.WaitForDebugger();
            }
            /* Yarn removes the need for this

            //
            // Create job directory and copy resources
            //
            string resources = Environment.GetEnvironmentVariable("XC_RESOURCEFILES");
            if (ExecutionHelper.InitializeForJobExecution(resources) == false)
            {
                return 1;
            }

            //
            // Set current directory to working directory
            //
            Directory.SetCurrentDirectory(ProcessPathHelper.JobPath);
            */
            //
            // Configure tracing
            //
            DebugHelper.InitializeLogging(startTime);

            // Ensure that there is a jvm.dll on the path.
            string pathString = Environment.GetEnvironmentVariable("PATH");
            var pathDirs = pathString.Split(';');
            bool found = false;
            foreach (var dir in pathDirs)
            {
                string targetFile = Path.Combine(dir, "jvm.dll");
                if (File.Exists(targetFile))
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                string javaHome = Environment.GetEnvironmentVariable("JAVA_HOME");
                if (String.IsNullOrEmpty(javaHome))
                {
                    throw new ApplicationException("DryadLINQ requires the JAVA_HOME environment variable to be set or the jvm.dll to be on the path.");
                }
                var jvmPath = ";" + Path.Combine(javaHome, "jre", "bin", "server");
                pathString +=  jvmPath;
                Environment.SetEnvironmentVariable("PATH", pathString);
            }

            //
            // Run the Graph Manager
            //
            int retCode = 0;
            try
            {
                LinqToDryadJM jm = new LinqToDryadJM();
                retCode = jm.Run(args);
            }
            catch (Exception e)
            {
                retCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);
                if (retCode == 0)
                {
                    DryadLogger.LogCritical(0, e);
                    retCode = unchecked((int)LinqToDryadException.E_FAIL);
                }
                else
                {
                    DryadLogger.LogCritical(retCode, e);
                }
                System.Threading.Thread.Sleep(10 * 60 * 1000);
            }

            DebugHelper.StopLogging(retCode);

            // NOTE: We don't want to log critical errors twice, so here we're assuming that
            // if the GM exited "gracefully" and returned an error code instead of throwing
            // an exception, that it has already logged the error.
            if (retCode != 0)
            {
                // If the Graph Manager already started executing, we need to exit the process.
                // Exiting the thread (returning from Main) will not necessarily cause the GM's
                // worker threads to exit

                // TODO: Consider deleting temp output stream from DSC
                // requires that we have access to the URI at this point, though
                Environment.Exit(retCode);
            }

            //
            // Cleanup all vertex tasks in case any became
            // unreachable.
            //

            return retCode;
        }