コード例 #1
0
        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);
            }
        }
コード例 #2
0
        ControllerFarmService()
        {
            bool loaded = false;

            //for (int retries = 0; !loaded && retries < 3; retries++)
            {
                try
                {
                    ReloadAllResources();
                    loaded = true;
                }
                catch (Exception e)
                {
                    Log.Error("Could not load resources on server start. Retying. " + e.ToString());
                    System.Threading.Thread.Sleep(200);
                }
            }

            System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (sender, e) =>
            {
                Log.Error("Exception in some TPL's task: " + e.ToString());
                e.SetObserved();
                //throw e.Exception;
            };

            //todo it was made for a mock creating task #1267
            if (CacheCollectorFactory.CheckMockMode())
            {
                CacheCollectorFactory.GetInstance().RunWithFarm(this);
            }
        }
コード例 #3
0
        public static void AddTask(TaskRunContext context, TaskStateInfo state)                                         //, TaskState state = TaskState.Started, string stateComment = "")
        {
            var taskCache = new TaskCache(context, state, CacheCollectorFactory.GetInstance().GetTaskCacheCollector()); // autosaves

            lock (_globalLock)
            {
                _cache[context.TaskId] = taskCache;
            }
        }
コード例 #4
0
        public Dictionary <string, Dictionary <string, List <NodeInfo> > > GetAllCacheableResourcesInfoStartedWith(DateTime date)
        {
            if (CacheCollectorFactory.CheckMockMode())
            {
                Common.Utility.LogInfo("Mock Mode enabled. nothing to return.");
                return(new Dictionary <string, Dictionary <string, List <NodeInfo> > >());
            }

            return(GetAllResourcesInfoStartWith(date));
        }
コード例 #5
0
ファイル: ResourceCache.cs プロジェクト: kbochenina/Kraken
        public static void ReloadResources(IEnumerable <Resource> resources)
        {
            lock (_globalLock)
            {
                while (_cache.Any())
                {
                    var elem = _cache.First();
                    lock (elem.Value.StateLock)
                    {
                        elem.Value.Save();
                        _cache.Remove(elem.Key);
                    }
                }

                var resourceNames = resources.Select(r => r.ResourceName);
                var nodeStates    = LoadStates(resourceNames);
                var gcCollector   = CacheCollectorFactory.GetInstance().GetResourceCacheCollector(resources);
                foreach (var resource in resources)
                {
                    var controller    = ControllerBuilder.Build(resource);
                    var resourceCache = new ResourceCache(resource, controller, gcCollector);

                    foreach (var node in resourceCache.NodeStateInfo)
                    {
                        var savedNodeState = nodeStates.FirstOrDefault(s => s.ResourceName == node.ResourceName && s.NodeName == node.NodeName);
                        if (savedNodeState != null)
                        {
                            node.ApplyState(savedNodeState);
                        }
                        else
                        {
                            node.State = NodeState.Busy; // to prevent node usage before actual state update, which is async
                        }
                    }

                    _cache[resource.ResourceName] = resourceCache;
                }

                /*
                 * //foreach (string name in resourceNames)
                 * PFX.Parallel.ForEach(resourceNames, (name) =>
                 * {
                 *  UpdateNodesState(name);
                 * });
                 */
            }
        }
コード例 #6
0
        public Dictionary <ulong, TaskStatInfo> GetAllCacheableTaskInfoStartedWith(DateTime date)
        {
            if (CacheCollectorFactory.CheckMockMode())
            {
                Common.Utility.LogInfo("Mock Mode enabled. nothing to return.");
                return(new Dictionary <ulong, TaskStatInfo>());
            }

            ulong[] ids = GetActiveTaskIds();
            Dictionary <ulong, TaskStatInfo> data = new Dictionary <ulong, TaskStatInfo>();

            //todo uncomment it later when rex will have been repaired
            return(data);

            foreach (var id in ids)
            {
                var statInfo = GetCacheableInfoForTask(id, date);
                if (statInfo != null)
                {
                    data.Add(id, statInfo);
                }
            }
            return(data);
        }