Search in sources :

Example 91 with ServiceTemplateId

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);
        }
    }
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 92 with ServiceTemplateId

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());
}
Also used : ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 93 with ServiceTemplateId

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());
        }
    }
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 94 with ServiceTemplateId

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());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 95 with ServiceTemplateId

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());
}
Also used : ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13