Example #1
0
        private async void ClearDownTimes()
        {
            bool confirmed = await JsRunTime.InvokeAsync <bool>("confirm", "Do you want to Remove Service Monitoring for the selected jobs?");

            if (confirmed)
            {
                result.JobId = string.Empty;
                foreach (var item in results.Where(i => i.IsJobSelected == true))
                {
                    item.ScheduledDownTime = null;
                    result.JobId          += item.JobId + ",";
                }
                result.JobId = result.JobId.TrimEnd(',');
                if (result.JobId == string.Empty)
                {
                    Toaster.Add("Please check the job(s) you want to clear.", MatToastType.Warning, "Warning", "⚠");
                }

                await ServiceManagerService.DeleteJobTimes(result);
                await GetData();

                GetStatus();
                ClearSelected();
                StartDate = DateTime.Now;
                EndDate   = DateTime.Now;
            }
            else
            {
                GetStatus();
            }
            StateHasChanged();
        }
Example #2
0
        public async Task StartsAndStopsServices()
        {
            // Arrange
            EnableServices();

            var serviceManagerService = new ServiceManagerService(
                _mockLog.Object,
                _mockServiceProvider.Object,
                _config.Object
                );

            // Act
            var task = serviceManagerService.StartServices();

            // Let it gracefully start services
            await Task.Delay(1000);

            // Record status
            var waitingForActivation = task.Status;

            // Gracefully stop services
            serviceManagerService.StopServices();

            // Assert

            // Let it finish its job
            // Check that services are stopped
            // If not done in 30 seconds, consider timeout
            Assert.Equal(await Task.WhenAny(task, Task.Delay(new TimeSpan(0, 0, 30))), task);

            Assert.Equal(TaskStatus.WaitingForActivation, waitingForActivation);

            _mockLog
            .Verify(
                log => log.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <FormattedLogValues>(
                        v => v
                        .ToString()
                        .Contains(
                            "All services stopped",
                            StringComparison.OrdinalIgnoreCase
                            )
                        ),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()
                    )
                );
        }
Example #3
0
        private async void SaveChanges()
        {
            if (StartDate <= EndDate)
            {
                bool confirmed = await JsRunTime.InvokeAsync <bool>("confirm", "Are you sure you want to make these changes?");

                if (confirmed)
                {
                    result.JobId = "";
                    foreach (var item in results.Where(i => i.IsJobSelected == true))
                    {
                        result.JobId          += item.JobId + ",";
                        item.ScheduledDownTime = StartDate.ToString() + " - " + EndDate.ToString();
                    }
                    result.JobId        = result.JobId.TrimEnd(',');
                    result.ServiceStart = StartDate.ToString();
                    result.ServiceStop  = EndDate.ToString();
                    await ServiceManagerService.UpdateJobStatuses(result);
                    await GetData();

                    StartDate = DateTime.Now;
                    EndDate   = DateTime.Now;
                }
                else
                {
                    GetStatus();
                    StartDate = DateTime.Now;
                    EndDate   = DateTime.Now;
                }
            }
            else
            {
                Toaster.Add("Start time must be less than end time.", MatToastType.Danger, "Warning", "⚠");
                GetStatus();
            }
            await GetData();

            GetStatus();
            StateHasChanged();
        }
Example #4
0
 private async Task GetData()
 {
     results = await ServiceManagerService.GetJobStatuses();
 }
Example #5
0
        public async Task RunsOnlyIfEnabled(ServiceManagerServices service)
        {
            // Arrange
            EnableServices(service);

            var serviceManagerService = new ServiceManagerService(
                _mockLog.Object,
                _mockServiceProvider.Object,
                _config.Object
                );

            // Act
            var task = serviceManagerService.StartServices();
            await Task.Delay(3000);

            serviceManagerService.StopServices();

            // Let it finish its job
            // Check that services are stopped
            // If not done in 30 seconds, consider timeout
            Assert.Equal(await Task.WhenAny(task, Task.Delay(new TimeSpan(0, 0, 30))), task);

            // Assert

            // Cache
            _mockCacheService.Verify(
                cache => cache.CacheMetricAsync(It.IsAny <Metric>()),
                service == ServiceManagerServices.Cache ? Times.AtLeastOnce() : Times.Never()
                );

            // Clean
            _mockCleanService.Verify(
                clean => clean.CleanDataPointsAsync(It.IsAny <TimeSpan?>()),
                service == ServiceManagerServices.Clean ? Times.AtLeastOnce() : Times.Never()
                );

            // Demo
            _mockDemoService.Verify(
                demo => demo.GenerateDemoDataAsync(
                    It.IsAny <Metrics>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>()
                    ),
                service == ServiceManagerServices.Demo ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDemoService.Verify(
                demo => demo.GenerateDemoLogAsync(It.IsAny <string>()),
                service == ServiceManagerServices.Demo ? Times.AtLeastOnce() : Times.Never()
                );

            // Health
            _mockHealthService.Verify(
                health => health.ProduceHealthReportAsync(),
                service == ServiceManagerServices.Health ? Times.AtLeastOnce() : Times.Never()
                );

            // Discrepancy
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindGapsAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindPingFailuresAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindHighLoadsAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.RecordDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindResolvedDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.ResolveDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );


            // Notification
            _mockNotificationService.Verify(
                notif => notif.ProcessNotificationQueueAsync(),
                service == ServiceManagerServices.Notification ? Times.AtLeastOnce() : Times.Never()
                );

            // Ping
            _mockPingService.Verify(
                ping => ping.PingServerAsync(It.IsAny <PingSetting>()),
                service == ServiceManagerServices.Ping ? Times.AtLeastOnce() : Times.Never()
                );

            // Verify run until completion
            _mockLog
            .Verify(
                log => log.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <FormattedLogValues>(
                        v => v
                        .ToString()
                        .Contains(
                            $"{service.ToString()} service run complete",
                            StringComparison.OrdinalIgnoreCase
                            )
                        ),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()
                    )
                );
        }