use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class MinHostsTest method testTwoTargetLabelsPresent.
@Test
public void testTwoTargetLabelsPresent() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest3", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(2, topologies.size());
TTopologyTemplate topology1 = topologies.get(0).getTopology();
TTopologyTemplate topology2 = topologies.get(1).getTopology();
assertEquals(8, topology1.getNodeTemplateOrRelationshipTemplate().size());
assertEquals(8, topology2.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(5, types1.size());
assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelHosts()) {
List<TNodeTemplate> predecessors = topologies.get(0).getHostedOnPredecessors(nodeTemplate);
if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
assertEquals(predecessors.size(), 2);
} else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
assertEquals(predecessors.size(), 1);
}
}
List<String> types2 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology2.getNodeTemplates()) {
types2.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(5, types2.size());
assertEquals(3, types2.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelHosts()) {
List<TNodeTemplate> predecessors = topologies.get(1).getHostedOnPredecessors(nodeTemplate);
if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
assertEquals(predecessors.size(), 1);
} else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
assertEquals(predecessors.size(), 2);
}
}
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class MinHostsTest method testFilter.
@Test
public void testFilter() throws Exception {
List<TopologyWrapper> topologies = new ArrayList<>();
for (int i = 1; i < 5; i++) {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest" + i, false);
topologies.add(new TopologyWrapper(repository.getElement(id).getTopologyTemplate()));
}
assertEquals(4, topologies.size());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> filtered = minHosts.filter(topologies);
assertEquals(2, filtered.size());
assertEquals(5, filtered.get(0).getNodeTemplates().size());
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class MinHostsTest method testNoTargetLabelsPresent.
@Test
public void testNoTargetLabelsPresent() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest4", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<String> ntIdsWithoutTargetLabel = topology.getTopLevelNTs().stream().filter(nt -> !ModelUtilities.getTargetLabel(nt).isPresent()).map(HasId::getId).collect(Collectors.toList());
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(2, topologies.size());
TTopologyTemplate topology1 = topologies.get(0).getTopology();
TTopologyTemplate topology2 = topologies.get(1).getTopology();
assertEquals(17, topology1.getNodeTemplateOrRelationshipTemplate().size());
assertEquals(17, topology2.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(10, types1.size());
assertEquals(7, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(2, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelNTs()) {
if (ntIdsWithoutTargetLabel.contains(nodeTemplate.getId())) {
assertEquals("pasture", topologies.get(0).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
}
}
List<String> types2 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology2.getNodeTemplates()) {
types2.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(10, types2.size());
assertEquals(7, types2.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
assertEquals(2, types2.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelNTs()) {
if (ntIdsWithoutTargetLabel.contains(nodeTemplate.getId())) {
assertEquals("field_-w1-wip1", topologies.get(1).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
}
}
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyMappingsWrapperTest method setUp.
@BeforeEach
public void setUp() throws Exception {
setRevisionTo("bb9ff7e08f7b72d30a2fae326740ef8051701671");
ServiceTemplateId policiesIO = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationFulfillPoliciesTest1", false);
policiesTopology = new TopologyWrapper(repository.getElement(policiesIO).getTopologyTemplate());
ServiceTemplateId minHostsId = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest4", false);
minHostsTopology = new TopologyWrapper(repository.getElement(minHostsId).getTopologyTemplate());
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class DASpecificationTest method getArtifactTypeOfDA.
@Test
public void getArtifactTypeOfDA() throws Exception {
setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
assertNotNull(topologyTemplate);
TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
assertNotNull(nodeTemplateWithAbstractDA);
assertNotNull(nodeTemplateWithAbstractDA.getDeploymentArtifacts());
TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0);
QName artifactTypeQName = deploymentArtifact.getArtifactType();
ArtifactTypeId artifactTypeId = new ArtifactTypeId(artifactTypeQName);
TArtifactType artifactType = this.repository.getElement(artifactTypeId);
assertEquals(artifactType.getTargetNamespace(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getTargetNamespace());
assertEquals(artifactType.getName(), DASpecification.getArtifactTypeOfDA(nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0)).getName());
}
Aggregations