Search in sources :

Example 26 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class InputsModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context."));
    ApplicationEnvironment environment = environmentContext.getEnvironment();
    DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
    if (deploymentInputs.getInputs() == null) {
        deploymentInputs.setInputs(Maps.newHashMap());
    }
    Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
    Map<String, PropertyValue> applicationInputs = inputService.getAppContextualInputs(context.getEnvironmentContext().get().getApplication(), topology.getInputs());
    Map<String, PropertyValue> locationInputs = inputService.getLocationContextualInputs(locations, topology.getInputs());
    // If the initial topology or any modifier configuration has changed since last inputs update then we refresh inputs.
    if (deploymentInputs.getLastUpdateDate() == null || deploymentInputs.getLastUpdateDate().before(context.getLastFlowParamUpdate())) {
        // FIXME exclude the application and location provided inputs from this method as it process them...
        boolean updated = deploymentInputService.synchronizeInputs(topology.getInputs(), deploymentInputs.getInputs());
        if (updated) {
            // save the config if changed. This is for ex, if an input has been deleted from the topology
            context.saveConfiguration(deploymentInputs);
        }
    }
    PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputsModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
    Map<String, AbstractPropertyValue> inputValues = Maps.newHashMap(deploymentInputs.getInputs());
    inputValues.putAll(applicationInputs);
    inputValues.putAll(locationInputs);
    inputValues.putAll(preconfiguredInputsConfiguration.getInputs());
    // Now that we have inputs ready let's process get_input functions in the topology to actually replace values.
    if (topology.getNodeTemplates() != null) {
        FunctionEvaluatorContext evaluatorContext = new FunctionEvaluatorContext(topology, inputValues);
        for (Entry<String, NodeTemplate> entry : topology.getNodeTemplates().entrySet()) {
            NodeTemplate nodeTemplate = entry.getValue();
            processGetInput(evaluatorContext, nodeTemplate, nodeTemplate.getProperties());
            if (nodeTemplate.getRelationships() != null) {
                for (Entry<String, RelationshipTemplate> relEntry : nodeTemplate.getRelationships().entrySet()) {
                    RelationshipTemplate relationshipTemplate = relEntry.getValue();
                    processGetInput(evaluatorContext, relationshipTemplate, relationshipTemplate.getProperties());
                }
            }
            if (nodeTemplate.getCapabilities() != null) {
                for (Entry<String, Capability> capaEntry : nodeTemplate.getCapabilities().entrySet()) {
                    Capability capability = capaEntry.getValue();
                    processGetInput(evaluatorContext, nodeTemplate, capability.getProperties());
                }
            }
            if (nodeTemplate.getRequirements() != null) {
                for (Entry<String, Requirement> requirementEntry : nodeTemplate.getRequirements().entrySet()) {
                    Requirement requirement = requirementEntry.getValue();
                    processGetInput(evaluatorContext, nodeTemplate, requirement.getProperties());
                }
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) FunctionEvaluatorContext(org.alien4cloud.tosca.utils.FunctionEvaluatorContext) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) Requirement(org.alien4cloud.tosca.model.templates.Requirement) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Location(alien4cloud.model.orchestrators.locations.Location)

Example 27 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class LocationMatchingModifier method resetMatchingConfiguration.

private void resetMatchingConfiguration(FlowExecutionContext context) {
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    context.saveConfiguration(new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId()));
}
Also used : DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 28 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class OrchestratorPropertiesValidationModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, OrchestratorPropertiesValidationModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        // we should not end-up here as location matching should be processed first
        context.log().error(new LocationPolicyTask());
        return;
    }
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    OrchestratorDeploymentProperties orchestratorDeploymentProperties = context.getConfiguration(OrchestratorDeploymentProperties.class, OrchestratorPropertiesValidationModifier.class.getSimpleName()).orElse(new OrchestratorDeploymentProperties(environment.getTopologyVersion(), environment.getId(), configurationOptional.get().getOrchestratorId()));
    orchestratorPropertiesValidationService.validate(orchestratorDeploymentProperties);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)

Example 29 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentService method createApplicationEnvironment.

/**
 * Create a new environment for a given application
 *
 * @param applicationId The id of the application.
 * @param name The environment name.
 * @param description The environment description.
 * @param environmentType The type of environment.
 * @return The newly created environment.
 */
public ApplicationEnvironment createApplicationEnvironment(String user, String applicationId, String name, String description, EnvironmentType environmentType, String topologyVersion) {
    ApplicationVersion applicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationId, topologyVersion));
    if (!applicationVersion.getApplicationId().equals(applicationId)) {
        throw new IllegalArgumentException("The topology version with id <" + topologyVersion + "> is not a topology of a version of the application with id <" + applicationId + ">");
    }
    // unique app env name for a given app
    ensureNameUnicity(applicationId, name);
    ApplicationEnvironment applicationEnvironment = new ApplicationEnvironment();
    applicationEnvironment.setId(UUID.randomUUID().toString());
    applicationEnvironment.setName(name);
    applicationEnvironment.setDescription(description);
    applicationEnvironment.setEnvironmentType(environmentType);
    applicationEnvironment.setApplicationId(applicationId);
    applicationEnvironment.setVersion(applicationVersion.getVersion());
    applicationEnvironment.setTopologyVersion(topologyVersion);
    Map<String, Set<String>> userRoles = Maps.newHashMap();
    userRoles.put(user, Sets.newHashSet(ApplicationEnvironmentRole.DEPLOYMENT_MANAGER.toString()));
    applicationEnvironment.setUserRoles(userRoles);
    alienDAO.save(applicationEnvironment);
    resourceUpdateInterceptor.runOnNewEnvironment(applicationEnvironment);
    return applicationEnvironment;
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) Set(java.util.Set) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 30 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentService method updateTopologyVersion.

public void updateTopologyVersion(ApplicationEnvironment applicationEnvironment, String oldTopologyVersion, String newVersion, String newTopologyVersion, String environmentIdToCopyInput) {
    applicationEnvironment.setVersion(newVersion);
    applicationEnvironment.setTopologyVersion(newTopologyVersion);
    if (environmentIdToCopyInput != null) {
        ApplicationEnvironment environmentToCopyInput = checkAndGetApplicationEnvironment(environmentIdToCopyInput, ApplicationRole.APPLICATION_MANAGER);
        alienDAO.save(applicationEnvironment);
        synchronizeEnvironmentInputs(environmentToCopyInput, applicationEnvironment);
    } else {
        alienDAO.save(applicationEnvironment);
    }
    publisher.publishEvent(new AfterEnvironmentTopologyVersionChanged(this, oldTopologyVersion, newTopologyVersion, applicationEnvironment.getId(), applicationEnvironment.getApplicationId()));
    resourceUpdateInterceptor.runOnEnvironmentTopologyVersionChanged(new TopologyVersionChangedInfo(applicationEnvironment, oldTopologyVersion, newTopologyVersion));
}
Also used : AfterEnvironmentTopologyVersionChanged(org.alien4cloud.alm.events.AfterEnvironmentTopologyVersionChanged) TopologyVersionChangedInfo(alien4cloud.common.ResourceUpdateInterceptor.TopologyVersionChangedInfo) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10