public StatusApiModel(StatusServiceModel model) { this.Status = new StatusResultApiModel(model.Status); this.Dependencies = new Dictionary <string, StatusResultApiModel>(); foreach (KeyValuePair <string, StatusResultServiceModel> pair in model.Dependencies) { this.Dependencies.Add(pair.Key, new StatusResultApiModel(pair.Value)); } this.Properties = model.Properties; }
public async Task <StatusServiceModel> GetStatusAsync(bool authRequired) { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); string storageAdapterName = "StorageAdapter"; string authName = "Auth"; // Check access to StorageAdapter var storageAdapterResult = await this.PingServiceAsync( storageAdapterName, this.servicesConfig.StorageAdapterApiUrl); SetServiceStatus(storageAdapterName, storageAdapterResult, result, errors); if (authRequired) { // Check access to Auth var authResult = await this.PingServiceAsync( authName, this.servicesConfig.UserManagementApiUrl); SetServiceStatus(authName, authResult, result, errors); result.Properties.Add("UserManagementApiUrl", this.servicesConfig?.UserManagementApiUrl); } // Preprovisioned IoT hub status var isHubPreprovisioned = this.IsHubConnectionStringConfigured(); if (isHubPreprovisioned) { var ioTHubResult = await this.devices.PingRegistryAsync(); SetServiceStatus("IoTHub", ioTHubResult, result, errors); } if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } result.Properties.Add("StorageAdapterApiUrl", this.servicesConfig?.StorageAdapterApiUrl); this.log.Info( "Service status request", () => new { Healthy = result.Status.IsHealthy, result.Status.Message }); return(result); }
private void SetServiceStatus( string dependencyName, StatusResultServiceModel serviceResult, StatusServiceModel result, List <string> errors) { if (!serviceResult.IsHealthy) { errors.Add(dependencyName + " check failed"); result.Status.IsHealthy = false; } result.Dependencies.Add(dependencyName, serviceResult); }
public async Task GetAsyncTest() { // Arrange StatusServiceModel statusServiceModel = new StatusServiceModel(true, "Is Alive"); this.statusServiceMock.Setup(x => x.GetStatusAsync()).Returns(Task.FromResult(statusServiceModel)); // Act var result = await this.controller.GetAsync(); // Assert Assert.True(result.Status.IsHealthy); Assert.Equal("0", result.Dependencies.Count.ToString()); }
public async Task GetAsyncTest() { // Arrange StatusServiceModel statusServiceModel = new StatusServiceModel(true, "Is Alive"); statusServiceModel.Dependencies.Add("Table Storage", new StatusResultServiceModel(true, "Is Alive")); statusServiceModel.Dependencies.Add("AzureB2C", new StatusResultServiceModel(true, "Is Alive")); this.statusServiceMock.Setup(x => x.GetStatusAsync()).Returns(Task.FromResult(statusServiceModel)); // Act var result = await this.controller.GetAsync(); // Assert Assert.True(result.Status.IsHealthy); Assert.Equal("2", result.Dependencies.Count.ToString()); foreach (StatusResultApiModel dependency in result.Dependencies.Values) { Assert.True(dependency.IsHealthy); } }
public async Task <StatusServiceModel> GetStatusAsync() { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); // TODO: Check connection to AAD this.log.Info( "Service status request", () => new { Healthy = result.Status.IsHealthy, result.Status.Message }); if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } return(result); }
public async Task <StatusServiceModel> GetStatusAsync() { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); // Loop over the IStatusOperation classes and get each status - set service status based on each response foreach (var dependency in this.Dependencies) { var service = dependency.Value; var serviceResult = await service.StatusAsync(); this.SetServiceStatus(dependency.Key, serviceResult, result, errors); } if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } result.Properties.AuthRequired = this.config.Global.AuthRequired; result.Properties.Endpoint = this.config.ASPNETCORE_URLS; return(result); }
public async Task <StatusServiceModel> GetStatusAsync() { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); string configName = "Config"; string deviceTelemetryName = "DeviceTelemetry"; string ioTHubManagerName = "IoTHubManager"; // Check access to Config var configResult = await this.PingServiceAsync(configName, this.servicesConfig.ConfigServiceUrl); SetServiceStatus(configName, configResult, result, errors); // Check access to Device Telemetry var deviceTelemetryResult = await this.PingServiceAsync( deviceTelemetryName, this.servicesConfig.DeviceTelemetryWebServiceUrl); SetServiceStatus(deviceTelemetryName, deviceTelemetryResult, result, errors); // Check access to IoTHubManager var ioTHubmanagerResult = await this.PingServiceAsync( ioTHubManagerName, this.servicesConfig.IotHubManagerServiceUrl); SetServiceStatus(ioTHubManagerName, ioTHubmanagerResult, result, errors); // Check access to Blob var blobResult = await this.blobStorageHelper.PingAsync(); SetServiceStatus("Blob", blobResult, result, errors); // Check access to Storage var alarmsCosmosDb = this.cosmosDbSql.Initialize(this.servicesConfig.AlarmsCosmosDbConfig); var storageResult = await alarmsCosmosDb.PingAsync(); SetServiceStatus("Storage", storageResult, result, errors); // Check access to EventHub //var eventHubResult = await this.PingEventHubAsync(); //SetServiceStatus("EventHub", eventHubResult, result, errors); // Add properties result.Properties.Add("ConfigServiceUrl", this.servicesConfig?.ConfigServiceUrl); result.Properties.Add("IotHubManagerServiceUrl", this.servicesConfig?.IotHubManagerServiceUrl); result.Properties.Add("TelemetryServiceUrl", this.servicesConfig?.DeviceTelemetryWebServiceUrl); result.Properties.Add("EventHubName", this.servicesConfig?.EventHubName); result.Properties.Add("MessagesStorageType", this.servicesConfig?.MessagesStorageType.ToString()); result.Properties.Add("AlarmsStorageType", this.servicesConfig?.AlarmsStorageType.ToString()); this.log.Info( "Service status request", () => new { Healthy = result.Status.IsHealthy, result.Status.Message }); if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } return(result); }
public async Task <StatusServiceModel> GetStatusAsync(bool authRequired) { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); var explorerUrl = string.Empty; string storageAdapterName = "StorageAdapter"; string storageName = "Storage"; string diagnosticsName = "Diagnostics"; string authName = "Auth"; string timeSeriesName = "TimeSeries"; string blobStorageName = "BlobStorage"; // Check access to StorageAdapter var storageAdapterResult = await this.PingServiceAsync( storageAdapterName, this.servicesConfig.StorageAdapterApiUrl); SetServiceStatus(storageAdapterName, storageAdapterResult, result, errors); // Check access to the BLOB storage var blobStorageResult = await this.blobStorageHelper.PingAsync(); SetServiceStatus(blobStorageName, blobStorageResult, result, errors); if (authRequired) { // Check access to Auth var authResult = await this.PingServiceAsync( authName, this.servicesConfig.UserManagementApiUrl); SetServiceStatus(authName, authResult, result, errors); result.Properties.Add("UserManagementApiUrl", this.servicesConfig?.UserManagementApiUrl); } // Check access to Diagnostics var diagnosticsResult = await this.PingServiceAsync( diagnosticsName, this.servicesConfig.DiagnosticsApiUrl); // Note: Overall simulation service status is independent of diagnostics service // Hence not using SetServiceStatus on diagnosticsResult result.Dependencies.Add(diagnosticsName, diagnosticsResult); // Add Time Series Dependencies if needed if (this.servicesConfig.StorageType.Equals( TIME_SERIES_KEY, StringComparison.OrdinalIgnoreCase)) { // Check connection to Time Series Insights var timeSeriesResult = await this.timeSeriesClient.PingAsync(); SetServiceStatus(timeSeriesName, timeSeriesResult, result, errors); // Add Time Series Insights explorer url var timeSeriesFqdn = this.servicesConfig.TimeSeriesFqdn; var environmentId = timeSeriesFqdn.Substring(0, timeSeriesFqdn.IndexOf(TIME_SERIES_EXPLORER_URL_SEPARATOR_CHAR)); explorerUrl = this.servicesConfig.TimeSeriesExplorerUrl + "?environmentId=" + environmentId + "&tid=" + this.servicesConfig.ActiveDirectoryTenant; result.Properties.Add(TIME_SERIES_EXPLORER_URL_KEY, explorerUrl); } // Check access to Storage var storageResult = await this.storageClient.PingAsync(); SetServiceStatus(storageName, storageResult, result, errors); if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } result.Properties.Add("DiagnosticsEndpointUrl", this.servicesConfig?.DiagnosticsApiUrl); result.Properties.Add("StorageAdapterApiUrl", this.servicesConfig?.StorageAdapterApiUrl); this.log.Info( "Service status request", () => new { Healthy = result.Status.IsHealthy, result.Status.Message }); return(result); }
public async Task <StatusServiceModel> GetStatusAsync() { var result = new StatusServiceModel(true, "Alive and well!"); var errors = new List <string>(); string storageAdapterName = "StorageAdapter"; string deviceTelemetryName = "DeviceTelemetry"; string deviceSimulationName = "DeviceSimulation"; string authName = "Auth"; // Check access to StorageAdapter var storageAdapterResult = await this.PingServiceAsync( storageAdapterName, this.servicesConfig.StorageAdapterApiUrl); SetServiceStatus(storageAdapterName, storageAdapterResult, result, errors); // Check access to Device Telemetry var deviceTelemetryResult = await this.PingServiceAsync( deviceTelemetryName, this.servicesConfig.TelemetryApiUrl); SetServiceStatus(deviceTelemetryName, deviceTelemetryResult, result, errors); // Check access to DeviceSimulation /* TODO: Remove PingSimulationAsync and use PingServiceAsync once DeviceSimulation has started * using the new 'Status' model */ var deviceSimulationResult = await this.PingSimulationAsync( deviceSimulationName, this.servicesConfig.DeviceSimulationApiUrl); SetServiceStatus(deviceSimulationName, deviceSimulationResult, result, errors); // Check access to Auth var authResult = await this.PingServiceAsync( authName, this.servicesConfig.UserManagementApiUrl); SetServiceStatus(authName, authResult, result, errors); // Add properties result.Properties.Add("DeviceSimulationApiUrl", this.servicesConfig?.DeviceSimulationApiUrl); result.Properties.Add("StorageAdapterApiUrl", this.servicesConfig?.StorageAdapterApiUrl); result.Properties.Add("UserManagementApiUrl", this.servicesConfig?.UserManagementApiUrl); result.Properties.Add("TelemetryApiUrl", this.servicesConfig?.TelemetryApiUrl); result.Properties.Add("SeedTemplate", this.servicesConfig?.SeedTemplate); result.Properties.Add("SolutionType", this.servicesConfig?.SolutionType); this.log.Info( "Service status request", () => new { Healthy = result.Status.IsHealthy, result.Status.Message }); if (errors.Count > 0) { result.Status.Message = string.Join("; ", errors); } return(result); }