Search in sources :

Example 11 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class NodeTypeScoreServiceTest method testScoreService.

@Test
public void testScoreService() throws InterruptedException {
    // Initialize test data
    NodeType indexedNodeType = new NodeType();
    indexedNodeType.setElementId("mordor");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("very_evil"));
    dao.save(indexedNodeType);
    String mordor100Id = indexedNodeType.getId();
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("deprecated_evil"));
    dao.save(indexedNodeType);
    String mordor101Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String isengard100Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("evil"));
    dao.save(indexedNodeType);
    String isengard101Id = indexedNodeType.getId();
    Topology topology = new Topology();
    topology.setId("topology");
    topology.setArchiveName("test-archive");
    topology.setArchiveVersion("1.0.0");
    topology.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    topology.setDependencies(Sets.newHashSet(new CSARDependency("middleEarth", "1.0.1")));
    topology.setNodeTemplates(MapUtil.newHashMap(new String[] { "isengard" }, new NodeTemplate[] { new NodeTemplate(indexedNodeType.getElementId(), null, null, null, null, null, null, null) }));
    dao.save(topology);
    indexedNodeType.setElementId("osgiliath");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String osgiliath100Id = indexedNodeType.getId();
    // perform scoring
    scoreService.run();
    // check that order on query is correct
    GetMultipleDataResult data = dao.search(NodeType.class, "", null, AlienConstants.DEFAULT_ES_SEARCH_SIZE);
    Assert.assertEquals(5, data.getData().length);
    Assert.assertEquals(isengard101Id, ((NodeType) data.getData()[0]).getId());
    Assert.assertEquals(1011, ((NodeType) data.getData()[0]).getAlienScore());
    Assert.assertEquals(mordor101Id, ((NodeType) data.getData()[1]).getId());
    Assert.assertEquals(1010, ((NodeType) data.getData()[1]).getAlienScore());
    Assert.assertEquals(osgiliath100Id, ((NodeType) data.getData()[2]).getId());
    Assert.assertEquals(1000, ((NodeType) data.getData()[2]).getAlienScore());
    Assert.assertEquals(mordor100Id, ((NodeType) data.getData()[3]).getId());
    Assert.assertEquals(10, ((NodeType) data.getData()[3]).getAlienScore());
    Assert.assertEquals(isengard100Id, ((NodeType) data.getData()[4]).getId());
    Assert.assertEquals(0, ((NodeType) data.getData()[4]).getAlienScore());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Date(java.util.Date) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 12 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TestModelUtil method createIndexedNodeType.

public static NodeType createIndexedNodeType(String id, String archiveName, String archiveVersion, String description, List<CapabilityDefinition> capabilities, List<RequirementDefinition> requirements, List<String> derivedFroms, List<String> defaultCapabilities, List<Tag> tags, Date creationDate, Date lastUpdateDate) {
    NodeType nodeType = new NodeType();
    nodeType.setElementId(id);
    nodeType.setArchiveName(archiveName);
    nodeType.setArchiveVersion(archiveVersion);
    nodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    nodeType.setCapabilities(capabilities);
    nodeType.setDescription(description);
    nodeType.setDefaultCapabilities(defaultCapabilities);
    nodeType.setRequirements(requirements);
    nodeType.setDerivedFrom(derivedFroms);
    nodeType.setTags(tags);
    nodeType.setCreationDate(creationDate);
    nodeType.setLastUpdateDate(lastUpdateDate);
    return nodeType;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 13 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class IndexedModelTest method mergeInheritableIndexMaps.

@Test
public void mergeInheritableIndexMaps() {
    NodeType son = new NodeType();
    son.setElementId("son");
    son.setArchiveVersion("1");
    PropertyDefinition propDef = new PropertyDefinition();
    AttributeDefinition attrDef = new AttributeDefinition();
    propDef.setType("string");
    propDef.setDefault(new ScalarPropertyValue("default_parent"));
    attrDef.setType("string");
    parent.setProperties(MapUtil.newHashMap(new String[] { "prop1" }, new PropertyDefinition[] { propDef }));
    parent.setAttributes(Maps.<String, IValue>newHashMap());
    parent.getAttributes().put("attr1", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_parent2"));
    propDef.setType("string");
    attrDef = new AttributeDefinition();
    attrDef.setType("version");
    parent.getProperties().put("prop2", propDef);
    parent.setAttributes(Maps.<String, IValue>newHashMap());
    parent.getAttributes().put("attr2", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_son"));
    propDef.setType("string");
    attrDef = new AttributeDefinition();
    attrDef.setType("integer");
    son.setProperties(MapUtil.newHashMap(new String[] { "prop1" }, new PropertyDefinition[] { propDef }));
    // son.setAttributes(MapUtil.newHashMap(new String[] { "attr1" }, new AttributeDefinition[] { attrDef }));
    son.setAttributes(Maps.<String, IValue>newHashMap());
    son.getAttributes().put("attr1", attrDef);
    propDef = new PropertyDefinition();
    propDef.setDefault(new ScalarPropertyValue("default_son2"));
    propDef.setType("integer");
    attrDef = new AttributeDefinition();
    attrDef.setType("boolean");
    son.getProperties().put("prop3", propDef);
    son.getAttributes().put("attr3", attrDef);
    IndexedModelUtils.mergeInheritableIndex(parent, son);
    // son should have 3 : 1 from himself, 1 from his parent, and one that he overrides from the parent
    assertEquals(3, son.getProperties().size());
    assertEquals(3, son.getAttributes().size());
    // son should'nt have parent's one when both defined the same
    PropertyDefinition propDefSon = son.getProperties().get("prop1");
    assertNotNull(propDefSon);
    assertEquals(new ScalarPropertyValue("default_son"), propDefSon.getDefault());
    AttributeDefinition attrDefSon = (AttributeDefinition) son.getAttributes().get("attr1");
    assertEquals("integer", attrDefSon.getType());
    // son has all parent's
    for (String key : parent.getProperties().keySet()) {
        assertTrue(son.getProperties().containsKey(key));
    }
    for (String key : parent.getAttributes().keySet()) {
        assertTrue(son.getAttributes().containsKey(key));
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 14 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class DefaultNodeMatcherTest method unknown_type_from_topology_should_not_match_any_location_resource.

@Test
public void unknown_type_from_topology_should_not_match_any_location_resource() throws Exception {
    // Given
    Map<String, MatchingConfiguration> emptyMatchingConfigurations = new HashMap<>();
    // When
    NodeTemplate wantedNodeTemplate = nodeTemplate("tosca.nodes.Unknown");
    NodeType wantedNodeType = new NodeType();
    List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, wantedNodeType, locationResources, emptyMatchingConfigurations);
    // Then
    assertThat(proposition).hasSize(0);
}
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 15 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7