use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method real_world_location_resource_compute_should_be_able_to_match_an_abstract_compute_from_topology.
@Test
public void real_world_location_resource_compute_should_be_able_to_match_an_abstract_compute_from_topology() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Compute");
NodeType wantedNodeType = new NodeType();
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(1);
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method abstract_template_should_be_matched_if_service_is_available_2.
@Test
public void abstract_template_should_be_matched_if_service_is_available_2() throws Exception {
// Given
Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
// When
NodeTemplate wantedNodeTemplate = nodeTemplate("alien.service.MongoDB");
NodeType wantedNodeType = new NodeType();
wantedNodeType.setAbstract(true);
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
// Then
assertThat(proposition).hasSize(1);
assertThat(proposition.get(0).isService()).isTrue();
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method nodeTemplate.
private NodeTemplate nodeTemplate(String type) {
NodeTemplate nodeTemplate = new NodeTemplate();
nodeTemplate.setType(type);
return nodeTemplate;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method testParseAttributConcatScalar.
@Test
public void testParseAttributConcatScalar() {
Map<String, NodeTemplate> nodeTemplates = Maps.newHashMap();
NodeTemplate nodeTemplate1 = new NodeTemplate();
nodeTemplate1.setProperties(MapUtil.newHashMap(new String[] { "the_property_name_1" }, new AbstractPropertyValue[] { new ScalarPropertyValue("the_property_value_1") }));
nodeTemplates.put("the_node_tempalte_1", nodeTemplate1);
NodeTemplate nodeTemplate2 = new NodeTemplate();
nodeTemplate2.setProperties(MapUtil.newHashMap(new String[] { "the_property_name_2" }, new AbstractPropertyValue[] { new ScalarPropertyValue("the_property_value_2") }));
nodeTemplates.put("the_node_tempalte_2", nodeTemplate2);
Topology topology = new Topology();
topology.setNodeTemplates(nodeTemplates);
Map<String, Map<String, InstanceInformation>> runtimeInformations = Maps.newHashMap();
// Create a IAttributeValue
ConcatPropertyValue concatAttributeValue = new ConcatPropertyValue();
ScalarPropertyValue scalarParameter1 = new ScalarPropertyValue();
ScalarPropertyValue scalarParameter2 = new ScalarPropertyValue();
ScalarPropertyValue scalarParameter3 = new ScalarPropertyValue();
ScalarPropertyValue scalarParameter4 = new ScalarPropertyValue();
scalarParameter1.setValue("http://");
scalarParameter2.setValue("mywebsiteurl");
scalarParameter3.setValue(":");
scalarParameter4.setValue("port");
concatAttributeValue.setParameters(new ArrayList<>());
concatAttributeValue.getParameters().add(scalarParameter1);
concatAttributeValue.getParameters().add(scalarParameter2);
concatAttributeValue.getParameters().add(scalarParameter3);
concatAttributeValue.getParameters().add(scalarParameter4);
String parsedConcatString = FunctionEvaluator.parseAttribute(null, concatAttributeValue, topology, runtimeInformations, "0", null, null);
String fullUrl = scalarParameter1.getValue() + scalarParameter2.getValue() + scalarParameter3.getValue() + scalarParameter4.getValue();
Assert.assertEquals(fullUrl, parsedConcatString);
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillRequirements.
private void fillRequirements(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getRequirements() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String requirementName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName);
// We cannot change the capability definition here or we will change the original one so we need a clone
requirementDefinition = CloneUtil.clone(requirementDefinition);
requirementDefinition.setId(key);
substituteNodeType.getRequirements().add(requirementDefinition);
}
}
}
Aggregations