Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        public void ReloadAllResources(string dumpingKey = null)
        {
            PFX.Task.Factory.StartNew(() =>
            {
                _resourcesLock.EnterWriteLock(); // the only update (i.e. write) to resources

                try
                {
                    Log.Info("Reloading resources for controller");
                    Console.WriteLine("Reloading resources for controller");

                    TaskCache.DumpAllTasks();

                    var resourceBase = new ResourceBaseServiceClient();

                    try
                    {
                        string farmId = Config.AppSettings[FARMID_PARAM_NAME];

                        var resources = resourceBase.GetResourcesForFarm(farmId, dumpingKey); // waits all other dumps
                        resourceBase.Close();

                        string[] resourceNames = resources.Select(r => r.ResourceName).ToArray();
                        Log.Info("Resources to reload for farm " + farmId + ": " + String.Join(", ", resourceNames));

                        ResourceCache.ReloadResources(resources);
                        TaskCache.RestoreTasks(resourceNames);
                        //TaskCache.ReloadTasks(resourceNames);

                        PFX.Parallel.ForEach(resourceNames, (name) =>
                        {
                            ResourceCache.UpdateNodesState(name);
                        });

                        Log.Info("Resource reloading done for farm " + farmId);
                    }
                    catch (Exception e)
                    {
                        resourceBase.Abort();
                        Log.Error("Exception on reloading resources: " + e.ToString());
                        throw;
                    }
                }
                finally
                {
                    _resourcesLock.ExitWriteLock();
                }
            });
        }