Search in sources :

Example 6 with NodeTemplate

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 7 with NodeTemplate

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();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) HashMap(java.util.HashMap) MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) NodeType(org.alien4cloud.tosca.model.types.NodeType) Test(org.junit.Test)

Example 8 with NodeTemplate

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;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate)

Example 9 with 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);
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) Test(org.junit.Test) AbstractToscaParserSimpleProfileTest(alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)

Example 10 with NodeTemplate

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);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Map(java.util.Map)

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