public void SetWorkingDirectoryTestSimpleScenario() { string workingDirectory = @"C:\"; GThreadMock threadFiller = new GThreadMock(); GThread thread = threadFiller; thread.SetWorkingDirectory(workingDirectory); Assert.AreEqual(workingDirectory, threadFiller.GetWorkingDirectory()); }
/// <summary> /// Executes a grid thread in its own Application Domain on the executor node. /// Returns the gridThread as a serialized byte array after execution. This byte array includes the results of execution of the GThread. /// </summary> /// <param name="thread">A byte array representing a serialized gridThread to be executed.</param> /// <returns>A byte array representing a serialized gridThread, after the execution is complete.</returns> public byte[] ExecuteThread(byte[] thread) { // ([email protected]): this should be revised - there is no log listener in this app domain so these logs do not go anywhere //kna: Since this method is actually //called on a different AppDomain, //we can catch exceptions in the caller //since cross-appdomain calls use remoting. //so the exception would be passed back! :) GThread gridThread = (GThread)Utils.DeserializeFromByteArray(thread); logger.Debug("Executor running GThread: " + gridThread.Id); logger.Debug("Working dir=" + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetWorkingDirectory(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetiBOT(_iBot); gridThread.Start(); gridThread.SetiBOT(null); logger.Debug("GThread " + gridThread.Id + " done. Serializing it to send back to the manager..."); return(Utils.SerializeToByteArray(gridThread)); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Executes a grid thread in its own Application Domain on the executor node. /// Returns the gridThread as a serialized byte array after execution. This byte array includes the results of execution of the GThread. /// </summary> /// <param name="thread">A byte array representing a serialized gridThread to be executed.</param> /// <returns>A byte array representing a serialized gridThread, after the execution is complete.</returns> internal byte[] ExecuteThread(byte[] thread, string workingDir) { //kna: NOTE to remember: Since this method is actually //called on a different AppDomain, //we can catch exceptions in the caller //since cross-appdomain calls use remoting. //so the exception would be passed back! :) GThread gridThread = (GThread)Utils.DeserializeFromByteArray(thread); //we pass the targetAppDomain to send logs to executor logger.Debug(string.Format("Executor running GThread: {0} [{1}] in {2} ", gridThread.Id, gridThread.GetType().FullName, workingDir)); gridThread.SetWorkingDirectory(workingDir); gridThread.StartThread(); logger.Debug("GThread " + gridThread.Id + " done. Serializing it to send back to the manager..."); return(Utils.SerializeToByteArray(gridThread)); }
//----------------------------------------------------------------------------------------------- //eduGRID Addition //written by Abhishek kumar dated March 5, 2007 //Reason: Inter process communication is not our concern here //we wish to allow communication bw the Gthread and //and the bot wrapper class that runs on executor node private void ExecuteThread() { byte[] rawThread = null; //this will contain the serialized Gthread logger.Info("Started ExecuteThread..."); try { //note: the above statement means that ibot will be initialized only when it //receives its first thread. this means that the response time for the first query //to this GExector will be high. //TODO: put initialize bot else where .. probably in constructor logger.Info("Bot is initialized."); //Get Thread rawThread = Manager.Executor_GetThread(Credentials, _CurTi); logger.Debug("Got thread from manager. executing it: " + _CurTi.ThreadId); //execute it byte[] thread = new byte[rawThread.Length]; rawThread.CopyTo(thread, 0); GThread gridThread = (GThread)Alchemi.Core.Utility.Utils.DeserializeFromByteArray(thread); logger.Debug("Executor running GThread: " + gridThread.Id); logger.Debug("Working dir=" + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); gridThread.SetWorkingDirectory(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); //eduGRID main link gridThread.SetiBOT(iBot); gridThread.Start(); logger.Debug("GThread " + gridThread.Id + " done. Serializing it to send back to the manager..."); byte[] finishedThread = Alchemi.Core.Utility.Utils.SerializeToByteArray(gridThread); //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 ExecuteThread..."); } }