public TaskDefinitionValidationResult ValidateTaskDefinition(IDeployTaskDefinition taskDefinition, DeployEnvironmentConfiguration environmentComponent) { var result = new TaskDefinitionValidationResult(); //Verify Static Values var environmentParmeters = taskDefinition.GetEnvironmentTaskParameterList(); foreach (var p in environmentParmeters) { var item = this.GetValidationResultItem(p, environmentComponent.ConfigurationValueList); result.EnvironmentResultList.Add(item); } var machineParameters = taskDefinition.GetMachineTaskParameterList(); foreach (var machine in environmentComponent.MachineList) { var machineResultList = new List<TaskDefinitionValidationResult.TaskDefinitionValidationResultItem>(); foreach (var p in machineParameters) { var item = this.GetValidationResultItem(p, machine.ConfigurationValueList); machineResultList.Add(item); } result.MachineResultList.Add(machine.Id, machineResultList); } result.BuildParameterList.AddRange(taskDefinition.GetBuildTaskParameterList()); result.DeployParameterList.AddRange(taskDefinition.GetDeployTaskParameterList()); return result; }
public void Run(string deployStateId, IDeployTaskStatusManager statusManager, List<IDeployTaskDefinition> taskDefinitionList, DeployComponent component, DeployEnvironmentConfiguration environmentComponent, DeployMachine machine, DeployBuild build, RuntimeSystemSettings runtimeSystemSettings) { int stepCounter = 0; foreach(var taskDefinition in taskDefinitionList) { stepCounter++; statusManager.Info(deployStateId, string.Format("Step {0}: Starting {1}", stepCounter, taskDefinition.TaskDefintionName)); DeployTaskExecutionResult result; //using (var impersontator = BeginImpersonation(deployStateId, statusManager, environmentComponent)) //{ var executor = _deployTaskFactory.CreateTaskExecutor(taskDefinition.GetTaskExecutorType()); result = executor.Execute(deployStateId, statusManager, taskDefinition, component, environmentComponent, machine, build, runtimeSystemSettings); //} switch(result.Status) { case EnumDeployTaskExecutionResultStatus.Success: statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, completed successfully", stepCounter, taskDefinition.TaskDefintionName)); break; case EnumDeployTaskExecutionResultStatus.Error: statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, failed", stepCounter, taskDefinition.TaskDefintionName)); return; //error error eject! //break; case EnumDeployTaskExecutionResultStatus.Warning: statusManager.Info(deployStateId, string.Format("Step {0}: End {1}, completed with warnings", stepCounter, taskDefinition.TaskDefintionName)); break; default: throw new UnknownEnumValueException(result.Status); } } }
private void AssertEnvironmentConfiguration(DeployEnvironmentConfiguration expected, DeployEnvironmentConfiguration actual) { Assert.IsNotNull(actual); AssertHelpers.AssertBaseDto(expected, actual); Assert.AreEqual(expected.ProjectId, actual.ProjectId); Assert.AreEqual(expected.ParentId, actual.ParentId); Assert.AreEqual(expected.ParentType, actual.ParentType); Assert.AreEqual(expected.DeployCredentialsId, actual.DeployCredentialsId); AssertHelpers.AssertDictionary(expected.ConfigurationValueList, actual.ConfigurationValueList); Assert.AreEqual(expected.MachineList.Count, actual.MachineList.Count); AssertHelpers.AssertMachineList(expected.MachineList, actual.MachineList); }
private ImpersonationContext BeginImpersonation(string deployStateId, IDeployTaskStatusManager statusManager, DeployEnvironmentConfiguration environmentComponent) { if(!string.IsNullOrEmpty(environmentComponent.DeployCredentialsId)) { var context = _impersonator.BeginImpersonation(environmentComponent.DeployCredentialsId); statusManager.Info(deployStateId, "Starting impersonation of " + context.Credentials.DisplayValue); return context; } else { statusManager.Info(deployStateId, "No impersonation"); return null; } }
private void LoadEnvironmentConfigurationChildren(DeployEnvironmentConfiguration item) { //item.ConfigurationValueList = GetEnvironmentConfigurationValueList(item.Id).ToDictionary(i=>i.ConfigurationName, i=>i.ConfigurationValue);; item.MachineList = GetMachineList(item.Id); }
private void SaveMachineList(DeployEnvironmentConfiguration configuration) { var itemsToInsert = new List<DeployMachine>(); var itemsToUpdate = new List<DeployMachine>(); var itemsToDelete = new List<DeployMachine>(); var existingList = GetMachineList(configuration.Id); foreach(var newItem in configuration.MachineList) { bool existingItem = existingList.Any(i=>i.Id == newItem.Id); if(existingItem) { itemsToUpdate.Add(newItem); } else { itemsToInsert.Add(newItem); } } foreach(var existingItem in existingList) { var newItem = configuration.MachineList.Any(i=>i.Id == existingItem.Id); if(!newItem) { itemsToDelete.Add(existingItem); } } using(var db = _sqlConnectionInfo.GetDB()) { foreach(var item in itemsToInsert) { var dbItem = SqlDeployMachine.FromDto(item); dbItem.SetCreatedFields(_userIdentity.UserName); db.Insert("DeployMachine", "ID", false, dbItem); } foreach(var item in itemsToUpdate) { var dbItem = SqlDeployMachine.FromDto(item); dbItem.SetUpdatedFields(_userIdentity.UserName); db.Update("DeployMachine", "ID", dbItem, item.Id); } foreach(var item in itemsToDelete) { var sql = PetaPoco.Sql.Builder //.Append("DELETE FROM DeployMachineConfigurationValue WHERE DeployMachineID=@0;", item.Id) .Append("DELETE FROM DeployMachine WHERE ID=@0;", item.Id); db.Execute(sql); } } }
public static SqlDeployEnvironmentConfiguration FromDto(DeployEnvironmentConfiguration item) { var returnValue = AutoMapper.Mapper.Map(item, new SqlDeployEnvironmentConfiguration()); if(item.ConfigurationValueList != null) { returnValue.ConfigurationValueListJson = item.ConfigurationValueList.ToJson(); } return returnValue; }
public void Execute(DeployEnvironmentConfiguration deployEnvironmentComponent, RuntimeSystemSettings runtimeSystemSettings) { throw new NotImplementedException(); }
private void AssertCreatedEnvironmentConfiguration(DeployEnvironmentConfiguration sourceItem, DeployEnvironmentConfiguration createdItem, DeployProject project, DeployEnvironment environment, EnumDeployStepParentType parentType) { Assert.IsNotNull(createdItem); AssertHelpers.AssertCreatedBaseDto(createdItem, this.UserName); Assert.AreEqual(project.Id, createdItem.ProjectId); Assert.AreEqual(sourceItem.ParentId, createdItem.ParentId); Assert.AreEqual(parentType, createdItem.ParentType); Assert.AreEqual(sourceItem.DeployCredentialsId, createdItem.DeployCredentialsId); AssertHelpers.AssertDictionary(sourceItem.ConfigurationValueList, createdItem.ConfigurationValueList); Assert.AreEqual(sourceItem.MachineList.Count, createdItem.MachineList.Count); foreach(var sourceMachine in sourceItem.MachineList) { var createdMachine = createdItem.MachineList.SingleOrDefault(i=>i.MachineName == sourceMachine.MachineName); Assert.IsNotNull(createdMachine); AssertHelpers.AssertCreatedBaseDto(createdMachine, this.UserName); Assert.AreEqual(project.Id, createdMachine.ProjectId); Assert.AreEqual(environment.Id, createdMachine.EnvironmentId); Assert.AreEqual(environment.EnvironmentName, createdMachine.EnvironmentName); Assert.AreEqual(sourceItem.Id, createdMachine.ParentId); AssertHelpers.AssertDictionary(sourceMachine.ConfigurationValueList, createdMachine.ConfigurationValueList); } }
public DeployEnvironmentConfiguration Unmask(DeployProject project, DeployEnvironmentConfiguration environmentConfiguration, DeployEnvironment originalEnvironment) { if(environmentConfiguration == null) { return null; } if(project == null) { throw new ArgumentNullException("Missing project"); } var newEnvironmentConfiguration = AutoMapper.Mapper.Map(environmentConfiguration, new DeployEnvironmentConfiguration()); if (string.IsNullOrEmpty(environmentConfiguration.Id)) { //New item being created, don't need to unmask return newEnvironmentConfiguration; } DeployEnvironmentConfiguration originalEnviromentConfiguration; switch(environmentConfiguration.ParentType) { case EnumDeployStepParentType.Configuration: originalEnviromentConfiguration = originalEnvironment.ConfigurationList.FirstOrDefault(i => i.ParentType == environmentConfiguration.ParentType && i.ParentId == environmentConfiguration.ParentId); break; case EnumDeployStepParentType.Component: originalEnviromentConfiguration = originalEnvironment.ComponentList.FirstOrDefault(i => i.ParentType == environmentConfiguration.ParentType && i.ParentId == environmentConfiguration.ParentId); break; default: throw new UnknownEnumValueException(environmentConfiguration.ParentType); } if(originalEnviromentConfiguration != null) { List<DeployStep> deploymentStepList = new List<DeployStep>(); switch (newEnvironmentConfiguration.ParentType) { case EnumDeployStepParentType.Component: var component = project.ComponentList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId); if (component != null) { deploymentStepList = component.DeploymentStepList; } break; case EnumDeployStepParentType.Configuration: var configuration = project.ConfigurationList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId); if (configuration != null) { deploymentStepList = configuration.DeploymentStepList; } break; default: throw new UnknownEnumValueException(newEnvironmentConfiguration.ParentType); } var definition = _deploymentValidator.GetComponentConfigurationDefinition(deploymentStepList); if (definition.EnvironmentTaskParameterList != null) { foreach (var parameterDefinition in definition.EnvironmentTaskParameterList.Where(i => i.Sensitive)) { if (newEnvironmentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName) && originalEnviromentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)) { if(newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] == this.MaskValue) { newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = originalEnviromentConfiguration.ConfigurationValueList[parameterDefinition.FieldName]; } } } } if (definition.MachineTaskParameterList != null && newEnvironmentConfiguration.MachineList != null && originalEnviromentConfiguration.MachineList != null) { foreach (var parameterDefinition in definition.MachineTaskParameterList.Where(i => i.Sensitive)) { foreach(var newMachineConfiguration in newEnvironmentConfiguration.MachineList) { var originalMachineConfiguration = originalEnviromentConfiguration.MachineList.FirstOrDefault(i=>i.Id == newMachineConfiguration.Id); if(originalMachineConfiguration != null) { if(newMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName) && originalMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)) { if (newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] == this.MaskValue) { newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = originalMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName]; } } } } } } } return newEnvironmentConfiguration; }
public DeployEnvironmentConfiguration Mask(DeployProject project, DeployEnvironmentConfiguration environmentConfiguration) { if(environmentConfiguration == null) { return null; } if (project == null) { throw new ArgumentNullException("Missing project"); } var newEnvironmentConfiguration = AutoMapper.Mapper.Map(environmentConfiguration, new DeployEnvironmentConfiguration()); if (newEnvironmentConfiguration.ConfigurationValueList != null && newEnvironmentConfiguration.ConfigurationValueList.Any()) { List<DeployStep> deploymentStepList = new List<DeployStep>(); switch (newEnvironmentConfiguration.ParentType) { case EnumDeployStepParentType.Component: var component = project.ComponentList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId); if(component != null) { deploymentStepList = component.DeploymentStepList; } break; case EnumDeployStepParentType.Configuration: var configuration = project.ConfigurationList.FirstOrDefault(i => i.Id == newEnvironmentConfiguration.ParentId); if(configuration != null) { deploymentStepList = configuration.DeploymentStepList; } break; } var definition = _deploymentValidator.GetComponentConfigurationDefinition(deploymentStepList); if(definition.EnvironmentTaskParameterList != null) { foreach(var parameterDefinition in definition.EnvironmentTaskParameterList.Where(i=>i.Sensitive)) { if (newEnvironmentConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)) { newEnvironmentConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = this.MaskValue; } } } if(definition.MachineTaskParameterList != null && newEnvironmentConfiguration.MachineList != null) { foreach (var parameterDefinition in definition.MachineTaskParameterList.Where(i => i.Sensitive)) { foreach(var newMachineConfiguration in newEnvironmentConfiguration.MachineList) { if (newMachineConfiguration.ConfigurationValueList.ContainsKey(parameterDefinition.FieldName)) { newMachineConfiguration.ConfigurationValueList[parameterDefinition.FieldName] = this.MaskValue; } } } } } return newEnvironmentConfiguration; }