Search in sources :

Example 36 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class WorkflowUtils method processInlineWorkflow.

private static void processInlineWorkflow(Map<String, Workflow> workflowMap, Workflow workflow) {
    final Set<String> newInlinedStepNames = new HashSet<>();
    // Clone the map as we iterate and in the same time modify it
    Maps.newHashMap(workflow.getSteps()).entrySet().stream().filter(entry -> entry.getValue().getActivity() instanceof InlineWorkflowActivity).forEach(inlinedStepEntry -> {
        String inlinedStepName = inlinedStepEntry.getKey();
        WorkflowStep inlinedStep = inlinedStepEntry.getValue();
        InlineWorkflowActivity inlineWorkflowActivity = (InlineWorkflowActivity) inlinedStep.getActivity();
        String inlinedName = inlineWorkflowActivity.getInline();
        Workflow inlined = workflowMap.get(inlinedName);
        if (inlined == null) {
            throw new NotFoundException("Inlined workflow " + inlinedName);
        }
        Map<String, WorkflowStep> generatedSteps = cloneSteps(inlined.getSteps());
        Map<String, WorkflowStep> generatedStepsWithNewNames = generatedSteps.entrySet().stream().collect(Collectors.toMap(entry -> {
            String newName = generateNewWfStepNameWithPrefix(inlinedStepEntry.getKey() + "_", workflow.getSteps().keySet(), newInlinedStepNames, entry.getKey());
            newInlinedStepNames.add(newName);
            if (!newName.equals(entry.getKey())) {
                entry.getValue().setName(newName);
                generatedSteps.forEach((generatedStepId, generatedStep) -> {
                    if (generatedStep.removeFollowing(entry.getKey())) {
                        generatedStep.addFollowing(newName);
                    }
                    if (generatedStep.removePreceding(entry.getKey())) {
                        generatedStep.addPreceding(newName);
                    }
                });
            }
            return newName;
        }, Map.Entry::getValue));
        // Find all root steps of the workflow and link them to the parent workflows
        final Map<String, WorkflowStep> rootInlinedSteps = generatedStepsWithNewNames.values().stream().filter(generatedStepWithNewName -> generatedStepWithNewName.getPrecedingSteps().isEmpty()).peek(rootInlinedStep -> rootInlinedStep.addAllPrecedings(inlinedStep.getPrecedingSteps())).collect(Collectors.toMap(WorkflowStep::getName, rootInlinedStep -> rootInlinedStep));
        inlinedStep.getPrecedingSteps().forEach(precedingStepName -> {
            WorkflowStep precedingStep = workflow.getSteps().get(precedingStepName);
            precedingStep.removeFollowing(inlinedStepName);
            precedingStep.addAllFollowings(rootInlinedSteps.keySet());
        });
        // Find all leaf steps of the workflow and link them to the parent workflows
        final Map<String, WorkflowStep> leafInlinedSteps = generatedStepsWithNewNames.values().stream().filter(generatedStepWithNewName -> generatedStepWithNewName.getOnSuccess().isEmpty()).peek(leafInlinedStep -> leafInlinedStep.addAllFollowings(inlinedStep.getOnSuccess())).collect(Collectors.toMap(WorkflowStep::getName, leafInlinedStep -> leafInlinedStep));
        inlinedStep.getOnSuccess().forEach(onSuccessStepName -> {
            WorkflowStep onSuccessStep = workflow.getSteps().get(onSuccessStepName);
            onSuccessStep.removePreceding(inlinedStepName);
            onSuccessStep.addAllPrecedings(leafInlinedSteps.keySet());
        });
        // Remove the inlined step and replace by other workflow's steps
        workflow.getSteps().remove(inlinedStepName);
        workflow.addAllSteps(generatedStepsWithNewNames);
    });
    // Check if the workflow contains inline activity event after processing
    boolean processedWorkflowContainsInline = workflow.getSteps().values().stream().anyMatch(step -> step.getActivity() instanceof InlineWorkflowActivity);
    if (processedWorkflowContainsInline) {
        // Recursively process inline workflow until no step is inline workflow
        processInlineWorkflow(workflowMap, workflow);
    }
}
Also used : NormativeComputeConstants(org.alien4cloud.tosca.normative.constants.NormativeComputeConstants) SetStateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity) NodeType(org.alien4cloud.tosca.model.types.NodeType) StringUtils(org.apache.commons.lang3.StringUtils) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) TopologyNavigationUtil(org.alien4cloud.tosca.utils.TopologyNavigationUtil) STOP(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.STOP) HashSet(java.util.HashSet) START(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.START) INSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.INSTALL) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) InvalidNameException(alien4cloud.exception.InvalidNameException) InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) Map(java.util.Map) Interface(org.alien4cloud.tosca.model.definitions.Interface) Operation(org.alien4cloud.tosca.model.definitions.Operation) Set(java.util.Set) TopologyContext(alien4cloud.paas.wf.TopologyContext) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) CallOperationWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity) NotFoundException(alien4cloud.exception.NotFoundException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) UNINSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.UNINSTALL) Pattern(java.util.regex.Pattern) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) ToscaTypeUtils.isOfType(org.alien4cloud.tosca.utils.ToscaTypeUtils.isOfType) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 37 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method swapSteps.

public void swapSteps(Topology topology, Csar csar, String workflowName, String stepId, String targetId) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.swapSteps(wf, stepId, targetId);
    WorkflowUtils.fillHostId(wf, topologyContext);
    if (log.isDebugEnabled()) {
        log.debug(WorkflowUtils.debugWorkflow(wf));
    }
    workflowValidator.validate(topologyContext, wf);
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Example 38 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method addActivity.

public void addActivity(Topology topology, Csar csar, String workflowName, String relatedStepId, boolean before, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.addActivity(wf, relatedStepId, before, target, targetRelationship, activity, topologyContext);
    WorkflowUtils.fillHostId(wf, topologyContext);
    if (log.isDebugEnabled()) {
        log.debug(WorkflowUtils.debugWorkflow(wf));
    }
    workflowValidator.validate(topologyContext, wf);
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Example 39 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method removeStep.

public void removeStep(Topology topology, Csar csar, String workflowName, String stepId) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.removeStep(wf, stepId, false);
    if (log.isDebugEnabled()) {
        log.debug(WorkflowUtils.debugWorkflow(wf));
    }
    workflowValidator.validate(topologyContext, wf);
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Example 40 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method removeEdge.

public Workflow removeEdge(Topology topology, Csar csar, String workflowName, String from, String to) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.removeEdge(wf, from, to);
    workflowValidator.validate(topologyContext, wf);
    return wf;
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5