Search in sources :

Example 71 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class IpSecAlgorithmTest method applySolutionTest.

@Test
public void applySolutionTest() throws Exception {
    this.setRevisionTo("a23f1c89c77fcde4de9fe7822532dc04e31731a0");
    IpSecAlgorithm ipSecAlgorithm = new IpSecAlgorithm();
    TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://plain.winery.opentosca.org/servicetemplates}ServiceTemplateWithIpSecProblem_w1-wip1"))).getTopologyTemplate();
    ArrayList<ComponentFinding> componentFindings = new ArrayList<>();
    componentFindings.add(new ComponentFinding(null, "NodeTypeWithImplementation_1.0-w1-wip1"));
    componentFindings.add(new ComponentFinding(null, "NodeTypeWithXmlElementProperty"));
    SolutionInputData inputData = new SolutionInputData();
    inputData.setFindings(componentFindings);
    ipSecAlgorithm.applySolution(topologyTemplate, inputData);
    assertEquals(4, topologyTemplate.getNodeTemplates().size());
    assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_1").getType());
    assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_2").getType());
    assertEquals(5, topologyTemplate.getRelationshipTemplates().size());
    TRelationshipTemplate forward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_2-securely_connectsTo-replaceableNode_1");
    assertNotNull(forward);
    assertEquals("replaceableNode_2", forward.getSourceElement().getRef().getId());
    assertEquals("replaceableNode_1", forward.getTargetElement().getRef().getId());
    TRelationshipTemplate backward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_1-securely_connectsTo-replaceableNode_2");
    assertNotNull(backward);
    assertEquals("replaceableNode_1", backward.getSourceElement().getRef().getId());
    assertEquals("replaceableNode_2", backward.getTargetElement().getRef().getId());
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) ComponentFinding(org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 72 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class TestRefinement method applyRefinement.

@Override
public Map<String, String> applyRefinement(RefinementCandidate refinement, TTopologyTemplate topology) {
    // import the refinement structure
    Map<String, String> idMapping = BackendUtils.mergeTopologyTemplateAinTopologyTemplateB(refinement.getRefinementModel().getRefinementTopology(), topology);
    // iterate over the refinement nodes and add the configured relations
    refinement.getRefinementModel().getRefinementTopology().getNodeTemplates().forEach(nodeTemplate -> refinement.getRefinementModel().getRelationMappings().stream().filter(relationMapping -> relationMapping.getRefinementElement().getId().equals(nodeTemplate.getId())).forEach(relationMapping -> {
        String relId = this.versionAppendix + "-" + relationMapping.getRelationType().getLocalPart();
        int counter = 0;
        while (Objects.nonNull(idMapping.get(relId))) {
            relId += counter++;
        }
        TRelationshipTemplate relationshipTemplate = new TRelationshipTemplate();
        relationshipTemplate.setType(relationMapping.getRelationType());
        relationshipTemplate.setId(relId);
        relationshipTemplate.setName(relationMapping.getRelationType().getLocalPart());
        // Retrieve the id from the correspondence node of the graph mapping.
        ToscaNode node = refinement.getDetectorGraph().getNode(relationMapping.getDetectorElement().getId());
        String topologyNodeId = refinement.getGraphMapping().getVertexCorrespondence(node, false).getId();
        if (relationMapping.getDirection() == OTRelationDirection.INGOING) {
            String targetId = idMapping.get(relationMapping.getRefinementElement().getId());
            relationshipTemplate.setSourceNodeTemplate(topology.getNodeTemplate(topologyNodeId));
            relationshipTemplate.setTargetNodeTemplate(topology.getNodeTemplate(targetId));
        } else {
            String sourceId = idMapping.get(relationMapping.getRefinementElement().getId());
            relationshipTemplate.setSourceNodeTemplate(topology.getNodeTemplate(sourceId));
            relationshipTemplate.setTargetNodeTemplate(topology.getNodeTemplate(topologyNodeId));
        }
        topology.addRelationshipTemplate(relationshipTemplate);
    }));
    return idMapping;
}
Also used : Logger(org.slf4j.Logger) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) LoggerFactory(org.slf4j.LoggerFactory) AbstractRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.AbstractRefinement) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) Objects(java.util.Objects) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) ToscaTypeMatcher(org.eclipse.winery.topologygraph.matching.ToscaTypeMatcher) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTRelationDirection(org.eclipse.winery.model.tosca.extensions.OTRelationDirection) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode)

Example 73 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class EnhancementUtilsTestWithGitBackedRepository method applyFeaturesToTopology.

@Test
void applyFeaturesToTopology() throws Exception {
    this.setRevisionTo("origin/plain");
    TTopologyTemplate topology = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://opentosca.org/add/management/to/instances/servicetemplates}STWithBasicManagementOnly_w1-wip1"))).getTopologyTemplate();
    // As we do not want to filter the features based on the deployment technology, the second parameter is null.
    EnhancementUtils.applyFeaturesForTopology(topology, EnhancementUtils.getAvailableFeaturesForTopology(topology, Collections.emptyList()));
    String ubuntuNodeTemplateId = "Ubuntu_16.04-w1";
    String mySqlNodeTemplateId = "MySQL-Database_w1";
    assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}Ubuntu_16.04-w1-" + ubuntuNodeTemplateId + "-Testing-Freeze_and_Defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(ubuntuNodeTemplateId).getType());
    assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}MySQL-Database_w1-" + mySqlNodeTemplateId + "-Freeze_and_defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(mySqlNodeTemplateId).getType());
    assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)));
    assertEquals(9, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)).size());
    assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)));
    assertEquals(3, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)).size());
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 74 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class PermutationHelper method generatePrmWithComplexRelationMaps.

static OTPatternRefinementModel generatePrmWithComplexRelationMaps() {
    /*
        ########                 ########        ######## 
        #  (1) #---------------> # (11) # -----> # (12) # 
        ########                 ########        ######## 
            |                    (2) |______________| (2)
            | (2)                   \/    
           \/                    ########
        ########---------------> # (13) #
        #  (2) #                 ########
        ########                     | (2)
                                    \/   
                                 ########
                                 # (14) #
                                 ########
         */
    TTopologyTemplate detector = generateDetectorWithTwoPatterns();
    // region refinement structure
    TNodeTemplate refinementNode_11 = new TNodeTemplate();
    refinementNode_11.setType("{http://ex.org}nodeType_11");
    refinementNode_11.setId("11");
    TNodeTemplate refinementNode_12 = new TNodeTemplate();
    refinementNode_12.setType("{http://ex.org}nodeType_12");
    refinementNode_12.setId("12");
    TNodeTemplate refinementNode_13 = new TNodeTemplate();
    refinementNode_13.setType("{http://ex.org}nodeType_13");
    refinementNode_13.setId("13");
    TNodeTemplate refinementNode_14 = new TNodeTemplate();
    refinementNode_14.setType("{http://ex.org}nodeType_14");
    refinementNode_14.setId("14");
    TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node12_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node13_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
    TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node11_connectsTo_node12).build();
    // endregion
    // region mappings
    OTPermutationMapping pattern1_to_node11 = new OTPermutationMapping.Builder("pm-1--11").setRefinementElement(refinementNode_11).setDetectorElement(detector.getNodeTemplate("1")).build();
    OTPermutationMapping pattern2_to_node13 = new OTPermutationMapping.Builder("pm-2--13").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
    // endregion
    // region prm
    List<OTPermutationMapping> list = new ArrayList<>();
    list.add(pattern1_to_node11);
    list.add(pattern2_to_node13);
    return new OTPatternRefinementModel.Builder().setName("PrmWithComplexRelationMappings").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setPermutationMappings(list).build();
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Example 75 with TTopologyTemplate

use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.

the class PermutationHelper method generatePrmWithTwoPatternsHostedOnAThird.

static OTPatternRefinementModel generatePrmWithTwoPatternsHostedOnAThird() {
    /*                   +----------------------------------+
            +---------------(------------------+               |
            |               |                 \/              \/ 
        ########         ########           ########        ######## 
        #  (1) #-------> #  (3) #           # (11) # -----> # (12) # 
        ########         ########           ########        ######## 
            | (2)           |(2)             (2) |______________| (2)
            |---------------+                   \/    
           \/                                ########
        ########---------------------------> # (13) #
        #  (2) #                             ########
        ########                                 | (2)
                                                \/   
                                             ########
                                             # (14) #
                                             ########
         */
    TTopologyTemplate detector = generateDetectorWithTwoPatternsHostedOnOne();
    // region refinement structure
    TNodeTemplate refinementNode_11 = new TNodeTemplate();
    refinementNode_11.setType("{http://ex.org}nodeType_11");
    refinementNode_11.setId("11");
    TNodeTemplate refinementNode_12 = new TNodeTemplate();
    refinementNode_12.setType("{http://ex.org}nodeType_12");
    refinementNode_12.setId("12");
    TNodeTemplate refinementNode_13 = new TNodeTemplate();
    refinementNode_13.setType("{http://ex.org}nodeType_13");
    refinementNode_13.setId("13");
    TNodeTemplate refinementNode_14 = new TNodeTemplate();
    refinementNode_14.setType("{http://ex.org}nodeType_14");
    refinementNode_14.setId("14");
    TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node12_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node13_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
    TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node13).addRelationshipTemplate(node13_hostedOn_node14).addRelationshipTemplate(node11_connectsTo_node12).build();
    // endregion
    // region mappings
    OTPermutationMapping pattern1_to_node11 = new OTPermutationMapping.Builder("pm-1--11").setRefinementElement(refinementNode_11).setDetectorElement(detector.getNodeTemplate("1")).build();
    OTPermutationMapping pattern2_to_node13 = new OTPermutationMapping.Builder("pm-2--13").setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
    OTPermutationMapping pattern3_to_node12 = new OTPermutationMapping.Builder("pm-3--12").setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_12).build();
    // endregion
    // region prm
    List<OTPermutationMapping> list = new ArrayList<>();
    list.add(pattern1_to_node11);
    list.add(pattern2_to_node13);
    list.add(pattern3_to_node12);
    return new OTPatternRefinementModel.Builder().setName("PrmWithComplexRelationMappings").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setPermutationMappings(list).build();
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)158 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)112 ArrayList (java.util.ArrayList)85 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)62 List (java.util.List)59 QName (javax.xml.namespace.QName)55 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)55 Test (org.junit.jupiter.api.Test)51 Map (java.util.Map)48 HashMap (java.util.HashMap)47 LinkedHashMap (java.util.LinkedHashMap)42 TNodeType (org.eclipse.winery.model.tosca.TNodeType)42 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)38 IRepository (org.eclipse.winery.repository.backend.IRepository)38 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)36 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)35 Objects (java.util.Objects)34 IOException (java.io.IOException)32 HashSet (java.util.HashSet)32 Collectors (java.util.stream.Collectors)32