Пример #1
0
        public void Start()
        {
            _subscriptions = new SubscriptionCollection(_messageBus);

            // On Core initialization, startup all necessary Stitches
            _subscriptions.Subscribe <CoreEvent>(b => b
                                                 .WithChannelName(CoreEvent.ChannelInitialized)
                                                 .Invoke(m => _service.StartRunningStitchesOnStartup())
                                                 .OnWorkerThread());

            // Upload package files
            _subscriptions.Listen <PackageFileUploadRequest, PackageFileUploadResponse>(l => l
                                                                                        .WithChannelName(PackageFileUploadRequest.ChannelLocal)
                                                                                        .Invoke(_service.UploadStitchPackageFile));
            _subscriptions.Listen <PackageFileUploadRequest, PackageFileUploadResponse>(l => l
                                                                                        .WithChannelName(PackageFileUploadRequest.ChannelFromRemote)
                                                                                        .Invoke(_service.UploadStitchPackageFileFromRemote));

            _subscriptions.Listen <LocalCreateInstanceRequest, LocalCreateInstanceResponse>(l => l
                                                                                            .OnDefaultChannel()
                                                                                            .Invoke(_service.CreateNewInstance));

            _subscriptions.Listen <InstanceRequest, InstanceResponse>(l => l
                                                                      .WithChannelName(InstanceRequest.ChannelClone)
                                                                      .Invoke(_service.CloneInstance));
            _subscriptions.Listen <InstanceRequest, InstanceResponse>(l => l
                                                                      .WithChannelName(InstanceRequest.ChannelStart)
                                                                      .Invoke(_service.StartInstance));
            _subscriptions.Listen <InstanceRequest, InstanceResponse>(l => l
                                                                      .WithChannelName(InstanceRequest.ChannelStop)
                                                                      .Invoke(_service.StopInstance));
            _subscriptions.Listen <InstanceRequest, InstanceResponse>(l => l
                                                                      .WithChannelName(InstanceRequest.ChannelDelete)
                                                                      .Invoke(_service.DeleteStitchInstance));

            _subscriptions.Listen <InstanceInformationRequest, List <InstanceInformation> >(l => l
                                                                                            .OnDefaultChannel()
                                                                                            .Invoke(m => _service.GetInstanceInformation()));
            _subscriptions.Listen <StitchResourceUsageRequest, StitchResourceUsage>(l => l
                                                                                    .OnDefaultChannel()
                                                                                    .Invoke(m => _service.GetInstanceResources(m.StitchInstanceId)));

            _subscriptions.Subscribe <StitchDataMessage>(b => b
                                                         .WithChannelName(StitchDataMessage.ChannelSendLocal)
                                                         .Invoke(_service.SendDataMessageToStitch)
                                                         .OnWorkerThread()
                                                         .WithFilter(m => !string.IsNullOrEmpty(m.ToStitchInstanceId)));
            _subscriptions.Subscribe <ObjectReceivedEvent <StitchDataMessage> >(b => b
                                                                                .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                                .Invoke(m => _service.SendDataMessageToStitch(m.Object)));

            _subscriptions.Subscribe <SendHeartbeatEvent>(b => b
                                                          .OnDefaultChannel()
                                                          .Invoke(m => _service.SendHeartbeat(m.HeartbeatId)));
        }
Пример #2
0
        public RequestExpectation <TRequest, TResponse> ExpectRequest <TRequest, TResponse>(string topic, Func <TRequest, bool> filter, string description)
        {
            var expectation = new RequestExpectation <TRequest, TResponse>(topic, description, filter);

            _expectations.Add(expectation);
            _subscriptions.Listen <TRequest, TResponse>(l => l
                                                        .WithTopic(topic)
                                                        .Invoke(r => expectation.TryHandle(r))
                                                        .Immediate()
                                                        .WithFilter(filter));
            return(expectation);
        }
Пример #3
0
 public void Start()
 {
     _subscriptions.Clear();
     _workerThreadId = _subscriptions.WorkerPool.StartDedicatedWorker().ThreadId;
     _subscriptions.Listen <DataRequest <StitchInstance>, DataResponse <StitchInstance> >(l => l
                                                                                          .WithDefaultTopic()
                                                                                          .Invoke(_service.HandleRequest)
                                                                                          .OnThread(_workerThreadId));
     _subscriptions.Listen <DataRequest <NodeStatus>, DataResponse <NodeStatus> >(l => l
                                                                                  .WithDefaultTopic()
                                                                                  .Invoke(_service.HandleRequest)
                                                                                  .OnThread(_workerThreadId));
     _subscriptions.Listen <DataRequest <CommandJob>, DataResponse <CommandJob> >(l => l
                                                                                  .WithDefaultTopic()
                                                                                  .Invoke(_service.HandleRequest)
                                                                                  .OnThread(_workerThreadId));
     _subscriptions.Listen <DataRequest <PackageFile>, DataResponse <PackageFile> >(l => l
                                                                                    .WithDefaultTopic()
                                                                                    .Invoke(_service.HandleRequest)
                                                                                    .OnThread(_workerThreadId));
 }
Пример #4
0
        public void Start()
        {
            _workerThreadId = _messageBus.ThreadPool.StartDedicatedWorker();

            _subscriptions = new SubscriptionCollection(_messageBus);

            _subscriptions.Listen <DataRequest <StitchInstance>, DataResponse <StitchInstance> >(l => l
                                                                                                 .OnDefaultChannel()
                                                                                                 .Invoke(_service.HandleRequest)
                                                                                                 .OnThread(_workerThreadId));
            _subscriptions.Listen <DataRequest <NodeStatus>, DataResponse <NodeStatus> >(l => l
                                                                                         .OnDefaultChannel()
                                                                                         .Invoke(_service.HandleRequest)
                                                                                         .OnThread(_workerThreadId));
            _subscriptions.Listen <DataRequest <CommandJob>, DataResponse <CommandJob> >(l => l
                                                                                         .OnDefaultChannel()
                                                                                         .Invoke(_service.HandleRequest)
                                                                                         .OnThread(_workerThreadId));
            _subscriptions.Listen <DataRequest <PackageFile>, DataResponse <PackageFile> >(l => l
                                                                                           .OnDefaultChannel()
                                                                                           .Invoke(_service.HandleRequest)
                                                                                           .OnThread(_workerThreadId));
        }
        public void SubscriptionCollection_CreateReport_Test()
        {
            var target = new SubscriptionCollection(new MessageBus());

            target.Subscribe <int>(b => b
                                   .WithTopic("test1")
                                   .Invoke(x => { }));
            target.Listen <int, string>(b => b
                                        .WithTopic("test2")
                                        .Invoke(x => "ok"));
            target.Participate <long, DateTime>(b => b
                                                .WithTopic("test3")
                                                .Invoke(x => DateTime.UtcNow));

            var report = target.ReportContents();

            report.Length.Should().Be(3);
        }
Пример #6
0
        public void Start()
        {
            _subscriptions = new SubscriptionCollection(_messageBus);

            int heartbeatTickMultiple = (_configuration.HeartbeatIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds;

            _subscriptions.TimerSubscribe(heartbeatTickMultiple, b => b
                                          .Invoke(e => _heartbeatService.SendScheduledHeartbeat()));

            int monitorTickMultiple = (_configuration.StitchMonitorIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds;

            _subscriptions.TimerSubscribe(monitorTickMultiple, b => b.Invoke(e => MonitorStitchStatus()));

            _subscriptions.Subscribe <StitchInstanceEvent>(b => b
                                                           .WithChannelName(StitchInstanceEvent.ChannelSynced)
                                                           .Invoke(_heartbeatService.StitchSyncReceived));

            _subscriptions.Listen <StitchHealthRequest, StitchHealthResponse>(l => l
                                                                              .OnDefaultChannel()
                                                                              .Invoke(_heartbeatService.GetStitchHealthReport));
        }
Пример #7
0
 public void Start()
 {
     _subscriptions.Listen <ModuleStatusRequest, ModuleStatusResponse>(l => l
                                                                       .WithDefaultTopic()
                                                                       .Invoke(GetModuleStatus));
 }
Пример #8
0
 public void Start()
 {
     _subscriptions.Listen <ModuleStatusRequest, ModuleStatusResponse>(l => l
                                                                       .OnDefaultChannel()
                                                                       .Invoke(GetModuleStatus));
 }
Пример #9
0
        public void Start()
        {
            _data.Initialize();
            _subscriptions = new SubscriptionCollection(_messageBus);
            _cacheThreadId = _messageBus.ThreadPool.StartDedicatedWorker();

            // On startup, publish the node status and get info from the backplane
            _subscriptions.Subscribe <CoreEvent>(b => b
                                                 .WithChannelName(CoreEvent.ChannelInitialized)
                                                 .Invoke(m => GenerateAndPublishNodeStatus()));
            _subscriptions.Subscribe <BackplaneEvent>(b => b
                                                      .WithChannelName(BackplaneEvent.ChannelNetworkIdChanged)
                                                      .Invoke(m => _service.SetNetworkNodeId(m.Data)));
            _subscriptions.Subscribe <BackplaneEvent>(b => b
                                                      .WithChannelName(BackplaneEvent.ChannelSetZones)
                                                      .Invoke(m => _service.SetClusterZones((m.Data ?? string.Empty).Split(','))));

            // Publish the status of the node every 60 seconds
            int timerTickMultiple = (_configuration.StatusBroadcastIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds;

            _subscriptions.TimerSubscribe(timerTickMultiple, b => b
                                          .Invoke(t => GenerateAndPublishNodeStatus())
                                          .OnWorkerThread());

            // TODO: Publish NodeStatus to cluster when Modules or StitchInstances change

            _subscriptions.Listen <StitchSummaryRequest, List <StitchSummary> >(b => b
                                                                                .OnDefaultChannel()
                                                                                .Invoke(_service.GetStitchSummaries));

            _subscriptions.Subscribe <ClusterMemberEvent>(b => b
                                                          .WithChannelName(ClusterMemberEvent.EnteringEvent)
                                                          .Invoke(SendNodeStatusToNewClusterNode));

            // Save node status from other nodes
            _subscriptions.Subscribe <ObjectReceivedEvent <NodeStatus> >(b => b
                                                                         .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                         .Invoke(m => _service.SaveNodeStatus(m.Object)));

            // Subscribe to events for caching stitch status
            _subscriptions.Subscribe <ObjectReceivedEvent <NodeStatus> >(b => b
                                                                         .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                         .Invoke(m => _data.StitchCache.AddNodeStatus(m, m.Object))
                                                                         .OnThread(_cacheThreadId));
            _subscriptions.Subscribe <StitchInstanceEvent>(b => b
                                                           .WithChannelName(StitchInstanceEvent.ChannelCreated)
                                                           .Invoke(_service.HandleLocalStitchCreated)
                                                           .OnThread(_cacheThreadId));
            _subscriptions.Subscribe <ObjectReceivedEvent <StitchInstanceEvent> >(b => b
                                                                                  .WithChannelName(ReceivedEvent.ReceivedEventName(StitchInstanceEvent.ChannelCreated))
                                                                                  .Invoke(m => _service.HandleRemoteStitchCreated(m, m.Object))
                                                                                  .OnThread(_cacheThreadId));
            _subscriptions.Subscribe <StitchInstanceEvent>(b => b
                                                           .WithChannelName(StitchInstanceEvent.ChannelDeleted)
                                                           .Invoke(_service.HandleLocalStitchDeleted)
                                                           .OnThread(_cacheThreadId));
            _subscriptions.Subscribe <ObjectReceivedEvent <StitchInstanceEvent> >(b => b
                                                                                  .WithChannelName(ReceivedEvent.ReceivedEventName(StitchInstanceEvent.ChannelDeleted))
                                                                                  .Invoke(m => _service.HandleRemoteStitchDeleted(m, m.Object))
                                                                                  .OnThread(_cacheThreadId));

            // TODO: On Stitch Started/Stopped we should publish notification to the cluster so other Master nodes can update their
            // caches.

            // Upload package files and distribute to all nodes
            _subscriptions.Listen <PackageFileUploadRequest, PackageFileUploadResponse>(l => l
                                                                                        .OnDefaultChannel()
                                                                                        .Invoke(UploadPackageFile));
            // Create new stitch instances
            _subscriptions.Listen <CreateInstanceRequest, CreateInstanceResponse>(l => l
                                                                                  .OnDefaultChannel()
                                                                                  .Invoke(_service.CreateNewInstances));
            _subscriptions.Subscribe <ObjectReceivedEvent <CreateInstanceRequest> >(b => b
                                                                                    .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                                    .Invoke(m => _service.CreateNewInstanceFromRemote(m, m.Object)));

            // Handle incoming commands
            _subscriptions.Listen <CommandRequest, CommandResponse>(b => b
                                                                    .OnDefaultChannel()
                                                                    .Invoke(_service.DispatchCommandRequest));
            _subscriptions.Subscribe <ObjectReceivedEvent <CommandRequest> >(b => b
                                                                             .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                             .Invoke(ore => _service.ReceiveCommandFromRemote(ore, ore.Object)));

            // Handle incoming command receipt messages
            _subscriptions.Subscribe <ObjectReceivedEvent <CommandReceipt> >(b => b
                                                                             .WithChannelName(ReceivedEvent.ChannelReceived)
                                                                             .Invoke(m => _service.ReceiveReceiptFromRemote(m, m.Object)));

            // Route StitchDataMessage to the correct node
            _subscriptions.Subscribe <StitchDataMessage>(b => b
                                                         .OnDefaultChannel()
                                                         .Invoke(_service.EnrichStitchDataMessageWithAddress));
        }