public void SetState(TaskStateInfo newStateInfo) { lock (this.StateLock) { if (_stateInfo != null && _stateInfo.IsFinished()) { Log.Warn(String.Format("Tried to change state of finished task {0} to {1} ('{2}')", this.Context.TaskId, newStateInfo.State, newStateInfo.StateComment )); // ignoring changes for finished tasks } else { this._stateInfo = new TaskStateInfo(newStateInfo); this.Save(); if (newStateInfo.IsFinished()) // completed on this iteration { var resource = ResourceCache.GetByName(this.Context.Resource.ResourceName); resource.Release(this.Context.NodesConfig); // todo : import to Storage } } } }
public void Run(TaskRunContext task) { _resourcesLock.EnterReadLock(); try { Log.Info("Running task " + task.ToString()); string resourceName = task.NodesConfig.First().ResourceName; var resourceCache = ResourceCache.GetByName(resourceName); lock (resourceCache.StateLock) { CheckNodeConfigConsistency(task.TaskId, task.NodesConfig, resourceCache.Resource); task.Resource = resourceCache.Resource; task.Controller = resourceCache.Controller; } try { resourceCache.Acquire(task.NodesConfig); // todo : m.b. move under resourceCache.StateLock? Log.Info(String.Format("Trying to run task {0} on resource {1}", task.TaskId, task.Resource.ResourceName)); task.LocalId = task.Controller.Run(task); Log.Info(String.Format("Task {0} ({1}) started on resource {2} with localId = {3}", task.TaskId, task.PackageName, task.Resource.ResourceName, task.LocalId )); var state = new TaskStateInfo(TaskState.Started, task.LocalId.ToString()); TaskCache.AddTask(task, state); } catch (Exception e) { resourceCache.Release(task.NodesConfig); Log.Error(String.Format("Unable to run task {0}: {1}", task.TaskId, e)); throw; } } catch (Exception e) { Log.Error(String.Format("Exception on Farm.Run(task {0}): {1}", task.TaskId, e)); throw; } finally { _resourcesLock.ExitReadLock(); } //todo for mock if (CacheCollectorFactory.CheckMockMode()) { CacheCollectorFactory.GetInstance().SendTask(task); } }
public NodeStateInfo[] GetNodesState(string resourceName) { _resourcesLock.EnterReadLock(); try { ResourceCache.UpdateNodesState(resourceName); // todo : unify. TaskCache.UpdateState(id) OR task.UpdateState() var resourceCache = ResourceCache.GetByName(resourceName); lock (resourceCache.StateLock) { var nodesState = resourceCache.NodeStateInfo.Select(state => new NodeStateInfo(state)).ToArray(); return(nodesState); } } catch (Exception e) { Log.Error(String.Format("Error on getting resource '{0}' state info: {1}", resourceName, e)); throw; } finally { _resourcesLock.ExitReadLock(); } }
public void InstallPackage(InstallationTicket ticket) { Common.Utility.ExceptionablePlaceWrapper(() => { var resource = ResourceCache.GetByName(ticket.ResourceName); InstallationUtility.RouteToController(resource, ticket); }, "Error at installation start. TicketId: " + ticket.Id, "Installation start was successful. TicketId: " + ticket.Id); }
public static void RestoreTasks(IEnumerable <string> resourceNames) { //todo create instance of GCCollector lock (_globalLock) { Log.Info("Restoring tasks for resources: " + String.Join(", ", resourceNames)); var tasks = LoadTasks(resourceNames); foreach (var task in tasks) { _cache[task.Context.TaskId] = task; if (!task.StateInfo.IsFinished()) { var res = ResourceCache.GetByName(task.Context.Resource.ResourceName); res.Acquire(task.Context.NodesConfig); } } } }