Search in sources :

Example 1 with SubstitutionTarget

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

the class TopologySubstitutionService method fillRequirements.

private void fillRequirements(Topology topology, NodeType substituteNodeType) {
    if (topology.getSubstitutionMapping().getRequirements() != null) {
        for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) {
            String key = e.getKey();
            String nodeName = e.getValue().getNodeTemplateName();
            String requirementName = e.getValue().getTargetId();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName);
            // We cannot change the capability definition here or we will change the original one so we need a clone
            requirementDefinition = CloneUtil.clone(requirementDefinition);
            requirementDefinition.setId(key);
            substituteNodeType.getRequirements().add(requirementDefinition);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Map(java.util.Map)

Example 2 with SubstitutionTarget

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

the class TopologySubstitutionService method fillCapabilities.

private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
    if (topology.getSubstitutionMapping().getCapabilities() != null) {
        for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
            String key = e.getKey();
            String nodeName = e.getValue().getNodeTemplateName();
            String capabilityName = e.getValue().getTargetId();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
            CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
            // We cannot change the capability definition here or we will change the original one so we need a clone
            capabilityDefinition = CloneUtil.clone(capabilityDefinition);
            capabilityDefinition.setId(key);
            substituteNodeType.getCapabilities().add(capabilityDefinition);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 3 with SubstitutionTarget

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

the class AddCapabilitySubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddCapabilitySubstitutionTypeOperation 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.getCapabilities() == null || !nodeTemplate.getCapabilities().containsKey(operation.getCapabilityId())) {
        throw new NotFoundException("Capability " + operation.getCapabilityId() + " 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> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
    if (substitutionCapabilities == null) {
        substitutionCapabilities = Maps.newHashMap();
        topology.getSubstitutionMapping().setCapabilities(substitutionCapabilities);
    } else if (substitutionCapabilities.containsKey(operation.getSubstitutionCapabilityId())) {
        // ensure name unicity
        throw new AlreadyExistException(String.format("A substitution with capability id <%s> already exists", operation.getSubstitutionCapabilityId()));
    }
    substitutionCapabilities.put(operation.getSubstitutionCapabilityId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getCapabilityId()));
}
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 4 with SubstitutionTarget

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

the class RemoveCapabilitySubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, RemoveCapabilitySubstitutionTypeOperation operation) {
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionCapabilities = topology.getSubstitutionMapping().getCapabilities();
    if (substitutionCapabilities == null) {
        throw new NotFoundException("No substitution capabilities has been found");
    }
    SubstitutionTarget target = substitutionCapabilities.remove(operation.getSubstitutionCapabilityId());
    if (target == null) {
        throw new NotFoundException("No substitution capability has been found for key " + operation.getSubstitutionCapabilityId());
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget)

Example 5 with SubstitutionTarget

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

the class RemoveRequirementSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, RemoveRequirementSubstitutionTypeOperation 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 requirements 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());
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) 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