/// <summary> /// Performs the request. /// </summary> /// <param name="arguments">The arguments.</param> /// <returns>The async <see cref="Task"/>.</returns> private static async Task PerformRequest(Dictionary <string, string> arguments) { try { var accountDetails = await CaasAuthentication.Authenticate( arguments["username"], arguments["password"], arguments["region"]); var runtimeContext = new RuntimeContext { AccountDetails = accountDetails, LogProvider = new ConsoleLogProvider() }; var taskBuilder = new TaskBuilder(); if (arguments["action"].ToLower() == "deploy") { var parametersFile = arguments.ContainsKey("parameters") ? arguments["parameters"] : null; var templateFile = arguments["template"]; var taskExecutor = taskBuilder.BuildTasksFromDeploymentTemplate(templateFile, parametersFile); var log = await taskExecutor.Execute(runtimeContext); Console.WriteLine($"Result: {log.Status}"); log.SaveToFile(arguments["deploymentlog"]); Console.WriteLine($"Complete! Deployment log written to {arguments["deploymentlog"]}."); if (taskExecutor.Context.OutputParameters != null) { Console.WriteLine("OUTPUT PARAMETERS:"); foreach (var param in taskExecutor.Context.OutputParameters) { Console.WriteLine($"{param.Key}: {param.Value}"); } } } else if (arguments["action"].ToLower() == "delete") { var deploymentLogFile = arguments["deploymentlog"]; var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(deploymentLogFile); var log = await taskExecutor.Execute(runtimeContext); Console.WriteLine($"Result: {log.Status}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Begins the processing asynchronously. /// </summary> /// <returns>The async <see cref="Task"/>.</returns> private async Task BeginProcessingAsync() { var runtimeContext = new RuntimeContext { AccountDetails = await CaasAuthentication.Authenticate(UserName, Password, Region), LogProvider = new ConsoleLogProvider() }; var taskBuilder = new TaskBuilder(); var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(ResolvePath(DeploymentLog)); var log = await taskExecutor.Execute(runtimeContext); Console.WriteLine($"Result: {log.Status}"); }
public async Task ParseAndExecuteDeletionTasks_Failed() { var client = new FakeHttpClient(); client.AddResponse("/network/deleteNatRule", "NatRule_Delete.json"); client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/removePublicIpBlock", "GenericError.json", HttpStatusCode.BadRequest); var logFile = Path.Combine(_resourceFolder, "StandardTemplateLog.json"); var taskBuilder = new TaskBuilder(); var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(logFile); var log = await taskExecutor.Execute(_runtimeContext); Assert.AreEqual(DeploymentLogStatus.Failed, log.Status); Assert.AreEqual(2, log.Resources.Count); Assert.AreEqual(ResourceLogStatus.Deleted, log.Resources[0].DeploymentStatus); Assert.AreEqual(ResourceLogStatus.Failed, log.Resources[1].DeploymentStatus); Assert.AreEqual("UNEXPECTED_ERROR", log.Resources[1].Error.ResponseCode); }
public async Task ParseAndExecuteDeletionTasks_Success() { var client = new FakeHttpClient(); client.AddResponse("/network/deleteNatRule", "NatRule_Delete.json"); client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/removePublicIpBlock", "PublicIpBlock_Delete.json"); client.AddResponse("/network/publicIpBlock/996b066e-bdce-11e4-8c14-b8ca3a5d9ef8", "PublicIpBlock_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/server/deleteServer", "Server_Delete.json"); client.AddResponse("/server/server/b42b40e1-351a-4df9-b726-2ccff01f2767", "Server_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/deleteVlan", "Vlan_Delete.json"); client.AddResponse("/network/vlan/997e2084-00b1-4d1d-96ce-099946679c6f", "Vlan_Get_NotFound.json", HttpStatusCode.BadRequest); var logFile = Path.Combine(_resourceFolder, "StandardTemplateLog.json"); var taskBuilder = new TaskBuilder(); var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(logFile); var log = await taskExecutor.Execute(_runtimeContext); Assert.AreEqual(DeploymentLogStatus.Success, log.Status); }
public async Task ParseAndExecuteDeletionTasks_Success() { var client = new FakeHttpClient(); client.AddResponse("/network/deleteNatRule", "NatRule_Delete.json"); client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/removePublicIpBlock", "PublicIpBlock_Delete.json"); client.AddResponse("/network/publicIpBlock/996b066e-bdce-11e4-8c14-b8ca3a5d9ef8", "PublicIpBlock_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/server/deleteServer", "Server_Delete.json"); client.AddResponse("/server/server/b42b40e1-351a-4df9-b726-2ccff01f2767", "Server_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/deleteVlan", "Vlan_Delete.json"); client.AddResponse("/network/vlan/997e2084-00b1-4d1d-96ce-099946679c6f", "Vlan_Get_NotFound.json", HttpStatusCode.BadRequest); var logFile = Path.Combine(_resourceFolder, "StandardTemplateLog.json"); var taskBuilder = new TaskBuilder(); var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(logFile); var log = await taskExecutor.Execute(_runtimeContext); Assert.AreEqual(DeploymentLogStatus.Success, log.Status); }
public async Task ParseAndExecuteDeletionTasks_Failed() { var client = new FakeHttpClient(); client.AddResponse("/network/deleteNatRule", "NatRule_Delete.json"); client.AddResponse("/network/natRule/a6b2e743-e330-4deb-a76e-0d9cb0b1d1bb", "NatRule_Get_NotFound.json", HttpStatusCode.BadRequest); client.AddResponse("/network/removePublicIpBlock", "GenericError.json", HttpStatusCode.BadRequest); var logFile = Path.Combine(_resourceFolder, "StandardTemplateLog.json"); var taskBuilder = new TaskBuilder(); var taskExecutor = taskBuilder.BuildTasksFromDeploymentLog(logFile); var log = await taskExecutor.Execute(_runtimeContext); Assert.AreEqual(DeploymentLogStatus.Failed, log.Status); Assert.AreEqual(2, log.Resources.Count); Assert.AreEqual(ResourceLogStatus.Deleted, log.Resources[0].DeploymentStatus); Assert.AreEqual(ResourceLogStatus.Failed, log.Resources[1].DeploymentStatus); Assert.AreEqual("UNEXPECTED_ERROR", log.Resources[1].Error.ResponseCode); }