use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class IpSecAlgorithmTest method applySolutionTest.
@Test
public void applySolutionTest() throws Exception {
this.setRevisionTo("a23f1c89c77fcde4de9fe7822532dc04e31731a0");
IpSecAlgorithm ipSecAlgorithm = new IpSecAlgorithm();
TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://plain.winery.opentosca.org/servicetemplates}ServiceTemplateWithIpSecProblem_w1-wip1"))).getTopologyTemplate();
ArrayList<ComponentFinding> componentFindings = new ArrayList<>();
componentFindings.add(new ComponentFinding(null, "NodeTypeWithImplementation_1.0-w1-wip1"));
componentFindings.add(new ComponentFinding(null, "NodeTypeWithXmlElementProperty"));
SolutionInputData inputData = new SolutionInputData();
inputData.setFindings(componentFindings);
ipSecAlgorithm.applySolution(topologyTemplate, inputData);
assertEquals(4, topologyTemplate.getNodeTemplates().size());
assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_1").getType());
assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_2").getType());
assertEquals(5, topologyTemplate.getRelationshipTemplates().size());
TRelationshipTemplate forward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_2-securely_connectsTo-replaceableNode_1");
assertNotNull(forward);
assertEquals("replaceableNode_2", forward.getSourceElement().getRef().getId());
assertEquals("replaceableNode_1", forward.getTargetElement().getRef().getId());
TRelationshipTemplate backward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_1-securely_connectsTo-replaceableNode_2");
assertNotNull(backward);
assertEquals("replaceableNode_1", backward.getSourceElement().getRef().getId());
assertEquals("replaceableNode_2", backward.getTargetElement().getRef().getId());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class TestRefinement method applyRefinement.
@Override
public Map<String, String> applyRefinement(RefinementCandidate refinement, TTopologyTemplate topology) {
// import the refinement structure
Map<String, String> idMapping = BackendUtils.mergeTopologyTemplateAinTopologyTemplateB(refinement.getRefinementModel().getRefinementTopology(), topology);
// iterate over the refinement nodes and add the configured relations
refinement.getRefinementModel().getRefinementTopology().getNodeTemplates().forEach(nodeTemplate -> refinement.getRefinementModel().getRelationMappings().stream().filter(relationMapping -> relationMapping.getRefinementElement().getId().equals(nodeTemplate.getId())).forEach(relationMapping -> {
String relId = this.versionAppendix + "-" + relationMapping.getRelationType().getLocalPart();
int counter = 0;
while (Objects.nonNull(idMapping.get(relId))) {
relId += counter++;
}
TRelationshipTemplate relationshipTemplate = new TRelationshipTemplate();
relationshipTemplate.setType(relationMapping.getRelationType());
relationshipTemplate.setId(relId);
relationshipTemplate.setName(relationMapping.getRelationType().getLocalPart());
// Retrieve the id from the correspondence node of the graph mapping.
ToscaNode node = refinement.getDetectorGraph().getNode(relationMapping.getDetectorElement().getId());
String topologyNodeId = refinement.getGraphMapping().getVertexCorrespondence(node, false).getId();
if (relationMapping.getDirection() == OTRelationDirection.INGOING) {
String targetId = idMapping.get(relationMapping.getRefinementElement().getId());
relationshipTemplate.setSourceNodeTemplate(topology.getNodeTemplate(topologyNodeId));
relationshipTemplate.setTargetNodeTemplate(topology.getNodeTemplate(targetId));
} else {
String sourceId = idMapping.get(relationMapping.getRefinementElement().getId());
relationshipTemplate.setSourceNodeTemplate(topology.getNodeTemplate(sourceId));
relationshipTemplate.setTargetNodeTemplate(topology.getNodeTemplate(topologyNodeId));
}
topology.addRelationshipTemplate(relationshipTemplate);
}));
return idMapping;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class EnhancementUtilsTestWithGitBackedRepository method applyFeaturesToTopology.
@Test
void applyFeaturesToTopology() throws Exception {
this.setRevisionTo("origin/plain");
TTopologyTemplate topology = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://opentosca.org/add/management/to/instances/servicetemplates}STWithBasicManagementOnly_w1-wip1"))).getTopologyTemplate();
// As we do not want to filter the features based on the deployment technology, the second parameter is null.
EnhancementUtils.applyFeaturesForTopology(topology, EnhancementUtils.getAvailableFeaturesForTopology(topology, Collections.emptyList()));
String ubuntuNodeTemplateId = "Ubuntu_16.04-w1";
String mySqlNodeTemplateId = "MySQL-Database_w1";
assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}Ubuntu_16.04-w1-" + ubuntuNodeTemplateId + "-Testing-Freeze_and_Defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(ubuntuNodeTemplateId).getType());
assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}MySQL-Database_w1-" + mySqlNodeTemplateId + "-Freeze_and_defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(mySqlNodeTemplateId).getType());
assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)));
assertEquals(9, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)).size());
assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)));
assertEquals(3, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)).size());
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PermutationHelper method generatePrmWithComplexRelationMaps.
static OTPatternRefinementModel generatePrmWithComplexRelationMaps() {
/*
######## ######## ########
# (1) #---------------> # (11) # -----> # (12) #
######## ######## ########
| (2) |______________| (2)
| (2) \/
\/ ########
########---------------> # (13) #
# (2) # ########
######## | (2)
\/
########
# (14) #
########
*/
TTopologyTemplate detector = generateDetectorWithTwoPatterns();
// region refinement structure
TNodeTemplate refinementNode_11 = new TNodeTemplate();
refinementNode_11.setType("{http://ex.org}nodeType_11");
refinementNode_11.setId("11");
TNodeTemplate refinementNode_12 = new TNodeTemplate();
refinementNode_12.setType("{http://ex.org}nodeType_12");
refinementNode_12.setId("12");
TNodeTemplate refinementNode_13 = new TNodeTemplate();
refinementNode_13.setType("{http://ex.org}nodeType_13");
refinementNode_13.setId("13");
TNodeTemplate refinementNode_14 = new TNodeTemplate();
refinementNode_14.setType("{http://ex.org}nodeType_14");
refinementNode_14.setId("14");
TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node12_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node13_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node11_connectsTo_node12).build();
// endregion
// region mappings
OTPermutationMapping pattern1_to_node11 = new OTPermutationMapping.Builder("pm-1--11").setRefinementElement(refinementNode_11).setDetectorElement(detector.getNodeTemplate("1")).build();
OTPermutationMapping pattern2_to_node13 = new OTPermutationMapping.Builder("pm-2--13").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
// endregion
// region prm
List<OTPermutationMapping> list = new ArrayList<>();
list.add(pattern1_to_node11);
list.add(pattern2_to_node13);
return new OTPatternRefinementModel.Builder().setName("PrmWithComplexRelationMappings").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setPermutationMappings(list).build();
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PermutationHelper method generatePrmWithTwoPatternsHostedOnAThird.
static OTPatternRefinementModel generatePrmWithTwoPatternsHostedOnAThird() {
/* +----------------------------------+
+---------------(------------------+ |
| | \/ \/
######## ######## ######## ########
# (1) #-------> # (3) # # (11) # -----> # (12) #
######## ######## ######## ########
| (2) |(2) (2) |______________| (2)
|---------------+ \/
\/ ########
########---------------------------> # (13) #
# (2) # ########
######## | (2)
\/
########
# (14) #
########
*/
TTopologyTemplate detector = generateDetectorWithTwoPatternsHostedOnOne();
// region refinement structure
TNodeTemplate refinementNode_11 = new TNodeTemplate();
refinementNode_11.setType("{http://ex.org}nodeType_11");
refinementNode_11.setId("11");
TNodeTemplate refinementNode_12 = new TNodeTemplate();
refinementNode_12.setType("{http://ex.org}nodeType_12");
refinementNode_12.setId("12");
TNodeTemplate refinementNode_13 = new TNodeTemplate();
refinementNode_13.setType("{http://ex.org}nodeType_13");
refinementNode_13.setId("13");
TNodeTemplate refinementNode_14 = new TNodeTemplate();
refinementNode_14.setType("{http://ex.org}nodeType_14");
refinementNode_14.setId("14");
TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node12_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node13_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node11_connectsTo_node12).build();
// endregion
// region mappings
OTPermutationMapping pattern1_to_node11 = new OTPermutationMapping.Builder("pm-1--11").setRefinementElement(refinementNode_11).setDetectorElement(detector.getNodeTemplate("1")).build();
OTPermutationMapping pattern2_to_node13 = new OTPermutationMapping.Builder("pm-2--13").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
OTPermutationMapping pattern3_to_node12 = new OTPermutationMapping.Builder("pm-3--12").setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_12).build();
// endregion
// region prm
List<OTPermutationMapping> list = new ArrayList<>();
list.add(pattern1_to_node11);
list.add(pattern2_to_node13);
list.add(pattern3_to_node12);
return new OTPatternRefinementModel.Builder().setName("PrmWithComplexRelationMappings").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setPermutationMappings(list).build();
}
Aggregations