public async Task DeleteAsync(DeploymentRequest request) { await client.DeleteAsync(request); }
public Deployment GetDeployment(DeploymentRequest request) { return client.Get(request).Deployment; }
public void DeployTest() { var scriptDirectory = @"DeploymentScripts"; var fullPathToScripts = Path.Combine(ScriptBaseDirectory, scriptDirectory); WebApplicationDeploymentService service = new WebApplicationDeploymentService(fullPathToScripts, "deploy.ps1", "backup.ps1", 1000 * 60 * 120, "Jay", "", "4uze8ata"); Application application = new Application { Name = "Cosmo", ExcludeFiles = "*exclude*.* Web.config", ExcludeDirectories = "Log PDFs" }; DeploymentTarget target = new DeploymentTarget { BackupDirectory = Path.Combine(TestsBaseDirectory + @"\PROD", @"Backups"), TargetDirectory = @"C:\Users\Jay\Documents\Visual Studio 2010\Projects\WebDeployer\Tests\PRODwebserver\Cosmo", SourceDirectory = Path.Combine(TestsBaseDirectory + @"\PROD", @"Deploy"), Application = application, Name = "PROD" }; DeploymentRequest request = new DeploymentRequest { DeploymentTarget = target }; var result = service.Deploy(request); //Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); }
public void Delete(DeploymentRequest request) { client.Delete(request); }
public void Constructor_ReturnObjectWithIdSetToMinusOne() { var deploymentRequest = new DeploymentRequest(); Assert.AreEqual(-1, deploymentRequest.Id); }
public DeploymentResponse Create(DeploymentRequest request) { return((new CreateInfrastructureInteractor()).Execute(request)); }
private TestForAccessResult TestDirectoryAccess(DeploymentRequest request) { var target = request.DeploymentTarget; var requiredDirectories = new [] { target.SourceDirectory, target.TargetDirectory, target.BackupDirectory }; var deniedDirectories = new List<String>(); var canAccessAllRequiredDirectories = true; using (new Impersonator(this.userName, this.domain, this.password)) { foreach (var directory in requiredDirectories) { var isAccessGranted = DirectoryAccessChecker.CheckDirectoryAccess(directory); if (!isAccessGranted) { canAccessAllRequiredDirectories = false; deniedDirectories.Add(directory); } } } return new TestForAccessResult { CanAccessAllRequiredDirectories = canAccessAllRequiredDirectories, DeniedDirectories = deniedDirectories.ToArray() }; }
public DeploymentResult Deploy(DeploymentRequest request) { var log = new StringBuilder(); var errors = new StringBuilder(); var output = new StringBuilder(); var stopwatch = new Stopwatch(); stopwatch.Start(); log.AppendFormat("WebDeployer log --- {0} {1}\n\n", DateTime.Now.ToLongDateString(), DateTime.Now.ToShortTimeString()); log.AppendFormat("Deploying {0} to {1}\n\n", request.DeploymentTarget.Application.Name, request.DeploymentTarget.Name); var target = request.DeploymentTarget; // test username & password var isValidScriptExecutionAccount = TestUsernamePassword(); if (!isValidScriptExecutionAccount) { log.AppendFormat("ERROR: Failed to impersonate script account: '{0}'\n", this.userName); return new DeploymentResult { Success = false, Log = log.ToString(), }; } log.AppendLine("SUCCESS: Impersonated script account"); // test directory access var testDirectoryAccessResult = TestDirectoryAccess(request); if (!testDirectoryAccessResult.CanAccessAllRequiredDirectories) { log.AppendFormat("ERROR: Can not access all required directories for this deployment request: {0}\n", String.Join(", ", testDirectoryAccessResult.DeniedDirectories)); return new DeploymentResult { Success = false, Log = log.ToString(), }; } log.AppendLine("SUCCESS: Can access all required directories"); // backup target directory to backups directory log.AppendFormat("Backing up deployment target directory: {0} to {1}\n", target.TargetDirectory, target.BackupDirectory); var backupScriptResult = Backup(target); output.Append(backupScriptResult.StandardOutput); errors.Append(backupScriptResult.StandardError); if (errors.Length > 0 || backupScriptResult.ExecutedWithinTimeout == false || backupScriptResult.ExitCode >= 8) { log.AppendLine("ERROR: Could not back up target directory (robocopy exit code >= 8 or timeout exceeeded)"); return new DeploymentResult { Success = false, Log = log.ToString(), StandardError = errors.ToString(), StandardOutput = output.ToString() }; } // deploy application log.AppendFormat("Copying web application to IIS: {0} to {1}\n", target.SourceDirectory, target.TargetDirectory); var scriptCommand = String.Format(@".\{0} -source '{1}' -target '{2}'", this.deploymentScriptName, target.SourceDirectory, target.TargetDirectory); if (!String.IsNullOrEmpty(target.Application.ExcludeFiles)) { scriptCommand += String.Format(" -excludefiles '{0}'", target.Application.ExcludeFiles); } if (!String.IsNullOrEmpty(target.Application.ExcludeDirectories)) { scriptCommand += String.Format(" -excludedirectories '{0}'", target.Application.ExcludeDirectories); } log.AppendFormat("Script command: {0}\n", scriptCommand); var deploymentScriptResult = this.scriptRunner.RunScript(this.userName, this.password, this.domain, scriptCommand, this.scriptWorkingDirectory, this.timeoutMilliseconds); output.Append(deploymentScriptResult.StandardOutput); errors.Append(deploymentScriptResult.StandardError); if (errors.Length > 0 || backupScriptResult.ExecutedWithinTimeout == false || backupScriptResult.ExitCode >= 8) { log.AppendLine("ERROR: Could not deploy web application to IIS (robocopy exit code >= 8 or timeout exceeeded)"); return new DeploymentResult { Success = false, Log = log.ToString(), StandardError = errors.ToString(), StandardOutput = output.ToString() }; } stopwatch.Stop(); log.AppendFormat("SUCCESS: Successfully deployed application. Elapsed seconds: {0}", stopwatch.Elapsed.TotalSeconds); var result = new DeploymentResult { Success = true, Log = log.ToString(), StandardOutput = output.ToString(), StandardError = errors.ToString(), Elapsed = stopwatch.Elapsed, ExitCode = deploymentScriptResult.ExitCode, }; File.WriteAllText(Path.Combine(target.TargetDirectory, @"deployment-output.log"), result.StandardOutput); return result; }
/// <summary> /// Create a new deployment /// </summary> /// <param name="bearerToken">Azure bearer token</param> /// <param name="subscription">Subscription for authorization (NULL for Tenant scope)</param> /// <param name="resourceGroupName">Name of the resource group the plan is homed in (NULL for Subscription scope)</param> /// <param name="deploymentName">A name for the deployment</param> /// <param name="request">Properties of the request</param> /// <param name="dataStorageLocation">If the deployment happens at tenant or subscription level, the geolocation where the deployment data is to stored</param> /// <returns>Response. NULL if there was a failure</returns> public static async Task <DeploymentResponse?> CreateDeployment(string bearerToken, Guid?subscription, string?resourceGroupName, string deploymentName, DeploymentRequestProperties request, string?dataStorageLocation = null) { if (string.IsNullOrWhiteSpace(bearerToken)) { throw new ArgumentNullException(nameof(bearerToken)); } if (string.IsNullOrWhiteSpace(deploymentName)) { throw new ArgumentNullException(nameof(deploymentName)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if ((subscription == null) || (subscription == Guid.Empty)) { // tenant scope resourceGroupName = null; } if (string.IsNullOrWhiteSpace(resourceGroupName) && string.IsNullOrWhiteSpace(dataStorageLocation)) { throw new ArgumentNullException($"When {nameof(resourceGroupName)} is null/empty, {nameof(dataStorageLocation)} must be provided."); } StringBuilder uri = new StringBuilder(); uri.Append("https://management.azure.com"); if (subscription.HasValue) { uri.Append("/subscriptions/").Append(subscription.Value.ToString("d")); if (resourceGroupName != null) { uri.Append("/resourceGroups/").Append(resourceGroupName); } } uri.Append("/providers/Microsoft.Resources/deployments/").Append(deploymentName); DeploymentRequest deploymentRequest = new DeploymentRequest() { Properties = request }; if (string.IsNullOrWhiteSpace(resourceGroupName)) { deploymentRequest.Location = dataStorageLocation; } tryAgain: RestApiResponse response = await RestApiClient.PUT( bearerToken, uri.ToString(), CLIENT_API_VERSION, (string.IsNullOrWhiteSpace(resourceGroupName) ? new Dictionary <string, string>() { { "location", dataStorageLocation ! } }
public async Task <DeploymentValidateResult> Validate4x4MSIoTSolutionUsingAzureRMTemplate(DeploymentRequest depReq, string token) { try { var credential = new TokenCredentials(token); var resourceManagementClient = new ResourceManagementClient(credential) { SubscriptionId = depReq.SubscriptionId }; // generates a parameter json required for ARM template deployment var parameterTemplateJson = Get4x4TemplateParameterJson(depReq); var deployment = new Deployment(); deployment.Properties = new DeploymentProperties { Mode = DeploymentMode.Incremental, TemplateLink = new TemplateLink(_armTemplateUrl), Parameters = parameterTemplateJson }; // This is for unit testing and validating the ARM template to be deployed var deploymentOutput = await resourceManagementClient.Deployments.ValidateAsync( depReq.ApplicationName, depReq.ApplicationName, deployment ); return(deploymentOutput); } catch (Exception e) { Log.Error("Validate Template Deployment error {@error}", e.Message); throw e; } }
public async Task <IActionResult> Backup(DeploymentRequest request) { await _remoteService.BackupDeployment(request.DeploymentId); return(RedirectToServer(request)); }
public async Task <IActionResult> Online(DeploymentRequest request) { await _remoteService.PutOnline(request.DeploymentId); return(RedirectToServer(request)); }
public async Task <DeploymentValidateResult> Validate4x4MSIoTSolutionUsingAzureRMTemplate(DeploymentRequest depReq) { try { var resourceManagementClient = await clientFactory.GetResourceMangementClientAsync(depReq.SubscriptionId); // generates a parameter json required for ARM template deployment var parameterTemplateJson = Get4x4TemplateParameterJson(depReq); var deployment = new Deployment(); deployment.Properties = new DeploymentProperties { Mode = DeploymentMode.Incremental, TemplateLink = new TemplateLink(armOptions.TemplateUrl), Parameters = parameterTemplateJson }; // This is for unit testing and validating the ARM template to be deployed var deploymentOutput = await resourceManagementClient.Deployments.ValidateAsync( depReq.ApplicationName, depReq.ApplicationName, deployment ); return(deploymentOutput); } catch (Exception e) { logger.LogError(e, "Validate Template Deployment error {error}", e.Message); throw; } }