public async Task <ApplicationInstallResponse> InstallApplication(int activeWorkspaceId) { var response = new ApplicationInstallResponse { Success = false, // Assume failure until life proves rosy and beautiful Message = string.Empty }; // This service implementation cares about the version var executingVersion = Assembly.GetExecutingAssembly().GetName().Version; // workspaceId branching if (activeWorkspaceId > 0) { response.Message = $"Failed to see latest version installed. Current version: {executingVersion}"; // Workspace install // Setup a timeout for the install var installTimeout = this.timeService.GetUtcNow().AddSeconds(Defaults.Database.RoundHouseTimeout); // We're gonna read the latest version. Once the latest version matches the one we are, succeed. Else fail. do { var currentVersionInstalled = await this.versionCheckService.CurrentVersionIsInstalled(executingVersion); if (currentVersionInstalled) { response.Success = true; break; } this.timeService.Sleep(TimeSpan.FromSeconds(5)); }while (this.timeService.GetUtcNow() < installTimeout); } else { // Admin case -- install as normal response = await this.applicationInstallationService.InstallApplication(); if (!response.Success) { return(response); } // Update pdb version try { await this.versionCheckService.UpdateLatestVersion(executingVersion); } catch (Exception ex) { this.logger.LogError("Failed to update version.", ex); } } return(response); }
public async Task <ApplicationInstallResponse> RunEveryTimeAsync() { var response = new ApplicationInstallResponse { Success = false, Message = string.Empty }; var exceptionError = string.Empty; try { // Do a server refresh to make sure that server table is populated exceptionError = Messages.Exception.PostInstallServerRefreshFailure; var currentServers = this.refreshServerService.GetServerList(); if (currentServers.Any()) { this.refreshServerService.UpdateServerList(currentServers); } // Flag Deploy EDDSQoS to all database servers exceptionError = Messages.Exception.PostInstallUpdateServerQoSFailure; await this.serverRepository.UpdateActiveServersPendingQosDeploymentAsync(); // Re-enable all agents exceptionError = Messages.Exception.PostInstallAgentEnableFailure; await this.agentManagerService.StartPerformanceDashboardAgentsAsync(); // Read instance setting configuration and Create agents as needed exceptionError = Messages.Exception.PostInstallAgentCreateFailure; var configs = await this.configurationRepository.ReadEddsConfigurationInfoAsync(ConfigurationKeys.Section, ConfigurationKeys.CreateAgentsOnInstall); if (configs.Any()) { var machineName = configs.FirstOrDefault(c => string.IsNullOrWhiteSpace(c.MachineName) == false)?.MachineName; if (string.IsNullOrEmpty(machineName)) { this.logger.LogWarning(Messages.Warning.PostInstallAgentCreateWarning); } else { var createdAgentIds = await this.agentManagerService.CreatePerformanceDashboardAgents(machineName); } } } catch (Exception ex) { response.Message = string.Format(exceptionError, ex.ToString()); return(response); } response.Success = true; return(response); }
public void InstallRequirementsPreInstall_Execute_Fails() { // Arrange var expectedResponse = new ApplicationInstallResponse { Success = false, Message = "The thing failed" }; this.preInstallServiceMock.Setup(m => m.RunEveryTimeAsync()).ReturnsAsync(expectedResponse); // Act var response = this.eventHandler.Execute(); // Assert Assert.That(response.Success, Is.EqualTo(expectedResponse.Success)); Assert.That(response.Message, Is.EqualTo(expectedResponse.Message)); }
public void Integration_ExecuteEventHandler() { //Arrange var expectedResponse = new ApplicationInstallResponse { Success = true }; this.postInstallServiceMock.Setup(m => m.RunEveryTimeAsync()).ReturnsAsync(expectedResponse); //Act var response = this.eventHandler.Execute(); //Assert Assert.IsTrue(response.Success, response.Message); this.postInstallServiceMock.VerifyAll(); }
public async Task InstallApplication_AdminCase_InstallFailure() { // Arrange var response = new ApplicationInstallResponse { Success = false }; this.applicationInstallationServiceMock.Setup(m => m.InstallApplication()).ReturnsAsync(response).Verifiable(); // Act var result = await this.deploymentInstallationService.InstallApplication(-1); // Assert Assert.That(result.Success, Is.False); this.applicationInstallationServiceMock.VerifyAll(); this.versionCheckServiceMock.VerifyAll(); }
public async Task InstallApplication_AdminCase_Success() { // Arrange var response = new ApplicationInstallResponse { Success = true }; this.applicationInstallationServiceMock.Setup(m => m.InstallApplication()).ReturnsAsync(response).Verifiable(); this.versionCheckServiceMock.Setup(m => m.UpdateLatestVersion(It.IsAny <Version>())).Verifiable(); // Act var result = await this.deploymentInstallationService.InstallApplication(-1); // Assert Assert.That(result.Success, Is.True); this.applicationInstallationServiceMock.VerifyAll(); this.versionCheckServiceMock.VerifyAll(); }
public async Task InstallApplication_AdminCase_UpdateVersionException() { // Arrange var response = new ApplicationInstallResponse { Success = true }; this.applicationInstallationServiceMock.Setup(m => m.InstallApplication()).ReturnsAsync(response).Verifiable(); var exception = new Exception("Failed to update to latest version"); this.versionCheckServiceMock.Setup(m => m.UpdateLatestVersion(It.IsAny <Version>())).Throws(exception); // Act var result = await this.deploymentInstallationService.InstallApplication(-1); // Assert Assert.That(result.Success, Is.True); this.applicationInstallationServiceMock.VerifyAll(); this.versionCheckServiceMock.VerifyAll(); this.loggerMock.Verify(m => m.LogError(It.IsAny <string>(), exception, (string)null), Times.Once); }
public async Task <ApplicationInstallResponse> RunEveryTimeAsync() { var response = new ApplicationInstallResponse() { Success = false }; var exceptionMessage = string.Empty; try { // Disable Agents exceptionMessage = Messages.Exception.PreInstallEventHandlerFailure; await this.agentManagerService.StopPerformanceDashboardAgentsAsync(); } catch (Exception ex) { response.Message = string.Format(exceptionMessage, ex.ToString()); return(response); } response.Success = true; return(response); }
public async Task <ApplicationInstallResponse> InstallApplication() { var response = new ApplicationInstallResponse { Success = false, // Assume failure until life proves rosy and beautiful Message = string.Empty }; try { // Initialize using (var conn = (SqlConnection)this.connectionFactory.GetEddsConnection()) { // Upgrade pre-RH databases for RH compatibility await this.logger.LogVerboseAsync("Performing legacy EDDSPerformance upgrade if necessary..."); this.sqlRepository.UpgradeIfMissingRoundhouse(); var perfExists = this.sqlRepository.PerformanceExists(); if (perfExists) { var servers = this.sqlRepository.GetRegisteredSQLServers(); this.hashConverter.ConvertHashes(this.sqlRepository, servers); this.sqlRepository.DeploymentRepository.InsertRoundhouseTimeoutSettingIfNotExists(); } // log the current server we're deploying performance to await this.logger.LogVerboseAsync($"EDDSPerformance deploying to {conn.DataSource}"); // Migrate EDDSPerformance var results = this.databaseDeployer.DeployPerformance(conn.DataSource); if (!results.Success) { // Deployment of EDDSPerformance failed - stop here var errors = results.Messages .Where(m => m.Severity != LogSeverity.Debug && (!results.Success || m.Severity != LogSeverity.Info)) // Give us more detailed logs when this thing fails .Select(m => m.Message.ToString()); foreach (var error in errors) { this.logger.LogError(error); } response.Message = this.logger.Text; return(response); } // Create tabs await this.logger.LogVerboseAsync($"Deploying tabs"); this.tabService.CreateApplicationTabs(); await this.logger.LogVerboseAsync("Application installation complete"); // Logging everything that's happening with the install (text logger), last error message sent // Result Handler output to database? } } catch (Exception ex) { await this.logger.LogVerboseAsync($"Installation failed due to exception: {ex.Message}"); await this.logger.LogVerboseAsync($"Exception: {ex.ToString()}"); response.Message = this.logger.Text; return(response); } response.Message = this.logger.Text; response.Success = true; return(response); }