Merge pull request #202 from Azure/isaac/SimulationCheck

Check Simulation Status
This commit is contained in:
Isaac 2018-11-28 17:00:17 -08:00 коммит произвёл GitHub
Родитель c41ab0cfc6 45c65aec57
Коммит 398393f5f3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -75,7 +75,7 @@ namespace Microsoft.Azure.IoTSolutions.AsaManager.Services
var storageResult = await alarmsCosmosDb.PingAsync(); var storageResult = await alarmsCosmosDb.PingAsync();
SetServiceStatus("Storage", storageResult, result, errors); SetServiceStatus("Storage", storageResult, result, errors);
// Check access to Event // Check access to EventHub
var eventHubResult = await this.PingEventHubAsync(); var eventHubResult = await this.PingEventHubAsync();
SetServiceStatus("EventHub", eventHubResult, result, errors); SetServiceStatus("EventHub", eventHubResult, result, errors);

Просмотреть файл

@ -53,7 +53,10 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services
SetServiceStatus(deviceTelemetryName, deviceTelemetryResult, result, errors); SetServiceStatus(deviceTelemetryName, deviceTelemetryResult, result, errors);
// Check access to DeviceSimulation // Check access to DeviceSimulation
var deviceSimulationResult = await this.PingServiceAsync(
/* TODO: Remove PingSimulationAsync and use PingServiceAsync once DeviceSimulation has started
* using the new 'Status' model */
var deviceSimulationResult = await this.PingSimulationAsync(
deviceSimulationName, deviceSimulationName,
this.servicesConfig.DeviceSimulationApiUrl); this.servicesConfig.DeviceSimulationApiUrl);
SetServiceStatus(deviceSimulationName, deviceSimulationResult, result, errors); SetServiceStatus(deviceSimulationName, deviceSimulationResult, result, errors);
@ -125,6 +128,31 @@ namespace Microsoft.Azure.IoTSolutions.UIConfig.Services
return result; return result;
} }
private async Task<StatusResultServiceModel> PingSimulationAsync(string serviceName, string serviceURL)
{
var result = new StatusResultServiceModel(false, $"{serviceName} check failed");
try
{
var response = await this.httpClient.GetAsync(this.PrepareRequest($"{serviceURL}/status"));
if (!response.IsSuccessStatusCode)
{
result.Message = $"Status code: {response.StatusCode}; Response: {response.Content}";
}
else
{
var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(response.Content);
result.Message = data["Status"].ToString();
result.IsHealthy = data["Status"].ToString().StartsWith("OK:");
}
}
catch (Exception e)
{
this.log.Error(result.Message, () => new { e });
}
return result;
}
private HttpRequest PrepareRequest(string path) private HttpRequest PrepareRequest(string path)
{ {
var request = new HttpRequest(); var request = new HttpRequest();