Search in sources :

Example 6 with DeploymentInputs

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;
}
Also used : AbstractTask(alien4cloud.topology.task.AbstractTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) DeploymentSubstitutionConfiguration(alien4cloud.deployment.model.DeploymentSubstitutionConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) LocationResourceTypes(alien4cloud.orchestrators.locations.services.LocationResourceTypes) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)

Example 7 with DeploymentInputs

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);
    }
}
Also used : DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) InputStream(java.io.InputStream) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 8 with 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);
        }
    }
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) HashMap(java.util.HashMap) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) Inject(javax.inject.Inject) IFileRepository(alien4cloud.component.repository.IFileRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) MultipartFile(org.springframework.web.multipart.MultipartFile) Topology(org.alien4cloud.tosca.model.templates.Topology) ArtifactRepositoryConstants(alien4cloud.component.repository.ArtifactRepositoryConstants) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) InputStream(java.io.InputStream) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) HashMap(java.util.HashMap) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 9 with DeploymentInputs

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));
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 10 with DeploymentInputs

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);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Deployment(alien4cloud.model.deployment.Deployment) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology)

Aggregations

DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)10 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 NotFoundException (alien4cloud.exception.NotFoundException)4 Map (java.util.Map)4 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)4 PreconfiguredInputsConfiguration (org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration)3 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Topology (org.alien4cloud.tosca.model.templates.Topology)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2 TopologyServiceCore (alien4cloud.topology.TopologyServiceCore)2 InputStream (java.io.InputStream)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 OnDeploymentConfigCopyEvent (org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent)2 AbstractDeploymentConfig (org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2