Search in sources :

Example 6 with OTStayMapping

use of org.eclipse.winery.model.tosca.extensions.OTStayMapping 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
}
Also used : ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) ToscaTypeMatcher(org.eclipse.winery.topologygraph.matching.ToscaTypeMatcher) AbstractRefinementTest(org.eclipse.winery.model.adaptation.substitution.refinement.AbstractRefinementTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with OTStayMapping

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

the class TopologyFragmentRefinementModelResource method savePrmMappingTopology.

@PUT
@Path("graphicPrmTopology")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Override
public TopologyTemplateResource savePrmMappingTopology(TTopologyTemplate topologyTemplate) {
    this.getTRefinementModel().resetAllMappings();
    RestUtils.persist(this);
    for (TRelationshipTemplate relTemplate : topologyTemplate.getRelationshipTemplates()) {
        String mappingId;
        // necessary for topologymodeler to create the IDs
        if (relTemplate.getId().startsWith("con")) {
            mappingId = relTemplate.getId().substring(relTemplate.getId().indexOf("_") + 1);
        } else {
            mappingId = relTemplate.getId();
        }
        if (relTemplate.getType().getLocalPart().startsWith("PermutationMapping")) {
            this.getPermutationMappings().addMapping(new OTPermutationMapping(new OTPermutationMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef())));
        }
        if (relTemplate.getType().getLocalPart().startsWith("RelationshipMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getRelationMappings().addMapping(new OTRelationMapping(new OTRelationMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setDirection(OTRelationDirection.fromValue(propertiesMap.get("direction"))).setRelationType(QName.valueOf(propertiesMap.get("applicableRelationshipType"))).setValidSourceOrTarget(QName.valueOf(propertiesMap.get("validEndpointType")))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("StayMapping")) {
            this.getStayMappings().addMapping(new OTStayMapping(new OTStayMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef())));
        }
        if (relTemplate.getType().getLocalPart().startsWith("AttributeMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getAttributeMappings().addMapping(new OTAttributeMapping(new OTAttributeMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setType(OTAttributeMappingType.fromValue(propertiesMap.get("type"))).setDetectorProperty(propertiesMap.get("detectorProperty")).setRefinementProperty(propertiesMap.get("refinementProperty"))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("DeploymentArtifactMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            this.getDeploymentArtifactMappings().addMapping(new OTDeploymentArtifactMapping(new OTDeploymentArtifactMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setArtifactType(QName.valueOf(propertiesMap.get("requiredDeploymentArtifactType")))));
        }
        if (relTemplate.getType().getLocalPart().startsWith("BehaviorPatternMapping")) {
            Map<String, String> propertiesMap = ((TEntityTemplate.WineryKVProperties) relTemplate.getProperties()).getKVProperties();
            ((PatternRefinementModelResource) this).getBehaviorPatternMappings().addMapping(new OTBehaviorPatternMapping(new OTBehaviorPatternMapping.Builder(mappingId).setDetectorElement(relTemplate.getSourceElement().getRef()).setRefinementElement(relTemplate.getTargetElement().getRef()).setProperty(new OTPropertyKV(propertiesMap.get("refinementProperty"), propertiesMap.get("refinementPropertyValue"))).setBehaviorPattern(propertiesMap.get("behaviorPattern"))));
        }
    }
    return new RefinementTopologyTemplateResource(this, this.getTRefinementModel(), GRAFIC_PRM_MODEL);
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) RefinementTopologyTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.topologytemplates.RefinementTopologyTemplateResource) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) 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) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 8 with OTStayMapping

use of org.eclipse.winery.model.tosca.extensions.OTStayMapping 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 9 with OTStayMapping

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

the class RefinementTopologyTemplateResource method createRelationshipsForMappings.

/**
 * convert mappings into Relationship for use in grafic prm modeling
 */
private void createRelationshipsForMappings(OTRefinementModel refinementModel) {
    for (OTPrmMapping mapping : getAllMappings(refinementModel)) {
        TRelationshipTemplate.Builder builder = new TRelationshipTemplate.Builder("con_" + mapping.getId(), QName.valueOf("{http://opentosca.org/prmMappingTypes}" + mapping.getId().substring(0, mapping.getId().indexOf("_"))), new TNodeTemplate(mapping.getDetectorElement().getId()), new TNodeTemplate(mapping.getRefinementElement().getId()));
        if (mapping instanceof OTPermutationMapping) {
            builder.setName("PermutationMapping");
        }
        if (mapping instanceof OTRelationMapping) {
            builder.setName("RelationshipMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("direction", ((OTRelationMapping) mapping).getDirection().value());
            kvproperties.put("applicableRelationshipType", ((OTRelationMapping) mapping).getRelationType().toString());
            kvproperties.put("validEndpointType", ((OTRelationMapping) mapping).getValidSourceOrTarget().toString());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTStayMapping) {
            builder.setName("StayMapping");
        }
        if (mapping instanceof OTAttributeMapping) {
            builder.setName("AttributeMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("type", ((OTAttributeMapping) mapping).getType().value());
            kvproperties.put("detectorProperty", ((OTAttributeMapping) mapping).getDetectorProperty());
            kvproperties.put("refinementProperty", ((OTAttributeMapping) mapping).getRefinementProperty());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTDeploymentArtifactMapping) {
            builder.setName("DeploymentArtifactMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("requiredDeploymentArtifactType", ((OTDeploymentArtifactMapping) mapping).getArtifactType().toString());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        if (mapping instanceof OTBehaviorPatternMapping) {
            builder.setName("BehaviorPatternMapping");
            LinkedHashMap<String, String> kvproperties = new LinkedHashMap<>();
            kvproperties.put("refinementProperty", ((OTBehaviorPatternMapping) mapping).getProperty().getKey());
            kvproperties.put("refinementPropertyValue", ((OTBehaviorPatternMapping) mapping).getProperty().getValue());
            kvproperties.put("behaviorPattern", ((OTBehaviorPatternMapping) mapping).getBehaviorPattern());
            TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
            properties.setKVProperties(kvproperties);
            builder.setProperties(properties);
        }
        TRelationshipTemplate templateForMapping = new TRelationshipTemplate(builder);
        prmModellingTopologyTemplate.addRelationshipTemplate(templateForMapping);
    }
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) LinkedHashMap(java.util.LinkedHashMap) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) OTBehaviorPatternMapping(org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Example 10 with OTStayMapping

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

the class PermutationGenerator method addNodeFromRefinementStructureToDetector.

private TNodeTemplate addNodeFromRefinementStructureToDetector(TNodeTemplate refinementElement, OTTopologyFragmentRefinementModel permutation, Map<String, String> alreadyAdded) {
    TNodeTemplate clone = SerializationUtils.clone(refinementElement);
    ModelUtilities.generateNewIdOfTemplate(clone, permutation.getDetector());
    permutation.getDetector().addNodeTemplate(clone);
    alreadyAdded.put(refinementElement.getId(), clone.getId());
    if (permutation.getStayMappings() == null) {
        permutation.setStayMappings(new ArrayList<>());
    }
    permutation.getStayMappings().add(new OTStayMapping(clone, refinementElement));
    return clone;
}
Also used : OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)9 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)7 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)7 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)6 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)6 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)6 ArrayList (java.util.ArrayList)5 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)5 Test (org.junit.jupiter.api.Test)5 LinkedHashMap (java.util.LinkedHashMap)4 OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)4 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)4 QName (javax.xml.namespace.QName)3 TPolicy (org.eclipse.winery.model.tosca.TPolicy)3 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)3 ToscaIsomorphismMatcher (org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher)3 ToscaEdge (org.eclipse.winery.topologygraph.model.ToscaEdge)3 ToscaGraph (org.eclipse.winery.topologygraph.model.ToscaGraph)3 Collections (java.util.Collections)2