use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PermutationHelper method generateDetectorWithThreePatterns.
private static TTopologyTemplate generateDetectorWithThreePatterns() {
TTopologyTemplate detector = generateDetectorWithTwoPatterns();
TNodeTemplate pattern_3 = new TNodeTemplate();
pattern_3.setType("{http://ex.org/patterns}pattern_3");
pattern_3.setId("3");
TRelationshipTemplate pattern2_hostedOn_pattern3 = ModelUtilities.createRelationshipTemplate(detector.getNodeTemplate("2"), pattern_3, QName.valueOf("{http://ex.org}relType_hostedOn"));
detector.addNodeTemplate(pattern_3);
detector.addRelationshipTemplate(pattern2_hostedOn_pattern3);
return detector;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PermutationHelper method generatePrmWithoutPermutationMaps.
static OTPatternRefinementModel generatePrmWithoutPermutationMaps() {
/*
######## ######## ########
# (1) #---------------> # (11) # -----> # (12) #
######## ######## ########
| (2) |______________| (2)
| (2) \/
\/ ########
########---------------> # (13) #
# (2) # ########
######## | (2)
| \/
| (2) ########
\/ # (15) #
########---------------> ########
# (3) #
########
*/
TTopologyTemplate detector = generateDetectorWithThreePatterns();
// 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");
TNodeTemplate refinementNode_15 = new TNodeTemplate();
refinementNode_15.setType("{http://ex.org}nodeType_15");
refinementNode_15.setId("15");
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 node14_hostedOn_node15 = ModelUtilities.createRelationshipTemplate(refinementNode_14, refinementNode_15, 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).addNodeTemplate(refinementNode_15).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node14_hostedOn_node15).addRelationshipTemplate(node11_connectsTo_node12).build();
// endregion
// region mappings
OTRelationMapping pattern1_to_node11 = new OTRelationMapping.Builder("rm-1--11").setRelationType(QName.valueOf("{http://ex.org}relType_connectsTo")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_11).build();
OTRelationMapping pattern2_to_node13 = new OTRelationMapping.Builder("rm-2--13").setRelationType(QName.valueOf("{http://ex.org}relType_hostedOn")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
OTRelationMapping pattern3_to_node14 = new OTRelationMapping.Builder("rm-3-14").setRelationType(QName.valueOf("{http://ex.org}relType_connectsTo")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_14).build();
return new OTPatternRefinementModel.Builder().setName("SimplePrm").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setRelationMappings(Arrays.asList(pattern1_to_node11, pattern2_to_node13, pattern3_to_node14)).build();
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PermutationHelper method generatePrmWithStayMapping.
static OTPatternRefinementModel generatePrmWithStayMapping() {
/*
######## ########
# (1) #----stay-------> # (11) #
######## ########
| (2) |
| (2) \/
\/ ########
########---------------> # (13) #
# (2) #--------+ ########
######## | | (2)
| | \/
| (2 +------> ########
\/ # (15) #
######## ########
# (3) #--------+ | (2)
######## | \/
| ########
+------> # (16) #
########
*/
TTopologyTemplate detector = generateDetectorWithThreePatterns();
// region refinement structure
TNodeTemplate refinementNode_11 = new TNodeTemplate();
refinementNode_11.setType("{http://ex.org}nodeType_11");
refinementNode_11.setId("11");
TNodeTemplate refinementNode_13 = new TNodeTemplate();
refinementNode_13.setType("{http://ex.org}nodeType_13");
refinementNode_13.setId("13");
TNodeTemplate refinementNode_15 = new TNodeTemplate();
refinementNode_15.setType("{http://ex.org}nodeType_15");
refinementNode_15.setId("15");
TNodeTemplate refinementNode_16 = new TNodeTemplate();
refinementNode_16.setType("{http://ex.org}nodeType_16");
refinementNode_16.setId("16");
TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node13_hostedOn_node15 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_15, QName.valueOf("{http://ex.org}relType_hostedOn"));
TRelationshipTemplate node15_hostedOn_node16 = ModelUtilities.createRelationshipTemplate(refinementNode_15, refinementNode_16, QName.valueOf("{http://ex.org}relType_hostedOn"));
TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_15).addNodeTemplate(refinementNode_16).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node15).addRelationshipTemplate(node15_hostedOn_node16).build();
// endregion
// region mappings
OTStayMapping pattern1_to_node11 = new OTStayMapping.Builder("sm-1--11").setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_11).build();
OTRelationMapping pattern2_to_node13 = new OTRelationMapping.Builder("pm-2--13").setRelationType("{http://ex.org}relType_hostedOn").setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
OTPermutationMapping pattern2_to_node15 = new OTPermutationMapping.Builder("pm-2--15").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_15).build();
OTRelationMapping pattern3_to_node16 = new OTRelationMapping.Builder("pm-3--16").setRelationType(QName.valueOf("{http://ex.org}relType_connectsTo")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_16).build();
// endregion
// region prm
ArrayList<OTPermutationMapping> mappings = new ArrayList<>();
mappings.add(pattern2_to_node15);
return new OTPatternRefinementModel.Builder().setName("PrmWithStaying").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setRelationMappings(Arrays.asList(pattern2_to_node13, pattern3_to_node16)).setStayMappings(Collections.singletonList(pattern1_to_node11)).setPermutationMappings(mappings).build();
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class PatternRefinementTest method redirectStayMappings.
// endregion
// region ********** redirectStayMappings **********
@Test
void redirectStayMappings() {
setUp();
/*
input:
####### (1) #######
# (1) # <----- # (2) #
####### #######
| (2)
\/
#######
# (4) #
#######
expected output:
####### (1) ######## ########
# (1) # <----- # (10) # # (11) #
####### ######## ########
| (2) | (2)
+-------|------+
\/
#######
# (4) #
#######
*/
// region *** add stay mapping to PRM ***
TTopologyTemplate refinementTopology = candidateForTopology.getRefinementModel().getRefinementTopology();
TTopologyTemplate detector = candidateForTopology.getRefinementModel().getDetector();
refinementTopology.getNodeTemplateOrRelationshipTemplate().removeIf(template -> template.getId().equals("13") || template.getId().equals("1213"));
TNodeTemplate nt12 = refinementTopology.getNodeTemplate("12");
assertNotNull(nt12);
nt12.setType("{http://ex.org}nodeType_4");
TNodeTemplate nt4 = detector.getNodeTemplate("8");
OTStayMapping nt4staysAsNt12 = new OTStayMapping.Builder("stay1").setDetectorElement(nt4).setRefinementElement(nt12).build();
((OTPatternRefinementModel) candidateForTopology.getRefinementModel()).setStayMappings(Collections.singletonList(nt4staysAsNt12));
// endregion
// recreate the candidate
ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topology2);
ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(detector);
GraphMapping<ToscaNode, ToscaEdge> mapping = new ToscaIsomorphismMatcher().findMatches(detectorGraph, topologyGraph, new ToscaTypeMatcher()).next();
candidateForTopology = new RefinementCandidate(candidateForTopology.getRefinementModel(), mapping, detectorGraph, 1);
PatternRefinement patternRefinement = new PatternRefinement();
patternRefinement.applyRefinement(candidateForTopology, topology2);
// region *** assertions ***
assertNotNull(topology2.getNodeTemplate("4"));
TRelationshipTemplate relation1012 = topology2.getRelationshipTemplate("1012");
assertNotNull(relation1012);
assertEquals("4", relation1012.getTargetElement().getRef().getId());
assertEquals("10", relation1012.getSourceElement().getRef().getId());
TRelationshipTemplate relation1112 = topology2.getRelationshipTemplate("1112");
assertNotNull(relation1112);
assertEquals("4", relation1112.getTargetElement().getRef().getId());
assertEquals("11", relation1112.getSourceElement().getRef().getId());
TRelationshipTemplate relation21 = topology2.getRelationshipTemplate("21");
assertNotNull(relation21);
assertEquals("1", relation21.getTargetElement().getRef().getId());
assertEquals("10", relation21.getSourceElement().getRef().getId());
// endregion
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class DriverInjection method injectDriver.
public static TTopologyTemplate injectDriver(TTopologyTemplate topologyTemplate) throws Exception {
List<TNodeTemplate> nodeTemplatesWithAbstractDA = DASpecification.getNodeTemplatesWithAbstractDAs(topologyTemplate);
for (TNodeTemplate nodeTemplateWithAbstractDA : nodeTemplatesWithAbstractDA) {
if (nodeTemplateWithAbstractDA.getDeploymentArtifacts() != null) {
List<TDeploymentArtifact> abstractDAsAttachedToNodeTemplate = nodeTemplateWithAbstractDA.getDeploymentArtifacts().stream().filter(da -> DASpecification.getArtifactTypeOfDA(da).getAbstract()).collect(Collectors.toList());
for (TDeploymentArtifact abstractDA : abstractDAsAttachedToNodeTemplate) {
Set<Pair<TRelationshipTemplate, TNodeTemplate>> nodeTemplatesWithConcreteDA = DASpecification.getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode(nodeTemplateWithAbstractDA, abstractDA, topologyTemplate);
for (Pair<TRelationshipTemplate, TNodeTemplate> pair : nodeTemplatesWithConcreteDA) {
TRelationshipTemplate relationshipTemplate = pair.getLeft();
TNodeTemplate nodeTemplate = pair.getRight();
TDeploymentArtifact concreteDeploymentArtifact = DASpecification.getSuitableConcreteDA(abstractDA, nodeTemplate);
if (concreteDeploymentArtifact != null) {
nodeTemplateWithAbstractDA.getDeploymentArtifacts().add(concreteDeploymentArtifact);
setDriverProperty(relationshipTemplate, concreteDeploymentArtifact);
}
}
// concrete DAs from the delivering Node Template must not be deleted. They are uploaded by the OpenTOSCA Container but not used.
nodeTemplateWithAbstractDA.getDeploymentArtifacts().remove(abstractDA);
}
}
}
return topologyTemplate;
}
Aggregations