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