Search in sources :

Example 26 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class PostMatchingNodeSetupModifier method doMergeNode.

@Override
protected boolean doMergeNode(Topology topology, FlowExecutionContext context, String nodeTemplateId, NodePropsOverride nodePropsOverride) {
    final ConfigChanged configChanged = new ConfigChanged();
    // play the super method first. This will process nodetemplate properties
    configChanged.changed = super.doMergeNode(topology, context, nodeTemplateId, nodePropsOverride);
    // Then process capabilities
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateId);
    Iterator<Entry<String, NodeCapabilitiesPropsOverride>> capabilitiesOverrideIter = safe(nodePropsOverride.getCapabilities()).entrySet().iterator();
    while (capabilitiesOverrideIter.hasNext()) {
        Entry<String, NodeCapabilitiesPropsOverride> overrideCapabilityProperties = capabilitiesOverrideIter.next();
        Capability capability = safe(nodeTemplate.getCapabilities()).get(overrideCapabilityProperties.getKey());
        if (capability == null) {
            // Manage clean logic
            configChanged.changed = true;
            capabilitiesOverrideIter.remove();
        } else {
            // Merge logic
            // When a selected node has changed we may need to cleanup properties that where defined but are not anymore on the capability
            CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
            capability.setProperties(mergeProperties(overrideCapabilityProperties.getValue().getProperties(), capability.getProperties(), capabilityType.getProperties(), s -> {
                configChanged.changed = true;
                context.log().info("The property [" + s + "] previously specified to configure capability [" + overrideCapabilityProperties.getKey() + "] of node [" + nodeTemplateId + "] cannot be set anymore as it is already specified by the matched location resource or in the topology.");
            }));
        }
    }
    return configChanged.changed;
}
Also used : Iterator(java.util.Iterator) NodeType(org.alien4cloud.tosca.model.types.NodeType) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Entry(java.util.Map.Entry) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeCapabilitiesPropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodeCapabilitiesPropsOverride) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) Capability(org.alien4cloud.tosca.model.templates.Capability) ToscaContext(alien4cloud.tosca.context.ToscaContext) Entry(java.util.Map.Entry) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeCapabilitiesPropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodeCapabilitiesPropsOverride) NodeCapabilitiesPropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodeCapabilitiesPropsOverride) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)

Example 27 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method removeRelationship.

public void removeRelationship(Topology topology, Csar csar, String sourceNodeId, String relationshipName, RelationshipTemplate relationshipTemplate) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
    NodeTemplate sourceNode = topology.getNodeTemplates().get(sourceNodeId);
    String targetNodeId = relationshipTemplate.getTarget();
    NodeTemplate targetNode = topologyContext.getTopology().getNodeTemplates().get(targetNodeId);
    for (Workflow wf : topology.getWorkflows().values()) {
        AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
        // Remove relationships from source to target
        // Remove relationships from target to source
        Map<String, RelationshipTemplate> sourceRelationships = sourceNode.getRelationships().entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(targetNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        Map<String, RelationshipTemplate> targetRelationships = AlienUtils.safe(targetNode.getRelationships()).entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(sourceNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        builder.removeRelationships(wf, sourceNodeId, sourceRelationships, targetNodeId, targetRelationships);
        sourceRelationships.entrySet().stream().filter(entry -> !entry.getKey().equals(relationshipName)).forEach(entry -> builder.addRelationship(wf, sourceNode.getName(), sourceNode, entry.getKey(), entry.getValue(), topologyContext));
        targetRelationships.forEach((id, relationship) -> builder.addRelationship(wf, targetNodeId, targetNode, id, relationship, topologyContext));
        // Remove unique relationship that we really want to remove
        WorkflowUtils.fillHostId(wf, topologyContext);
    }
    postProcessTopologyWorkflows(topologyContext);
    debugWorkflow(topologyContext.getTopology());
}
Also used : ToscaParser(alien4cloud.tosca.parser.ToscaParser) Lists(org.elasticsearch.common.collect.Lists) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) HashMap(java.util.HashMap) STOP(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.STOP) Maps(org.elasticsearch.common.collect.Maps) DefaultDeclarativeWorkflows(org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows) START(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.START) INSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.INSTALL) Map(java.util.Map) YamlParserUtil(alien4cloud.utils.YamlParserUtil) Csar(org.alien4cloud.tosca.model.Csar) WorkflowValidator(alien4cloud.paas.wf.validation.WorkflowValidator) AlienUtils(alien4cloud.utils.AlienUtils) Resource(javax.annotation.Resource) TaskCode(alien4cloud.topology.task.TaskCode) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ICSARRepositorySearchService(alien4cloud.component.ICSARRepositorySearchService) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) AbstractWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.AbstractWorkflowActivity) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PostConstruct(javax.annotation.PostConstruct) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException) Topology(org.alien4cloud.tosca.model.templates.Topology) UNINSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.UNINSTALL) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) WorkflowUtils(alien4cloud.paas.wf.util.WorkflowUtils) WorkflowTask(alien4cloud.topology.task.WorkflowTask) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) HashMap(java.util.HashMap) Map(java.util.Map)

Example 28 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class TopologyCompositionService method recursivelyBuildSubstitutionStack.

/**
 * Deeply explore this topology to detect if some type must be substituted by the corresponding topology template content and feed the {@link Deque}. <br>
 * BTW, rename the nodes by prefixing all the node names.
 */
private void recursivelyBuildSubstitutionStack(Topology topology, Deque<CompositionCouple> stack, String prefix) {
    if (topology == null || topology.getNodeTemplates() == null || topology.getNodeTemplates().isEmpty()) {
        return;
    }
    for (Entry<String, NodeTemplate> nodeEntry : topology.getNodeTemplates().entrySet()) {
        String nodeName = nodeEntry.getKey();
        String type = nodeEntry.getValue().getType();
        // FIXME use tosca context, beware of child topologies (dependencies to use ? conflicts ?)
        NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, type, topology.getDependencies());
        if (nodeType.getSubstitutionTopologyId() != null) {
            // this node type is a proxy for a topology template
            Topology child = topologyServiceCore.getOrFail(nodeType.getSubstitutionTopologyId());
            CompositionCouple couple = new CompositionCouple(topology, child, nodeName, nodeName + "_");
            renameNodes(couple);
            stack.offer(couple);
            recursivelyBuildSubstitutionStack(child, stack, nodeName + "_");
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 29 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class ManagedServiceResourceService method create.

/**
 * Create a Service resource associated with the given environment.
 *
 * @param environmentId The environment to create a service for, the service version will be the one of the environment current associated version.
 * @param serviceName The name of the service as it should appears.
 * @param fromRuntime If we should try to create the service from the runtime topology related to the environment.
 * @return the id of the created service
 *
 * @throws AlreadyExistException if a service with the given name, or related to the given environment already exists
 * @throws alien4cloud.exception.NotFoundException if <b>fromRuntime</b> is set to true, but the environment is not deployed
 * @throws MissingSubstitutionException if topology related to the environment doesn't define a substitution type
 */
public synchronized String create(String serviceName, String environmentId, boolean fromRuntime) {
    ApplicationEnvironment environment = checkAndGetApplicationEnvironment(environmentId);
    // check that the service does not exists already for this environment
    if (alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environmentId)).count() > 0) {
        throw new AlreadyExistException("A service resource for environment <" + environmentId + "> and version <" + environment.getTopologyVersion() + "> already exists.");
    }
    Topology topology;
    String state = ToscaNodeLifecycleConstants.INITIAL;
    Deployment deployment = null;
    if (fromRuntime) {
        deployment = deploymentService.getActiveDeploymentOrFail(environmentId);
        topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        DeploymentStatus currentStatus = deploymentRuntimeStateService.getDeploymentStatus(deployment);
        state = managedServiceResourceEventService.getInstanceStateFromDeploymentStatus(currentStatus);
        if (state == null) {
            // We need a valid deployment state to expose as service.
            throw new InvalidDeploymentStatusException("Creating a service out of a running deployment is possible only when it's status is one of [DEPLOYED, FAILURE, UNDEPLOYED] current was <" + currentStatus + ">", currentStatus);
        }
    } else {
        topology = topologyServiceCore.getOrFail(Csar.createId(environment.getApplicationId(), environment.getTopologyVersion()));
    }
    if (topology.getSubstitutionMapping() == null) {
        throw new MissingSubstitutionException("Substitution is required to expose a topology.");
    }
    // The elementId of the type created out of the substitution is currently the archive name.
    String serviceId = serviceResourceService.create(serviceName, environment.getTopologyVersion(), topology.getArchiveName(), environment.getTopologyVersion(), environmentId);
    // Update the service relationships definition from the topology substitution
    updateServiceRelationship(serviceId, topology);
    if (fromRuntime) {
        managedServiceResourceEventService.updateRunningService((DeploymentTopology) topology, serviceResourceService.getOrFail(serviceId), deployment, state);
    }
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
    // trigger a ManagedServiceCreatedEvent
    publisher.publishEvent(new ManagedServiceCreatedEvent(this, serviceResource));
    return serviceId;
}
Also used : MissingSubstitutionException(org.alien4cloud.alm.service.exceptions.MissingSubstitutionException) InvalidDeploymentStatusException(org.alien4cloud.alm.service.exceptions.InvalidDeploymentStatusException) Deployment(alien4cloud.model.deployment.Deployment) ServiceResource(alien4cloud.model.service.ServiceResource) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) AlreadyExistException(alien4cloud.exception.AlreadyExistException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ManagedServiceCreatedEvent(org.alien4cloud.alm.events.ManagedServiceCreatedEvent) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 30 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class InputService method onCopyConfiguration.

@EventListener
@Order(10)
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.getInputs())) {
        // Nothing to copy
        return;
    }
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getInputs())) {
        Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
        Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
            // Copy only inputs which satisfy the new input definition
            try {
                if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
                    ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
                }
                return true;
            } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
                return false;
            }
        }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(inputsToCopy)) {
            DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
            if (targetDeploymentInputs == null) {
                targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
            }
            // Copy inputs from original topology
            targetDeploymentInputs.setInputs(inputsToCopy);
            deploymentConfigurationDao.save(targetDeploymentInputs);
        }
    }
}
Also used : ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) TagUtil(alien4cloud.utils.TagUtil) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Service(org.springframework.stereotype.Service) Application(alien4cloud.model.application.Application) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) ConstraintPropertyService(alien4cloud.utils.services.ConstraintPropertyService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EventListener(org.springframework.context.event.EventListener) PropertyService(alien4cloud.utils.services.PropertyService) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)80 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)23 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)17 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)10 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)10 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 Component (org.springframework.stereotype.Component)9 IOException (java.io.IOException)8 List (java.util.List)8 Set (java.util.Set)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8