Search in sources :

Example 1 with TopologyWrapper

use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.

the class MinExternalConnectionsTest method filter.

@Test
public void filter() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest1", false);
    TTopologyTemplate twoExternal = repository.getElement(id).getTopologyTemplate();
    ModelUtilities.setTargetLabel(twoExternal.getNodeTemplate("shetland_pony_2"), "PastureProvider");
    ModelUtilities.setTargetLabel(twoExternal.getNodeTemplate("shetland_pony_3"), "PastureProvider");
    TTopologyTemplate oneExternal = AllocationUtils.deepCopy(twoExternal);
    ModelUtilities.setTargetLabel(oneExternal.getNodeTemplate("shetland_pony_2"), "FieldProvider");
    ModelUtilities.setTargetLabel(oneExternal.getNodeTemplate("shetland_pony_3"), "FieldProvider");
    List<TopologyWrapper> topologies = new ArrayList<>();
    topologies.add(new TopologyWrapper(twoExternal));
    topologies.add(new TopologyWrapper(oneExternal));
    Criteria minExternalConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
    List<TopologyWrapper> filtered = minExternalConnections.filter(topologies);
    assertEquals(1, filtered.size());
    TTopologyTemplate result = filtered.get(0).getTopology();
    assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_2")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_3")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_4")).get());
}
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) Test(org.junit.jupiter.api.Test)

Example 2 with TopologyWrapper

use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.

the class Allocation method getTopology.

private TopologyWrapper getTopology(ServiceTemplateId serviceTemplateId) throws AllocationException {
    TServiceTemplate serviceTemplate = repository.getElement(serviceTemplateId);
    TopologyWrapper topology = new TopologyWrapper(serviceTemplate.getTopologyTemplate());
    checkValidity(topology);
    return topology;
}
Also used : TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 3 with TopologyWrapper

use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.

the class PoliciesFilter method filter.

public List<TopologyWrapper> filter() {
    List<List<TTopologyTemplate>> fragmentsFulfilling = new ArrayList<>();
    // sort topologies by the policies they fulfill
    for (Map.Entry<TNodeTemplate, List<PolicyWrapper>> entry : policiesForNTs.entrySet()) {
        if (entry.getValue().isEmpty()) {
            continue;
        }
        List<TNodeTemplate> fragments = new ArrayList<>();
        for (TopologyWrapper topology : topologies) {
            fragments.add(getPolicyFragment(topology, entry.getKey().getId()));
        }
        PolicyComparison comparison = new PolicyComparison(entry.getValue(), fragments);
        fragmentsFulfilling.add(comparison.getFragmentsFulfillingPolicies());
    }
    // get topologies that fulfill all policies
    List<List<TopologyWrapper>> topologiesFulfilling = toTopologies(fragmentsFulfilling);
    Iterator<List<TopologyWrapper>> iterator = topologiesFulfilling.iterator();
    List<TopologyWrapper> intersection = iterator.next();
    while (iterator.hasNext()) {
        intersection.retainAll(iterator.next());
    }
    return intersection;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Map(java.util.Map) HashMap(java.util.HashMap) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 4 with TopologyWrapper

use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.

the class PoliciesFilter method toTopologies.

private List<List<TopologyWrapper>> toTopologies(List<List<TTopologyTemplate>> fragmentsByPolicies) {
    List<List<TopologyWrapper>> topologiesByPolicies = new ArrayList<>();
    for (List<TTopologyTemplate> fragments : fragmentsByPolicies) {
        List<TopologyWrapper> toTopologies = new ArrayList<>();
        for (TTopologyTemplate topologyTemplate : fragments) {
            // nts uniquely identifiable because of cloneNotEquals
            toTopologies.add(topologiesByFragments.get(topologyTemplate.getNodeTemplates().get(0)));
        }
        topologiesByPolicies.add(toTopologies);
    }
    return topologiesByPolicies;
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)

Example 5 with TopologyWrapper

use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.

the class MinExternalConnections method filter.

/**
 * Filters topologies based on the amount of their external connectsTo Relationship Templates.
 *
 * @return all topologies with minimum external Relationship Template amount
 */
@Override
public List<TopologyWrapper> filter(List<TopologyWrapper> topologies) {
    List<TopologyWrapper> minExternalRTs = new ArrayList<>();
    int minExternalRTsCount = Integer.MAX_VALUE;
    for (TopologyWrapper topology : topologies) {
        int externalRTsCount = 0;
        for (TRelationshipTemplate relationshipTemplate : topology.getConnectsTos(topology.getRelationshipTemplates())) {
            TNodeTemplate source = topology.getSourceNT(relationshipTemplate);
            TNodeTemplate target = topology.getTargetNT(relationshipTemplate);
            // only consider connectsTos between top level nts
            if (!topology.isTopLevelNT(source) || !topology.isTopLevelNT(target)) {
                continue;
            }
            // external edge?
            String sourceTargetLabel = ModelUtilities.getTargetLabel(source).get();
            String targetTargetLabel = ModelUtilities.getTargetLabel(target).get();
            if (!sourceTargetLabel.equals(targetTargetLabel)) {
                externalRTsCount++;
            }
        }
        if (externalRTsCount < minExternalRTsCount) {
            minExternalRTs.clear();
            minExternalRTs.add(topology);
            minExternalRTsCount = externalRTsCount;
        } else if (externalRTsCount == minExternalRTsCount) {
            minExternalRTs.add(topology);
        }
    }
    return minExternalRTs;
}
Also used : TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)25 Test (org.junit.jupiter.api.Test)16 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)15 ArrayList (java.util.ArrayList)13 Criteria (org.eclipse.winery.repository.targetallocation.Criteria)13 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)11 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)9 List (java.util.List)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 FulfillPolicies (org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)1 MinExternalConnections (org.eclipse.winery.repository.targetallocation.criteria.minexternalconnections.MinExternalConnections)1 FragmentsCache (org.eclipse.winery.repository.targetallocation.util.FragmentsCache)1 PermutationHelper (org.eclipse.winery.repository.targetallocation.util.PermutationHelper)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1