Search in sources :

Example 21 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ToscaBehaviorPatternMatcherTest method propertiesCompatible.

@Test
public void propertiesCompatible() {
    LinkedHashMap<String, String> refinementProps = new LinkedHashMap<>();
    refinementProps.put("null", null);
    refinementProps.put("empty", "");
    refinementProps.put("star", "*");
    refinementProps.put("match", "this has to match");
    refinementProps.put("ignoreCase", "THIS HAS TO MATCH INDEPENDENT OF CASE");
    LinkedHashMap<String, String> candidateProps = new LinkedHashMap<>();
    candidateProps.put("null", "does not have to be null");
    candidateProps.put("empty", "does not have to be empty");
    candidateProps.put("star", "this has to be non-null and non-empty");
    candidateProps.put("match", "this has to match");
    candidateProps.put("ignoreCase", "this has to match independent of case");
    TNodeTemplate refinement = new TNodeTemplate();
    refinement.setId("refinement");
    ModelUtilities.setPropertiesKV(refinement, refinementProps);
    ToscaNode refinementNode = new ToscaNode();
    refinementNode.setNodeTemplate(refinement);
    TNodeTemplate candidate = new TNodeTemplate();
    candidate.setId("candidate");
    ModelUtilities.setPropertiesKV(candidate, candidateProps);
    ToscaNode candidateNode = new ToscaNode();
    candidateNode.setNodeTemplate(candidate);
    OTPatternRefinementModel prm = new OTPatternRefinementModel();
    prm.setRefinementTopology(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement)));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    ToscaBehaviorPatternMatcher matcher = new ToscaBehaviorPatternMatcher(prm, null);
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    refinementProps.put("doesNotMatch", "something");
    candidateProps.put("doesNotMatch", "something else");
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
    // props with behavior pattern mappings can be ignored
    List<OTBehaviorPatternMapping> behaviorPatternMappings = new ArrayList<>();
    OTBehaviorPatternMapping behaviorPatternMapping = new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setRefinementElement(refinement).setProperty(new OTPropertyKV("doesNotMatch", "")));
    behaviorPatternMappings.add((OTBehaviorPatternMapping) PatternDetectionUtils.swapDetectorWithRefinement(behaviorPatternMapping));
    prm.setBehaviorPatternMappings(behaviorPatternMappings);
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("empty", "");
    assertTrue(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("star", null);
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
    candidateProps.put("star", "");
    assertFalse(matcher.propertiesCompatible(refinementNode, candidateNode));
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 22 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ToscaComponentPatternMatcherTest method componentPatternsCompatible.

@Test
public void componentPatternsCompatible() {
    // prm1 doesn't match the candidate but implements the same Component Pattern 'patternType1'
    TNodeTemplate detector1 = new TNodeTemplate(new TNodeTemplate.Builder("detector1", new QName("patternType1")));
    TNodeTemplate refinement1 = new TNodeTemplate(new TNodeTemplate.Builder("refinement1", new QName("concreteType1")));
    ToscaNode refinement1Node = new ToscaNode();
    refinement1Node.setNodeTemplate(refinement1);
    List<OTPermutationMapping> permutationMappings1 = new ArrayList<>();
    permutationMappings1.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detector1).setRefinementElement(refinement1)));
    OTPatternRefinementModel prm1 = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(detector1))).setRefinementStructure(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement1))).setPermutationMappings(permutationMappings1));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm1);
    // prm2 matches the candidate and also implements the Component Pattern 'patternType1'
    TNodeTemplate detector2 = new TNodeTemplate(new TNodeTemplate.Builder("detector2", new QName("patternType1")));
    TNodeTemplate refinement2 = new TNodeTemplate(new TNodeTemplate.Builder("refinement2", new QName("concreteType2")));
    ToscaNode refinement2Node = new ToscaNode();
    refinement2Node.setNodeTemplate(refinement2);
    List<OTPermutationMapping> permutationMappings2 = new ArrayList<>();
    permutationMappings2.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detector2).setRefinementElement(refinement2)));
    OTPatternRefinementModel prm2 = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(detector2))).setRefinementStructure(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinement2))).setPermutationMappings(permutationMappings2));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm2);
    List<OTRefinementModel> prms = new ArrayList<>();
    prms.add(prm1);
    ToscaComponentPatternMatcher matcher = new ToscaComponentPatternMatcher(prm1, null, prms, new HashMap<>());
    ToscaNode candidate = new ToscaNode();
    candidate.setNodeTemplate(new TNodeTemplate(new TNodeTemplate.Builder("nt1", new QName("concreteType2"))));
    // only prm1 available -> doesn't match
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prms.add(prm2);
    // now prm2 can also be used -> matches
    assertTrue(matcher.isCompatible(refinement1Node, candidate));
    prms.clear();
    prms.add(prm2);
    matcher = new ToscaComponentPatternMatcher(prm2, null, prms, new HashMap<>());
    // prm2 used directly -> also matches
    assertTrue(matcher.isCompatible(refinement2Node, candidate));
    prms.add(prm1);
    // still matches
    assertTrue(matcher.isCompatible(refinement2Node, candidate));
    matcher = new ToscaComponentPatternMatcher(prm1, null, prms, new HashMap<>());
    OTPermutationMapping oneTooMany = new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(new TNodeTemplate(new TNodeTemplate.Builder("tmp1", new QName("tmp1")))).setRefinementElement(refinement1));
    permutationMappings1.add((OTPermutationMapping) PatternDetectionUtils.swapDetectorWithRefinement(oneTooMany));
    // detector is associated with multiple Component patterns -> not one-to-one
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    oneTooMany.setDetectorElement(detector1);
    oneTooMany.setRefinementElement(new TNodeTemplate(new TNodeTemplate.Builder("tmp2", new QName("tmp2"))));
    PatternDetectionUtils.swapDetectorWithRefinement(oneTooMany);
    // refinement element is associated with multiple Component patterns -> not one-to-one
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    permutationMappings1.remove(oneTooMany);
    // after removal, it's one-to-one again
    assertTrue(matcher.isCompatible(refinement1Node, candidate));
    // empty or null
    prm2.getPermutationMappings().clear();
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm1.getPermutationMappings().clear();
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm2.setPermutationMappings(null);
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
    prm1.setPermutationMappings(null);
    assertFalse(matcher.isCompatible(refinement1Node, candidate));
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 23 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class PatternDetectionUtilsTest method swapDetectorWithRefinement.

@Test
public void swapDetectorWithRefinement() {
    TTopologyTemplate detector = new TTopologyTemplate();
    TTopologyTemplate refinementStructure = new TTopologyTemplate();
    TEntityTemplate detectorElement = new TNodeTemplate();
    TEntityTemplate refinementElement = new TNodeTemplate();
    OTRelationMapping relationMapping = new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setDirection(OTRelationDirection.INGOING).setRelationType("relationType").setValidSourceOrTarget(QName.valueOf("validSourceOrTarget")));
    OTPermutationMapping permutationMapping = new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement));
    OTAttributeMapping attributeMapping = new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setDetectorProperty("detectorProperty").setRefinementProperty("refinementProperty"));
    OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement));
    OTDeploymentArtifactMapping deploymentArtifactMapping = new OTDeploymentArtifactMapping(new OTDeploymentArtifactMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement).setArtifactType(QName.valueOf("artifactType")));
    OTBehaviorPatternMapping behaviorPatternMapping = new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("behaviorPattern").setProperty(new OTPropertyKV("key", "value")));
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinementStructure).setRelationMappings(Collections.singletonList(relationMapping)).setPermutationMappings(Collections.singletonList(permutationMapping)).setAttributeMappings(Collections.singletonList(attributeMapping)).setStayMappings(Collections.singletonList(stayMapping)).setDeploymentArtifactMappings(Collections.singletonList(deploymentArtifactMapping)).setBehaviorPatternMappings(Collections.singletonList(behaviorPatternMapping)));
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    assertEquals(prm.getDetector(), refinementStructure);
    assertEquals(prm.getRefinementStructure(), detector);
    assertEquals(relationMapping.getDetectorElement(), refinementElement);
    assertEquals(relationMapping.getRefinementElement(), detectorElement);
    assertEquals(relationMapping.getDirection(), OTRelationDirection.INGOING);
    assertEquals(relationMapping.getRelationType(), QName.valueOf("relationType"));
    assertEquals(relationMapping.getValidSourceOrTarget(), QName.valueOf("validSourceOrTarget"));
    assertEquals(permutationMapping.getDetectorElement(), refinementElement);
    assertEquals(permutationMapping.getRefinementElement(), detectorElement);
    assertEquals(attributeMapping.getDetectorElement(), refinementElement);
    assertEquals(attributeMapping.getRefinementElement(), detectorElement);
    assertEquals(attributeMapping.getDetectorProperty(), "refinementProperty");
    assertEquals(attributeMapping.getRefinementProperty(), "detectorProperty");
    assertEquals(stayMapping.getDetectorElement(), refinementElement);
    assertEquals(stayMapping.getRefinementElement(), detectorElement);
    assertEquals(deploymentArtifactMapping.getDetectorElement(), refinementElement);
    assertEquals(deploymentArtifactMapping.getRefinementElement(), detectorElement);
    assertEquals(deploymentArtifactMapping.getArtifactType(), QName.valueOf("artifactType"));
    assertEquals(behaviorPatternMapping.getDetectorElement(), refinementElement);
    assertEquals(behaviorPatternMapping.getRefinementElement(), detectorElement);
    assertEquals(behaviorPatternMapping.getBehaviorPattern(), "behaviorPattern");
    assertEquals(behaviorPatternMapping.getProperty(), new OTPropertyKV("key", "value"));
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 24 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class BehaviorPatternDetectionTest method removeIncompatibleBehaviorPatterns.

@Test
public void removeIncompatibleBehaviorPatterns() {
    List<TPolicy> behaviorPatterns = new ArrayList<>();
    behaviorPatterns.add(new TPolicy(new TPolicy.Builder(QName.valueOf("noProp")).setName("noProp")));
    behaviorPatterns.add(new TPolicy(new TPolicy.Builder(QName.valueOf("oneProp")).setName("oneProp")));
    behaviorPatterns.add(new TPolicy(new TPolicy.Builder(QName.valueOf("multiProps")).setName("multiProps")));
    TNodeTemplate detectorElement = new TNodeTemplate(new TNodeTemplate.Builder("detectorElement", QName.valueOf("{ns}patternType")).setPolicies(behaviorPatterns).setX("1").setY("1"));
    TNodeTemplate refinementElement = new TNodeTemplate(new TNodeTemplate.Builder("refinementElement", QName.valueOf("{ns}concreteType")).setX("1").setY("1"));
    LinkedHashMap<String, String> refinementProps = new LinkedHashMap<>();
    refinementProps.put("oneProp", "true");
    refinementProps.put("multiPropsProp1", "true");
    refinementProps.put("multiPropsProp2", "true");
    refinementProps.put("multiPropsProp3", "*");
    refinementProps.put("multiPropsProp4", "");
    refinementProps.put("multiPropsProp5", null);
    ModelUtilities.setPropertiesKV(refinementElement, refinementProps);
    TNodeTemplate candidateElement = new TNodeTemplate(new TNodeTemplate.Builder("candidateElement", QName.valueOf("{ns}concreteType")).setX("1").setY("1"));
    LinkedHashMap<String, String> candidateProps = new LinkedHashMap<>();
    candidateProps.put("oneProp", "false");
    candidateProps.put("multiPropsProp1", "false");
    candidateProps.put("multiPropsProp2", "false");
    candidateProps.put("multiPropsProp3", "");
    candidateProps.put("multiPropsProp4", null);
    candidateProps.put("multiPropsProp5", "");
    ModelUtilities.setPropertiesKV(candidateElement, candidateProps);
    List<OTBehaviorPatternMapping> behaviorPatternMappings = new ArrayList<>();
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap0").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("oneProp").setProperty(new OTPropertyKV("oneProp", "true"))));
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap1").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("multiProps").setProperty(new OTPropertyKV("multiPropsProp1", "true"))));
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap2").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("multiProps").setProperty(new OTPropertyKV("multiPropsProp2", "true"))));
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap3").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("multiProps").setProperty(new OTPropertyKV("multiPropsProp3", "*"))));
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap4").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("multiProps").setProperty(new OTPropertyKV("multiPropsProp4", ""))));
    behaviorPatternMappings.add(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder("behaviorPatternMap5").setDetectorElement(detectorElement).setRefinementElement(refinementElement).setBehaviorPattern("multiProps").setProperty(new OTPropertyKV("multiPropsProp5", null))));
    TTopologyTemplate detector = new TTopologyTemplate();
    detector.addNodeTemplate(detectorElement);
    TTopologyTemplate refinementStructure = new TTopologyTemplate();
    refinementStructure.addNodeTemplate(refinementElement);
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinementStructure).setBehaviorPatternMappings(behaviorPatternMappings));
    // needs to be swapped manually as only PRMs retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    TTopologyTemplate topology = new TTopologyTemplate();
    topology.addNodeTemplate(candidateElement);
    ToscaGraph topologyGraph = ToscaTransformer.createTOSCAGraph(topology);
    ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(prm.getDetector());
    IToscaMatcher matcher = new ToscaBehaviorPatternMatcher(prm, null);
    ToscaIsomorphismMatcher isomorphismMatcher = new ToscaIsomorphismMatcher();
    Iterator<GraphMapping<ToscaNode, ToscaEdge>> matches = isomorphismMatcher.findMatches(detectorGraph, topologyGraph, matcher);
    RefinementCandidate refinementCandidate = new RefinementCandidate(prm, matches.next(), detectorGraph, 1);
    // 'noProp' is applicable independent of properties as no behavior pattern mappings are specified
    BehaviorPatternDetection behaviorPatternDetection = new BehaviorPatternDetection(new DefaultRefinementChooser());
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    List<TPolicy> policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 1);
    assertEquals(policies.get(0).getName(), "noProp");
    // 'noProp' still applicable, 'oneProp' now applicable as well because property is set
    candidateProps.put("oneProp", "true");
    topology.getNodeTemplateOrRelationshipTemplate().clear();
    topology.addNodeTemplate(candidateElement);
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 2);
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("noProp")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
    // 'noProp' & 'oneProp' still applicable, 'multiProps' not applicable because not all properties are set
    candidateProps.put("multiPropsProp1", "true");
    topology.getNodeTemplateOrRelationshipTemplate().clear();
    topology.addNodeTemplate(candidateElement);
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 2);
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("noProp")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
    // 'noProp' & 'oneProp' still applicable, 'multiProps' not applicable because not all properties are set
    candidateProps.put("multiPropsProp2", "true");
    topology.getNodeTemplateOrRelationshipTemplate().clear();
    topology.addNodeTemplate(candidateElement);
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 2);
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("noProp")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
    // 'noProp' & 'oneProp' & 'multiProps' applicable
    candidateProps.put("multiPropsProp3", "non-null and non-empty");
    topology.getNodeTemplateOrRelationshipTemplate().clear();
    topology.addNodeTemplate(candidateElement);
    behaviorPatternDetection.applyRefinement(refinementCandidate, topology);
    assertEquals(topology.getNodeTemplateOrRelationshipTemplate().size(), 1);
    policies = topology.getNodeTemplates().get(0).getPolicies();
    assertEquals(policies.size(), 3);
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("noProp")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("oneProp")));
    assertTrue(policies.stream().anyMatch(policy -> policy.getName().equals("multiProps")));
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) GraphMapping(org.jgrapht.GraphMapping) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) Iterator(java.util.Iterator) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) Collections(java.util.Collections) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ToscaTransformer(org.eclipse.winery.topologygraph.transformation.ToscaTransformer) NonNull(org.eclipse.jdt.annotation.NonNull) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) ToscaBehaviorPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaBehaviorPatternMatcher) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) TPolicy(org.eclipse.winery.model.tosca.TPolicy) OTPropertyKV(org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.jupiter.api.Test)

Example 25 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ComponentPatternDetection method addRelationMappings.

private void addRelationMappings(ComponentPatternCandidate componentPatternCandidate, OTPatternRefinementModel adaptedPrm) {
    TNodeTemplate detectorElement = componentPatternCandidate.getDetectorElement();
    TNodeTemplate refinementElement = componentPatternCandidate.getRefinementElement();
    OTPatternRefinementModel otherPrm = componentPatternCandidate.getOtherPrm();
    TNodeTemplate otherDetectorElement = componentPatternCandidate.getOtherDetectorElement();
    // Redirect and add Relation Mappings of PDRM_x
    if (otherPrm.getRelationMappings() != null) {
        otherPrm.getRelationMappings().stream().filter(mapping -> mapping.getDetectorElement().getId().equals(otherDetectorElement.getId()) && mapping.getRefinementElement().getType().equals(refinementElement.getType())).forEach(mapping -> {
            mapping.setDetectorElement(detectorElement);
            mapping.setRefinementElement(refinementElement);
            adaptedPrm.getRelationMappings().add(mapping);
        });
    }
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) TopologyFragmentRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.topologyrefinement.TopologyFragmentRefinement) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Set(java.util.Set) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) HashMap(java.util.HashMap) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) Collectors(java.util.stream.Collectors) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) Objects(java.util.Objects) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) ToscaComponentPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaComponentPatternMatcher) List(java.util.List) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) ComponentPatternCandidate(org.eclipse.winery.topologygraph.matching.patterndetection.ComponentPatternCandidate) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Aggregations

OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)33 Test (org.junit.jupiter.api.Test)23 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)16 ArrayList (java.util.ArrayList)14 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 List (java.util.List)12 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)12 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)10 QName (javax.xml.namespace.QName)8 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)8 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)8 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Arrays (java.util.Arrays)7 LinkedHashMap (java.util.LinkedHashMap)7 PermutationHelper.addAllPermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings)7 PermutationHelper.generateComplexPrmWithPatternSet (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet)7 PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird)7