Exemplo n.º 1
0
        // TODO: Need a mechanism to change zones, once we startup. We should be able to add/remove
        // zone membership at runtime (and preferrably, store those in the data module so we can
        // check that on startup and override the values in the config file)

        public void Start()
        {
            // Setup subscriptions
            _workerThreadId = _messageBus.ThreadPool.StartDedicatedWorker();
            _subscriptions  = new SubscriptionCollection(_messageBus);

            _subscriptions.Subscribe <ClusterMessage>(s => s
                                                      .WithChannelName(ClusterMessage.SendEventName)
                                                      .Invoke(e => _backplane.Send(e))
                                                      .OnThread(_workerThreadId));
            _subscriptions.Subscribe <CoreEvent>(b => b
                                                 .WithChannelName(CoreEvent.ChannelInitialized)
                                                 .Invoke(BroadcastNetworkInformation));
            _subscriptions.Subscribe <FileTransferRequest>(b => b
                                                           .OnDefaultChannel()
                                                           .Invoke(m => _backplane.TransferPackageFile(m.GroupName, m.NetworkNodeId, m.FilePath, m.FileName, m.Adaptor, m.JobId, m.TaskId)));

            // TODO: Listen to requests to get current network id, zones, etc.
            // TODO: Request to get info on known peers/zones?
            // TODO: Uptime/connected stats?

            var context = _backplane.Start();

            _nodeNetworkId = context.NodeNetworkId;
            _log.LogInformation("Joined cluster with NetworkNodeId={0}", _nodeNetworkId);
        }
Exemplo n.º 2
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)));
        }
Exemplo n.º 3
0
 public void Start()
 {
     _subscriptions = new SubscriptionCollection(_messageBus);
     _subscriptions.Subscribe <AlertEvent>(b => b
                                           .WithDefaultTopic()
                                           .Invoke(ReceiveAlert));
 }
Exemplo n.º 4
0
        public PublishExpectation <TPayload> ExpectPublish <TPayload>(string topic, Func <TPayload, bool> filter, string description)
        {
            var expectation = new PublishExpectation <TPayload>(topic, description, filter);

            _expectations.Add(expectation);
            _subscriptions.Subscribe <TPayload>(builder => builder
                                                .WithTopic(topic)
                                                .Invoke(p => expectation.TryReceive(p))
                                                .Immediate()
                                                .WithFilter(filter));
            return(expectation);
        }
Exemplo n.º 5
0
        public void Start()
        {
            _subscriptions = new SubscriptionCollection(_messageBus);

            _threadId = _messageBus.ThreadPool.StartDedicatedWorker();

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithChannelName(LogEvent.LevelDebug)
                                                .Invoke(l => _log.Debug(l.Message))
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithChannelName(LogEvent.LevelInformation)
                                                .Invoke(l => _log.Info(l.Message))
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithChannelName(LogEvent.LevelWarning)
                                                .Invoke(l => _log.Warn(l.Message))
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithChannelName(LogEvent.LevelError)
                                                .Invoke(l =>
            {
                if (l.Exception != null)
                {
                    _log.Error(l.Message, l.Exception);
                }
                else
                {
                    _log.Error(l.Message);
                }
            })
                                                .OnThread(_threadId));
        }
Exemplo n.º 6
0
        public void Start()
        {
            _subscriptions.Clear();
            _threadId = _subscriptions.WorkerPool.StartDedicatedWorker().ThreadId;
            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithTopic(LogEvent.LevelDebug)
                                                .Invoke(LogDebug)
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithTopic(LogEvent.LevelInformation)
                                                .Invoke(LogInformation)
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithTopic(LogEvent.LevelWarning)
                                                .Invoke(LogWarning)
                                                .OnThread(_threadId));

            _subscriptions.Subscribe <LogEvent>(b => b
                                                .WithTopic(LogEvent.LevelError)
                                                .Invoke(LogError)
                                                .OnThread(_threadId));
        }
        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);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 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));
        }