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