コード例 #1
0
        private void Update(string name, VersionedContainer <EnvironmentInfo> container)
        {
            if (isDisposed)
            {
                return;
            }

            try
            {
                var environmentPath = pathHelper.BuildEnvironmentPath(name);

                var environmentExists = zooKeeperClient.Exists(new ExistsRequest(environmentPath)
                {
                    Watcher = nodeWatcher
                });
                if (!environmentExists.IsSuccessful)
                {
                    return;
                }

                if (environmentExists.Stat == null)
                {
                    container.Clear();
                }
                else
                {
                    if (!container.NeedUpdate(environmentExists.Stat.ModifiedZxId))
                    {
                        return;
                    }

                    var environmentData = zooKeeperClient.GetData(new GetDataRequest(environmentPath)
                    {
                        Watcher = nodeWatcher
                    });
                    if (environmentData.Status == ZooKeeperStatus.NodeNotFound)
                    {
                        container.Clear();
                    }
                    if (!environmentData.IsSuccessful)
                    {
                        return;
                    }

                    var info = EnvironmentNodeDataSerializer.Deserialize(name, environmentData.Data);
                    container.Update(environmentData.Stat.ModifiedZxId, info);
                }
            }
            catch (Exception error)
            {
                log.Error(error, "Failed to update '{Environment}' environment.", name);
            }
        }
コード例 #2
0
        public void Update()
        {
            if (isDisposed)
            {
                return;
            }

            try
            {
                var applicationExists = zooKeeperClient.Exists(new ExistsRequest(applicationNodePath)
                {
                    Watcher = nodeWatcher
                });
                if (!applicationExists.IsSuccessful)
                {
                    return;
                }

                if (applicationExists.Stat == null)
                {
                    Clear();
                    return;
                }

                if (applicationContainer.NeedUpdate(applicationExists.Stat.ModifiedZxId))
                {
                    var applicationData = zooKeeperClient.GetData(new GetDataRequest(applicationNodePath)
                    {
                        Watcher = nodeWatcher
                    });
                    if (applicationData.Status == ZooKeeperStatus.NodeNotFound)
                    {
                        Clear();
                    }
                    if (!applicationData.IsSuccessful)
                    {
                        return;
                    }

                    var info = ApplicationNodeDataSerializer.Deserialize(environmentName, applicationName, applicationData.Data);
                    if (applicationContainer.Update(applicationData.Stat.ModifiedZxId, info))
                    {
                        UpdateServiceTopology();
                    }
                }

                if (replicasContainer.NeedUpdate(applicationExists.Stat.ModifiedChildrenZxId))
                {
                    var applicationChildren = zooKeeperClient.GetChildren(new GetChildrenRequest(applicationNodePath)
                    {
                        Watcher = nodeWatcher
                    });
                    if (applicationChildren.Status == ZooKeeperStatus.NodeNotFound)
                    {
                        Clear();
                    }
                    if (!applicationChildren.IsSuccessful)
                    {
                        return;
                    }

                    var replicas = UrlParser.Parse(applicationChildren.ChildrenNames.Select(pathHelper.Unescape));
                    if (replicasContainer.Update(applicationChildren.Stat.ModifiedChildrenZxId, replicas))
                    {
                        UpdateServiceTopology();
                    }
                }
            }
            catch (Exception error)
            {
                log.Error(error, "Failed to update '{Application} application in '{Environment}' environment.", applicationName, environmentName);
            }
        }