Search in sources :

Example 21 with Topology

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

the class EditorService method undoRedo.

/**
 * Undo or redo operations until the given index (including)
 *
 * @param topologyId The id of the topology for which to undo or redo operations.
 * @param at The index on which to place the undo/redo cursor (-1 means no operations, then 0 is first operation etc.)
 * @param lastOperationId The last known operation id for client optimistic locking.
 * @return The topology DTO.
 */
public TopologyDTO undoRedo(String topologyId, int at, String lastOperationId) {
    try {
        initContext(topologyId, lastOperationId);
        if (-1 > at || at > EditionContextManager.get().getOperations().size()) {
            throw new NotFoundException("Unable to find the requested index for undo/redo");
        }
        checkTopologyRecovery();
        if (at == EditionContextManager.get().getLastOperationIndex()) {
            // nothing to change.
            return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
        }
        // TODO Improve this by avoiding dao query for (deep) cloning topology and keeping cache for TOSCA types that are required.
        editionContextManager.reset();
        Topology topology = EditionContextManager.getTopology();
        Csar csar = EditionContextManager.getCsar();
        for (int i = 0; i < at + 1; i++) {
            AbstractEditorOperation operation = EditionContextManager.get().getOperations().get(i);
            IEditorOperationProcessor processor = processorMap.get(operation.getClass());
            processor.process(csar, topology, operation);
        }
        EditionContextManager.get().setLastOperationIndex(at);
        return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
    } catch (IOException e) {
        // FIXME undo should be fail-safe...
        return null;
    } finally {
        EditionContextManager.get().setCurrentOperation(null);
        editionContextManager.destroy();
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) NotFoundException(alien4cloud.exception.NotFoundException) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) Topology(org.alien4cloud.tosca.model.templates.Topology) IOException(java.io.IOException) EditorIOException(org.alien4cloud.tosca.editor.exception.EditorIOException) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 22 with Topology

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

the class ResetTopologyProcessor method process.

@Override
public void process(Csar csar, Topology topology, ResetTopologyOperation operation) {
    Topology newTopology = new Topology();
    newTopology.setArchiveName(topology.getArchiveName());
    newTopology.setArchiveVersion(topology.getArchiveVersion());
    newTopology.setWorkspace(topology.getWorkspace());
    workflowBuilderService.initWorkflows(workflowBuilderService.buildTopologyContext(newTopology, csar));
    try {
        EditionContextManager.get().reset(newTopology);
    } catch (IOException e) {
        // FIXME what to do here????
        log.error("Error occurs when trying to reset the topology <" + topology.getId() + ">", e);
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) IOException(java.io.IOException)

Example 23 with Topology

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

the class ApplicationStepDefinitions method The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template.

@Then("^The created application topology is the same as the one in the base topology template$")
public void The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template() throws Throwable {
    // created topology
    String topologyId = Csar.createId(CURRENT_APPLICATION.getId(), VersionUtil.DEFAULT_VERSION_NAME);
    Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId));
    TopologyDTO createdTopology = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
    // base topology template
    // quick win solution
    authSteps.I_am_authenticated_with_role("ARCHITECT");
    String topoResponse = Context.getRestClientInstance().get("/rest/v1/catalog/topologies/" + TopologyTemplateStepDefinitions.CURRENT_TOPOLOGY_TEMP_ID);
    Topology topologyTemplateBase = JsonUtil.read(topoResponse, Topology.class, Context.getJsonMapper()).getData();
    Map<String, NodeTemplate> nodeTemplates = topologyTemplateBase.getNodeTemplates();
    // node templates count test
    assertEquals(createdTopology.getTopology().getNodeTemplates().size(), nodeTemplates.size());
    // node templates name / type test
    for (Map.Entry<String, NodeTemplate> entry : createdTopology.getTopology().getNodeTemplates().entrySet()) {
        assertTrue(nodeTemplates.containsKey(entry.getKey()));
        assertTrue(nodeTemplates.get(entry.getKey()).getType().equals(entry.getValue().getType()));
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) TestUtils.nullAsString(alien4cloud.it.utils.TestUtils.nullAsString) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) Then(cucumber.api.java.en.Then)

Example 24 with Topology

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

the class InputArtifactsModifier method processInputArtifacts.

/**
 * Inject input artifacts in the corresponding nodes.
 *
 * @param topology The topology in which to inject input artifacts.
 * @param inputArtifacts The input artifacts to inject in the topology.
 */
private void processInputArtifacts(Topology topology, Map<String, DeploymentArtifact> inputArtifacts) {
    if (topology.getInputArtifacts() != null && !topology.getInputArtifacts().isEmpty()) {
        // we'll build a map inputArtifactId -> List<DeploymentArtifact>
        Map<String, List<DeploymentArtifact>> artifactMap = Maps.newHashMap();
        // iterate over nodes in order to remember all nodes referencing an input artifact
        for (NodeTemplate nodeTemplate : topology.getNodeTemplates().values()) {
            if (MapUtils.isNotEmpty(nodeTemplate.getArtifacts())) {
                processInputArtifactForTemplate(artifactMap, nodeTemplate);
            }
            if (MapUtils.isNotEmpty(nodeTemplate.getRelationships())) {
                nodeTemplate.getRelationships().entrySet().stream().filter(relationshipTemplateEntry -> MapUtils.isNotEmpty(relationshipTemplateEntry.getValue().getArtifacts())).forEach(relationshipTemplateEntry -> processInputArtifactForTemplate(artifactMap, relationshipTemplateEntry.getValue()));
            }
        }
        // Override the artifacts definition in the topology with the input artifact data.
        Map<String, DeploymentArtifact> allInputArtifact = new HashMap<>();
        allInputArtifact.putAll(topology.getInputArtifacts());
        if (MapUtils.isNotEmpty(inputArtifacts)) {
            allInputArtifact.putAll(inputArtifacts);
        }
        for (Map.Entry<String, DeploymentArtifact> inputArtifact : allInputArtifact.entrySet()) {
            List<DeploymentArtifact> nodeArtifacts = artifactMap.get(inputArtifact.getKey());
            if (nodeArtifacts != null) {
                for (DeploymentArtifact nodeArtifact : nodeArtifacts) {
                    nodeArtifact.setArtifactRef(inputArtifact.getValue().getArtifactRef());
                    nodeArtifact.setArtifactName(inputArtifact.getValue().getArtifactName());
                    nodeArtifact.setArtifactRepository(inputArtifact.getValue().getArtifactRepository());
                    nodeArtifact.setRepositoryName(inputArtifact.getValue().getRepositoryName());
                    nodeArtifact.setRepositoryCredential(inputArtifact.getValue().getRepositoryCredential());
                    nodeArtifact.setRepositoryURL(inputArtifact.getValue().getRepositoryURL());
                    nodeArtifact.setArchiveName(inputArtifact.getValue().getArchiveName());
                    nodeArtifact.setArchiveVersion(inputArtifact.getValue().getArchiveVersion());
                }
            }
        }
    }
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Lists(org.elasticsearch.common.collect.Lists) Iterator(java.util.Iterator) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) InputArtifactUtil(alien4cloud.utils.InputArtifactUtil) HashMap(java.util.HashMap) Maps(com.google.common.collect.Maps) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) AbstractInstantiableTemplate(org.alien4cloud.tosca.model.templates.AbstractInstantiableTemplate) List(java.util.List) Component(org.springframework.stereotype.Component) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Entry(java.util.Map.Entry) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) HashMap(java.util.HashMap) List(java.util.List) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Topology

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

the class SuggestionService method postProcessSuggestionFromArchive.

public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
    ArchiveRoot archiveRoot = parsingResult.getResult();
    ParsingContext context = parsingResult.getContext();
    if (archiveRoot.hasToscaTopologyTemplate()) {
        Topology topology = archiveRoot.getTopology();
        Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
        if (MapUtils.isEmpty(nodeTemplateMap)) {
            return;
        }
        for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
            NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
            String nodeName = nodeTemplateEntry.getKey();
            if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
                checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
            }
            Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
            if (MapUtils.isNotEmpty(capabilityMap)) {
                for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
                    String capabilityName = capabilityEntry.getKey();
                    Capability capability = capabilityEntry.getValue();
                    if (MapUtils.isNotEmpty(capability.getProperties())) {
                        checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
                    }
                }
            }
            Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
            if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
                for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
                    String relationshipName = relationshipEntry.getKey();
                    RelationshipTemplate relationship = relationshipEntry.getValue();
                    if (MapUtils.isNotEmpty(relationship.getProperties())) {
                        checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
                    }
                }
            }
        }
    }
    if (archiveRoot.hasToscaTypes()) {
        Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
        if (MapUtils.isNotEmpty(allNodeTypes)) {
            for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
                NodeType nodeType = nodeTypeEntry.getValue();
                if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
                    for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
                        NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
                        if (nodeFilter != null) {
                            Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
                            if (MapUtils.isNotEmpty(capabilitiesFilters)) {
                                for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
                                    FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
                                    for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
                                        List<PropertyConstraint> constraints = constraintEntry.getValue();
                                        checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
                                    }
                                }
                            }
                        // FIXME check also the value properties filter of a node filter
                        }
                    }
                }
            }
        }
    }
}
Also used : RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) ParsingContext(alien4cloud.tosca.parser.ParsingContext) Capability(org.alien4cloud.tosca.model.templates.Capability) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) NodeFilter(org.alien4cloud.tosca.model.definitions.NodeFilter)

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