예제 #1
0
        protected void CreateApplicationNode(string environment, string application, IReadOnlyDictionary <string, string> properties = null)
        {
            var info = new ApplicationInfo(environment, application, properties);
            var data = ApplicationNodeDataSerializer.Serialize(info);

            var path = PathHelper.BuildApplicationPath(environment, application);

            CreateOrUpdate(path, data);
        }
예제 #2
0
        public async Task <IReadOnlyList <string> > GetAllReplicasAsync(string environment, string application)
        {
            var data = await zooKeeperClient.GetChildrenAsync(new GetChildrenRequest(pathHelper.BuildApplicationPath(environment, application))).ConfigureAwait(false);

            if (data.Status == ZooKeeperStatus.NodeNotFound)
            {
                return(new string[0]);
            }

            data.EnsureSuccess();
            return(data.ChildrenNames.Select(n => pathHelper.Unescape(n)).ToList());
        }
예제 #3
0
        public void Build_should_combine_with_prefix(string prefix)
        {
            var environment = "default";
            var application = "App.1";
            var replica     = "http://some-infra-host123:13528/";

            var path = new ServiceDiscoveryPathHelper(prefix, ZooKeeperPathEscaper.Instance);

            path.BuildEnvironmentPath(environment).Should().Be("/prefix/nested/default");
            path.BuildApplicationPath(environment, application).Should().Be("/prefix/nested/default/App.1");
            path.BuildReplicaPath(environment, application, replica).Should().Be("/prefix/nested/default/App.1/http%3A%2F%2Fsome-infra-host123%3A13528%2F");
        }
예제 #4
0
        internal ServiceBeacon(
            [NotNull] IZooKeeperClient zooKeeperClient,
            [NotNull] ReplicaInfo replicaInfo,
            [CanBeNull] ServiceBeaconSettings settings,
            [CanBeNull] ILog log)
        {
            this.zooKeeperClient = zooKeeperClient ?? throw new ArgumentNullException(nameof(settings));
            this.replicaInfo     = replicaInfo = replicaInfo ?? throw new ArgumentNullException(nameof(settings));
            this.settings        = settings ?? new ServiceBeaconSettings();
            this.log             = (log ?? LogProvider.Get()).ForContext <ServiceBeacon>();

            var pathHelper = new ServiceDiscoveryPathHelper(this.settings.ZooKeeperNodesPrefix, this.settings.ZooKeeperNodesPathEscaper);

            environmentNodePath = pathHelper.BuildEnvironmentPath(replicaInfo.Environment);
            applicationNodePath = pathHelper.BuildApplicationPath(replicaInfo.Environment, replicaInfo.Application);
            replicaNodePath     = pathHelper.BuildReplicaPath(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica);
            replicaNodeData     = ReplicaNodeDataSerializer.Serialize(replicaInfo);

            nodeWatcher = new AdHocNodeWatcher(OnNodeEvent);
        }
예제 #5
0
        public void TryParse_should_parse_replica_path(
            [Values(null, "prefix/node", "/prefix/node", "prefix/node/", "/prefix/node/")]
            string prefix,
            [Values("environment", "EEE/eee")] string environment,
            [Values("application", "AAA/aaa")] string application,
            [Values("replica", "RRR/rrr")] string replica)
        {
            var path = new ServiceDiscoveryPathHelper(prefix, ZooKeeperPathEscaper.Instance);

            path.TryParse(path.BuildEnvironmentPath(environment))
            .Should()
            .Be(((string environment, string application, string replica)?)(environment?.ToLowerInvariant(), null, null));

            path.TryParse(path.BuildApplicationPath(environment, application))
            .Should()
            .Be(((string environment, string application, string replica)?)(environment?.ToLowerInvariant(), application, null));

            path.TryParse(path.BuildReplicaPath(environment, application, replica))
            .Should()
            .Be(((string environment, string application, string replica)?)(environment?.ToLowerInvariant(), application, replica));
        }