//----------------------------------------------------------------------------------------------- /// <summary> /// Creates a task on the Manager from the provided XML task representation and returns its Id. /// </summary> /// <param name="manager"></param> /// <param name="sc">Security Credentials</param> /// <param name="taskXml"></param> /// <returns>application id</returns> public static string CreateTask(IManager manager, SecurityCredentials sc, string taskXml) { // TODO: validate against schema string taskId = manager.Owner_CreateApplication(sc); XmlDocument doc = new XmlDocument(); doc.LoadXml(taskXml); FileDependencyCollection manifest = new FileDependencyCollection(); foreach (XmlNode manifestFile in doc.SelectNodes("task/manifest/embedded_file")) { EmbeddedFileDependency dep = new EmbeddedFileDependency(manifestFile.Attributes["name"].Value); dep.Base64EncodedContents = manifestFile.InnerText; manifest.Add(dep); logger.Debug("Added dependency to manifest: " + dep.FileName); } manager.Owner_SetApplicationManifest(sc, taskId, manifest); foreach (XmlNode jobXml in doc.SelectNodes("task/job")) { int jobId = int.Parse(jobXml.Attributes["id"].Value); jobXml.Attributes.Remove(jobXml.Attributes["id"]); // TODO: allow setting of priority in xml file AddJob(manager, sc, taskId, jobId, 0, jobXml.OuterXml); logger.Debug("Added job to manager: " + jobId); } return(taskId); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Adds the list of users to the Alchemi database /// /// </summary> /// <param name="sc">security credentials to verify if the user has permissions to perform this operation. /// (i.e add list of users, which is associated with the permission: ManageUsers).</param> /// <param name="adds">a DataTable object containing the list of users to be added</param> public void Admon_AddUsers(SecurityCredentials sc, UserStorageView[] adds) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageUsers); ManagerStorageFactory.ManagerStorage().AddUsers(adds); }
public bool AuthenticateUser(Alchemi.Core.SecurityCredentials sc) { if (sc == null) { return(false); } bool isPresent = false; IObjectContainer container = GetStorage(); try { IList <UserStorageView> users = container.Query <UserStorageView>(delegate(UserStorageView user) { return(user.Username == sc.Username && user.PasswordMd5Hash == sc.Password); }); if (users.Count > 0) { isPresent = true; } } finally { container.Close(); } return(isPresent); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Adds a job to the manager /// </summary> /// <param name="manager"></param> /// <param name="sc">security credentials used to perform this operation</param> /// <param name="taskId"></param> /// <param name="jobId"></param> /// <param name="priority"></param> /// <param name="jobXml"></param> public static void AddJob(IManager manager, SecurityCredentials sc, string taskId, int jobId, int priority, string jobXml) { manager.Owner_SetThread( sc, new ThreadIdentifier(taskId, jobId, priority), Utils.SerializeToByteArray(JobFromXml(jobId, jobXml)) ); }
public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials, string remoteObjectPrefix) { _OwnEP = ownEP; _Credentials = credentials; _ManagerEP = managerEP; _RemoteObjPrefix = remoteObjectPrefix; Init(); }
public void Admon_DeleteApplication(SecurityCredentials sc, ApplicationStorageView applicationToDelete) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageAllApps); logger.Debug(String.Format("Deleting application {0}.", applicationToDelete.ApplicationId)); ManagerStorageFactory.ManagerStorage().DeleteApplication(applicationToDelete); }
public void Admon_GetLiveApplicationListTestSimpleScenario() { SetupApplicationsGroupsAndUsers(Permission.ManageOwnApp); SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5)); ApplicationStorageView[] result = Admon_GetUserApplicationList(sc); Assert.AreEqual(1, result.Length); }
/// <summary> /// Initialised the remoted "node" /// </summary> protected void Init() { if (_Initted) { return; } if (_Connection != null) { _Credentials = new SecurityCredentials(_Connection.Username, _Connection.Password); _ManagerEP = _Connection.RemoteEP; } GetManagerRef(); RemoteSelf(); _Initted = true; }
//----------------------------------------------------------------------------------------------- // public methods //----------------------------------------------------------------------------------------------- /// <summary> /// Initialised the remoted "node" /// </summary> protected void Init() { if (_Initted) { return; } if (_Connection != null) { _Credentials = new SecurityCredentials(_Connection.Username, _Connection.Password); _ManagerEP = new RemoteEndPoint(_Connection.Host, _Connection.Port, RemotingMechanism.TcpBinary); } GetManagerRef(); RemoteSelf(); _Initted = true; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the finished jobs as an xml string /// </summary> /// <param name="manager"></param> /// <param name="sc">security credentials used to perform this operation</param> /// <param name="taskId"></param> /// <returns>XML string representing the job</returns> public static string GetFinishedJobs(IManager manager, SecurityCredentials sc, string taskId) { byte[][] FinishedThreads = manager.Owner_GetFinishedThreads(sc, taskId); XmlStringWriter xsw = new XmlStringWriter(); xsw.Writer.WriteStartElement("task"); xsw.Writer.WriteAttributeString("id", taskId); for (int i = 0; i < FinishedThreads.Length; i++) { GJob job = (GJob)Utils.DeserializeFromByteArray(FinishedThreads[i]); xsw.Writer.WriteRaw("\n" + CrossPlatformHelper.XmlFromJob(job) + "\n"); logger.Debug("Writing thread:" + job.Id); } xsw.Writer.WriteEndElement(); // close job return(xsw.GetXmlString()); }
protected override string GetUserCountSqlQuery( SecurityCredentials sc ) { return String.Format( "select cast(count(*) as int4) as authenticated from usr where usr_name = '{0}' and password = '******'" , Utils.MakeSqlSafe( sc.Username ) , Utils.MakeSqlSafe( sc.Password ) ); }
/// <summary> /// Authenticate a user's security credentials /// </summary> /// <param name="sc">Security credentials to authenticate</param> /// <returns>True if the authentication is successful, false otherwise.</returns> public bool AuthenticateUser(SecurityCredentials sc) { if (sc == null || sc.Username == null || sc.Password == null) { return false; } object userCount = RunSqlReturnScalar( this.GetUserCountSqlQuery( sc ) ); return Convert.ToBoolean(userCount); }
public bool CheckPermission(SecurityCredentials sc, Permission perm) { if (sc == null) { return false; } UserStorageView user = null; IObjectContainer container = GetStorage(); int groupId = -1; try { IList<UserStorageView> users = container.Query<UserStorageView>(delegate(UserStorageView userFinder) { return String.Compare(userFinder.Username, sc.Username, true) == 0 && userFinder.PasswordMd5Hash == sc.Password; }); if (users.Count > 0) user = users[0]; if (user == null) return false; else groupId = user.GroupId; } finally { container.Close(); } foreach (Permission permission in GetGroupPermissions(groupId)) { // in the SQL implementation the higher leverl permissions are considered to // include the lower leverl permissions if ((int)permission >= (int)perm) { return true; } } return false; }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(DefaultErrorHandler); Console.WriteLine("\nAlchemi [.NET Grid Computing Framework]"); Console.WriteLine("http://www.alchemi.net\n"); Console.WriteLine("Job Submitter v{0}", Utils.AssemblyVersion); IManager manager; SecurityCredentials sc; if (args.Length < 4) { Usage(); return; } try { manager = (IManager) GNode.GetRemoteRef(new RemoteEndPoint(args[0], int.Parse(args[1]), RemotingMechanism.TcpBinary)); manager.PingManager(); sc = new SecurityCredentials(args[2], args[3]); manager.AuthenticateUser(sc); Console.Write("Connected to Manager at {0}:{1}\n", args[0], args[1]); } catch (Exception e) { Error("Could not connect to Manager", e); return; } Aliases aliases = Aliases.FromFile(Path.Combine(System.Windows.Forms.Application.StartupPath, "aliases.dat")); string[] cmd; bool interactive; if (args.Length > 4) { cmd = new string[args.Length - 4]; for (int i=0; i<args.Length - 4; i++) { cmd[i] = args[i+4]; } interactive = false; } else { cmd = new string[] {""}; interactive = true; } while (true) { if (interactive) { Console.Write("\n> "); string line = Console.ReadLine(); cmd = line.Split(); cmd[0] = cmd[0].ToLower(); } try { string appId; switch (cmd[0]) { case "st": case "submittask": // taskXmlFile string task = EmbedFiles(Utils.ReadStringFromFile(cmd[1])); appId = CrossPlatformHelper.CreateTask(manager, sc, task); string newAlias = aliases.NewAlias(appId); try { WriteLine("Task submitted (alias = {1}).", appId, newAlias); } catch { } break; case "gfj": case "getfinishedjobs": // alias, (directory, default=".") appId = (string) aliases.Table[cmd[1]]; string taskDir = cmd.Length > 2 ? cmd[2] : "."; string taskXml = CrossPlatformHelper.GetFinishedJobs(manager, sc, appId); XmlDocument fin = new XmlDocument(); fin.LoadXml(taskXml); WriteLine("Got {0} job(s).", fin.SelectNodes("task/job").Count); Console.WriteLine("Job XML: \n" + taskXml); foreach (XmlNode outputFileNode in fin.SelectNodes("task/job/output/embedded_file")) { //string jobDir = string.Format("{0}\\job_{1}", taskDir, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value); string jobDir = taskDir; if (!Directory.Exists(jobDir)) { Directory.CreateDirectory(jobDir); } //if (outputFileNode.InnerText != "") //{ string filePath = string.Format("{0}\\{1}", jobDir, outputFileNode.Attributes["name"].Value); Utils.WriteBase64EncodedToFile( filePath, outputFileNode.InnerText ); WriteLine("Wrote file {0} for job {1}.", filePath, outputFileNode.ParentNode.ParentNode.Attributes["id"].Value); // } } break; // TODO: (allow option to specify alias) case "ct": case "createtask": // no arguments appId = manager.Owner_CreateApplication(sc); WriteLine(appId); WriteLine("Task created (alias = {1}).", appId, aliases.NewAlias(appId)); break; case "aj": case "addjob": // alias, jobXml, jobId, (priority, default=0) appId = (string) aliases.Table[cmd[1]]; int priority = 0; if (cmd.Length > 4) { priority = int.Parse(cmd[4]); } CrossPlatformHelper.AddJob(manager, sc, appId, int.Parse(cmd[3]), priority, EmbedFiles(Utils.ReadStringFromFile(cmd[2]))); WriteLine("Job added."); break; /* case "listapps": // no arguments DataTable apps = manager.Owner_GetLiveApplicationList(null).Tables[0]; apps.Columns.Add("alias", typeof(string)); apps.Columns.Add("state_disp", typeof(string)); foreach (DataRow app in apps.Rows) { string alias = aliases.GetAlias(app["application_id"].ToString()); if (alias == "") { alias = aliases.NewAlias(app["application_id"].ToString()); } app["alias"] = alias; app["state_disp"] = Enum.Parse(typeof(ApplicationState), app["state"].ToString()).ToString(); } Console.WriteLine(ConsoleFormatter.FormatDataTable( apps, new string[] {"alias", "state_disp", "time_created"}, new string[] {"alias", "state", "time_created"} )); break; case "listthreads": // alias appId = (string) aliases.Table[cmd[1]]; DataTable threads = manager.Owner_GetThreadList(null, appId).Tables[0]; threads.Columns.Add("state_disp", typeof(string)); foreach (DataRow thread in threads.Rows) { thread["state_disp"] = Enum.Parse(typeof(ThreadState), thread["state"].ToString()); } Console.WriteLine(ConsoleFormatter.FormatDataTable( threads, new string[] {"thread_id", "state_disp", "time_started", "time_finished"}, new string[] {"thread_id", "state", "time_started", "time_finished"} )); break; case "getthreadstate": // alias, threadId appId = (string) aliases.Table[cmd[1]]; ThreadState state = manager.Owner_GetThreadState(null, new ThreadIdentifier(appId, int.Parse(cmd[2]))); WriteLine("State = {0}.", state); break; case "abortthread": // alias, threadId appId = (string) aliases.Table[cmd[1]]; manager.Owner_AbortThread(null, new ThreadIdentifier(appId, int.Parse(cmd[2]))); WriteLine("Thread aborted."); break; case "stoptask": // alias appId = (string) aliases.Table[cmd[1]]; manager.Owner_StopApplication(null, appId); WriteLine("Task stopped."); break; */ case "h": case "help": case "?": if (cmd.Length == 2) { Usage(cmd[1]); } else { Usage(); } break; case "quit": case "q": case "exit": case "x": return; default: Error("Unknown command '{0}'", cmd[0]); break; } } catch (Exception e) { Error("Incorrect syntax or parameter (" + e.Message.ToString() + ")"); } if (!interactive) { return; } } }
public bool CheckPermission(SecurityCredentials sc, Permission perm) { // get the user's groupId int groupId = -1; foreach(UserStorageView user in _users) { if(String.Compare(user.Username, sc.Username, true) == 0 && user.PasswordMd5Hash == sc.Password) { groupId = user.GroupId; break; } } if (groupId == -1) { return false; } foreach(Permission permission in GetGroupPermissions(groupId)) { // in the SQL implementation the higher leverl permissions are considered to // include the lower leverl permissions if ((int)permission >= (int)perm) { return true; } } return false; }
/// <summary> /// Creates an empty task on a Manager and returns its Id. /// </summary> /// <param name="manager"></param> /// <param name="sc">Security Credentials</param> /// <returns>application id</returns> public static string CreateTask(IManager manager, SecurityCredentials sc) { return(manager.Owner_CreateApplication(sc)); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Register a new executor with this manager /// </summary> /// <param name="sc">security credentials to verify if the executor has permission to perform this operation /// (i.e register executor, which is associated with the ExecuteThread permission)</param> /// <param name="info">executor information</param> /// <returns>the id of the executor registered</returns> public string Executor_RegisterNewExecutor(SecurityCredentials sc, string existingExecutorId, ExecutorInfo info) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ExecuteThread); //logger.Debug("Registering new executor"); return _Executors.RegisterNew(sc, existingExecutorId, info); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the state of the given thread. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e get thread state, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="ti">ThreadIdentifier of thread whose state is to be retrieved</param> /// <returns>state of the given thread</returns> public ThreadState Owner_GetThreadState(SecurityCredentials sc, ThreadIdentifier ti) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, ti.ApplicationId); logger.Debug("Getting state for thread: "+ti.ThreadId); return _Applications[ti.ApplicationId][ti.ThreadId].State; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Determines whether the manager has the application manifest for the given application id. /// </summary> /// <param name="sc">security credentials</param> /// <param name="appId">application id</param> /// <returns>whether the manager has the application manifest</returns> public bool Owner_HasApplicationManifest(SecurityCredentials sc, string appId) { // This method only returns whether an application has a manifest or not and should not require authentication or authorization. //AuthenticateUser(sc); //ApplicationAuthorizationCheck(sc, appId); logger.Debug("Checking application for manifest: " + appId); try { MApplication app = _Applications[appId]; return ((app != null) && (app.Manifest != null)); } catch { return false; } }
/// <summary> /// Gets the count of the finished threads. /// </summary> /// <param name="sc"></param> /// <param name="appId"></param> /// <returns>Number of threads finished</returns> public int Owner_GetFinishedThreadCount(SecurityCredentials sc, string appId) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, appId); //logger.Debug("Getting count of total finished threads for app: " + appId); int totCount = 0; //get the count of threads which have the state "dead" in the database //..i.e returned to owner after finishing or aborted. totCount = _Applications[appId].ThreadCount(ThreadState.Dead); return totCount; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the finished threads as a byte array. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e get finished threads, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="appId">id of the application whose completed threads need to be retrieved</param> /// <returns>2-D byte array representing all the finished threads in serialized form.</returns> public byte[][] Owner_GetFinishedThreads(SecurityCredentials sc, string appId) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, appId); //logger.Debug("getting finished thread for app:"+appId); return _Applications[appId].FinishedThreads; }
/// <summary> /// Delete group and all associated users. /// </summary> /// <param name="sc"></param> /// <param name="groupToDelete"></param> public void Admon_DeleteGroup(SecurityCredentials sc, GroupStorageView groupToDelete) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageUsers); logger.Debug(String.Format("Deleting group.", groupToDelete.GroupId)); ManagerStorageFactory.ManagerStorage().DeleteGroup(groupToDelete); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the exception that occured when the given thread was executing. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e get failed thread exception, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="ti">ThreadIdentifier of the failed thread</param> /// <returns></returns> public Exception Owner_GetFailedThreadException(SecurityCredentials sc, ThreadIdentifier ti) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, ti.ApplicationId); logger.Debug("Getting exception for thread:"+ti.ThreadId); return _Applications[ti.ApplicationId][ti.ThreadId].FailedThreadException; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the current state of the given application. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e GetApplicationState, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="appId">application id of the application whose state is to be queried</param> /// <returns>the state of the application</returns> public ApplicationState Owner_GetApplicationState(SecurityCredentials sc, string appId) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, appId); logger.Debug("Getting application state..."+appId); return _Applications[appId].State; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Creates a new application on the manager /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e CreateApplication, which is associated with the ManageOwnApp permission)</param> /// <returns></returns> public string Owner_CreateApplication(SecurityCredentials sc) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageOwnApp); logger.Debug("Creating new application..."); return _Applications.CreateNew(sc.Username); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Sets the manifest for the application, which consists for the input/output dependencies for this application. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e SetApplicationManifest, which is associated with the ManageOwnApp permission)</param> /// <param name="appId">application whose manifest needs to be set</param> /// <param name="manifest">the manifest to set</param> public void Owner_SetApplicationManifest(SecurityCredentials sc, string appId, FileDependencyCollection manifest) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, appId); logger.Debug("Setting manifest for application: "+appId); _Applications[appId].Manifest = manifest; }
public static string GetFailedThreadException(IManager manager, SecurityCredentials sc, ThreadIdentifier ti) { return(manager.Owner_GetFailedThreadException(sc, ti).ToString()); }
public void Owner_SetApplicationName(SecurityCredentials sc, string appId, String applicationName) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageOwnApp); logger.Debug("Creating new application..."); _Applications[appId].ApplicationName = applicationName; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Updates the heartbeat info of an executor /// </summary> /// <param name="sc">security credentials to verify if the executor has permission to perform this operation /// (i.e HeartBeat, which is associated with the ExecuteThread permission)</param> /// <param name="executorId">executor id</param> /// <param name="info">heartbeat info</param> public void Executor_Heartbeat(SecurityCredentials sc, string executorId, HeartbeatInfo info) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ExecuteThread); _Executors[executorId].HeartbeatUpdate(info); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Aborts the thread. This is called by the owner of the thread. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e abort thread, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="ti">ThreadIdentifier of the thread to abort</param> public void Owner_AbortThread(SecurityCredentials sc, ThreadIdentifier ti) { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, ti.ApplicationId); MThread thread = _Applications[ti.ApplicationId][ti.ThreadId]; logger.Debug("Owner called abort thread:"+ti.ThreadId); // if running on an executor, ask it to abort the thread if (thread.State != ThreadState.Dead && thread.State != ThreadState.Finished) { AbortThread(ti, thread.CurrentExecutorId); thread.State = ThreadState.Dead; } }
/// <summary> /// Creates a new instance of the GNode class /// </summary> /// <param name="managerEP">Manager end point</param> /// <param name="ownEP">Own end point</param> /// <param name="credentials">The credentials.</param> protected GNode(EndPoint managerEP, EndPoint ownEP, SecurityCredentials credentials) : this(managerEP, ownEP, credentials, DefaultRemoteObjectPrefix) { }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the status of the given job /// </summary> /// <param name="manager"></param> /// <param name="sc">security credentials used to perform this operation</param> /// <param name="taskId"></param> /// <param name="jobId"></param> /// <returns>job status</returns> public static int GetJobState(IManager manager, SecurityCredentials sc, string taskId, int jobId) { return(Convert.ToInt32(manager.Owner_GetThreadState(sc, new ThreadIdentifier(taskId, jobId)))); }
public bool AuthenticateUser(SecurityCredentials sc) { if (sc == null) { return false; } for(int index=0; index<_users.Count; index++) { UserStorageView user = (UserStorageView)_users[index]; if (user.Username == sc.Username && user.PasswordMd5Hash == sc.Password) { return true; } } return false; }
public UserStorageView[] GetGroupUsers(SecurityCredentials sc, Int32 groupId) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ManageUsers); logger.Debug(String.Format("Getting group {0} users.", groupId)); return ManagerStorageFactory.ManagerStorage().GetGroupUsers(groupId); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Gets the thread with the given identifier, as a byte array. /// This is called by a remote executor requesting a thread from the manager. /// </summary> /// <param name="sc">security credentials to verify if the executor has permission to perform this operation /// (i.e GetThread, which is associated with the ExecuteThread permission)</param> /// <param name="ti">ThreadIdentifier</param> /// <returns>A byte array representing the serialized thread</returns> public byte[] Executor_GetThread(SecurityCredentials sc, ThreadIdentifier ti) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ExecuteThread); byte[] retval; MThread t = _Applications[ti.ApplicationId][ti.ThreadId]; // TODO: hierarchical grids ignored until after v1.0.0 //if (_Applications[ti.ApplicationId].IsPrimary) //{ retval = t.Value; //} //else //{ // retval = Manager.Executor_GetThread(null, ti); //} t.State = ThreadState.Started; logger.Debug("set thread status to started. returning the byte array:"+ti.ThreadId); return retval; }
//----------------------------------------------------------------------------------------------- /// <summary> /// Sets the given thread to a finished state. /// This is called by a remote executor after completing execution of this thread. /// The thread may be successfully finished or failed. /// </summary> /// <param name="sc">security credentials to verify if the executor has permission to perform this operation /// (i.e SetFinishedThread, which is associated with the ExecuteThread permission)</param> /// <param name="ti">ThreadIdentifier</param> /// <param name="thread">the byte array representing the serialized thread</param> /// <param name="e">Any exception that may have occured during the execution of the thread</param> public void Executor_SetFinishedThread(SecurityCredentials sc, ThreadIdentifier ti, byte[] thread, Exception e) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ExecuteThread); MApplication app = _Applications[ti.ApplicationId]; MThread t = _Applications[ti.ApplicationId][ti.ThreadId]; if (app == null) { //invalid application id passed. normally this should not happen. throw new InvalidApplicationException("Invalid application id: "+ti.ApplicationId, null); } if (t == null) { //invalid thread id. this should normally not happen. throw new InvalidThreadException("Invalid thread id: "+ti.ApplicationId+":"+ti.ThreadId, null); } if (app.IsPrimary) { if (thread!=null) { try { t.Value = thread; } catch(Exception ex) { logger.Debug("Error saving thread to disk:"+ex.Message); //thread could not be saved to disk on the Manager //so set it as failed! //if e is not null, then let us get the exception which caused it to fail anyway. if (e==null) e = ex; } } if (e != null) { try { logger.Debug("thread failed. ti: " + ti.ThreadId + "," + e.Message); t.FailedThreadException = e; } catch (Exception ex) { logger.Debug("error saving thread-exception for failed thread to disk: threadId="+ti.ThreadId+", thread-fail-reason:" + e.Message, ex); } } else { logger.Debug("thread completed successfully. ti:"+ti.ThreadId ); } } else { // TODO: hierarchical grids ignored until after v1.0.0 //Manager.Executor_SetFinishedThread(null, ti, thread, e); } t.State = ThreadState.Finished; InternalShared.Instance.DedicatedSchedulerActive.Set(); logger.Debug("Set the thread ("+ti.ThreadId +") state to finished. And set the dedicatedSchedulerActive."); }
/// <summary> /// Check if a permisson is set. /// </summary> /// <param name="sc">Security credentials to use in the check.</param> /// <param name="perm">Permission to check for</param> /// <returns>true if the permission is set, false otherwise</returns> public bool CheckPermission(SecurityCredentials sc, Permission perm) { string query = String.Format("select count(*) as permitted from usr inner join grp on grp.grp_id = usr.grp_id inner join grp_prm on grp_prm.grp_id = grp.grp_id inner join prm on prm.prm_id = grp_prm.prm_id where usr.usr_name = '{0}' and prm.prm_id >= {1}", Utils.MakeSqlSafe(sc.Username), (int)perm); return Convert.ToBoolean(RunSqlReturnScalar(query)); }
public static void AbortTask(IManager manager, SecurityCredentials sc, string taskId) { manager.Owner_StopApplication(sc, taskId); }
/// <summary> /// Creates an instance of the GExecutor with the given end points /// (one for itself, and one for the manager), credentials and other options. /// </summary> /// <param name="managerEP">Manager end point</param> /// <param name="ownEP">Own end point</param> /// <param name="id">executor id</param> /// <param name="dedicated">Specifies whether the executor is dedicated</param> /// <param name="sc">Security credentials</param> /// <param name="baseDir">Working directory for the executor</param> public GExecutor(EndPoint managerEP, EndPoint ownEP, string id, bool dedicated, bool autoRevertToNDE, SecurityCredentials sc, string baseDir) : base(managerEP, ownEP, sc) { _AutoRevertToNDE = autoRevertToNDE; _Dedicated = dedicated; _Id = id; if (String.IsNullOrEmpty(_Id)) { logger.Info("Registering new executor"); _Id = Manager.Executor_RegisterNewExecutor(this.Credentials, null, this.Info); logger.Info("Successfully Registered new executor:" + _Id); } _GridAppDomains = new Dictionary<string, GridAppDomain>(); _ActiveWorkers = new Dictionary<ThreadIdentifier, ExecutorWorker>(); //handle exception since we want to connect to the manager //even if it doesnt succeed the first time. //that is, we need to handle InvalidExecutor and ConnectBack Exceptions. //WCF requires this to execute in another thread. Thread t = new Thread(new ThreadStart(DoConnectThread)); t.Start(); t.Join(); }
public static void AbortJob(IManager manager, SecurityCredentials sc, ThreadIdentifier ti) { manager.Owner_AbortThread(sc, ti); }
/// <summary> /// Creates a new instance of the GConnection class /// </summary> /// <param name="managerEP">manager end point</param> /// <param name="ownEP">own end point</param> /// <param name="credentials"></param> public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials) : this(managerEP, ownEP, credentials, DefaultRemoteObjectPrefix) { }
//----------------------------------------------------------------------------------------------- /// <summary> /// Clean up all application related files on the executors. /// </summary> /// <param name="sc">security credentials to verify if the owner has permission to perform this operation /// (i.e stop application, which is associated with the ManageOwnApp / ManageAllApps permission)</param> /// <param name="appid"></param> public void Owner_CleanupApplication(SecurityCredentials sc, string appid) { try { AuthenticateUser(sc); ApplicationAuthorizationCheck(sc, appid); ExecutorStorageView[] executorsStorage = _Executors.AvailableDedicatedExecutors; foreach (ExecutorStorageView executorStorage in executorsStorage) { try { string executorId = executorStorage.ExecutorId; MExecutor me = new MExecutor(executorId); //do it for dedicated ones only. if (me.RemoteRef!=null) me.RemoteRef.Manager_CleanupApplication(appid); } catch{} } logger.Debug("Cleaning up files on the manager for app: "+appid); string appDir = string.Format("{0}\\dat\\application_{1}", AppDomain.CurrentDomain.BaseDirectory, appid); logger.Debug("Deleting: " + appDir); Directory.Delete(appDir,true); logger.Debug("Clean up finished for app: "+appid); } catch (Exception e) { logger.Debug("Clean up app: " + appid + " error: " + e.Message ); } }
public static int GetApplicationState(IManager manager, SecurityCredentials sc, string taskId) { return(Convert.ToInt32(manager.Owner_GetApplicationState(sc, taskId))); }
//----------------------------------------------------------------------------------------------- /// <summary> /// Resets a thread which is executing. /// </summary> /// <param name="sc">security credentials to verify if the executor has permission to perform this operation /// (i.e RelinquishThread, which is associated with the ExecuteThread permission)</param> /// <param name="ti">ThreadIdentifier of the thread to relinquish</param> public void Executor_RelinquishThread(SecurityCredentials sc, ThreadIdentifier ti) { AuthenticateUser(sc); EnsurePermission(sc, Permission.ExecuteThread); new MThread(ti).Reset(); logger.Debug("Reset thread: "+ti.ThreadId); }