use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class BehaviorPatternDetection method addCompatibleBehaviorPatterns.
private void addCompatibleBehaviorPatterns(TEntityTemplate refinementElement, RefinementCandidate refinement) {
OTPatternRefinementModel prm = (OTPatternRefinementModel) refinement.getRefinementModel();
TEntityTemplate detectorElement = prm.getStayMappings().stream().filter(stayMapping -> stayMapping.getRefinementElement().getId().equals(refinementElement.getId())).findFirst().get().getDetectorElement();
ToscaEntity detectorEntity = refinement.getDetectorGraph().getVertexOrEdge(detectorElement.getId()).get();
TEntityTemplate stayingElement = getEntityCorrespondence(detectorEntity, refinement.getGraphMapping());
List<TPolicy> refinementPolicies = ((HasPolicies) refinementElement).getPolicies();
List<TPolicy> stayingPolicies = ((HasPolicies) stayingElement).getPolicies();
if (refinementPolicies != null) {
if (stayingPolicies != null) {
// avoid duplicates
refinementPolicies.forEach(refinementPolicy -> {
boolean policyExists = stayingPolicies.stream().anyMatch(stayingPolicy -> stayingPolicy.getPolicyType().equals(refinementPolicy.getPolicyType()));
if (!policyExists) {
stayingPolicies.add(refinementPolicy);
}
});
} else {
((HasPolicies) stayingElement).setPolicies(new ArrayList<>(refinementPolicies));
}
removeIncompatibleBehaviorPatterns(refinementElement, stayingElement, refinement);
}
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class PermutationGeneratorTestWithGitBackedRepository method simplePrmTest.
@Test
void simplePrmTest() throws Exception {
this.setRevisionTo("origin/plain");
OTPatternRefinementModel refinementModel = generatePrmWithoutPermutationMaps();
PatternRefinementModelId id = new PatternRefinementModelId(refinementModel.getTargetNamespace(), refinementModel.getIdFromIdOrNameField(), false);
RepositoryFactory.getRepository().setElement(id, refinementModel);
PermutationGenerator generator = new PermutationGenerator();
Map<String, OTTopologyFragmentRefinementModel> permutations = generator.generatePermutations(refinementModel);
assertEquals(6, permutations.size());
OTTopologyFragmentRefinementModel permutation_1 = permutations.get("SimplePrm_permutation-1-w1-wip1");
assertNotNull(permutation_1);
assertEquals(4, permutation_1.getDetector().getNodeTemplates().size());
assertEquals(4, permutation_1.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_2 = permutations.get("SimplePrm_permutation-2-w1-wip1");
assertNotNull(permutation_2);
assertEquals(3, permutation_2.getDetector().getNodeTemplates().size());
assertEquals(2, permutation_2.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_3 = permutations.get("SimplePrm_permutation-3-w1-wip1");
assertNotNull(permutation_3);
assertEquals(4, permutation_3.getDetector().getNodeTemplates().size());
assertEquals(3, permutation_3.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_1_2 = permutations.get("SimplePrm_permutation-1-2-w1-wip1");
assertNotNull(permutation_1_2);
assertEquals(4, permutation_1_2.getDetector().getNodeTemplates().size());
assertEquals(4, permutation_1_2.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_1_3 = permutations.get("SimplePrm_permutation-1-3-w1-wip1");
assertNotNull(permutation_1_3);
assertEquals(5, permutation_1_3.getDetector().getNodeTemplates().size());
assertEquals(5, permutation_1_3.getDetector().getRelationshipTemplates().size());
OTTopologyFragmentRefinementModel permutation_2_3 = permutations.get("SimplePrm_permutation-2-3-w1-wip1");
assertNotNull(permutation_2_3);
assertEquals(4, permutation_2_3.getDetector().getNodeTemplates().size());
assertEquals(3, permutation_2_3.getDetector().getRelationshipTemplates().size());
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.
the class PatternRefinementTest method applyPropertyMappings.
// endregion
// region ********** applyPropertyMappings **********
@Test
public void applyPropertyMappings() {
setUp();
/*
input:
####### (1) ######### (1) ####### ######## ########
# (1) # <----- # (2) # <----- # (3) # # (10) # # (11) #
####### ######### ####### ######## ########
# p=1 # | # k= #
# x=2 # | ########
######### | (2) | (2)
| (2) +-------|------+
\/ \/
####### ########
# (4) # # (12) #
####### ########
# a=3 # # j= #
# b=4 # ########
####### | (2)
\/
########
# (13) #
########
# a= #
# b= #
# c=0 #
########
expected output
####### (1) ######### (1) ####### ######## ########
# (1) # <----- # (2) # <----- # (3) # # (10) # # (11) #
####### ######### ####### ######## ########
# p=1 # | # k=2 #
# x=2 # | ########
######### | (2) | (2)
| (2) +-------|------+
\/ \/
####### ########
# (4) # # (12) #
####### ########
# a=3 # # j=1 #
# b=4 # ########
####### | (2)
\/
########
# (13) #
########
# a=3 #
# b=4 #
# c=0 #
######## */
// region *** setup the PRM ***
TNodeTemplate nt13 = candidateForTopology.getRefinementModel().getRefinementTopology().getNodeTemplate("13");
assert nt13 != null;
TEntityTemplate.WineryKVProperties nt13Props = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt13PropsMap = new LinkedHashMap<>();
nt13PropsMap.put("a", null);
nt13PropsMap.put("b", null);
nt13PropsMap.put("c", "0");
nt13Props.setKVProperties(nt13PropsMap);
nt13.setProperties(nt13Props);
TNodeTemplate nt12 = candidateForTopology.getRefinementModel().getRefinementTopology().getNodeTemplate("12");
assert nt12 != null;
TEntityTemplate.WineryKVProperties nt12Props = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt12PropsMap = new LinkedHashMap<>();
nt12PropsMap.put("j", null);
nt12Props.setKVProperties(nt12PropsMap);
nt12.setProperties(nt12Props);
TNodeTemplate nt11 = candidateForTopology.getRefinementModel().getRefinementTopology().getNodeTemplate("11");
assert nt11 != null;
TEntityTemplate.WineryKVProperties nt11Props = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt11PropsMap = new LinkedHashMap<>();
nt11PropsMap.put("k", null);
nt11Props.setKVProperties(nt11PropsMap);
nt11.setProperties(nt11Props);
OTAttributeMapping allOn4to13 = new OTAttributeMapping(new OTAttributeMapping.Builder());
allOn4to13.setType(OTAttributeMappingType.ALL);
allOn4to13.setDetectorElement(candidateForTopology.getRefinementModel().getDetector().getNodeTemplate("8"));
allOn4to13.setRefinementElement(nt13);
OTAttributeMapping pIn2_to_jIn12 = new OTAttributeMapping(new OTAttributeMapping.Builder());
pIn2_to_jIn12.setType(OTAttributeMappingType.SELECTIVE);
pIn2_to_jIn12.setDetectorElement(candidateForTopology.getRefinementModel().getDetector().getNodeTemplate("7"));
pIn2_to_jIn12.setRefinementElement(nt12);
pIn2_to_jIn12.setDetectorProperty("p");
pIn2_to_jIn12.setRefinementProperty("j");
OTAttributeMapping xIn2_to_kIn11 = new OTAttributeMapping(new OTAttributeMapping.Builder());
xIn2_to_kIn11.setType(OTAttributeMappingType.SELECTIVE);
xIn2_to_kIn11.setDetectorElement(candidateForTopology.getRefinementModel().getDetector().getNodeTemplate("7"));
xIn2_to_kIn11.setRefinementElement(nt11);
xIn2_to_kIn11.setDetectorProperty("x");
xIn2_to_kIn11.setRefinementProperty("k");
List<OTAttributeMapping> relationMappings = new ArrayList<>();
relationMappings.add(allOn4to13);
relationMappings.add(pIn2_to_jIn12);
relationMappings.add(xIn2_to_kIn11);
((OTPatternRefinementModel) candidateForTopology.getRefinementModel()).setAttributeMappings(relationMappings);
// endregion
// region *** setup the topology ***
TNodeTemplate nt2 = topology.getNodeTemplate("2");
assert nt2 != null;
TEntityTemplate.WineryKVProperties nt2Props = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt2PropsMap = new LinkedHashMap<>();
nt2PropsMap.put("p", "1");
nt2PropsMap.put("x", "2");
nt2Props.setKVProperties(nt2PropsMap);
nt2.setProperties(nt2Props);
TNodeTemplate nt4 = topology.getNodeTemplate("4");
assert nt4 != null;
TEntityTemplate.WineryKVProperties nt4Props = new TEntityTemplate.WineryKVProperties();
LinkedHashMap<String, String> nt4PropsMap = new LinkedHashMap<>();
nt4PropsMap.put("a", "3");
nt4PropsMap.put("b", "4");
nt4Props.setKVProperties(nt4PropsMap);
nt4.setProperties(nt4Props);
Map<String, String> idMapping = BackendUtils.mergeTopologyTemplateAinTopologyTemplateB(candidateForTopology.getRefinementModel().getRefinementTopology(), topology);
// endregion
PatternRefinement patternRefinement = new PatternRefinement();
patternRefinement.applyPropertyMappings(candidateForTopology, "8", nt4, topology, idMapping);
TNodeTemplate node13 = topology.getNodeTemplate("13");
assertNotNull(node13);
Map<String, String> properties13 = ModelUtilities.getPropertiesKV(node13);
assertNotNull(properties13);
assertEquals(3, properties13.size());
assertEquals("3", properties13.get("a"));
assertEquals("4", properties13.get("b"));
assertEquals("0", properties13.get("c"));
patternRefinement.applyPropertyMappings(candidateForTopology, "7", nt2, topology, idMapping);
TNodeTemplate node11 = topology.getNodeTemplate("11");
assertNotNull(node11);
Map<String, String> properties11 = ModelUtilities.getPropertiesKV(node11);
TNodeTemplate node12 = topology.getNodeTemplate("12");
assertNotNull(node12);
Map<String, String> properties12 = ModelUtilities.getPropertiesKV(node12);
assertNotNull(properties11);
assertEquals(1, properties11.size());
assertEquals("2", properties11.get("k"));
assertNotNull(properties12);
assertEquals(1, properties12.size());
assertEquals("1", properties12.get("j"));
TNodeTemplate node10 = topology.getNodeTemplate("10");
assertNotNull(node10);
assertNull(node10.getProperties());
}
use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel 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.extensions.OTPatternRefinementModel in project winery by eclipse.
the class PatternDetectionUtilsTest method toPdrms.
@Test
public void toPdrms() {
List<OTRefinementModel> refinementModels = new ArrayList<>();
refinementModels.add(new OTTestRefinementModel());
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
refinementModels.add(new OTTopologyFragmentRefinementModel());
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
OTPatternRefinementModel prm = new OTPatternRefinementModel();
refinementModels.add(prm);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
prm.setIsPdrm(true);
refinementModels.add(prm);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 1);
prm.setIsPdrm(false);
PatternDetectionUtils.toPdrms(refinementModels);
assertEquals(refinementModels.size(), 0);
}
Aggregations