Search in sources :

Example 1 with OTAttributeMapping

use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping 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));
}
Also used : ArrayList(java.util.ArrayList) 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) 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)

Example 2 with OTAttributeMapping

use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping 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));
}
Also used : ArrayList(java.util.ArrayList) 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) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 3 with OTAttributeMapping

use of org.eclipse.winery.model.tosca.extensions.OTAttributeMapping 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());
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) AbstractRefinementTest(org.eclipse.winery.model.adaptation.substitution.refinement.AbstractRefinementTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with OTAttributeMapping

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

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

the class PatternDetectionUtils method swapDetectorWithRefinement.

/**
 * To reuse the pattern refinement implementation for the pattern detection process, the detector is swapped with
 * the refinement.
 */
@ADR(31)
public static OTPatternRefinementModel swapDetectorWithRefinement(OTPatternRefinementModel prm) {
    TTopologyTemplate detector = prm.getDetector();
    prm.setDetector(prm.getRefinementTopology());
    prm.setRefinementTopology(detector);
    Stream.of(prm.getRelationMappings() == null ? Stream.empty() : prm.getRelationMappings().stream(), prm.getPermutationMappings() == null ? Stream.empty() : prm.getPermutationMappings().stream(), prm.getAttributeMappings() == null ? Stream.empty() : prm.getAttributeMappings().stream(), prm.getStayMappings() == null ? Stream.empty() : prm.getStayMappings().stream(), prm.getDeploymentArtifactMappings() == null ? Stream.empty() : prm.getDeploymentArtifactMappings().stream(), prm.getBehaviorPatternMappings() == null ? Stream.empty() : prm.getBehaviorPatternMappings().stream()).flatMap(Function.identity()).map(OTPrmMapping.class::cast).forEach(mapping -> {
        if (mapping instanceof OTAttributeMapping) {
            OTAttributeMapping attributeMapping = (OTAttributeMapping) mapping;
            swapDetectorWithRefinement(attributeMapping);
        } else {
            swapDetectorWithRefinement(mapping);
        }
    });
    return prm;
}
Also used : OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ADR(io.github.adr.embedded.ADR)

Aggregations

OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)8 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)6 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)5 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 OTDeploymentArtifactMapping (org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping)4 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)4 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)4 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)3 OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)3 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)2 Test (org.junit.jupiter.api.Test)2 ADR (io.github.adr.embedded.ADR)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1