Search in sources :

Example 1 with EntityGraph

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")));
    });
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) StringWriter(java.io.StringWriter) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest) Entity(io.github.edmm.core.parser.Entity) MappingEntity(io.github.edmm.core.parser.MappingEntity) Stream(java.util.stream.Stream) EntityGraph(io.github.edmm.core.parser.EntityGraph) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ScalarEntity(io.github.edmm.core.parser.ScalarEntity) MappingEntity(io.github.edmm.core.parser.MappingEntity) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) EdmmDependantTest(org.eclipse.winery.edmm.EdmmDependantTest)

Example 2 with EntityGraph

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();
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) TransformationManager(org.eclipse.winery.edmm.TransformationManager) File(java.io.File) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with EntityGraph

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();
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) DeploymentModel(io.github.edmm.model.DeploymentModel) PluginSupportResult(io.github.edmm.model.PluginSupportResult) PluginService(io.github.edmm.core.plugin.PluginService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with EntityGraph

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;
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) MappingEntity(io.github.edmm.core.parser.MappingEntity) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant)

Example 5 with 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();
}
Also used : EntityGraph(io.github.edmm.core.parser.EntityGraph) StringWriter(java.io.StringWriter)

Aggregations

EntityGraph (io.github.edmm.core.parser.EntityGraph)10 EdmmDependantTest (org.eclipse.winery.edmm.EdmmDependantTest)6 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)6 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 Test (org.junit.jupiter.api.Test)6 MappingEntity (io.github.edmm.core.parser.MappingEntity)5 StringWriter (java.io.StringWriter)5 Entity (io.github.edmm.core.parser.Entity)4 ScalarEntity (io.github.edmm.core.parser.ScalarEntity)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Arrays (java.util.Arrays)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 PluginService (io.github.edmm.core.plugin.PluginService)1