Skip to content

Commit

Permalink
Update EDMM export
Browse files Browse the repository at this point in the history
  • Loading branch information
miwurster committed Mar 22, 2021
1 parent e097b36 commit d4bd577
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -39,6 +41,7 @@
import org.eclipse.winery.model.tosca.TRelationshipType;
import org.eclipse.winery.model.tosca.TRelationshipTypeImplementation;
import org.eclipse.winery.model.tosca.TServiceTemplate;
import org.eclipse.winery.model.tosca.extensions.OTParticipant;
import org.eclipse.winery.model.tosca.utils.ModelUtilities;

import io.github.edmm.core.parser.Entity;
Expand Down Expand Up @@ -85,20 +88,79 @@ public EdmmConverter(Map<QName, TNodeType> nodeTypes, Map<QName, TRelationshipTy
}

public EntityGraph transform(TServiceTemplate serviceTemplate) {

EntityGraph entityGraph = new EntityGraph();

setMetadata(entityGraph);

List<TNodeTemplate> nodeTemplates = serviceTemplate.getTopologyTemplate().getNodeTemplates();
List<TRelationshipTemplate> relationshipTemplates = serviceTemplate.getTopologyTemplate().getRelationshipTemplates();
if (!nodeTemplates.isEmpty()) {
entityGraph.addEntity(new MappingEntity(EntityGraph.COMPONENTS, entityGraph));
}

nodeTemplates.forEach(nodeTemplate -> createNode(nodeTemplate, entityGraph));
relationshipTemplates.forEach(relationship -> createRelation(relationship, entityGraph));

List<OTParticipant> participants = serviceTemplate.getTopologyTemplate().getParticipants();
if (participants != null && !participants.isEmpty()) {
entityGraph.addEntity(new MappingEntity(EntityGraph.PARTICIPANTS, entityGraph));
participants.forEach(participant -> createParticipant(participant, nodeTemplates, entityGraph));
}

createTechnologyMapping(nodeTemplates, entityGraph);

return entityGraph;
}

private void setMetadata(EntityGraph entityGraph) {
entityGraph.addEntity(new ScalarEntity("edm_1_0", EntityGraph.VERSION, entityGraph));
entityGraph.addEntity(new ScalarEntity("12345", EntityGraph.MULTI_ID, entityGraph));
}

private void createTechnologyMapping(List<TNodeTemplate> nodeTemplates, EntityGraph entityGraph) {

Map<String, List<TNodeTemplate>> deploymentTechnologyMapping = new HashMap<>();
for (TNodeTemplate nodeTemplate : nodeTemplates) {
Map<QName, String> attributes = nodeTemplate.getOtherAttributes();
String key = attributes.get(QName.valueOf("{http://www.opentosca.org/winery/extensions/tosca/2013/02/12}deployment-technology"));
deploymentTechnologyMapping.computeIfAbsent(key, k -> new ArrayList<>());
deploymentTechnologyMapping.get(key).add(nodeTemplate);
}

if (!deploymentTechnologyMapping.isEmpty()) {
entityGraph.addEntity(new MappingEntity(EntityGraph.ORCHESTRATION_TECHNOLOGY, entityGraph));
deploymentTechnologyMapping.forEach((key, nodes) -> {
EntityId entity = EntityGraph.ORCHESTRATION_TECHNOLOGY.extend(key);
entityGraph.addEntity(new SequenceEntity(entity, entityGraph));
for (TNodeTemplate nodeTemplate : nodes) {
EntityId valueEntity = entity.extend(nodeTemplate.getId());
entityGraph.addEntity(new ScalarEntity(nodeTemplate.getId(), valueEntity, entityGraph));
}
});
}
}

private void createParticipant(OTParticipant participant, List<TNodeTemplate> nodeTemplates, EntityGraph entityGraph) {

EntityId participantEntity = EntityGraph.PARTICIPANTS.extend(participant.getName());
entityGraph.addEntity(new MappingEntity(participantEntity, entityGraph));

EntityId endpointEntityId = participantEntity.extend(DefaultKeys.ENDPOINT);
entityGraph.addEntity(new ScalarEntity(participant.getUrl(), endpointEntityId, entityGraph));

EntityId componentsEntityId = participantEntity.extend(DefaultKeys.COMPONENTS);
entityGraph.addEntity(new SequenceEntity(componentsEntityId, entityGraph));

for (TNodeTemplate nodeTemplate : nodeTemplates) {
Map<QName, String> attributes = nodeTemplate.getOtherAttributes();
String name = attributes.get(QName.valueOf("{http://www.opentosca.org/winery/extensions/tosca/2013/02/12}participant"));
if (participant.getName().equals(name)) {
EntityId valueEntity = componentsEntityId.extend(nodeTemplate.getId());
entityGraph.addEntity(new ScalarEntity(nodeTemplate.getId(), valueEntity, entityGraph));
}
}
}

private void createRelation(TRelationshipTemplate relationship, EntityGraph entityGraph) {
EntityId sourceComponentEntityId = EntityGraph.COMPONENTS.extend(relationship.getSourceElement().getRef().getId());
// the entity will always be in the graph since we first transform the NodeTemplates
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<io.rest-assured>3.0.2</io.rest-assured>
<xerces.xercesImpl.version>2.12.0</xerces.xercesImpl.version>
<snakeyaml.version>1.25</snakeyaml.version>
<edmm.version>v1.0.15</edmm.version>
<edmm.version>1.0.18</edmm.version>

<!-- grouped libraries -->
<org.apache.cxf.version>2.7.6</org.apache.cxf.version>
Expand Down

0 comments on commit d4bd577

Please sign in to comment.