public GetAutoBookVersionModel GetVersion() { string url = $"{_autoBook.Api}/version"; var webRequest = CreateHttpWebRequest(url, "GET", GetAuthHeaders(authType, _accessToken), string.Empty, null); var webResponse = (HttpWebResponse)webRequest.GetResponse(); ThrowExceptionIfNotSuccess(webResponse, new List <HttpStatusCode>() { HttpStatusCode.OK }); // Get response GetAutoBookVersionModel version = null; using (var reader = new StreamReader(webResponse.GetResponseStream())) { string data = reader.ReadToEnd().ToLower(); version = DeserializeContentBody <GetAutoBookVersionModel>(data); } return(version); }
/// <summary> /// Executes provisioning tests /// </summary> /// <returns></returns> private List <SystemTestResult> ExecuteProvisioningTests(List <AutoBook> autoBooks) { List <SystemTestResult> results = new List <SystemTestResult>(); using (var scope = _repositoryFactory.BeginRepositoryScope()) { var autoBookInstanceConfigurationRepository = scope.CreateRepository <IAutoBookInstanceConfigurationRepository>(); if (!_autoBooks.Settings.AutoProvisioning) // Auto-provisioning enabled { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Warning, _category, "Automatic AutoBook provisioning is disabled. AutoBooks must be managed manually. " + "Crashed AutoBooks will not be automatically restarted.", "")); } if (String.IsNullOrEmpty(_autoBooks.Settings.ApplicationVersion)) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Error, _category, "The AutoBook version is not set in the configuration. It is not possible to create AutoBook instances.", "")); } if (String.IsNullOrEmpty(_autoBooks.Settings.ProvisioningAPIURL)) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Error, _category, "The Provisioning API URL is not set in the configuration. It is not possible to create AutoBook instances.", "")); } if (_autoBooks.Settings.AutoProvisioning) { var autoBookInstanceConfigurations = autoBookInstanceConfigurationRepository.GetAll(); if (!autoBookInstanceConfigurations.Any()) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Error, _category, "There are no AutoBook instance configurations. It is not possible to create AutoBook instances.", "")); } if (_autoBooks.Settings.MinInstances > 0) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Warning, _category, string.Format("The minimum number of AutoBook instances is set to {0} but, for cost reasons, it is recommended to be zero so that " + "the instances are deleted when they are no longer needed.", _autoBooks.Settings.MinInstances), "")); } } // Warn if AutoBooks are running the wrong versions if (!_autoBooks.Settings.Locked && !String.IsNullOrEmpty(_autoBooks.Settings.ApplicationVersion)) // Do nothing if provisioning in progress { foreach (var autoBook in autoBooks) { IAutoBook autoBookInterface = _autoBooks.GetInterface(autoBook); try { GetAutoBookVersionModel getAutoBookVersionModel = autoBookInterface.GetVersion(); if (getAutoBookVersionModel.Version.ToUpper() != _autoBooks.Settings.ApplicationVersion.ToUpper()) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Warning, _category, string.Format("AutoBook {0} is running version {1} but the settings indicate that it should be running {2}. Please check that auto-provisioning is working.", autoBook.Id, getAutoBookVersionModel.Version, _autoBooks.Settings.ApplicationVersion), "")); } } catch { }; // Ignore error } } if (!_autoBooks.Settings.Locked) // Don't check if provisioning in progress { // Warn if insufficient AutoBooks if (_autoBooks.Settings.MinInstances > 0 && autoBooks.Count < _autoBooks.Settings.MinInstances) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Warning, _category, string.Format("The settings indicate a minimum of {0} AutoBooks but currently there are only {1} AutoBooks.", _autoBooks.Settings.MinInstances, autoBooks.Count), "")); } // Warn if too many AutoBooks if (_autoBooks.Settings.MaxInstances > 0 && autoBooks.Count > _autoBooks.Settings.MaxInstances) { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Warning, _category, string.Format("The settings indicate a maximum of {0} AutoBooks but currently there are {1} AutoBooks.", _autoBooks.Settings.MinInstances, autoBooks.Count), "")); } } // Test AutoBooks API. If we can't contact it then we can't provision AutoBooks try { bool testProvisioningResult = _autoBooks.TestProvisioning(); } catch { results.Add(new SystemTestResult(SystemTestResult.ResultTypes.Error, _category, "There was an error testing the AutoBooks API. It will prevent AutoBooks from being provisioned, unprovisioned or restarted.", "")); } } return(results); }