use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.
the class ComponentPatternDetectionTest method prm2.
private OTPatternRefinementModel prm2() {
// region: detector
TNodeTemplate relationalDb = new TNodeTemplate(new TNodeTemplate.Builder("relationalDb-d2", QName.valueOf("{ns}relational-db")).setX("1").setY("1"));
ModelUtilities.setPropertiesKV(relationalDb, new LinkedHashMap<>());
TNodeTemplate privateCloud = new TNodeTemplate(new TNodeTemplate.Builder("privateCloud-d2", QName.valueOf("{ns}private-cloud")).setX("1").setY("1"));
ModelUtilities.setPropertiesKV(privateCloud, new LinkedHashMap<>());
TRelationshipTemplate relationalDbToPrivateCloud = new TRelationshipTemplate(new TRelationshipTemplate.Builder("relationalDb-privateCloud-d2", QName.valueOf("{ns}hostedOn"), relationalDb, privateCloud));
TTopologyTemplate detector = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(relationalDb, privateCloud)).addRelationshipTemplates(Arrays.asList(relationalDbToPrivateCloud)));
// endregion
// region: refinement
TNodeTemplate database = new TNodeTemplate(new TNodeTemplate.Builder("database-rs2", QName.valueOf("{ns}mysql-db-5.7")).setX("1").setY("1"));
TNodeTemplate dbms = new TNodeTemplate(new TNodeTemplate.Builder("dbms-rs2", QName.valueOf("{ns}mysql-dbms-5.7")).setX("1").setY("1"));
TNodeTemplate vm = new TNodeTemplate(new TNodeTemplate.Builder("windows-server-2019-rs2", QName.valueOf("{ns}vm")).setX("1").setY("1"));
TNodeTemplate vsphere = new TNodeTemplate(new TNodeTemplate.Builder("vsphere-rs2", QName.valueOf("{ns}vsphere-7")).setX("1").setY("1"));
LinkedHashMap<String, String> dbProps = new LinkedHashMap<>();
dbProps.put("dbName", "database");
ModelUtilities.setPropertiesKV(database, dbProps);
LinkedHashMap<String, String> dbmsProps = new LinkedHashMap<>();
dbmsProps.put("adminPort", "33062");
ModelUtilities.setPropertiesKV(dbms, dbmsProps);
LinkedHashMap<String, String> vmProps = new LinkedHashMap<>();
vmProps.put("ram", "64GB");
ModelUtilities.setPropertiesKV(vm, vmProps);
LinkedHashMap<String, String> vsphereProps = new LinkedHashMap<>();
vsphereProps.put("api", "vsphere.uni-stuttgart");
ModelUtilities.setPropertiesKV(vsphere, vsphereProps);
TRelationshipTemplate dbToDbms = new TRelationshipTemplate(new TRelationshipTemplate.Builder("db-dbms-rs2", QName.valueOf("{ns}hostedOn"), database, dbms));
TRelationshipTemplate dbmsToVm = new TRelationshipTemplate(new TRelationshipTemplate.Builder("dbms-vm-rs2", QName.valueOf("{ns}hostedOn"), dbms, vm));
TRelationshipTemplate vmToVsphere = new TRelationshipTemplate(new TRelationshipTemplate.Builder("vm-vsphere-rs2", QName.valueOf("{ns}hostedOn"), vm, vsphere));
TTopologyTemplate refinement = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(database, dbms, vm, vsphere)).addRelationshipTemplates(Arrays.asList(dbToDbms, dbmsToVm, vmToVsphere)));
// endregion
List<OTPermutationMapping> permutationMappings = new ArrayList<>();
permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(relationalDb).setRefinementElement(database)));
permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vsphere)));
List<OTAttributeMapping> attributeMappings = new ArrayList<>();
attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(relationalDb).setDetectorProperty("name").setRefinementElement(database).setRefinementProperty("dbName").setType(OTAttributeMappingType.SELECTIVE)));
attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(privateCloud).setDetectorProperty("interface").setRefinementElement(vsphere).setRefinementProperty("api").setType(OTAttributeMappingType.SELECTIVE)));
List<OTRelationMapping> relationMappings = new ArrayList<>();
relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(relationalDb).setRefinementElement(database).setRelationType("{ns}secureSqlConnection").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vm).setRelationType("{ns}hostedOn").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
return new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinement).setPermutationMappings(permutationMappings).setAttributeMappings(attributeMappings).setRelationMappings(relationMappings));
}
use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.
the class ComponentPatternDetectionTest method prm1.
private OTPatternRefinementModel prm1() {
// region: detector
TNodeTemplate processorD = new TNodeTemplate(new TNodeTemplate.Builder("processor-d1", QName.valueOf("{ns}java-8-app")).setX("1").setY("1"));
LinkedHashMap<String, String> processorDProps = new LinkedHashMap<>();
processorDProps.put("port", "8081");
ModelUtilities.setPropertiesKV(processorD, processorDProps);
TNodeTemplate executionEnv = new TNodeTemplate(new TNodeTemplate.Builder("executionEnv-d1", QName.valueOf("{ns}execution-env")).setX("1").setY("1"));
TNodeTemplate privateCloud = new TNodeTemplate(new TNodeTemplate.Builder("privateCloud-d1", QName.valueOf("{ns}private-cloud")).setX("1").setY("1"));
TRelationshipTemplate processorDToExecutionEnv = new TRelationshipTemplate(new TRelationshipTemplate.Builder("processorD-executionEnv-d1", QName.valueOf("{ns}hostedOn"), processorD, executionEnv));
TRelationshipTemplate executionEnvToPrivateCloud = new TRelationshipTemplate(new TRelationshipTemplate.Builder("executionEnv-privateCloud-d1", QName.valueOf("{ns}hostedOn"), executionEnv, privateCloud));
TTopologyTemplate detector = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(processorD, executionEnv, privateCloud)).addRelationshipTemplates(Arrays.asList(processorDToExecutionEnv, executionEnvToPrivateCloud)));
// endregion
// region: refinement
TNodeTemplate processorRs = new TNodeTemplate(new TNodeTemplate.Builder("processor-rs1", QName.valueOf("{ns}java-8-app")).setX("1").setY("1"));
TNodeTemplate webserver = new TNodeTemplate(new TNodeTemplate.Builder("webserver-rs1", QName.valueOf("{ns}tomcat-9")).setX("1").setY("1"));
TNodeTemplate vm = new TNodeTemplate(new TNodeTemplate.Builder("ubuntu-2004-rs1", QName.valueOf("{ns}vm")).setX("1").setY("1"));
TNodeTemplate openstack = new TNodeTemplate(new TNodeTemplate.Builder("openstack-rs1", QName.valueOf("{ns}openstack-victoria")).setX("1").setY("1"));
LinkedHashMap<String, String> processorRsProps = new LinkedHashMap<>();
processorRsProps.put("port", "8081");
ModelUtilities.setPropertiesKV(processorRs, processorRsProps);
LinkedHashMap<String, String> webserverProps = new LinkedHashMap<>();
webserverProps.put("jmxPort", "9091");
ModelUtilities.setPropertiesKV(webserver, webserverProps);
LinkedHashMap<String, String> vmProps = new LinkedHashMap<>();
vmProps.put("ram", "128GB");
ModelUtilities.setPropertiesKV(vm, vmProps);
LinkedHashMap<String, String> openstackProps = new LinkedHashMap<>();
openstackProps.put("api", "openstack.uni-stuttgart");
ModelUtilities.setPropertiesKV(openstack, openstackProps);
TRelationshipTemplate processorToWebserver = new TRelationshipTemplate(new TRelationshipTemplate.Builder("processor-webserver-rs1", QName.valueOf("{ns}hostedOn"), processorRs, webserver));
TRelationshipTemplate webserverToVm = new TRelationshipTemplate(new TRelationshipTemplate.Builder("webserver-vm-rs1", QName.valueOf("{ns}hostedOn"), webserver, vm));
TRelationshipTemplate vmToOpenstack = new TRelationshipTemplate(new TRelationshipTemplate.Builder("vm-openstack-rs1", QName.valueOf("{ns}hostedOn"), vm, openstack));
TTopologyTemplate refinement = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(processorRs, webserver, vm, openstack)).addRelationshipTemplates(Arrays.asList(processorToWebserver, webserverToVm, vmToOpenstack)));
// endregion
OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(processorD).setRefinementElement(processorRs));
List<OTPermutationMapping> permutationMappings = new ArrayList<>();
permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(executionEnv).setRefinementElement(webserver)));
permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(openstack)));
List<OTAttributeMapping> attributeMappings = new ArrayList<>();
attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(executionEnv).setDetectorProperty("port").setRefinementElement(webserver).setRefinementProperty("jmxPort").setType(OTAttributeMappingType.SELECTIVE)));
attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(privateCloud).setDetectorProperty("interface").setRefinementElement(openstack).setRefinementProperty("api").setType(OTAttributeMappingType.SELECTIVE)));
List<OTRelationMapping> relationMappings = new ArrayList<>();
relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vm).setRelationType("{ns}hostedOn").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
return new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinement).setStayMappings(Arrays.asList(stayMapping)).setPermutationMappings(permutationMappings).setAttributeMappings(attributeMappings).setRelationMappings(relationMappings));
}
use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping in project winery by eclipse.
the class PermutationGeneratorTest method checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping2.
@Test
void checkMutabilityOfPrmWithAutomaticallyDeterminableComplexRelationMapping2() {
OTPatternRefinementModel refinementModel = generatePrmWithComplexRelationMaps2();
PermutationGenerator permutationGenerator = new PermutationGenerator();
assertTrue(permutationGenerator.checkMutability(refinementModel));
List<OTPermutationMapping> mappings = refinementModel.getPermutationMappings();
assertEquals(6, mappings.size());
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("11")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("12")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("1") && permutationMap.getRefinementElement().getId().equals("13")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("14")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("2") && permutationMap.getRefinementElement().getId().equals("15")));
assertTrue(refinementModel.getPermutationMappings().removeIf(permutationMap -> permutationMap.getDetectorElement().getId().equals("con-1--2") && permutationMap.getRefinementElement().getId().equals("14")));
}
use of org.eclipse.winery.model.tosca.extensions.OTPermutationMapping 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.extensions.OTPermutationMapping 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