Search in sources :

Example 36 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.

the class TopologyCatalogResource method getTopologyByIdAndVersion.

@GET
@Path("/topologies/{topologyId}/versions/{versionId}")
@Timed
public Response getTopologyByIdAndVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
    Topology result = catalogService.getTopology(topologyId, versionId);
    if (result != null) {
        return WSUtils.respondEntity(result, OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 37 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.

the class TopologyCatalogResource method cloneTopology.

@POST
@Path("/topologies/{topologyId}/actions/clone")
@Timed
public Response cloneTopology(@PathParam("topologyId") Long topologyId, @QueryParam("namespaceId") Long namespaceId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN);
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE);
    Topology originalTopology = catalogService.getTopology(topologyId);
    if (originalTopology != null) {
        Topology clonedTopology = catalogService.cloneTopology(namespaceId, originalTopology);
        return WSUtils.respondEntity(clonedTopology, OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 38 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.

the class TopologyCatalogResource method getComponentsToReconfigure.

@GET
@Path("/topologies/{topologyId}/reconfigure")
@Timed
public Response getComponentsToReconfigure(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
    Topology topology = catalogService.getTopology(topologyId);
    if (topology != null) {
        return WSUtils.respondEntity(catalogService.getComponentsToReconfigure(topology), OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 39 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.

the class TopologyCatalogResource method addTopology.

@POST
@Path("/topologies")
@Timed
public Response addTopology(Topology topology, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN);
    if (StringUtils.isEmpty(topology.getName())) {
        throw BadRequestException.missingParameter(Topology.NAME);
    }
    if (StringUtils.isEmpty(topology.getConfig())) {
        throw BadRequestException.missingParameter(Topology.CONFIG);
    }
    Topology createdTopology = catalogService.addTopology(topology);
    SecurityUtil.addAcl(authorizer, securityContext, NAMESPACE, createdTopology.getId(), EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdTopology, CREATED);
}
Also used : Permission(com.hortonworks.streamline.streams.security.Permission) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 40 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.

the class TopologyCatalogResource method exportTopology.

@GET
@Path("/topologies/{topologyId}/actions/export")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Timed
public Response exportTopology(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, READ, EXECUTE);
    Topology topology = catalogService.getTopology(topologyId);
    if (topology != null) {
        String exportedTopology = catalogService.exportTopology(topology);
        if (!StringUtils.isEmpty(exportedTopology)) {
            InputStream is = new ByteArrayInputStream(exportedTopology.getBytes(StandardCharsets.UTF_8));
            return Response.status(OK).entity(is).header("Content-Disposition", "attachment; filename=\"" + topology.getName() + ".json\"").build();
        }
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Topology (com.hortonworks.streamline.streams.catalog.Topology)67 Timed (com.codahale.metrics.annotation.Timed)39 Path (javax.ws.rs.Path)27 GET (javax.ws.rs.GET)17 IOException (java.io.IOException)12 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)9 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)8 List (java.util.List)8 Map (java.util.Map)8 POST (javax.ws.rs.POST)8 Expectations (mockit.Expectations)8 Test (org.junit.Test)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 TopologyComponent (com.hortonworks.streamline.streams.catalog.TopologyComponent)6 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)6 ArrayList (java.util.ArrayList)6 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)5 Collections (java.util.Collections)5