public EndpointRegistryTests()
 {
     _monitorRegistry    = new Mock <IHealthMonitorRegistry>();
     _configurationStore = new Mock <IEndpointConfigurationStore>();
     _statsRepository    = new Mock <IEndpointStatsRepository>();
     _registry           = new EndpointRegistry(_monitorRegistry.Object, _configurationStore.Object, _statsRepository.Object);
 }
        public void RegisterEndpoint(IRabbitListenerEndpoint endpoint, IRabbitListenerContainerFactory factory)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            if (string.IsNullOrEmpty(endpoint.Id))
            {
                throw new InvalidOperationException("Endpoint id must be set");
            }

            if (StartImmediately && EndpointRegistry == null)
            {
                throw new InvalidOperationException("No registry available");
            }

            // Factory may be null, we defer the resolution right before actually creating the container
            var descriptor = new AmqpListenerEndpointDescriptor(endpoint, factory);

            lock (_endpointDescriptors)
            {
                if (StartImmediately)
                { // Register and start immediately
                    EndpointRegistry.RegisterListenerContainer(descriptor.Endpoint, ResolveContainerFactory(descriptor), true);
                }
                else
                {
                    _endpointDescriptors.Add(descriptor);
                }
            }
        }
 public EndpointRegistryTests()
 {
     _monitorRegistry = new Mock<IHealthMonitorRegistry>();
     _configurationStore = new Mock<IEndpointConfigurationStore>();
     _statsRepository=new Mock<IEndpointStatsRepository>();
     _registry = new EndpointRegistry(_monitorRegistry.Object, _configurationStore.Object,_statsRepository.Object);
 }
Exemplo n.º 4
0
        public void EndpointRegistry_should_keep_refuseUid_after_register_new_Endpoint()
        {
            var reg      = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);

            reg.RegisterWritableEndpoint(address1, actorA, null);
            reg.MarkAsQuarantined(address1, 42, deadline);
            reg.RefuseUid(address1).Should().Be(42);
            reg.IsQuarantined(address1, 42).Should().BeTrue();

            reg.UnregisterEndpoint(actorA);
            // Quarantined marker is kept so far
            var policy = reg.WritableEndpointWithPolicyFor(address1);

            policy.Should().BeOfType <EndpointManager.Quarantined>();
            policy.AsInstanceOf <EndpointManager.Quarantined>().Uid.Should().Be(42);
            policy.AsInstanceOf <EndpointManager.Quarantined>().Deadline.Should().Be(deadline);

            reg.RefuseUid(address1).Should().Be(42);
            reg.IsQuarantined(address1, 42).Should().BeTrue();

            reg.RegisterWritableEndpoint(address1, actorB, null);
            // Quarantined marker is gone
            var policy2 = reg.WritableEndpointWithPolicyFor(address1);

            policy2.Should().BeOfType <EndpointManager.Pass>();
            policy2.AsInstanceOf <EndpointManager.Pass>().Endpoint.Should().Be(actorB);
            // but we still have the refuseUid
            reg.RefuseUid(address1).Should().Be(42);
            reg.IsQuarantined(address1, 42).Should().BeTrue();
        }
Exemplo n.º 5
0
 public DiagramApiController(IProvideBreakdown[] breakdownProviders, EndpointRegistry endpointRegistry, EndpointInstanceActivityTracker activityTracker, MessageTypeRegistry messageTypeRegistry)
 {
     this.breakdownProviders  = breakdownProviders;
     this.endpointRegistry    = endpointRegistry;
     this.activityTracker     = activityTracker;
     this.messageTypeRegistry = messageTypeRegistry;
 }
Exemplo n.º 6
0
        public void MetricAggregationByInstanceIsScopedToLogicalEndpoint()
        {
            var processingTimeStore = new ProcessingTimeStore();
            var endpointRegistry    = new EndpointRegistry();

            var apiController = CreateConroller(processingTimeStore, endpointRegistry);

            var instanceAId = new EndpointInstanceId("EndpointA", "instance");
            var instanceBId = new EndpointInstanceId("EndpointB", "instance");

            endpointRegistry.Record(instanceAId);
            endpointRegistry.Record(instanceBId);

            var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory);
            var now    = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals));

            var dataA = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 5
            };
            var dataB = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 10
            };

            processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName));
            processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName));

            var result = apiController.GetSingleEndpointMetrics(instanceAId.EndpointName);

            var contentResult = result as OkNegotiatedContentResult <MonitoredEndpointDetails>;
            var model         = contentResult.Content;

            Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average);
        }
Exemplo n.º 7
0
        public new void Setup()
        {
            endpointRegistry    = new EndpointRegistry();
            criticalTimeStore   = new CriticalTimeStore();
            processingTimeStore = new ProcessingTimeStore();
            retriesStore        = new RetriesStore();
            queueLengthProvider = new FakeQueueLengthProvider();
            queueLengthStore    = new QueueLengthStore();
            queueLengthProvider.Initialize(string.Empty, (entryDtos, dto) => queueLengthStore.Store(entryDtos.Select(e => ToEntry(e)).ToArray(), ToEndpointInputQueue(dto)));

            var settings = new Settings {
                EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5)
            };

            activityTracker = new EndpointInstanceActivityTracker(settings);

            messageTypeRegistry = new MessageTypeRegistry();

            var breakdownProviders = new IProvideBreakdown[]
            {
                criticalTimeStore,
                processingTimeStore,
                retriesStore,
                queueLengthStore
            };

            var controller = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry)
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint")
            };

            GetMonitoredEndpoints      = () => controller.GetAllEndpointsMetrics();
            GetMonitoredSingleEndpoint = endpointName => controller.GetSingleEndpointMetrics(endpointName);
        }
 public EndpointRegistryTests()
 {
     _healthMonitorTypeRegistry = new Mock <IHealthMonitorTypeRegistry>();
     _configurationStore        = new Mock <IEndpointConfigurationRepository>();
     _statsRepository           = new Mock <IEndpointStatsRepository>();
     _registry = new EndpointRegistry(_healthMonitorTypeRegistry.Object, _configurationStore.Object, _statsRepository.Object, _statsManager.Object, _timeCoordinator.Object);
 }
Exemplo n.º 9
0
        public void EndpointRegistry_must_remove_readonly_endpoints_if_marked_as_failed()
        {
            var reg = new EndpointRegistry();

            reg.RegisterReadOnlyEndpoint(address1, actorA);
            reg.MarkAsFailed(actorA, Deadline.Now);
            Assert.Null(reg.ReadOnlyEndpointFor(address1));
        }
        public void EndpointRegistry_should_load_endpoints_from_store()
        {
            var endpoint = new Endpoint(Guid.NewGuid(), MonitorMock.Mock("monitor"), "address", "name", "group");
            _configurationStore.Setup(s => s.LoadEndpoints(_monitorRegistry.Object)).Returns(new[] { endpoint });

            var registry = new EndpointRegistry(_monitorRegistry.Object, _configurationStore.Object,_statsRepository.Object);

            Assert.Same(endpoint, registry.GetById(endpoint.Id));
        }
        public void EndpointRegistry_should_load_endpoints_from_repository()
        {
            var endpoint = new Endpoint(_timeCoordinator.Object, new EndpointIdentity(Guid.NewGuid(), "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow));
            _configurationStore.Setup(s => s.LoadEndpoints()).Returns(new[] { endpoint });

            var registry = new EndpointRegistry(_healthMonitorTypeRegistry.Object, _configurationStore.Object, _statsManager.Object, _timeCoordinator.Object);

            Assert.Same(endpoint, registry.GetById(endpoint.Identity.Id));
        }
        public void EndpointRegistry_should_load_endpoints_from_repository()
        {
            var endpoint = new Endpoint(_timeCoordinator.Object, new EndpointIdentity(Guid.NewGuid(), "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow));

            _configurationStore.Setup(s => s.LoadEndpoints()).Returns(new[] { endpoint });

            var registry = new EndpointRegistry(_healthMonitorTypeRegistry.Object, _configurationStore.Object, _statsManager.Object, _timeCoordinator.Object);

            Assert.Same(endpoint, registry.GetById(endpoint.Identity.Id));
        }
        public void EndpointRegistry_should_load_endpoints_from_store()
        {
            var endpoint = new Endpoint(Guid.NewGuid(), MonitorMock.Mock("monitor"), "address", "name", "group");

            _configurationStore.Setup(s => s.LoadEndpoints(_monitorRegistry.Object)).Returns(new[] { endpoint });

            var registry = new EndpointRegistry(_monitorRegistry.Object, _configurationStore.Object, _statsRepository.Object);

            Assert.Same(endpoint, registry.GetById(endpoint.Id));
        }
Exemplo n.º 14
0
 static MonitoredEndpointInstance[] GetMonitoredEndpointInstances(EndpointRegistry endpointRegistry, string endpointName, EndpointInstanceActivityTracker activityTracker)
 {
     return(endpointRegistry.GetForEndpointName(endpointName)
            .Select(endpointInstance => new MonitoredEndpointInstance
     {
         Id = endpointInstance.InstanceId,
         Name = endpointInstance.InstanceName,
         IsStale = activityTracker.IsStale(endpointInstance)
     }).ToArray());
 }
Exemplo n.º 15
0
 public void EndpointRegistry_must_be_able_to_register_Gated_policy_for_an_address()
 {
     var reg = new EndpointRegistry();
     Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
     reg.RegisterWritableEndpoint(address1, actorA);
     var deadline = Deadline.Now;
     reg.MarkAsFailed(actorA, deadline);
     Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Gated>().TimeOfRelease);
     Assert.False(reg.IsReadOnly(actorA));
     Assert.False(reg.IsWritable(actorA));
 }
Exemplo n.º 16
0
 static MonitoredEndpoint[] GetMonitoredEndpoints(EndpointRegistry endpointRegistry, EndpointInstanceActivityTracker activityTracker)
 {
     return(endpointRegistry.GetGroupedByEndpointName()
            .Select(endpoint => new MonitoredEndpoint
     {
         Name = endpoint.Key,
         EndpointInstanceIds = endpoint.Value.Select(i => i.InstanceId).ToArray(),
         IsStale = endpoint.Value.Any(activityTracker.IsStale)
     })
            .ToArray());
 }
Exemplo n.º 17
0
        public void EndpointRegistry_must_be_able_to_register_a_readonly_endpoint()
        {
            var reg = new EndpointRegistry();
            Assert.Null(reg.ReadOnlyEndpointFor(address1));

            Assert.Equal(actorA, reg.RegisterReadOnlyEndpoint(address1, actorA));
            Assert.Equal(actorA, reg.ReadOnlyEndpointFor(address1));
            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            Assert.False(reg.IsWritable(actorA));
            Assert.True(reg.IsReadOnly(actorA));
            Assert.False(reg.IsQuarantined(address1, 42));
        }
Exemplo n.º 18
0
        public void EndpointRegistry_should_be_able_to_register_Quarantined_policy_for_an_address()
        {
            var reg      = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            reg.MarkAsQuarantined(address1, 42, deadline);
            Assert.True(reg.IsQuarantined(address1, 42));
            Assert.False(reg.IsQuarantined(address1, 33));
            Assert.Equal(42, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Quarantined>().Uid);
            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Quarantined>().Deadline);
        }
Exemplo n.º 19
0
        public void Fix_1845_EndpointRegistry_should_override_ReadOnly_endpoint()
        {
            var reg      = new EndpointRegistry();
            var endpoint = TestActor;

            reg.RegisterReadOnlyEndpoint(address1, endpoint, 1);
            reg.RegisterReadOnlyEndpoint(address1, endpoint, 2);

            var ep = reg.ReadOnlyEndpointFor(address1);

            ep.Item1.ShouldBe(endpoint);
            ep.Item2.ShouldBe(2);
        }
Exemplo n.º 20
0
        public void EndpointRegistry_must_be_able_to_register_Gated_policy_for_an_address()
        {
            var reg = new EndpointRegistry();

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            reg.RegisterWritableEndpoint(address1, actorA);
            var deadline = Deadline.Now;

            reg.MarkAsFailed(actorA, deadline);
            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Gated>().TimeOfRelease);
            Assert.False(reg.IsReadOnly(actorA));
            Assert.False(reg.IsWritable(actorA));
        }
Exemplo n.º 21
0
        public void EndpointRegistry_must_be_able_to_register_a_readonly_endpoint()
        {
            var reg = new EndpointRegistry();

            Assert.Null(reg.ReadOnlyEndpointFor(address1));

            Assert.Equal(actorA, reg.RegisterReadOnlyEndpoint(address1, actorA));
            Assert.Equal(actorA, reg.ReadOnlyEndpointFor(address1));
            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            Assert.False(reg.IsWritable(actorA));
            Assert.True(reg.IsReadOnly(actorA));
            Assert.False(reg.IsQuarantined(address1, 42));
        }
Exemplo n.º 22
0
        public void EndpointRegistry_should_prune_outdated_Gated_directives_properly()
        {
            var reg = new EndpointRegistry();

            reg.RegisterWritableEndpoint(address1, actorA, null);
            reg.RegisterWritableEndpoint(address2, actorB, null);
            reg.MarkAsFailed(actorA, Deadline.Now);
            var farIntheFuture = Deadline.Now + TimeSpan.FromSeconds(60);

            reg.MarkAsFailed(actorB, farIntheFuture);
            reg.Prune();

            Assert.Equal(farIntheFuture, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf <EndpointManager.Gated>().TimeOfRelease);
        }
        public void When_known_endpoint_instance_changes_name_existing_entry_is_used_and_udpated()
        {
            var registry = new EndpointRegistry();

            var originalId = new EndpointInstanceId("LogicalName", "instance-id", "original-name");
            var renamedId  = new EndpointInstanceId(originalId.EndpointName, originalId.InstanceId, "renamed-name");

            registry.Record(originalId);
            registry.Record(renamedId);

            var records = registry.GetForEndpointName(originalId.EndpointName).ToArray();

            Assert.AreEqual(1, records.Length, "Existing entry should be reused");
            Assert.AreEqual("renamed-name", records[0].InstanceName);
        }
Exemplo n.º 24
0
        public void EndpointRegistry_should_overwrite_Quarantine_policy_with_Pass_on_RegisterWritableEndpoint()
        {
            var reg            = new EndpointRegistry();
            var deadline       = Deadline.Now + TimeSpan.FromMinutes(30);
            var quarantinedUid = 42;

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            reg.MarkAsQuarantined(address1, quarantinedUid, deadline);
            Assert.True(reg.IsQuarantined(address1, quarantinedUid));

            var writableUid = 43;

            reg.RegisterWritableEndpoint(address1, TestActor, writableUid);
            Assert.True(reg.IsWritable(TestActor));
        }
Exemplo n.º 25
0
        public void EndpointRegistry_should_not_report_endpoint_as_writable_if_no_Pass_policy()
        {
            var reg      = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);

            Assert.False(reg.IsWritable(TestActor)); // no policy

            reg.RegisterWritableEndpoint(address1, TestActor, 42);
            Assert.True(reg.IsWritable(TestActor));                // pass
            reg.MarkAsFailed(TestActor, deadline);
            Assert.False(reg.IsWritable(TestActor));               // Gated
            reg.RegisterWritableEndpoint(address1, TestActor, 43); // restarted
            Assert.True(reg.IsWritable(TestActor));                // pass
            reg.MarkAsQuarantined(address1, 43, deadline);
            Assert.False(reg.HasWritableEndpointFor(address1));    // Quarantined
        }
Exemplo n.º 26
0
        public void EndpointRegistry_must_be_able_to_register_a_writeable_endpoint_and_policy()
        {
            var reg = new EndpointRegistry();
            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));

            Assert.Equal(actorA, reg.RegisterWritableEndpoint(address1, actorA));

            Assert.IsType<EndpointManager.Pass>(reg.WritableEndpointWithPolicyFor(address1));
            Assert.Equal(actorA, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Pass>().Endpoint);

            Assert.Null(reg.ReadOnlyEndpointFor(address1));
            Assert.True(reg.IsWritable(actorA));
            Assert.False(reg.IsReadOnly(actorA));

            Assert.False(reg.IsQuarantined(address1, 42));
        }
Exemplo n.º 27
0
        public void EndpointRegistry_must_be_able_to_register_a_writeable_endpoint_and_policy()
        {
            var reg = new EndpointRegistry();

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));

            Assert.Equal(actorA, reg.RegisterWritableEndpoint(address1, actorA));

            Assert.IsType <EndpointManager.Pass>(reg.WritableEndpointWithPolicyFor(address1));
            Assert.Equal(actorA, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Pass>().Endpoint);

            Assert.Null(reg.ReadOnlyEndpointFor(address1));
            Assert.True(reg.IsWritable(actorA));
            Assert.False(reg.IsReadOnly(actorA));

            Assert.False(reg.IsQuarantined(address1, 42));
        }
        protected void RegisterAllEndpoints()
        {
            if (EndpointRegistry == null)
            {
                throw new InvalidOperationException("No registry available");
            }

            lock (_endpointDescriptors)
            {
                foreach (var descriptor in _endpointDescriptors)
                {
                    EndpointRegistry.RegisterListenerContainer(descriptor.Endpoint, ResolveContainerFactory(descriptor));
                }

                StartImmediately = true;  // trigger immediate startup
            }
        }
Exemplo n.º 29
0
        public void EndpointRegistry_should_overwrite_Gated_policy_with_Pass_on_RegisterWritableEndpoint()
        {
            var reg         = new EndpointRegistry();
            var deadline    = Deadline.Now + TimeSpan.FromMinutes(30);
            var willBeGated = 42;

            reg.RegisterWritableEndpoint(address1, TestActor, willBeGated);
            Assert.NotNull(reg.WritableEndpointWithPolicyFor(address1));
            Assert.True(reg.IsWritable(TestActor));
            reg.MarkAsFailed(TestActor, deadline);
            Assert.False(reg.IsWritable(TestActor));

            var writableUid = 43;

            reg.RegisterWritableEndpoint(address1, TestActor, writableUid);
            Assert.True(reg.IsWritable(TestActor));
        }
Exemplo n.º 30
0
        public void EndpointRegistry_must_be_able_to_register_writable_and_readonly_endpoint_correctly()
        {
            var reg = new EndpointRegistry();
            Assert.Null(reg.ReadOnlyEndpointFor(address1));
            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));

            Assert.Equal(actorA, reg.RegisterReadOnlyEndpoint(address1, actorA));
            Assert.Equal(actorB, reg.RegisterWritableEndpoint(address1, actorB));

            Assert.Equal(actorA, reg.ReadOnlyEndpointFor(address1));
            Assert.Equal(actorB, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Pass>().Endpoint);

            Assert.False(reg.IsWritable(actorA));
            Assert.True(reg.IsWritable(actorB));

            Assert.True(reg.IsReadOnly(actorA));
            Assert.False(reg.IsReadOnly(actorB));
        }
Exemplo n.º 31
0
        public void EndpointRegistry_must_keep_tombstones_when_removing_an_endpoint()
        {
            var reg = new EndpointRegistry();

            reg.RegisterWritableEndpoint(address1, actorA);
            reg.RegisterWritableEndpoint(address2, actorB);
            var deadline = Deadline.Now;

            reg.MarkAsFailed(actorA, deadline);
            reg.MarkAsQuarantined(address2, 42, deadline);

            reg.UnregisterEndpoint(actorA);
            reg.UnregisterEndpoint(actorB);

            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Gated>().TimeOfRelease);
            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf <EndpointManager.Quarantined>().Deadline);
            Assert.Equal(42, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf <EndpointManager.Quarantined>().Uid);
        }
Exemplo n.º 32
0
        public void EndpointRegistry_must_be_able_to_register_writable_and_readonly_endpoint_correctly()
        {
            var reg = new EndpointRegistry();

            Assert.Null(reg.ReadOnlyEndpointFor(address1));
            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));

            Assert.Equal(actorA, reg.RegisterReadOnlyEndpoint(address1, actorA));
            Assert.Equal(actorB, reg.RegisterWritableEndpoint(address1, actorB));

            Assert.Equal(actorA, reg.ReadOnlyEndpointFor(address1));
            Assert.Equal(actorB, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf <EndpointManager.Pass>().Endpoint);

            Assert.False(reg.IsWritable(actorA));
            Assert.True(reg.IsWritable(actorB));

            Assert.True(reg.IsReadOnly(actorA));
            Assert.False(reg.IsReadOnly(actorB));
        }
        public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            IPrincipal      principal = null;
            GenericIdentity identity;

            var credentials = context.ParseAuthorizationHeader();
            var adminCred   = CredentialsProvider.GetAdminCredentials();
            var pullCred    = CredentialsProvider.GetMonitorCredentials();

            if (credentials == null)
            {
                return(Task.FromResult(0));
            }

            if (credentials.Equals(adminCred))
            {
                identity  = new GenericIdentity(credentials.Id.ToString());
                principal = new GenericPrincipal(identity, new[] { SecurityRole.Admin.ToString() });
            }
            else if (credentials.Equals(pullCred))
            {
                identity  = new GenericIdentity(pullCred.Id.ToString());
                principal = new GenericPrincipal(identity, new[] { SecurityRole.Monitor.ToString() });
            }
            else
            {
                string encryptedPassword = credentials.Password.ToSha256Hash();
                var    endpoint          = EndpointRegistry.GetById(credentials.Id);

                if (endpoint?.Password == encryptedPassword)
                {
                    context.Request.Properties[_passwordKey] = encryptedPassword;
                    identity  = new GenericIdentity(credentials.Id.ToString());
                    principal = new GenericPrincipal(identity, null);
                }
            }

            context.Principal = principal;

            return(Task.FromResult(0));
        }
Exemplo n.º 34
0
        public void Setup()
        {
            endpointRegistry    = new EndpointRegistry();
            criticalTimeStore   = new CriticalTimeStore();
            processingTimeStore = new ProcessingTimeStore();
            retriesStore        = new RetriesStore();
            queueLengthProvider = new DefaultQueueLengthProvider();
            queueLengthStore    = new QueueLengthStore();
            queueLengthProvider.Initialize(string.Empty, queueLengthStore);

            var settings = new Settings {
                EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5)
            };

            activityTracker = new EndpointInstanceActivityTracker(settings);

            messageTypeRegistry = new MessageTypeRegistry();

            var breakdownProviders = new IProvideBreakdown[]
            {
                criticalTimeStore,
                processingTimeStore,
                retriesStore,
                queueLengthStore
            };

            var monitoredEndpointsModule = new MonitoredEndpointsModule(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry)
            {
                Context = new NancyContext()
                {
                    Request = new Request("Get", "/monitored-endpoints", "HTTP")
                }
            };

            var dictionary = monitoredEndpointsModule.Routes.ToDictionary(r => r.Description.Path, r => r.Action);

            GetMonitoredEndpoints      = () => dictionary["/monitored-endpoints"](new object(), new CancellationToken(false));
            GetMonitoredSingleEndpoint = endpointName => dictionary["/monitored-endpoints/{endpointName}"](new { EndpointName = endpointName }.ToDynamic(), new CancellationToken());
        }
        public void Setup()
        {
            settings = new Settings {
                EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5)
            };
            activityTracker     = new EndpointInstanceActivityTracker(settings);
            processingTimeStore = new ProcessingTimeStore();
            endpointRegistry    = new EndpointRegistry();

            var messageTypeRegistry = new MessageTypeRegistry();
            var breakdownProviders  = new IProvideBreakdown[]
            {
                processingTimeStore,
                new CriticalTimeStore(),
                new RetriesStore(),
                new QueueLengthStore()
            };

            apiController = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry)
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint")
            };
        }
Exemplo n.º 36
0
        public async Task MetricAggregationByInstanceIsScopedToLogicalEndpoint()
        {
            var processingTimeStore = new ProcessingTimeStore();
            var endpointRegistry    = new EndpointRegistry();

            var queryAction = CreateQuery(processingTimeStore, endpointRegistry);

            var instanceAId = new EndpointInstanceId("EndpointA", "instance");
            var instanceBId = new EndpointInstanceId("EndpointB", "instance");

            endpointRegistry.Record(instanceAId);
            endpointRegistry.Record(instanceBId);

            var period = HistoryPeriod.FromMinutes(MonitoredEndpointsModule.DefaultHistory);
            var now    = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals));

            var dataA = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 5
            };
            var dataB = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 10
            };

            processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName));
            processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName));

            var result = await queryAction(new
            {
                instanceAId.EndpointName
            }.ToDynamic(), new CancellationToken());

            var model = (MonitoredEndpointDetails)result.NegotiationContext.DefaultModel;


            Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average);
        }
Exemplo n.º 37
0
        public void EndpointRegistry_should_overwrite_Gated_policy_with_Pass_on_RegisterWritableEndpoint()
        {
            var reg = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);
            var willBeGated = 42;

            reg.RegisterWritableEndpoint(address1, TestActor, willBeGated, null);
            Assert.NotNull(reg.WritableEndpointWithPolicyFor(address1));
            Assert.True(reg.IsWritable(TestActor));
            reg.MarkAsFailed(TestActor, deadline);
            Assert.False(reg.IsWritable(TestActor));

            var writableUid = 43;
            reg.RegisterWritableEndpoint(address1, TestActor, writableUid, willBeGated);
            Assert.True(reg.IsWritable(TestActor));
        }
Exemplo n.º 38
0
        public void EndpointRegistry_should_overwrite_Quarantine_policy_with_Pass_on_RegisterWritableEndpoint()
        {
            var reg = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);
            var quarantinedUid = 42;

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            reg.MarkAsQuarantined(address1, quarantinedUid, deadline);
            Assert.True(reg.IsQuarantined(address1, quarantinedUid));

            var writableUid = 43;
            reg.RegisterWritableEndpoint(address1, TestActor, writableUid, quarantinedUid);
            Assert.True(reg.IsWritable(TestActor));
        }
Exemplo n.º 39
0
        public void Fix_1845_EndpointRegistry_should_override_ReadOnly_endpoint()
        {
            var reg = new EndpointRegistry();
            var endpoint = TestActor;
            reg.RegisterReadOnlyEndpoint(address1, endpoint, 1);
            reg.RegisterReadOnlyEndpoint(address1, endpoint, 2);

            var ep = reg.ReadOnlyEndpointFor(address1);
            ep.Item1.ShouldBe(endpoint);
            ep.Item2.ShouldBe(2);
        }
 public EndpointRegistryTests()
 {
     _healthMonitorTypeRegistry = new Mock<IHealthMonitorTypeRegistry>();
     _configurationStore = new Mock<IEndpointConfigurationRepository>();
     _registry = new EndpointRegistry(_healthMonitorTypeRegistry.Object, _configurationStore.Object, _statsManager.Object, _timeCoordinator.Object);
 }
Exemplo n.º 41
0
        void Initialize()
        {
            var endpointRegistry = new EndpointRegistry();
            var handlerRegistry = new HandlerRegistry();

            var messageTrees = CreateMessageTrees(messages).ToArray();
            var messagesInOrder = messageTrees.SelectMany(x => x.Walk()).ToArray();

            // NOTE: All sending endpoints are created first to ensure version info is retained
            foreach (var message in messagesInOrder)
            {
                endpointRegistry.Register(CreateSendingEndpoint(message));
            }

            foreach (var message in messagesInOrder)
            {
                endpointRegistry.Register(CreateProcessingEndpoint(message));
            }

            foreach (var message in messagesInOrder)
            {
                var sendingEndpoint = endpointRegistry.Get(CreateSendingEndpoint(message));
                if (!endpoints.Contains(sendingEndpoint))
                {
                    endpoints.Add(sendingEndpoint);
                }

                var processingEndpoint = endpointRegistry.Get(CreateProcessingEndpoint(message));
                if (!endpoints.Contains(processingEndpoint))
                {
                    endpoints.Add(processingEndpoint);
                }

                Handler sendingHandler;
                Handler processingHandler;

                if (handlerRegistry.TryRegisterHandler(CreateSendingHandler(message, sendingEndpoint), out sendingHandler))
                {
                    handlers.Add(sendingHandler);
                    sendingEndpoint.Handlers.Add(sendingHandler);
                }

                sendingHandler.UpdateProcessedAtGuess(message.TimeSent);

                if (handlerRegistry.TryRegisterHandler(CreateProcessingHandler(message, processingEndpoint), out processingHandler))
                {
                    handlers.Add(processingHandler);
                    processingEndpoint.Handlers.Add(processingHandler);
                }
                else
                {
                    UpdateProcessingHandler(processingHandler, message, processingEndpoint);
                }

                var arrow = CreateArrow(message);
                arrow.ToHandler = processingHandler;
                arrow.FromHandler = sendingHandler;

                var messageProcessingRoute = CreateRoute(arrow, processingHandler);
                arrow.MessageProcessingRoute = messageProcessingRoute;
                processingRoutes.Add(messageProcessingRoute);
                processingHandler.In = arrow;

                sendingHandler.Out = sendingHandler.Out.Concat(new[] { arrow }).OrderBy(a => a).ToList();
            }
        }
 public HealthMonitorTests()
 {
     _testableHealthMonitor = new TestableHealthMonitor();
     _endpointRegistry = new EndpointRegistry(new HealthMonitorRegistry(new[] { _testableHealthMonitor }), new Mock<IEndpointConfigurationStore>().Object);
 }
Exemplo n.º 43
0
        static DiagramApiController CreateConroller(ProcessingTimeStore processingTimeStore, EndpointRegistry endpointRegistry)
        {
            var criticalTimeStore = new CriticalTimeStore();
            var retriesStore      = new RetriesStore();
            var queueLengthStore  = new QueueLengthStore();

            var settings = new Settings
            {
                EndpointUptimeGracePeriod = TimeSpan.FromMinutes(5)
            };
            var activityTracker = new EndpointInstanceActivityTracker(settings);

            var messageTypeRegistry = new MessageTypeRegistry();

            var breakdownProviders = new IProvideBreakdown[]
            {
                processingTimeStore,
                criticalTimeStore,
                retriesStore,
                queueLengthStore
            };

            var controller = new DiagramApiController(breakdownProviders, endpointRegistry, activityTracker, messageTypeRegistry)
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/monitored-endpoint")
            };

            return(controller);
        }
Exemplo n.º 44
0
        public void EndpointRegistry_must_keep_tombstones_when_removing_an_endpoint()
        {
            var reg = new EndpointRegistry();
            reg.RegisterWritableEndpoint(address1, actorA);
            reg.RegisterWritableEndpoint(address2, actorB);
            var deadline = Deadline.Now;
            reg.MarkAsFailed(actorA, deadline);
            reg.MarkAsQuarantined(address2, 42, deadline);

            reg.UnregisterEndpoint(actorA);
            reg.UnregisterEndpoint(actorB);

            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Gated>().TimeOfRelease);
            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf<EndpointManager.Quarantined>().Deadline);
            Assert.Equal(42, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf<EndpointManager.Quarantined>().Uid);
        }
Exemplo n.º 45
0
 public void EndpointRegistry_must_remove_readonly_endpoints_if_marked_as_failed()
 {
     var reg = new EndpointRegistry();
     reg.RegisterReadOnlyEndpoint(address1, actorA);
     reg.MarkAsFailed(actorA, Deadline.Now);
     Assert.Null(reg.ReadOnlyEndpointFor(address1));
 }
Exemplo n.º 46
0
        public void EndpointRegister_should_not_report_endpoint_as_writeable_if_no_Pass_policy()
        {
            var reg = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);
            
            Assert.False(reg.IsWritable(TestActor)); // no policy

            reg.RegisterWritableEndpoint(address1, TestActor, 42, null);
            Assert.True(reg.IsWritable(TestActor)); // pass
            reg.MarkAsFailed(TestActor, deadline); 
            Assert.False(reg.IsWritable(TestActor)); // Gated
            reg.RegisterWritableEndpoint(address1, TestActor, 43, 42); // restarted
            Assert.True(reg.IsWritable(TestActor)); // pass
            reg.MarkAsQuarantined(address1, 43, deadline);
            Assert.False(reg.HasWriteableEndpointFor(address1)); // Quarantined
        }
Exemplo n.º 47
0
        public void EndpointRegistry_should_prune_outdated_Gated_directives_properly()
        {
            var reg = new EndpointRegistry();
            reg.RegisterWritableEndpoint(address1, actorA);
            reg.RegisterWritableEndpoint(address2, actorB);
            reg.MarkAsFailed(actorA, Deadline.Now);
            var farIntheFuture = Deadline.Now + TimeSpan.FromSeconds(60);
            reg.MarkAsFailed(actorB, farIntheFuture);
            reg.Prune();

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            Assert.Equal(farIntheFuture, reg.WritableEndpointWithPolicyFor(address2).AsInstanceOf<EndpointManager.Gated>().TimeOfRelease);
        }
Exemplo n.º 48
0
        public void EndpointRegistry_should_be_able_to_register_Quarantined_policy_for_an_address()
        {
            var reg = new EndpointRegistry();
            var deadline = Deadline.Now + TimeSpan.FromMinutes(30);

            Assert.Null(reg.WritableEndpointWithPolicyFor(address1));
            reg.MarkAsQuarantined(address1, 42, deadline);
            Assert.True(reg.IsQuarantined(address1, 42));
            Assert.False(reg.IsQuarantined(address1, 33));
            Assert.Equal(42, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Quarantined>().Uid);
            Assert.Equal(deadline, reg.WritableEndpointWithPolicyFor(address1).AsInstanceOf<EndpointManager.Quarantined>().Deadline);
        }