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()));
}
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());
}
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());
}
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());
}
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));
}
Aggregations