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;
})));
}
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();
}
Aggregations