Search in sources :

Example 11 with SubstitutionTarget

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

the class AddRequirementSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddRequirementSubstitutionTypeOperation operation) {
    if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) {
        throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist");
    }
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName());
    if (nodeTemplate.getRequirements() == null || !nodeTemplate.getRequirements().containsKey(operation.getRequirementId())) {
        throw new NotFoundException("Requirement " + operation.getRequirementId() + " do not exist for node " + operation.getNodeTemplateName());
    }
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements();
    if (substitutionRequirements == null) {
        substitutionRequirements = Maps.newHashMap();
        topology.getSubstitutionMapping().setRequirements(substitutionRequirements);
    } else if (substitutionRequirements.containsKey(operation.getSubstitutionRequirementId())) {
        // ensure name unicity
        throw new AlreadyExistException(String.format("The substitution requirement <%s> already exists", operation.getSubstitutionRequirementId()));
    }
    substitutionRequirements.put(operation.getSubstitutionRequirementId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getRequirementId()));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 12 with SubstitutionTarget

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

the class SetSubstitutionCapabilityServiceRelationshipProcessor method process.

@Override
public void process(Csar csar, Topology topology, SetSubstitutionCapabilityServiceRelationshipOperation operation) {
    if (topology.getSubstitutionMapping() == null) {
        throw new NotFoundException("The substitution capability with id <" + operation.getSubstitutionCapabilityId() + "> cannot be found.");
    }
    SubstitutionTarget substitutionTarget = safe(topology.getSubstitutionMapping().getCapabilities()).get(operation.getSubstitutionCapabilityId());
    if (substitutionTarget == null) {
        throw new NotFoundException("The substitution capability with id <" + operation.getSubstitutionCapabilityId() + "> cannot be found.");
    }
    super.process(csar, topology, substitutionTarget, operation.getRelationshipType(), operation.getRelationshipVersion());
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget)

Example 13 with SubstitutionTarget

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

the class SetSubstitutionRequirementServiceRelationshipProcessor method process.

@Override
public void process(Csar csar, Topology topology, SetSubstitutionRequirementServiceRelationshipOperation operation) {
    if (topology.getSubstitutionMapping() == null) {
        throw new NotFoundException("The substitution requirement with id <" + operation.getSubstitutionRequirementId() + "> cannot be found.");
    }
    SubstitutionTarget substitutionTarget = safe(topology.getSubstitutionMapping().getRequirements()).get(operation.getSubstitutionRequirementId());
    if (substitutionTarget == null) {
        throw new NotFoundException("The substitution requirement with id <" + operation.getSubstitutionRequirementId() + "> cannot be found.");
    }
    super.process(csar, topology, substitutionTarget, operation.getRelationshipType(), operation.getRelationshipVersion());
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget)

Example 14 with SubstitutionTarget

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

the class UpdateRequirementSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateRequirementSubstitutionTypeOperation operation) {
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements();
    if (substitutionRequirements == null) {
        throw new NotFoundException("No substitution requirement has been found");
    }
    SubstitutionTarget target = substitutionRequirements.remove(operation.getSubstitutionRequirementId());
    if (target == null) {
        throw new NotFoundException("No substitution requirement has been found for key " + operation.getSubstitutionRequirementId());
    }
    if (substitutionRequirements.containsKey(operation.getNewRequirementId())) {
        throw new AlreadyExistException(String.format("Can not rename from <%s> to <%s> since requirement <%s> already exists", operation.getSubstitutionRequirementId(), operation.getNewRequirementId(), operation.getNewRequirementId()));
    }
    substitutionRequirements.put(operation.getNewRequirementId(), target);
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 15 with SubstitutionTarget

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

the class TopologyUtils method updateOnNodeTemplateNameChange.

/**
 * Update properties in a topology
 */
private static void updateOnNodeTemplateNameChange(String oldNodeTemplateName, String newNodeTemplateName, Topology topology) {
    // Output properties
    updateKey(topology.getOutputProperties(), oldNodeTemplateName, newNodeTemplateName);
    // output capabilities properties
    updateKey(topology.getOutputCapabilityProperties(), oldNodeTemplateName, newNodeTemplateName);
    // output attributes
    updateKey(topology.getOutputAttributes(), oldNodeTemplateName, newNodeTemplateName);
    // substitution mapping
    if (topology.getSubstitutionMapping() != null) {
        if (topology.getSubstitutionMapping().getCapabilities() != null) {
            for (SubstitutionTarget st : topology.getSubstitutionMapping().getCapabilities().values()) {
                if (st.getNodeTemplateName().equals(oldNodeTemplateName)) {
                    st.setNodeTemplateName(newNodeTemplateName);
                }
            }
        }
        if (topology.getSubstitutionMapping().getRequirements() != null) {
            for (SubstitutionTarget st : topology.getSubstitutionMapping().getRequirements().values()) {
                if (st.getNodeTemplateName().equals(oldNodeTemplateName)) {
                    st.setNodeTemplateName(newNodeTemplateName);
                }
            }
        }
    }
}
Also used : SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget)

Aggregations

SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)16 NotFoundException (alien4cloud.exception.NotFoundException)8 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 AlreadyExistException (alien4cloud.exception.AlreadyExistException)4 Map (java.util.Map)4 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 NodeType (org.alien4cloud.tosca.model.types.NodeType)3 Capability (org.alien4cloud.tosca.model.templates.Capability)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 InstanceInformation (alien4cloud.paas.model.InstanceInformation)1 ToscaTypeLoader (alien4cloud.tosca.container.ToscaTypeLoader)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 Set (java.util.Set)1 ManagedServiceUpdatedEvent (org.alien4cloud.alm.events.ManagedServiceUpdatedEvent)1 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)1 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)1 PolicyTemplate (org.alien4cloud.tosca.model.templates.PolicyTemplate)1 PolicyType (org.alien4cloud.tosca.model.types.PolicyType)1