use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class DeploymentTopologyDTOBuilder method build.
/**
* Create a deployment topology dto from the context of the execution of a deployment flow.
*
* @param executionContext The deployment flow execution context.
* @return The deployment topology.
*/
private DeploymentTopologyDTO build(FlowExecutionContext executionContext) {
// re-create the deployment topology object for api compatibility purpose
DeploymentTopology deploymentTopology = new DeploymentTopology();
ReflectionUtil.mergeObject(executionContext.getTopology(), deploymentTopology);
deploymentTopology.setInitialTopologyId(executionContext.getTopology().getId());
deploymentTopology.setEnvironmentId(executionContext.getEnvironmentContext().get().getEnvironment().getId());
deploymentTopology.setVersionId(executionContext.getEnvironmentContext().get().getEnvironment().getTopologyVersion());
DeploymentTopologyDTO deploymentTopologyDTO = new DeploymentTopologyDTO();
topologyDTOBuilder.initTopologyDTO(deploymentTopology, deploymentTopologyDTO);
// Convert log result to validation result.
TopologyValidationResult validationResult = new TopologyValidationResult();
for (AbstractTask task : executionContext.getLog().getInfos()) {
validationResult.addInfo(task);
}
for (AbstractTask task : executionContext.getLog().getWarnings()) {
validationResult.addWarning(task);
}
for (AbstractTask task : executionContext.getLog().getErrors()) {
validationResult.addTask(task);
}
validationResult.setValid(validationResult.getTaskList() == null || validationResult.getTaskList().isEmpty());
deploymentTopologyDTO.setValidation(validationResult);
Optional<PreconfiguredInputsConfiguration> preconfiguredInputsConfiguration = executionContext.getConfiguration(PreconfiguredInputsConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
if (!preconfiguredInputsConfiguration.isPresent()) {
deploymentTopology.setPreconfiguredInputProperties(Maps.newHashMap());
} else {
deploymentTopology.setPreconfiguredInputProperties(preconfiguredInputsConfiguration.get().getInputs());
}
Optional<DeploymentInputs> inputsOptional = executionContext.getConfiguration(DeploymentInputs.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
if (!inputsOptional.isPresent()) {
deploymentTopology.setDeployerInputProperties(Maps.newHashMap());
deploymentTopology.setUploadedInputArtifacts(Maps.newHashMap());
} else {
deploymentTopology.setDeployerInputProperties(inputsOptional.get().getInputs());
deploymentTopology.setUploadedInputArtifacts(inputsOptional.get().getInputArtifacts());
}
Optional<DeploymentMatchingConfiguration> matchingConfigurationOptional = executionContext.getConfiguration(DeploymentMatchingConfiguration.class, DeploymentTopologyDTOBuilder.class.getSimpleName());
if (!matchingConfigurationOptional.isPresent()) {
return deploymentTopologyDTO;
}
DeploymentMatchingConfiguration matchingConfiguration = matchingConfigurationOptional.get();
deploymentTopology.setOrchestratorId(matchingConfiguration.getOrchestratorId());
deploymentTopology.setLocationGroups(matchingConfiguration.getLocationGroups());
deploymentTopologyDTO.setLocationPolicies(matchingConfiguration.getLocationIds());
// Good enough approximation as it doesn't contains just the location dependencies.
deploymentTopology.setLocationDependencies(executionContext.getTopology().getDependencies());
DeploymentSubstitutionConfiguration substitutionConfiguration = new DeploymentSubstitutionConfiguration();
substitutionConfiguration.setSubstitutionTypes(new LocationResourceTypes());
// fill DTO with policies substitution stuffs
fillDTOWithPoliciesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
// fill DTO with nodes substitution stuffs
fillDTOWithNodesSubstitutionConfiguration(executionContext, deploymentTopology, deploymentTopologyDTO, matchingConfiguration, substitutionConfiguration);
deploymentTopologyDTO.setAvailableSubstitutions(substitutionConfiguration);
ApplicationEnvironment environment = executionContext.getEnvironmentContext().get().getEnvironment();
OrchestratorDeploymentProperties orchestratorDeploymentProperties = executionContext.getConfiguration(OrchestratorDeploymentProperties.class, this.getClass().getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), matchingConfiguration.getOrchestratorId()));
deploymentTopology.setProviderDeploymentProperties(orchestratorDeploymentProperties.getProviderDeploymentProperties());
deploymentTopologyDTO.setSecretCredentialInfos((List<SecretCredentialInfo>) executionContext.getExecutionCache().get(FlowExecutionContext.SECRET_CREDENTIAL));
return deploymentTopologyDTO;
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputArtifactService method updateInputArtifact.
/**
* Update an input artifact value in the deployment topology
*
* @param environment The environment for which to update the input artifact.
* @param topology The topology for which to update the artifact.
* @param inputArtifactId The id of the input artifact to update.
* @param artifactFile The file
* @throws IOException
*/
public void updateInputArtifact(ApplicationEnvironment environment, Topology topology, String inputArtifactId, MultipartFile artifactFile) throws IOException {
checkInputArtifactExist(inputArtifactId, topology);
DeploymentInputs deploymentInputs = getDeploymentInputs(environment.getTopologyVersion(), environment.getId());
// FIXME ensure that deployment inputs are up-to date
DeploymentArtifact artifact = getDeploymentArtifact(inputArtifactId, deploymentInputs);
try (InputStream artifactStream = artifactFile.getInputStream()) {
String artifactFileId = artifactRepository.storeFile(artifactStream);
artifact.setArtifactName(artifactFile.getOriginalFilename());
artifact.setArtifactRef(artifactFileId);
artifact.setArtifactRepository(ArtifactRepositoryConstants.ALIEN_ARTIFACT_REPOSITORY);
artifact.setRepositoryName(null);
artifact.setRepositoryURL(null);
deploymentConfigurationDao.save(deploymentInputs);
}
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputArtifactService method onCopyConfiguration.
@EventListener
@Order(11)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputArtifacts())) {
// Nothing to copy
return;
}
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
Map<String, DeploymentArtifact> inputsArtifactsDefinitions = topology.getInputArtifacts();
// Copy only artifacts which exists in the new topology's definition
Map<String, DeploymentArtifact> inputsArtifactsToCopy = deploymentInputs.getInputArtifacts().entrySet().stream().filter(inputEntry -> inputsArtifactsDefinitions.containsKey(inputEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(inputsArtifactsToCopy)) {
// There's something to copy
DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (targetDeploymentInputs == null) {
targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
}
targetDeploymentInputs.setInputArtifacts(inputsArtifactsToCopy);
deploymentConfigurationDao.save(targetDeploymentInputs);
}
}
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class InputValidationModifier method process.
/**
* Validate all required input is provided with a non null value.
*
* @param topology The topology to process.
* @param context The object that stores warnings and errors (tasks) associated with the execution flow. Note that the flow will end-up if an error
*/
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentInputs> inputsOptional = context.getConfiguration(DeploymentInputs.class, InputValidationModifier.class.getSimpleName());
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputValidationModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
// Define a task regarding properties
PropertiesTask task = new PropertiesTask();
task.setCode(TaskCode.INPUT_PROPERTY);
task.setProperties(Maps.newHashMap());
task.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList());
Map<String, AbstractPropertyValue> inputValues = safe(inputsOptional.orElse(new DeploymentInputs()).getInputs());
Map<String, PropertyValue> predefinedInputValues = safe(preconfiguredInputsConfiguration.getInputs());
// override deployer inputValues with predefinedInputValues
inputValues = Maps.newHashMap(inputValues);
inputValues.putAll(predefinedInputValues);
for (Entry<String, PropertyDefinition> propDef : safe(topology.getInputs()).entrySet()) {
if (propDef.getValue().isRequired() && inputValues.get(propDef.getKey()) == null) {
task.getProperties().get(TaskLevel.REQUIRED).add(propDef.getKey());
}
}
if (CollectionUtils.isNotEmpty(task.getProperties().get(TaskLevel.REQUIRED))) {
context.log().error(task);
}
// Check input artifacts
deploymentInputArtifactValidationService.validate(topology, inputsOptional.orElse(new DeploymentInputs())).forEach(inputArtifactTask -> context.log().error(inputArtifactTask));
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.
the class BlockStorageEventHandler method updateApplicationTopology.
private void updateApplicationTopology(PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, final Map<String, Object> persistentProperties) {
Deployment deployment = deploymentService.get(persistentResourceEvent.getDeploymentId());
String topologyId = deployment.getSourceId() + ":" + deployment.getVersionId();
Topology topology = topoServiceCore.getOrFail(topologyId);
// The deployment topology may have changed and the node removed, in such situations there is nothing to update as the block won't be reused.
NodeTemplate nodeTemplate;
try {
nodeTemplate = TopologyUtils.getNodeTemplate(topology, persistentResourceEvent.getNodeTemplateId());
} catch (NotFoundException e) {
log.warn("Fail to update persistent resource for node {}", persistentResourceEvent.getNodeTemplateId(), e);
return;
}
for (String propertyName : persistentProperties.keySet()) {
Object propertyValue = persistentProperties.get(propertyName);
AbstractPropertyValue abstractPropertyValue = nodeTemplate.getProperties().get(propertyName);
if (abstractPropertyValue != null && abstractPropertyValue instanceof FunctionPropertyValue) {
// the value is set in the topology
FunctionPropertyValue function = (FunctionPropertyValue) abstractPropertyValue;
if (function.getFunction().equals(ToscaFunctionConstants.GET_INPUT) && propertyValue instanceof String) {
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
// the value is set in the input (deployment setup)
log.info("Updating deploymentsetup [ {} ] input properties [ {} ] to add a new VolumeId", deploymentInputs.getId(), function.getTemplateName());
log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", propertyName, persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
deploymentInputs.getInputs().put(function.getTemplateName(), new ScalarPropertyValue((String) propertyValue));
deploymentConfigurationDao.save(deploymentInputs);
} else {
// this is not supported / print a warning
log.warn("Failed to store the id of the created block storage [ {} ] for deployment [ {} ] application [ {} ] environment [ {} ]");
return;
}
} else {
DeploymentMatchingConfiguration matchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
log.info("Updating deployment topology: Persistent resource property [ {} ] for node template <{}.{}> to add a value", propertyName, matchingConfiguration.getId(), persistentResourceEvent.getNodeTemplateId());
log.debug("Value to add: [ {} ]. New value is [ {} ]", persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
matchingConfiguration.getMatchedNodesConfiguration().get(persistentResourceEvent.getNodeTemplateId()).getProperties().put(propertyName, getPropertyValue(propertyValue));
deploymentConfigurationDao.save(matchingConfiguration);
}
}
}
Aggregations