Search in sources :

Example 36 with Capability

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

the class NodeMatchingReplaceModifier method processSpecificReplacement.

@Override
protected void processSpecificReplacement(NodeTemplate replacingNode, NodeTemplate replacedTopologyNode, Set<String> topologyNotMergedProps) {
    // Also merge relationships
    replacingNode.setRelationships(replacedTopologyNode.getRelationships());
    // not miss any capability
    for (Map.Entry<String, Capability> locationCapabilityEntry : safe(replacingNode.getCapabilities()).entrySet()) {
        // Merge capabilities properties from the topology into the substituted node un-set properties
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, locationCapabilityEntry.getValue().getType());
        Capability locationCapability = locationCapabilityEntry.getValue();
        Capability abstractCapability = safe(replacedTopologyNode.getCapabilities()).get(locationCapabilityEntry.getKey());
        // Ignore injection of location values for scalable capability
        if (abstractCapability != null && MapUtils.isNotEmpty(abstractCapability.getProperties())) {
            if (capabilityType != null && !ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
                locationCapability.setProperties(CollectionUtils.merge(abstractCapability.getProperties(), locationCapability.getProperties(), true, topologyNotMergedProps));
            } else {
                locationCapability.setProperties(abstractCapability.getProperties());
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) Map(java.util.Map)

Example 37 with Capability

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

the class UnSetNodeCapabilityPropertyAsOutputProcessor method check.

@SuppressWarnings("unchecked")
private void check(UnSetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
    if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
        throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
    }
    Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
    if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
        throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
    }
    Set<String> values = (Set<String>) MapUtil.get(topology.getOutputCapabilityProperties(), operation.getNodeName().concat(".").concat(operation.getCapabilityName()));
    if (!AlienUtils.safe(values).contains(operation.getPropertyName())) {
        throw new NotFoundException("Node " + operation.getNodeName() + " capability " + operation.getCapabilityName() + " 's property " + operation.getPropertyName() + " not found in outputs");
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException)

Example 38 with Capability

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

the class RenameInputProcessor method processInputOperation.

@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
    if (!inputs.containsKey(operation.getInputName())) {
        throw new NotFoundException("Input " + operation.getInputName() + " not found");
    }
    if (operation.getInputName().equals(operation.getNewInputName())) {
        // nothing has changed.
        return;
    }
    if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
        throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
    }
    if (inputs.containsKey(operation.getNewInputName())) {
        throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
    }
    PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
    inputs.put(operation.getNewInputName(), propertyDefinition);
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
        renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
        if (nodeTemp.getRelationships() != null) {
            for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
                renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
            }
        }
        if (nodeTemp.getCapabilities() != null) {
            for (Capability capability : nodeTemp.getCapabilities().values()) {
                renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
            }
        }
    }
    // rename preconfigured input
    renamePreconfiguredInput(csar, topology, operation);
    log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 39 with Capability

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

the class ReplaceNodeProcessor method updateRelationshipsCapabilitiesRelationships.

private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) {
    List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates());
    for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
        RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship();
        Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName());
        if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) {
            Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType());
            targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey());
            // check that the relationship type is still valid with the new capability
            RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType());
            if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) {
                NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType());
                RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName());
                NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
                CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey());
                RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition);
                targetRelationship.setType(validRelationshipType.getElementId());
                targetRelationship.setType(validRelationshipType.getElementId());
                targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts())));
                targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes())));
                Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
                TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null);
                targetRelationship.setProperties(properties);
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) LinkedHashMap(java.util.LinkedHashMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 40 with Capability

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

the class FunctionEvaluatorTest method getEvaluationContext.

/**
 * Generate the topology below (no need type validations) and inputs to be used for next tests.
 *
 * @return A function evaluator context for the test topology.
 */
private FunctionEvaluatorContext getEvaluationContext() {
    NodeTemplate myNode = new NodeTemplate();
    myNode.setProperties(Maps.newHashMap());
    setPropertiesValues(myNode.getProperties(), "");
    Capability capability = new Capability();
    myNode.setCapabilities(Maps.newHashMap());
    myNode.getCapabilities().put("my_capability", capability);
    capability.setProperties(Maps.newHashMap());
    setPropertiesValues(capability.getProperties(), "capa ");
    Topology topology = new Topology();
    topology.setNodeTemplates(Maps.newHashMap());
    topology.getNodeTemplates().put("my_node", myNode);
    Map<String, AbstractPropertyValue> inputs = Maps.newHashMap();
    inputs.put("scalar_input", new ScalarPropertyValue("scalar input value"));
    return new FunctionEvaluatorContext(topology, inputs);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) Topology(org.alien4cloud.tosca.model.templates.Topology) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

Capability (org.alien4cloud.tosca.model.templates.Capability)50 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)27 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)26 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)14 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)12 Map (java.util.Map)10 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 NotFoundException (alien4cloud.exception.NotFoundException)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 Test (org.junit.Test)9 Set (java.util.Set)8 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 Location (alien4cloud.model.orchestrators.locations.Location)3 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)3