Search in sources :

Example 1 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method fillAttributesFromOutputCapabilitiesProperties.

private void fillAttributesFromOutputCapabilitiesProperties(Topology topology, NodeType substituteNodeType) {
    Map<String, Map<String, Set<String>>> outputCapabilityProperties = topology.getOutputCapabilityProperties();
    if (outputCapabilityProperties != null) {
        for (Map.Entry<String, Map<String, Set<String>>> ocpe : outputCapabilityProperties.entrySet()) {
            String nodeName = ocpe.getKey();
            NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
            for (Map.Entry<String, Set<String>> cpe : ocpe.getValue().entrySet()) {
                String capabilityName = cpe.getKey();
                String capabilityTypeName = nodeTemplate.getCapabilities().get(capabilityName).getType();
                CapabilityType capabilityType = ToscaContext.getOrFail(CapabilityType.class, capabilityTypeName);
                for (String propertyName : cpe.getValue()) {
                    PropertyDefinition pd = capabilityType.getProperties().get(propertyName);
                    // there is a conflict
                    addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
                }
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 2 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class TopologyDTOBuilder method getCapabilityTypes.

private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
    Map<String, CapabilityType> types = Maps.newHashMap();
    Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
    for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
        if (nodeType != null) {
            for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
                types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
            }
            for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
                if (capabilityType != null) {
                    types.put(requirementDefinition.getType(), capabilityType);
                } else {
                    // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
                    NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
                    // add it to the actual node types map
                    delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
                }
            }
        }
    }
    for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
        topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
    }
    return types;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class SetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    if (operation.getCapabilityName().equals(FORBIDDEN_CAPABILITY)) {
        throw new UnsupportedSecretException("We cannot set a secret on the capability " + operation.getCapabilityName());
    }
    if ("".equals(operation.getSecretPath())) {
        throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + "is null.");
    }
    FunctionPropertyValue getSecret = new FunctionPropertyValue();
    getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
    getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
    nodeTemplate.getCapabilities().get(operation.getCapabilityName()).getProperties().put(operation.getPropertyName(), getSecret);
    log.debug("Set the property [ {} ] of capability template [ {} ] of node [ {} ] to the secret path [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) UnsupportedSecretException(org.alien4cloud.tosca.editor.exception.UnsupportedSecretException) Capability(org.alien4cloud.tosca.model.templates.Capability) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) InvalidSecretPathException(org.alien4cloud.tosca.editor.exception.InvalidSecretPathException)

Example 4 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    // check if the node property value is a get_secret
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (currentValue != null && !isGetSecret(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
    }
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType());
    PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
    capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 5 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class LocationResourceService method setTemplateCapabilityProperty.

private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Location location = locationService.getOrFail(resourceTemplate.getLocationId());
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies());
    Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName);
    CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName);
    CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies());
    PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName);
    propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)48 Capability (org.alien4cloud.tosca.model.templates.Capability)25 NodeType (org.alien4cloud.tosca.model.types.NodeType)21 Set (java.util.Set)20 Test (org.junit.Test)18 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)14 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)9 Csar (org.alien4cloud.tosca.model.Csar)8 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)8 NotFoundException (alien4cloud.exception.NotFoundException)7 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)5 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 List (java.util.List)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)2