Search in sources :

Example 46 with NodeTemplate

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

the class DeleteNodeProcessor method removeRelationShipReferences.

/**
 * Removes all relationships connected to the removed node (either as source or target)
 *
 * @param removedNode The name of the removed node
 * @param topology The topology in which to remove the references.
 * @param typesTobeUnloaded List of types to remove from the topology (when relationships are removed)
 */
private void removeRelationShipReferences(String removedNode, Csar csar, Topology topology, List<String> typesTobeUnloaded) {
    List<String> relationshipsToRemove = Lists.newArrayList();
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        if (removedNode.equals(nodeTemplate.getName())) {
            // remove all relationships
            for (Entry<String, RelationshipTemplate> relationshipTemplateEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
                typesTobeUnloaded.add(relationshipTemplateEntry.getValue().getType());
                workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplateEntry.getKey(), relationshipTemplateEntry.getValue());
            }
        } else {
            // This is for later removal
            relationshipsToRemove.clear();
            for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
                if (removedNode.equals(relationshipTemplate.getTarget())) {
                    relationshipsToRemove.add(relationshipTemplate.getName());
                    typesTobeUnloaded.add(relationshipTemplate.getType());
                    workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
                }
            }
            // remove the relationship from the node's relationship map.
            for (String relationshipToRemove : relationshipsToRemove) {
                nodeTemplate.getRelationships().remove(relationshipToRemove);
            }
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 47 with NodeTemplate

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

the class ReplaceNodeProcessor method removeTheRelationshipsOnSource.

/**
 * If the node to replace is an target of relationship, we should swapped the relationship on source and clean used workflow steps
 */
private Map<String, Map<String, RelationshipTemplate>> removeTheRelationshipsOnSource(Topology topology, Csar csar, String nodeToReplace) {
    Map<String, Map<String, RelationshipTemplate>> relationshipDeleted = Maps.newLinkedHashMap();
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        if (!nodeToReplace.equals(nodeTemplate.getName())) {
            List<String> relationshipsToRemove = Lists.newArrayList();
            for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
                if (nodeToReplace.equals(relationshipTemplate.getTarget())) {
                    relationshipsToRemove.add(relationshipTemplate.getName());
                    if (!relationshipDeleted.containsKey(relationshipTemplate.getName())) {
                        Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
                        // we save the RelationshipTemplate, so we will preserve the current properties of this relationship
                        relationshipDeleted.put(nodeTemplate.getName(), relationships);
                    }
                    relationshipDeleted.get(nodeTemplate.getName()).put(relationshipTemplate.getName(), relationshipTemplate);
                    // we should remove this relationship to maintain a great a workflow
                    workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
                }
            }
        }
    }
    return relationshipDeleted;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap)

Example 48 with NodeTemplate

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

the class UpdateCapabilityPropertyValueProcessor method process.

@Override
@SneakyThrows
public void process(Csar csar, Topology topology, UpdateCapabilityPropertyValueOperation operation) {
    String propertyName = operation.getPropertyName();
    Object propertyValue = operation.getPropertyValue();
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    Capability capability = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
    if (!capabilityType.getProperties().containsKey(propertyName)) {
        throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + capabilityType + ">");
    }
    log.debug("Updating property [ {} ] of the capability [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, capability.getType(), operation.getNodeName(), topology.getId(), capabilityType.getProperties().get(propertyName), propertyValue);
    try {
        propertyService.setCapabilityPropertyValue(capability, capabilityType.getProperties().get(propertyName), propertyName, propertyValue);
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) SneakyThrows(lombok.SneakyThrows)

Example 49 with NodeTemplate

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

the class UpdateNodePropertyValueProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateNodePropertyValueOperation operation) {
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemp = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    String propertyName = operation.getPropertyName();
    Object propertyValue = operation.getPropertyValue();
    NodeType node = ToscaContext.getOrFail(NodeType.class, nodeTemp.getType());
    PropertyDefinition propertyDefinition = node.getProperties().get(propertyName);
    if (propertyDefinition == null) {
        throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + nodeTemp.getType() + ">");
    }
    log.debug("Updating property [ {} ] of the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, operation.getNodeName(), topology.getId(), nodeTemp.getProperties().get(propertyName), propertyValue);
    try {
        propertyService.setPropertyValue(nodeTemp, propertyDefinition, propertyName, propertyValue);
    } catch (ConstraintFunctionalException e) {
        throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 50 with NodeTemplate

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

the class RenameInputArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, RenameInputArtifactOperation operation) {
    if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
        throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
    }
    if (safe(topology.getInputArtifacts()).containsKey(operation.getNewInputName())) {
        throw new AlreadyExistException("Input artifact with name <" + operation.getNewInputName() + "> already exists.");
    }
    if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
        throw new NotFoundException("Input artifact with name <" + operation.getInputName() + "> does not exists.");
    }
    DeploymentArtifact inputArtifact = topology.getInputArtifacts().remove(operation.getInputName());
    topology.getInputArtifacts().put(operation.getNewInputName(), inputArtifact);
    // change the value of concerned node template artifacts
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact dArtifact : safe(nodeTemplate.getArtifacts()).values()) {
            InputArtifactUtil.updateInputArtifactIdIfNeeded(dArtifact, operation.getInputName(), operation.getNewInputName());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10