Search in sources :

Example 1 with Capability

use of org.alien4cloud.tosca.model.templates.Capability in project yorc-a4c-plugin by ystia.

the class ShowTopology method printNode.

/**
 * Print info about a Node
 * @param node
 */
private static void printNode(PaaSNodeTemplate node) {
    log.debug("******* Compute Node " + node.getId() + " *******");
    NodeTemplate nt = node.getTemplate();
    log.debug("CsarPath = " + node.getCsarPath());
    log.debug("Type = " + nt.getType());
    // Children
    List<PaaSNodeTemplate> children = node.getChildren();
    for (PaaSNodeTemplate child : children) {
        log.info("Child: " + child.getId());
    }
    // properties
    for (String prop : nt.getProperties().keySet()) {
        AbstractPropertyValue absval = nt.getProperties().get(prop);
        if (absval instanceof ScalarPropertyValue) {
            ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
            log.debug(">> Property: " + prop + "=" + scaval.getValue());
        }
    }
    // Attributes
    Map<String, IValue> attrs = nt.getAttributes();
    if (attrs != null) {
        for (String attname : attrs.keySet()) {
            IValue att = attrs.get(attname);
            log.debug(">> Attribute: " + attname + "=" + att);
        }
    }
    // capabilities
    Map<String, Capability> capabilities = nt.getCapabilities();
    if (capabilities != null) {
        for (String capname : capabilities.keySet()) {
            Capability cap = capabilities.get(capname);
            log.debug(">> Capability " + capname);
            log.debug("type : " + cap.getType());
            log.debug("properties : " + cap.getProperties());
        }
    }
    // requirements
    Map<String, Requirement> requirements = nt.getRequirements();
    if (requirements != null) {
        for (String reqname : requirements.keySet()) {
            Requirement req = requirements.get(reqname);
            log.debug(">> Requirement: " + reqname);
            log.debug("type : " + req.getType());
            log.debug("properties : " + req.getProperties());
        }
    }
    // relationships
    Map<String, RelationshipTemplate> relations = nt.getRelationships();
    if (relations != null) {
        for (String relname : relations.keySet()) {
            RelationshipTemplate rel = relations.get(relname);
            log.debug(">> Relationship: " + relname);
            log.debug("type : " + rel.getType());
            log.debug("properties : " + rel.getProperties());
        }
    }
    // artifacts
    Map<String, DeploymentArtifact> artifacts = nt.getArtifacts();
    if (artifacts != null) {
        for (DeploymentArtifact art : artifacts.values()) {
            printArtifact(art);
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) Requirement(org.alien4cloud.tosca.model.templates.Requirement) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 2 with Capability

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

the class FunctionEvaluator method doGetProperty.

private static AbstractPropertyValue doGetProperty(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, FunctionPropertyValue function) {
    if (targetTemplate == null) {
        return null;
    }
    // If a requirement or capability name is defined then it is applied to the node template.
    if (function.getCapabilityOrRequirementName() != null) {
        if (targetTemplate instanceof RelationshipTemplate) {
            throw new IllegalArgumentException("Get property that specifies a capability or relationship target must be placed on a node template and not a relationship template.");
        }
        AbstractPropertyValue propertyValue = null;
        Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName());
        if (targetCapability != null) {
            propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch());
        }
        if (propertyValue == null) {
            Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName());
            if (requirement != null) {
                propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch());
            }
        }
        if (propertyValue == null) {
            // try to find the value from the host node.
            propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
        }
        return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
    }
    // Try to fetch from the node.
    AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch());
    if (propertyValue == null && targetTemplate instanceof NodeTemplate) {
        propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
    }
    // if the property refers to a function (get_input/get_property then try to resolve it).
    return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
Also used : Requirement(org.alien4cloud.tosca.model.templates.Requirement) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 3 with Capability

use of org.alien4cloud.tosca.model.templates.Capability 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 Capability

use of org.alien4cloud.tosca.model.templates.Capability 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 Capability

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

the class PaaSUtilsTest method buildPaaSNodeTemplate.

private PaaSNodeTemplate buildPaaSNodeTemplate() {
    Map<String, Capability> capabilities = Maps.newHashMap();
    capabilities.put(fakeCapa1, buildFakeCapability());
    NodeTemplate nodeTemplate = buildFakeNodeTemplate(capabilities);
    Map<String, Operation> operations = Maps.newHashMap();
    operations.put(operation1, buildFakeOperation());
    Map<String, Interface> interfaces = Maps.newHashMap();
    interfaces.put(interface1, buildFakeInterface(operations));
    return buildFakePaaSNodeTemplate(nodeTemplate, interfaces);
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability)

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