Search in sources :

Example 1 with CyclicReferenceException

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

the class AddNodeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddNodeOperation operation) {
    NameValidationUtils.validateNodeName(operation.getNodeName());
    AlienUtils.failIfExists(topology.getNodeTemplates(), operation.getNodeName(), "A node template with the given name {} already exists in the topology {}.", operation.getNodeName(), topology.getId());
    NodeType nodeType = toscaTypeSearchService.findByIdOrFail(NodeType.class, operation.getIndexedNodeTypeId());
    if (nodeType.getSubstitutionTopologyId() != null) {
        // it's a try to add this topology's type
        if (nodeType.getSubstitutionTopologyId().equals(topology.getId())) {
            throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself");
        }
        // detect try to add a substitution topology that indirectly reference this one
        topologyCompositionService.recursivelyDetectTopologyCompositionCyclicReference(topology.getId(), nodeType.getSubstitutionTopologyId());
    }
    if (topology.getNodeTemplates() == null) {
        topology.setNodeTemplates(new LinkedHashMap<>());
    }
    log.debug("Create node template [ {} ]", operation.getNodeName());
    NodeType loadedIndexedNodeType = topologyService.loadType(topology, nodeType);
    NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(loadedIndexedNodeType);
    nodeTemplate.setName(operation.getNodeName());
    if (operation.getCoords() != null) {
        // Set the position information of the node as meta-data.
        nodeTemplate.setTags(Lists.newArrayList(new Tag(Constants.X_META, String.valueOf(operation.getCoords().getX())), new Tag(Constants.Y_META, String.valueOf(operation.getCoords().getY()))));
    }
    topology.getNodeTemplates().put(operation.getNodeName(), nodeTemplate);
    log.debug("Adding a new Node template <" + operation.getNodeName() + "> bound to the node type <" + operation.getIndexedNodeTypeId() + "> to the topology <" + topology.getId() + "> .");
    TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
    workflowBuilderService.addNode(topologyContext, operation.getNodeName());
    if (!operation.isSkipAutoCompletion()) {
        danglingRequirementService.addDanglingRequirements(topology, topologyContext, nodeTemplate, operation.getRequirementSkipAutoCompletion());
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Tag(alien4cloud.model.common.Tag) TopologyContext(alien4cloud.paas.wf.TopologyContext) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

Example 2 with CyclicReferenceException

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

the class TopologyCompositionService method recursivelyDetectTopologyCompositionCyclicReference.

/**
 * Deeply explore composition in order to detect cyclic reference: if a descendant references the mainTopologyId.
 */
public void recursivelyDetectTopologyCompositionCyclicReference(String mainTopologyId, String substitutionTopologyId) {
    Topology child = topologyServiceCore.getOrFail(substitutionTopologyId);
    if (child == null || child.getNodeTemplates() == null || child.getNodeTemplates().isEmpty()) {
        return;
    }
    for (Entry<String, NodeTemplate> nodeEntry : child.getNodeTemplates().entrySet()) {
        String type = nodeEntry.getValue().getType();
        NodeType nodeType = csarRepoSearchService.getElementInDependencies(NodeType.class, type, child.getDependencies());
        if (nodeType.getSubstitutionTopologyId() != null) {
            if (nodeType.getSubstitutionTopologyId().equals(mainTopologyId)) {
                throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself (even indirectly)");
            }
            recursivelyDetectTopologyCompositionCyclicReference(mainTopologyId, nodeType.getSubstitutionTopologyId());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

Aggregations

CyclicReferenceException (alien4cloud.exception.CyclicReferenceException)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 Tag (alien4cloud.model.common.Tag)1 TopologyContext (alien4cloud.paas.wf.TopologyContext)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1