public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, Database.NotificationCenter, ContextPool, Database.DatabaseShutdown))
                {
                    using (Database.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var alert in storedNotifications)
                        {
                            await writer.WriteToWebSocket(alert.Json);
                        }
                    }

                    foreach (var operation in Database.Operations.GetActive().OrderBy(x => x.Description.StartTime))
                    {
                        var action = OperationChanged.Create(Database.Name, operation.Id, operation.Description, operation.State, operation.Killable);

                        await writer.WriteToWebSocket(action.ToJson());
                    }
                    writer.AfterTrackActionsRegistration = ServerStore.NotifyAboutClusterTopologyAndConnectivityChanges;
                    await writer.WriteNotifications(null);
                }
            }
        }
Beispiel #2
0
        public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                var isValidFor = GetDatabaseAccessValidationFunc();
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.NotificationCenter, ServerStore.ContextPool, ServerStore.ServerShutdown))
                {
                    using (ServerStore.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var action in storedNotifications)
                        {
                            if (isValidFor != null)
                            {
                                if (action.Json.TryGet("Database", out string db) == false ||
                                    isValidFor(db) == false)
                                {
                                    continue; // not valid for this, skipping
                                }
                            }

                            await writer.WriteToWebSocket(action.Json);
                        }
                    }

                    foreach (var operation in ServerStore.Operations.GetActive().OrderBy(x => x.Description.StartTime))
                    {
                        var action = OperationChanged.Create(null, operation.Id, operation.Description, operation.State, operation.Killable);

                        await writer.WriteToWebSocket(action.ToJson());
                    }

                    await writer.WriteNotifications(isValidFor);
                }
            }
        }
Beispiel #3
0
        private void RaiseNotifications(OperationStatusChange change, Operation operation)
        {
            var operationChanged = OperationChanged.Create(_name, change.OperationId, operation.Description, change.State, operation.Killable);

            operation.NotifyCenter(operationChanged, x => _notificationCenter.Add(x));

            _changes?.RaiseNotifications(change);
        }
 private static List <Notification> CreateSampleNotificationsForFilterOutTest()
 {
     return(new List <Notification>
     {
         AlertRaised.Create(
             null,
             "DatabaseTopologyWarning",
             "DatabaseTopologyWarning_MSG",
             AlertType.DatabaseTopologyWarning,
             NotificationSeverity.Info),
         DatabaseChanged.Create(null, DatabaseChangeType.Put), // filtered out, DatabaseChange
         AlertRaised.Create(
             null,
             "LicenseManager_AGPL3",
             "LicenseManager_AGPL3_MSG",
             AlertType.ClusterTransactionFailure,
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "LicenseManager_AGPL3",
             "LicenseManager_AGPL3_MSG",
             AlertType.LicenseManager_AGPL3, // filtered out explicitly
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "RevisionsConfigurationNotValid",
             "RevisionsConfigurationNotValid_MSG",
             AlertType.RevisionsConfigurationNotValid, // filtered out explicitly
             NotificationSeverity.Info),
         AlertRaised.Create(
             null,
             "Certificates_ReplaceError",
             "Certificates_ReplaceError_MSG",
             AlertType.Certificates_ReplaceError,
             NotificationSeverity.Info),
         PerformanceHint.Create(
             null,
             "SlowIO",
             "SlowIO_MSG",
             PerformanceHintType.SlowIO, // filtered out, PerformanceHint
             NotificationSeverity.Info,
             "test"),
         PerformanceHint.Create(
             null,
             "SqlEtl_SlowSql",
             "SqlEtl_SlowSql_MSG",
             PerformanceHintType.SqlEtl_SlowSql, // filtered out, PerformanceHint
             NotificationSeverity.Info,
             "test"),
         OperationChanged.Create(null, 1, new Operations.OperationDescription(), new OperationState()
         {
             Result = new PersistableResult()
         }, false),
         DatabaseChanged.Create(null, DatabaseChangeType.Delete) // filtered out, DatabaseChange
     });
 }
Beispiel #5
0
        public void Should_persist_operation_if_result_requires_persistance()
        {
            using (var database = CreateDocumentDatabase())
            {
                database.NotificationCenter.Add(OperationChanged.Create(database.Name, 1, new Operations.OperationDescription(), new OperationState()
                {
                    Result = new PersistableResult()
                }, false));

                IEnumerable <NotificationTableValue> actions;
                using (database.NotificationCenter.GetStored(out actions))
                {
                    Assert.Equal(1, actions.Count());
                }
            }
        }