示例#1
0
        /// <summary>
        /// Cleans up all the application related files on the executor.
        /// </summary>
        /// <param name="appid">Application Id</param>
        public void Manager_CleanupApplication(string appid)
        {
            try
            {
                //unload the app domain and clean up all the files here, for this application.
                try
                {
                    lock (_GridAppDomains)
                    {
                        GridAppDomain gad = (GridAppDomain)_GridAppDomains[appid];
                        if (gad != null && _GridAppDomains.ContainsKey(appid))
                        {
                            logger.Debug("Unloading AppDomain for application:" + appid);

                            //eduGRID Addition
                            //AppDomain.Unload(gad.Domain);

                            _GridAppDomains.Remove(appid);
                        }
                        else
                        {
                            logger.Debug("Appdomain not found in collection.");
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Debug("Error unloading appdomain:", e);
                }

                string appDir = GetApplicationDirectory(appid);
                logger.Debug("Cleaning up files on executor:" + _Id + " for application:" + appid);

                logger.Debug("Deleting: " + appDir);
                Directory.Delete(appDir, true);
                logger.Debug("Clean up finished for app:" + appid);
            }
            catch (Exception e)
            {
                //just debug info. to see why clean up failed.
                logger.Debug("Clean up app error: " + e.Message);
            }
        }
示例#2
0
 /// <summary>
 /// Cleans up all the application related files on the executor.
 /// </summary>
 /// <param name="appid">Application Id</param>
 public void Manager_CleanupApplication(string appid)
 {
     try
     {
         //unload the app domain and clean up all the files here, for this application.
         try
         {
             if (_GridAppDomains != null)
             {
                 lock (_GridAppDomains)
                 {
                     if (_GridAppDomains.ContainsKey(appid))
                     {
                         GridAppDomain gad = _GridAppDomains[appid];
                         if (gad != null)
                         {
                             logger.Debug("Unloading AppDomain for application:" + appid);
                             AppDomain.Unload(gad.Domain);
                             _GridAppDomains.Remove(appid);
                         }
                     }
                     else
                     {
                         logger.Debug("Appdomain not found in collection - " + appid);
                     }
                 }
             }
         }
         catch (Exception e)
         {
             logger.Debug("Error unloading appdomain:", e);
         }
         Cleanup(appid);
     }
     catch (Exception e)
     {
         //just debug info. to see why clean up failed.
         logger.Debug("Clean up app error: " + e.Message);
     }
 }
示例#3
0
        private void ExecuteThreadInAppDomain()
        {
            byte[] rawThread = null;

            try
            {
                logger.Info("Started ExecuteThreadInAppDomain...");

                logger.Info(string.Format("executing grid thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId));

                string appDir = GetApplicationDirectory(_CurTi.ApplicationId);
                logger.Debug("AppDir on executor=" + appDir);

                if (!_GridAppDomains.Contains(_CurTi.ApplicationId))
                {
                    lock (_GridAppDomains)
                    {
                        // make sure that by the time the lock was acquired the app domain is still not created
                        if (!_GridAppDomains.Contains(_CurTi.ApplicationId))
                        {
                            // create application domain for newly encountered grid application
                            logger.Debug("app dir on executor: " + appDir);

                            //before initializing clear dir..
                            foreach (string F in Directory.GetFiles(appDir))
                            {
                                try //becoz exception should not be created for an issue as small as this
                                {
                                    File.Delete(F);
                                }
                                catch (Exception ex)
                                {
                                }
                            }

                            FileDependencyCollection manifest = Manager.Executor_GetApplicationManifest(Credentials, _CurTi.ApplicationId);
                            if (manifest != null)
                            {
                                foreach (FileDependency dep in manifest)
                                {
                                    try //so that IO error does not occur if files already exist
                                    {
                                        logger.Debug("Unpacking file: " + dep.FileName + " to " + appDir);
                                        dep.UnPackToFolder(appDir);
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                            }
                            else
                            {
                                logger.Warn("Executor_GetApplicationManifest from the Manager returned null");
                            }


                            initialize_GridThreadExecutor();

                            _GridAppDomains.Add(
                                _CurTi.ApplicationId,
                                new GridAppDomain(GridThreadApplicationDomain, GridThreadExecutor)
                                );

                            logger.Info("Created app domain, policy, got instance of GridAppDomain and added to hashtable...all done once for this application");
                        }
                        else
                        {
                            logger.Info("I got the lock but this app domain is already created.");
                        }
                    }
                }

                //get thread from manager
                GridAppDomain gad = (GridAppDomain)_GridAppDomains[_CurTi.ApplicationId];

                //if we have an exception in the secondary appdomain, it will raise an exception in this method, since the cross-app-domain call
                //uses remoting internally, and it is just as if a remote method has caused an exception. we have a handler for that below anyway.

                rawThread = Manager.Executor_GetThread(Credentials, _CurTi);
                logger.Debug("Got thread from manager. executing it: " + _CurTi.ThreadId);

                //execute it

                byte[] finishedThread = gad.Executor.ExecuteThread(rawThread);
                logger.Info(string.Format("ExecuteThread returned for thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId));


                //set its status to finished
                Manager.Executor_SetFinishedThread(Credentials, _CurTi, finishedThread, null);
                logger.Info(string.Format("Finished executing grid thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId));
            }
            catch (ThreadAbortException)
            {
                if (_CurTi != null)
                {
                    logger.Warn(string.Format("aborted grid thread # {0}.{1}", _CurTi.ApplicationId, _CurTi.ThreadId));
                }
                else
                {
                    logger.Warn(string.Format("aborted grid thread # {0}.{1}", null, null));
                }

                Thread.ResetAbort();
            }
            catch (Exception e)
            {
                logger.Warn(string.Format("grid thread # {0}.{1} failed ({2})", _CurTi.ApplicationId, _CurTi.ThreadId, e.GetType()), e);
                try
                {
                    //some exceptions such as Win32Exception caused problems when passed directly into this method.
                    //so better create another new exception object and send it over.
                    Exception eNew = new Exception(e.ToString());
                    Manager.Executor_SetFinishedThread(Credentials, _CurTi, rawThread, eNew);
                }
                catch (Exception ex1)
                {
                    if (_CurTi != null)
                    {
                        logger.Warn("Error trying to set failed thread for App: " + _CurTi.ApplicationId + ", thread=" + _CurTi.ThreadId + ". Original Exception = \n" + e.ToString(), ex1);
                    }
                    else
                    {
                        logger.Warn("Error trying to set failed thread: Original exception = " + e.ToString(), ex1);
                    }
                }
            }
            finally
            {
                _CurTi = null;
                _ReadyToExecute.Set();

                logger.Info("Exited ExecuteThreadInAppDomain...");
            }
        }