Ejemplo n.º 1
0
        public void CollectClusterMetadata(IEnumerable<string> nodesAddresses)
        {
            Core.Server.Log.Debug("Collecting cluster metadata");

            if (nodesAddresses == null || nodesAddresses.Count() == 0)
                throw new BadConfigurationException("There are no addresses to get metadata from");

            List<ExtendedNodeInfo> nodesInfo = null;
            foreach (var address in nodesAddresses)
            {
                using (var proxy = new SafeInternalQueueServiceProxy(address))
                {
                    try
                    {
                        nodesInfo = proxy.GetExtendedMetadata();
                        if (nodesInfo != null)
                            break; //todo: it would be nice to check if all the data is the same
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
            if (nodesInfo == null || nodesInfo.Count == 0)
                throw new BadConfigurationException("No nodes were found in cluster");

            foreach (var nodeInfo in nodesInfo)
            {
                var node = ProxyHelper.TranslateNodeInfo(nodeInfo);
                if (!Core.Server.Configuration.Nodes.All.Contains(node))
                {
                    Core.Server.Log.Debug("Adding {1} at {0} to cluster", node.InternalAddress, nodeInfo.IsMaster ? "Master" : "Slave");
                    Core.Server.Configuration.Nodes.AddNewNode(node);
                }
            }

            ProxyHelper.EnsureNodesConfigurationIsValid();

            Core.Server.Log.Debug("Collecting cluster metadata has finished. Proxies are still not created");
        }
Ejemplo n.º 2
0
        public void StartBackgroundSync(ExtendedNodeInfo nodeInfo, Dictionary<string, int> aggregateVersions)
        {
            //todo MM: ensure single background task
            Task.Factory.StartNew(() =>
            {
                Dictionary<string, int> writtenVersions = aggregateVersions,
                                        currentVersions = AggregateRepository.Instance.GetLastVersions();

                using(var requester = new SafeInternalQueueServiceProxy(nodeInfo.InternalAddress))
                {
                    requester.Open();
                    while (!writtenVersions.AreEqualToVersions(currentVersions))
                    {
                        writtenVersions = DoSync(requester, aggregateVersions);
                        currentVersions = AggregateRepository.Instance.GetLastVersions();
                    }
                }

                OnSynchronizationFinished(nodeInfo, writtenVersions);
            });
        }
Ejemplo n.º 3
0
 public void CreateProxy()
 {
     if (Proxy != null)
         throw new InvalidOperationException("Proxy cannot be be created more than 1 time");
     if (!IsSelf)
         Proxy = new SafeInternalQueueServiceProxy(InternalAddress);
 }