use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class FulfillPoliciesTest method testApprox.
@Test
public void testApprox() throws Exception {
JsonNode params = JacksonProvider.mapper.readTree("{\"policySelection\":[" + "{\"policy\":\"floorwarmth10\",\"property\":\"warmth\",\"operator\":\"approx\"}," + "{\"policy\":\"floorwarmth30\",\"property\":\"warmth\",\"operator\":\"approx\"}]}");
Criteria fulfillPolicies = new FulfillPolicies(params, Integer.MAX_VALUE);
List<TTopologyTemplate> allocatedTopologies = fulfillPolicies.allocate(topology).stream().map(TopologyWrapper::getTopology).collect(Collectors.toList());
assertEquals(1, allocatedTopologies.size());
TTopologyTemplate allocated = allocatedTopologies.get(0);
assertEquals(8, allocated.getNodeTemplates().size());
// set by criteria
assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_4")).get());
// set by user
assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PatternDetectionUtils method swapDetectorWithRefinement.
/**
* To reuse the pattern refinement implementation for the pattern detection process, the detector is swapped with
* the refinement.
*/
@ADR(31)
public static OTPatternRefinementModel swapDetectorWithRefinement(OTPatternRefinementModel prm) {
TTopologyTemplate detector = prm.getDetector();
prm.setDetector(prm.getRefinementTopology());
prm.setRefinementTopology(detector);
Stream.of(prm.getRelationMappings() == null ? Stream.empty() : prm.getRelationMappings().stream(), prm.getPermutationMappings() == null ? Stream.empty() : prm.getPermutationMappings().stream(), prm.getAttributeMappings() == null ? Stream.empty() : prm.getAttributeMappings().stream(), prm.getStayMappings() == null ? Stream.empty() : prm.getStayMappings().stream(), prm.getDeploymentArtifactMappings() == null ? Stream.empty() : prm.getDeploymentArtifactMappings().stream(), prm.getBehaviorPatternMappings() == null ? Stream.empty() : prm.getBehaviorPatternMappings().stream()).flatMap(Function.identity()).map(OTPrmMapping.class::cast).forEach(mapping -> {
if (mapping instanceof OTAttributeMapping) {
OTAttributeMapping attributeMapping = (OTAttributeMapping) mapping;
swapDetectorWithRefinement(attributeMapping);
} else {
swapDetectorWithRefinement(mapping);
}
});
return prm;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class MinHostsTest method test5Pony3FieldProvider.
@Test
public void test5Pony3FieldProvider() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest5_-w1-wip1", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ModelUtilities.setTargetLabel(topology.getTopology().getNodeTemplate("shetland_pony_3"), "FieldProvider");
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(1, topologies.size());
TTopologyTemplate allocated = topologies.get(0).getTopology();
assertEquals(6, allocated.getNodeTemplates().size());
assertEquals(4, allocated.getRelationshipTemplates().size());
assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
assertEquals(2, allocated.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class MinHostsTest method test5Original.
@Test
public void test5Original() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest5_-w1-wip1", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(1, topologies.size());
TTopologyTemplate allocated = topologies.get(0).getTopology();
assertEquals(6, allocated.getNodeTemplates().size());
assertEquals(5, allocated.getRelationshipTemplates().size());
assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
assertEquals(1, allocated.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class MinHostsTest method testOneTopLevelTwoPossibilitiesNoTargetLabel.
@Test
public void testOneTopLevelTwoPossibilitiesNoTargetLabel() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest1", 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(9, topology1.getNodeTemplateOrRelationshipTemplate().size());
assertEquals(9, topology2.getNodeTemplateOrRelationshipTemplate().size());
List<String> types1 = new ArrayList<>();
for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
types1.add(nodeTemplate.getType().getLocalPart());
}
assertEquals(6, types1.size());
assertTrue(types1.contains("shetland_pony"));
assertTrue(types1.contains("pasture"));
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(6, types2.size());
assertTrue(types2.contains("shetland_pony"));
assertTrue(types2.contains("field_-w1-wip1"));
for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelNTs()) {
if (ntIdsWithoutTargetLabel.contains(nodeTemplate.getId())) {
assertEquals("field_-w1-wip1", topologies.get(1).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
}
}
}
Aggregations