Пример #1
0
 public EnvironmentsStorage(IZooKeeperClient zooKeeperClient, ServiceDiscoveryPathHelper pathHelper, ActionsQueue eventsHandler, ILog log)
 {
     this.zooKeeperClient = zooKeeperClient;
     this.pathHelper      = pathHelper;
     this.eventsHandler   = eventsHandler;
     this.log             = log;
     nodeWatcher          = new AdHocNodeWatcher(OnNodeEvent);
 }
Пример #2
0
        public ServiceDiscoveryManager(
            [NotNull] IZooKeeperClient zooKeeperClient,
            [CanBeNull] ServiceDiscoveryManagerSettings settings = null,
            [CanBeNull] ILog log = null)
        {
            this.zooKeeperClient = zooKeeperClient ?? throw new ArgumentNullException(nameof(zooKeeperClient));
            this.settings        = settings ?? new ServiceDiscoveryManagerSettings();
            this.log             = (log ?? LogProvider.Get()).ForContext <ServiceDiscoveryManager>();

            pathHelper = new ServiceDiscoveryPathHelper(this.settings.ZooKeeperNodesPrefix, this.settings.ZooKeeperNodesPathEscaper);
        }
Пример #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
        public ServiceLocator(
            [NotNull] IZooKeeperClient zooKeeperClient,
            [CanBeNull] ServiceLocatorSettings settings = null,
            [CanBeNull] ILog log = null)
        {
            this.zooKeeperClient = zooKeeperClient;
            this.settings        = settings ?? new ServiceLocatorSettings();
            this.log             = (log ?? LogProvider.Get()).ForContext <ServiceLocator>();

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

            eventsQueue         = new ActionsQueue(this.log);
            environmentsStorage = new EnvironmentsStorage(zooKeeperClient, pathHelper, eventsQueue, log);
            applicationsStorage = new ApplicationsStorage(zooKeeperClient, pathHelper, eventsQueue, log);
        }
Пример #5
0
        public void Should_use_default_replica_builder()
        {
            CreateEnvironmentNode("default");

            using (var beacon = new ServiceBeacon(ZooKeeperClient))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var builder = ReplicaInfoBuilder.Build(null, true);
                var path    = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                              .BuildReplicaPath(builder.Environment, builder.Application, builder.Replica);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize(builder.Environment, builder.Application, builder.Replica, data).Properties;

                dict[ReplicaInfoKeys.Application].Should().Be(builder.Application);
            }
        }
Пример #6
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);
        }
Пример #7
0
        public void Start_should_create_node_with_replica_properties()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            replica.SetProperty("key", "value");
            CreateEnvironmentNode(replica.Environment);

            using (var beacon = GetServiceBeacon(replica))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                           .BuildReplicaPath(replica.Environment, replica.Application, replica.Replica);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize(replica.Environment, replica.Application, replica.Replica, data).Properties;

                dict["key"].Should().Be("value");
            }
        }
        public ApplicationWithReplicas(
            string environmentName,
            string applicationName,
            string applicationNodePath,
            IZooKeeperClient zooKeeperClient,
            ServiceDiscoveryPathHelper pathHelper,
            ActionsQueue eventsQueue,
            ILog log)
        {
            this.environmentName     = environmentName;
            this.applicationName     = applicationName;
            this.applicationNodePath = applicationNodePath;
            this.zooKeeperClient     = zooKeeperClient;
            this.pathHelper          = pathHelper;
            this.eventsQueue         = eventsQueue;
            this.log = log;

            nodeWatcher          = new AdHocNodeWatcher(OnNodeEvent);
            applicationContainer = new VersionedContainer <ApplicationInfo>();
            replicasContainer    = new VersionedContainer <Uri[]>();
        }
Пример #9
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));
        }
Пример #10
0
        public void Should_use_replica_builder()
        {
            var url = "https://github.com/vostok";

            CreateEnvironmentNode("default");

            using (var beacon = new ServiceBeacon(
                       ZooKeeperClient,
                       setup => setup.SetUrl(new Uri(url)).SetApplication("test")))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                           .BuildReplicaPath("default", "test", url);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize("default", "test", url, data).Properties;

                dict[ReplicaInfoKeys.Replica].Should().Be(url);
                dict[ReplicaInfoKeys.Application].Should().Be("test");
            }
        }
Пример #11
0
        public void Unescape_should_unescape_escaped(string segment)
        {
            var pathHelper = new ServiceDiscoveryPathHelper("", ZooKeeperPathEscaper.Instance);

            pathHelper.Unescape(pathHelper.Escape(segment)).Should().Be(segment);
        }