Search in sources :

Example 6 with OTDeploymentArtifactMapping

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

the class TopologyFragmentRefinement method applyDeploymentArtifactMapping.

private boolean applyDeploymentArtifactMapping(RefinementCandidate refinement, TNodeTemplate detectorNode, TNodeTemplate matchingNode, TTopologyTemplate topology, Map<String, String> idMapping) {
    List<OTDeploymentArtifactMapping> deploymentArtifactMappings = ((OTTopologyFragmentRefinementModel) refinement.getRefinementModel()).getDeploymentArtifactMappings();
    return matchingNode.getDeploymentArtifacts() == null || matchingNode.getDeploymentArtifacts().isEmpty() || (deploymentArtifactMappings != null && matchingNode.getDeploymentArtifacts().stream().filter(deploymentArtifact -> deploymentArtifact.getArtifactType() != null).allMatch(deploymentArtifact -> deploymentArtifactMappings.stream().filter(mapping -> mapping.getDetectorElement().getId().equals(detectorNode.getId())).anyMatch(mapping -> {
        if (ModelUtilities.isOfType(mapping.getArtifactType(), deploymentArtifact.getArtifactType(), this.artifactTypes)) {
            if (idMapping != null) {
                TNodeTemplate addedNode = topology.getNodeTemplate(idMapping.get(mapping.getRefinementElement().getId()));
                if (addedNode != null) {
                    List<TDeploymentArtifact> existingDAs = addedNode.getDeploymentArtifacts();
                    if (existingDAs == null) {
                        existingDAs = new ArrayList<>();
                        addedNode.setDeploymentArtifacts(existingDAs);
                    } else if (existingDAs.stream().anyMatch(da -> da.getName().equals(deploymentArtifact.getName()))) {
                        deploymentArtifact.setName(deploymentArtifact.getName() + UUID.randomUUID());
                    }
                    existingDAs.add(deploymentArtifact);
                } else {
                    LOGGER.error("Error while adding Deployment Artifacts! Node was not added to the topology!");
                }
            }
            return true;
        }
        return false;
    })));
}
Also used : OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) GraphMapping(org.jgrapht.GraphMapping) LoggerFactory(org.slf4j.LoggerFactory) RefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementChooser) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) ToscaPrmPropertyMatcher(org.eclipse.winery.topologygraph.matching.ToscaPrmPropertyMatcher) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTAttributeMappingType(org.eclipse.winery.model.tosca.extensions.OTAttributeMappingType) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) Logger(org.slf4j.Logger) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) RefinementUtils.redirectRelation(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.redirectRelation) AbstractRefinement(org.eclipse.winery.model.adaptation.substitution.refinement.AbstractRefinement) UUID(java.util.UUID) RefinementId(org.eclipse.winery.model.ids.extensions.RefinementId) Collectors(java.util.stream.Collectors) RefinementUtils(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils) HasId(org.eclipse.winery.model.tosca.HasId) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) RefinementCandidate(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate) OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 7 with OTDeploymentArtifactMapping

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

the class PermutationHelper method generateComplexPrmWithPatternSet.

static OTPatternRefinementModel generateComplexPrmWithPatternSet() {
    /*                +------------------------+   
                          |                        \| 
        ########----------+      ########        ######## 
        #  (1) #---------------> # (11) # -----> # (12) # 
        ########                 ########        ######## 
            |                        | (2)           | (2)
            | (2)                   \/              \/    
           \/                    ########        ######## 
        ########---------------> # (13) #-------># (14) # 
        #  (2) #                 ########        ######## 
        ########--------+            | (2)           |
            |           |           \/               |      
            | (2)       +------> ########            |
           \/                    # (15) #        (2) |       
        ########---------------> ########            |
        #  (3) #                     | (2)           |
        ########                    \/               |
                                 ########            |
                                 # (16) #<-----------+ 
                                 ######## 
         */
    TTopologyTemplate detector = generateDetectorWithThreePatterns();
    // 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");
    TNodeTemplate refinementNode_15 = new TNodeTemplate();
    refinementNode_15.setType("{http://ex.org}nodeType_15");
    refinementNode_15.setId("15");
    TNodeTemplate refinementNode_16 = new TNodeTemplate();
    refinementNode_16.setType("{http://ex.org}nodeType_16");
    refinementNode_16.setId("16");
    TRelationshipTemplate node11_connectsTo_node12 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_12, QName.valueOf("{http://ex.org}relType_connectsTo"));
    TRelationshipTemplate node11_hostedOn_node13 = ModelUtilities.createRelationshipTemplate(refinementNode_11, refinementNode_13, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node12_hostedOn_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_12, refinementNode_14, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node13_connectsTo_node14 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_14, QName.valueOf("{http://ex.org}relType_connectsTo"));
    TRelationshipTemplate node13_hostedOn_node15 = ModelUtilities.createRelationshipTemplate(refinementNode_13, refinementNode_15, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node14_hostedOn_node16 = ModelUtilities.createRelationshipTemplate(refinementNode_14, refinementNode_16, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TRelationshipTemplate node15_hostedOn_node16 = ModelUtilities.createRelationshipTemplate(refinementNode_15, refinementNode_16, QName.valueOf("{http://ex.org}relType_hostedOn"));
    TTopologyTemplate refinementStructure = new TTopologyTemplate.Builder().addNodeTemplate(refinementNode_11).addNodeTemplate(refinementNode_12).addNodeTemplate(refinementNode_13).addNodeTemplate(refinementNode_14).addNodeTemplate(refinementNode_15).addNodeTemplate(refinementNode_16).addRelationshipTemplate(node11_connectsTo_node12).addRelationshipTemplate(node11_hostedOn_node13).addRelationshipTemplate(node12_hostedOn_node14).addRelationshipTemplate(node13_connectsTo_node14).addRelationshipTemplate(node13_hostedOn_node15).addRelationshipTemplate(node14_hostedOn_node16).addRelationshipTemplate(node15_hostedOn_node16).build();
    // endregion
    // region mappings
    OTRelationMapping pattern1_to_node11 = new OTRelationMapping.Builder("rm-1--11").setRelationType("{http://ex.org}relType_connectsTo").setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_11).build();
    OTDeploymentArtifactMapping pattern1_to_node12 = new OTDeploymentArtifactMapping.Builder("dam-1--12").setDetectorElement(detector.getNodeTemplate("1")).setRefinementElement(refinementNode_12).setArtifactType(QName.valueOf("{http://ex.org}artType_war")).build();
    OTAttributeMapping pattern2_to_node13 = new OTAttributeMapping.Builder("am-2--13").setType(OTAttributeMappingType.ALL).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_13).build();
    OTRelationMapping pattern2_to_node15 = new OTRelationMapping.Builder("rm-2--15").setRelationType("{http://ex.org}relType_connectsTo").setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("2")).setRefinementElement(refinementNode_15).build();
    OTRelationMapping pattern3_to_node15 = new OTRelationMapping.Builder("rm-3--15").setRelationType(QName.valueOf("{http://ex.org}relType_connectsTo")).setDirection(OTRelationDirection.INGOING).setDetectorElement(detector.getNodeTemplate("3")).setRefinementElement(refinementNode_15).build();
    // endregion
    // region relation mappings
    ArrayList<OTRelationMapping> relationMappings = new ArrayList<>();
    relationMappings.add(pattern1_to_node11);
    relationMappings.add(pattern2_to_node15);
    relationMappings.add(pattern3_to_node15);
    return new OTPatternRefinementModel.Builder().setName("ComplexPrmWithPatternSet").setTargetNamespace("http://ex.org").setDetector(detector).setRefinementStructure(refinementStructure).setAttributeMappings(Collections.singletonList(pattern2_to_node13)).setRelationMappings(relationMappings).setDeploymentArtifactMappings(Collections.singletonList(pattern1_to_node12)).build();
}
Also used : OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTDeploymentArtifactMapping(org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) 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)

Aggregations

OTDeploymentArtifactMapping (org.eclipse.winery.model.tosca.extensions.OTDeploymentArtifactMapping)7 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)5 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)5 OTAttributeMapping (org.eclipse.winery.model.tosca.extensions.OTAttributeMapping)5 OTRelationMapping (org.eclipse.winery.model.tosca.extensions.OTRelationMapping)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)4 ArrayList (java.util.ArrayList)3 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)3 OTBehaviorPatternMapping (org.eclipse.winery.model.tosca.extensions.OTBehaviorPatternMapping)3 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)3 LinkedHashMap (java.util.LinkedHashMap)2 QName (javax.xml.namespace.QName)2 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)2 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)2 OTPropertyKV (org.eclipse.winery.model.tosca.extensions.kvproperties.OTPropertyKV)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1