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 void Run(TaskRunContext task) { lock (task.Lock) { Log.Info("Running task " + task.ToString()); string resourceName = task.NodesConfig.First().ResourceName; if (task.NodesConfig.Any(node => node.ResourceName != resourceName)) { Log.Error("Node configs have different resources: " + String.Join(", ", task.NodesConfig.Select(c => c.ResourceName))); throw new ArgumentException("All node configs should have the same resource name"); } lock (_resourcesCacheLock) { if (!_resourcesCache.ContainsKey(resourceName)) { Log.Error("No controller for resource " + resourceName); throw new ArgumentException("No such resource controller"); } var unknownNodes = task.NodesConfig.Select(n => n.NodeName).Except(_nodeStateCache[resourceName].Select(n => n.NodeName)); if (unknownNodes.Any()) { Log.Error(String.Format( "Task {0} has unknown nodes for resource {1}: {2}", task.TaskId, resourceName, String.Join(", ", unknownNodes) )); throw new Exception("Wrong node config for task " + task.TaskId.ToString() + ": " + String.Join(", ", unknownNodes)); } task.Resource = _resourcesCache[resourceName]; task.Controller = _controllers[resourceName]; } // POSSIBLE DATA RACE?! if state is inside controller SubmitTask(task); lock (_tasksCacheLock) { _tasksCache.Add(task.TaskId, task); } } }