use of io.github.edmm.core.parser.EntityGraph in project winery by eclipse.
the class EdmmConverterTest method transformProperties.
@Test
void transformProperties() {
// region *** build the TopologyTemplate ***
TTopologyTemplate.Builder topology = new TTopologyTemplate.Builder();
topology.addNodeTemplate(nodeTemplates.get("test_node_3"));
// endregion
TServiceTemplate serviceTemplate = new TServiceTemplate();
serviceTemplate.setTopologyTemplate(topology.build());
EdmmConverter edmmConverter = new EdmmConverter(nodeTypes, relationshipTypes, nodeTypeImplementations, relationshipTypeImplementations, artifactTemplates, edmmTypeExtendsMapping, edmm1to1Mapping);
EntityGraph transform = edmmConverter.transform(serviceTemplate);
assertNotNull(transform);
assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals("properties")));
Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof MappingEntity && entity.getName().equals(key) && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties") && entity.getChildren().size() == 1));
});
Stream.of("os_family", "public_key", "ssh_port").forEach(key -> {
assertTrue(transform.vertexSet().stream().anyMatch(entity -> entity instanceof ScalarEntity && entity.getName().equals(key) && !((ScalarEntity) entity).getValue().isEmpty() && entity.getParent().isPresent() && entity.getParent().get().getName().equals("properties")));
});
}
use of io.github.edmm.core.parser.EntityGraph in project winery by eclipse.
the class EdmmResource method transform.
@GET
@Path("transform")
@Produces(MimeTypes.MIMETYPE_ZIP)
public Response transform(@QueryParam(value = "target") String target) {
EntityGraph graph = RestUtils.getEdmmEntityGraph(this.element, false);
GraphNormalizer.normalize(graph);
String wineryRepository = Environments.getInstance().getRepositoryConfig().getRepositoryRoot();
String filename;
byte[] response;
try {
// the transform command applies the transformation towards the specific target deployment files
// and return a zip of them
TransformationManager transformationManager = new TransformationManager();
File zipFile = transformationManager.transform(graph, target, wineryRepository);
filename = zipFile.getName();
response = FileUtils.readFileToByteArray(zipFile);
} catch (Exception e) {
// we send back a Server Error
String message = String.format("<html><body>" + "<div> %s </div>" + "<div> Probably something is missing in the service template XML or something went wrong on the server </div>" + "</body></html>", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_HTML).entity(message).build();
}
return Response.ok().header("Content-Disposition", "attachment; filename=\"" + filename + "\"").type(MimeTypes.MIMETYPE_ZIP).entity(response).build();
}
use of io.github.edmm.core.parser.EntityGraph in project winery by eclipse.
the class EdmmResource method checkModelSupport.
@GET
@Path("check-model-support")
@Produces(MediaType.APPLICATION_JSON)
public Response checkModelSupport() {
EntityGraph graph = RestUtils.getEdmmEntityGraph(this.element, true);
GraphNormalizer.normalize(graph);
PluginService pluginService = PluginManager.getInstance().getPluginService();
// getting the model from the graph
DeploymentModel model = new DeploymentModel(UUID.randomUUID().toString(), graph);
List<PluginSupportResult> result = pluginService.checkModelSupport(model);
return Response.ok().type(MediaType.APPLICATION_JSON).entity(result).build();
}
use of io.github.edmm.core.parser.EntityGraph in project winery by eclipse.
the class EdmmConverter method transform.
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;
}
use of io.github.edmm.core.parser.EntityGraph in project winery by eclipse.
the class RestUtils method getEdmmModel.
public static Response getEdmmModel(TServiceTemplate element, boolean useAbsolutPaths) {
EntityGraph transform = getEdmmEntityGraph(element, useAbsolutPaths);
StringWriter stringWriter = new StringWriter();
transform.generateYamlOutput(stringWriter);
return Response.ok().type(MimeTypes.MIMETYPE_YAML).entity(stringWriter.toString()).build();
}
Aggregations