Search in sources :

Example 16 with NodeTemplate

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

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

the class FunctionEvaluatorTest method nodeGetComplexPropList.

@Test
public void nodeGetComplexPropList() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("get_complex_prop_list"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("list value 2", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 18 with NodeTemplate

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

the class FunctionEvaluatorTest method nodeGetComplexPropMap.

@Test
public void nodeGetComplexPropMap() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("get_complex_prop_map"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("element 1 value", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 19 with NodeTemplate

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

the class FunctionEvaluatorTest method nodeConcatGetConcatProp.

@Test
public void nodeConcatGetConcatProp() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("concat_get_concat_prop"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("get concat is: input is: scalar input value property is: scalar value", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 20 with NodeTemplate

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

the class FunctionEvaluatorTest method nodeGetSecretProp.

@Test
public void nodeGetSecretProp() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    AbstractPropertyValue resolved = FunctionEvaluator.tryResolveValue(context, template, template.getProperties(), template.getProperties().get("get_secret_prop"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(FunctionPropertyValue.class, resolved.getClass());
    Assert.assertEquals("get_secret", ((FunctionPropertyValue) resolved).getFunction());
    Assert.assertEquals("my/path", ((FunctionPropertyValue) resolved).getParameters().get(0));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10