Search in sources :

Example 1 with FlowExecutionContext

use of org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext in project yorc-a4c-plugin by ystia.

the class OpenStackBSComputeWFModifier method doProcess.

private void doProcess(Topology topology, FlowExecutionContext context) {
    Csar csar = new Csar(topology.getArchiveName(), topology.getArchiveVersion());
    Workflow installWF = topology.getWorkflows().get("install");
    Workflow uninstallWF = topology.getWorkflows().get("uninstall");
    Set<NodeTemplate> bsSet = TopologyNavigationUtil.getNodesOfType(topology, YORC_OPENSTACK_BS_TYPE, true);
    // Let's process all BS
    bsSet.forEach(bs -> safe(bs.getRelationships()).forEach((rn, rt) -> {
        if ("tosca.capabilities.Attachment".equals(rt.getRequirementType())) {
            // Attachment found
            context.getLog().info("Found a BlockStorage <{}> with an attachment on <{}>. Let's swap their workflow steps to match Yorc " + "expectations.", bs.getName(), rt.getTarget());
            String computeNodeName = rt.getTarget();
            // Now lets locate corresponding wf steps in install wf
            for (Map.Entry<String, WorkflowStep> workflowStepEntry : installWF.getSteps().entrySet()) {
                if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
                    for (String precedingStepName : workflowStepEntry.getValue().getPrecedingSteps()) {
                        WorkflowStep precedingStep = installWF.getSteps().get(precedingStepName);
                        if (precedingStep.getTarget().equals(computeNodeName)) {
                            // We do not use swap operation here as it may mess up other workflow edges
                            // First remove the edge between steps
                            RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
                            removeEdgeOperation.setWorkflowName(installWF.getName());
                            removeEdgeOperation.setFromStepId(precedingStepName);
                            removeEdgeOperation.setToStepId(workflowStepEntry.getKey());
                            log.debug("Swapping {} with target {}", precedingStepName, workflowStepEntry.getKey());
                            removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
                            // Then reconnect them in the right sequence
                            ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
                            connectStepFromOperation.setWorkflowName(installWF.getName());
                            connectStepFromOperation.setFromStepIds(new String[] { workflowStepEntry.getKey() });
                            connectStepFromOperation.setToStepId(precedingStepName);
                            connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
                            break;
                        }
                    }
                    break;
                }
            }
            // Now lets locate corresponding wf steps in uninstall wf
            for (Map.Entry<String, WorkflowStep> workflowStepEntry : uninstallWF.getSteps().entrySet()) {
                if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
                    for (String onSuccessStepName : workflowStepEntry.getValue().getOnSuccess()) {
                        WorkflowStep onSuccessStep = uninstallWF.getSteps().get(onSuccessStepName);
                        if (onSuccessStep.getTarget().equals(computeNodeName)) {
                            // We do not use swap operation here as it may mess up other workflow edges
                            // First remove the edge between steps
                            RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
                            removeEdgeOperation.setWorkflowName(uninstallWF.getName());
                            removeEdgeOperation.setFromStepId(workflowStepEntry.getKey());
                            removeEdgeOperation.setToStepId(onSuccessStepName);
                            log.debug("Swapping {} with target {}", onSuccessStepName, workflowStepEntry.getKey());
                            removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
                            // Then reconnect them in the right sequence
                            ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
                            connectStepFromOperation.setWorkflowName(uninstallWF.getName());
                            connectStepFromOperation.setFromStepIds(new String[] { onSuccessStepName });
                            connectStepFromOperation.setToStepId(workflowStepEntry.getKey());
                            connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
                            break;
                        }
                    }
                    break;
                }
            }
        // Start & Stop make no sense for those kind of nodes in Yorc as those operations are not implemented.
        // Do not change those WFs
        }
    }));
}
Also used : ToscaContextual(alien4cloud.tosca.context.ToscaContextual) Csar(org.alien4cloud.tosca.model.Csar) WorkflowValidator(alien4cloud.paas.wf.validation.WorkflowValidator) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Resource(javax.annotation.Resource) Set(java.util.Set) ConnectStepFromProcessor(org.alien4cloud.tosca.editor.processors.workflow.ConnectStepFromProcessor) TopologyModifierSupport(org.alien4cloud.alm.deployment.configuration.flow.TopologyModifierSupport) TopologyNavigationUtil(org.alien4cloud.tosca.utils.TopologyNavigationUtil) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) RemoveEdgeProcessor(org.alien4cloud.tosca.editor.processors.workflow.RemoveEdgeProcessor) Csar(org.alien4cloud.tosca.model.Csar) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 2 with FlowExecutionContext

use of org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext 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 3 with FlowExecutionContext

use of org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method prepareDeployment.

@Override
@ToscaContextual
public DeploymentTopologyDTO prepareDeployment(Topology topology, Application application, ApplicationEnvironment environment, ApplicationTopologyVersion topologyVersion, IDeploymentConfigAction deploymentConfigAction) {
    // Execute the update
    deploymentConfigAction.execute(application, environment, topologyVersion, topology);
    FlowExecutionContext executionContext = flowExecutor.executeDeploymentFlow(topology, application, environment);
    return build(executionContext);
}
Also used : FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 4 with FlowExecutionContext

use of org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext in project alien4cloud by alien4cloud.

the class NodeMatchingSubstitutionService method onCopyConfiguration.

// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.PolicyMatchingSubstitutionService#onCopyConfiguration
@EventListener
// Process this after location matching copy (first element).
@Order(30)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    DeploymentMatchingConfiguration targetConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
    if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups()) || targetConfiguration == null || MapUtils.isEmpty(targetConfiguration.getLocationGroups())) {
        // Nothing to copy
        return;
    }
    // We have to execute a piece of the deployment flow to find out matching candidates so we copy only required inputs
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
        Application application = applicationService.getOrFail(target.getApplicationId());
        FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, target));
        flowExecutor.execute(topology, getMatchingFlow(), executionContext);
        Map<String, Set<String>> locResTemplateIdsPerNodeIds = (Map<String, Set<String>>) executionContext.getExecutionCache().get(FlowExecutionContext.SELECTED_MATCH_NODE_LOCATION_TEMPLATE_BY_NODE_ID_MAP);
        // Update the substitution on the target if available substitution is always compatible
        Map<String, String> validOnNewEnvSubstitutedNodes = safe(sourceConfiguration.getMatchedLocationResources()).entrySet().stream().filter(entry -> locResTemplateIdsPerNodeIds.containsKey(entry.getKey()) && locResTemplateIdsPerNodeIds.get(entry.getKey()).contains(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(validOnNewEnvSubstitutedNodes)) {
            if (targetConfiguration.getMatchedLocationResources() == null) {
                targetConfiguration.setMatchedLocationResources(Maps.newHashMap());
            }
            validOnNewEnvSubstitutedNodes.forEach((key, value) -> {
                targetConfiguration.getMatchedLocationResources().put(key, value);
                // Copy properties set on the node to the new one
                targetConfiguration.getMatchedNodesConfiguration().put(key, safe(sourceConfiguration.getMatchedNodesConfiguration()).get(key));
            });
            deploymentConfigurationDao.save(targetConfiguration);
        }
    }
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedNodeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedNodeModifier) EventListener(org.springframework.context.event.EventListener) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutor(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor) AbstractComposedModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NodeMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingCompositeModifier) Topology(org.alien4cloud.tosca.model.templates.Topology) Set(java.util.Set) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 5 with FlowExecutionContext

use of org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext in project alien4cloud by alien4cloud.

the class PolicyMatchingReplaceModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    super.process(topology, context);
    for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
        PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
        String policyImplMeta = TagUtil.getTagValue(policyType.getTags(), "a4c_policy_impl");
        if (policyImplMeta == null) {
            context.log().warn("Matched policy {} for {} does not define an alien topology modifier implementation, it may not be taken in account.", policyTemplate.getType(), policyTemplate.getName());
            continue;
        }
        String[] policyImpl = policyImplMeta.split(":");
        if (policyImpl.length != 3) {
            context.log().error("Matched policy {} for policy {} defines an invalid modifier implementation {}, format should be policy_plugin_id:policy_plugin_bean:injection_phase", policyTemplate.getType(), policyTemplate.getName(), policyImplMeta);
        }
        try {
            ITopologyModifier modifier = pluginModifierRegistry.getPluginBean(policyImpl[0], policyImpl[1]);
            List<ITopologyModifier> phaseModifiers = (List<ITopologyModifier>) context.getExecutionCache().computeIfAbsent(policyImpl[2], s -> Lists.<ITopologyModifier>newArrayList());
            // No need to add a modifier more than once for a phase
            if (!phaseModifiers.contains(modifier)) {
                phaseModifiers.add(modifier);
            }
        } catch (MissingPluginException e) {
            context.log().error("Implementation specified for policy type {} that refers to plugin bean {}, {} cannot be found.", policyTemplate.getType(), policyImpl[0], policyImpl[1]);
        }
    }
}
Also used : TagUtil(alien4cloud.utils.TagUtil) Set(java.util.Set) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) PluginModifierRegistry(org.alien4cloud.alm.deployment.configuration.flow.modifiers.PluginModifierRegistry) Map(java.util.Map) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ToscaContext(alien4cloud.tosca.context.ToscaContext) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) List(java.util.List) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Aggregations

FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)12 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)6 Map (java.util.Map)6 EnvironmentContext (org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext)6 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)6 Set (java.util.Set)5 NotFoundException (alien4cloud.exception.NotFoundException)4 List (java.util.List)4 Inject (javax.inject.Inject)4 Csar (org.alien4cloud.tosca.model.Csar)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 ToscaContext (alien4cloud.tosca.context.ToscaContext)3 Maps (com.google.common.collect.Maps)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 Component (org.springframework.stereotype.Component)3 ApplicationService (alien4cloud.application.ApplicationService)2 Application (alien4cloud.model.application.Application)2