コード例 #1
0
        public async Task <IReplicaInfo> GetReplicaAsync(string environment, string application, string replica)
        {
            var data = await zooKeeperClient.GetDataAsync(new GetDataRequest(pathHelper.BuildReplicaPath(environment, application, replica))).ConfigureAwait(false);

            if (data.Status == ZooKeeperStatus.NodeNotFound)
            {
                return(null);
            }

            data.EnsureSuccess();
            var envData = ReplicaNodeDataSerializer.Deserialize(environment, application, replica, data.Data);

            return(envData);
        }
コード例 #2
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");
        }
コード例 #3
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);
        }
コード例 #4
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));
        }
コード例 #5
0
 protected void WaitReplicaRegistered(ReplicaInfo replica, bool expected = true)
 {
     WaitNodeExists(PathHelper.BuildReplicaPath(replica.Environment, replica.Application, replica.Replica), expected);
 }