Search in sources :

Example 26 with Topology

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

the class TopologyCatalogResource method removeTopology.

@DELETE
@Path("/topologies/{topologyId}")
@Timed
public Response removeTopology(@PathParam("topologyId") Long topologyId, @javax.ws.rs.QueryParam("onlyCurrent") boolean onlyCurrent, @javax.ws.rs.QueryParam("force") boolean force, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, DELETE);
    if (!force) {
        Topology result = catalogService.getTopology(topologyId);
        if (result == null) {
            throw EntityNotFoundException.byId(topologyId.toString());
        }
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        try {
            String runtimeTopologyId = actionsService.getRuntimeTopologyId(result, asUser);
            if (StringUtils.isNotEmpty(runtimeTopologyId)) {
                throw BadRequestException.message("Can't remove topology while Topology is running - topology id: " + topologyId);
            }
        } catch (TopologyNotAliveException e) {
        // OK to continue
        } catch (StormNotReachableException | IOException e) {
            // users need to make a request with force parameter on
            throw new StreamingEngineNotReachableException(e.getMessage(), e);
        }
    }
    Response response;
    if (onlyCurrent) {
        response = removeCurrentTopologyVersion(topologyId);
    } else {
        response = removeAllTopologyVersions(topologyId);
    }
    SecurityUtil.removeAcl(authorizer, securityContext, NAMESPACE, topologyId);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Topology(com.hortonworks.streamline.streams.catalog.Topology) IOException(java.io.IOException) StreamingEngineNotReachableException(com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 27 with Topology

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

the class TopologyCatalogResource method removeAllTopologyVersions.

private Response removeAllTopologyVersions(Long topologyId) {
    Collection<TopologyVersion> versions = catalogService.listTopologyVersionInfos(WSUtils.topologyVersionsQueryParam(topologyId));
    Long currentVersionId = catalogService.getCurrentVersionId(topologyId);
    Topology res = null;
    for (TopologyVersion version : versions) {
        Topology removed = catalogService.removeTopology(topologyId, version.getId(), true);
        if (removed != null && removed.getVersionId().equals(currentVersionId)) {
            res = removed;
        }
    }
    // remove topology state information
    catalogService.removeTopologyState(topologyId);
    if (res != null) {
        return WSUtils.respondEntity(res, OK);
    } else {
        throw EntityNotFoundException.byId(topologyId.toString());
    }
}
Also used : TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) Topology(com.hortonworks.streamline.streams.catalog.Topology)

Example 28 with Topology

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

the class TopologyDashboardResource method listTopologies.

@GET
@Path("/topologies/dashboard")
@Timed
public Response listTopologies(@javax.ws.rs.QueryParam("sort") String sortType, @javax.ws.rs.QueryParam("ascending") Boolean ascending, @javax.ws.rs.QueryParam("latencyTopN") Integer latencyTopN, @Context SecurityContext securityContext) {
    Collection<Topology> topologies = catalogService.listTopologies();
    boolean topologyUser = SecurityUtil.hasRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER);
    if (topologyUser) {
        LOG.debug("Returning all topologies since user has role: {}", Roles.ROLE_TOPOLOGY_USER);
    } else {
        topologies = SecurityUtil.filter(authorizer, securityContext, NAMESPACE, topologies, READ);
    }
    Response response;
    if (topologies != null) {
        if (sortType == null) {
            sortType = DEFAULT_SORT_TYPE;
        }
        if (ascending == null) {
            ascending = DEFAULT_SORT_ORDER_ASCENDING;
        }
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        List<CatalogResourceUtil.TopologyDashboardResponse> detailedTopologies = enrichTopologies(topologies, asUser, sortType, ascending, latencyTopN);
        response = WSUtils.respondEntities(detailedTopologies, OK);
    } else {
        response = WSUtils.respondEntities(Collections.emptyList(), OK);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 29 with Topology

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

the class TopologyEventSamplingResource method enableSampling.

@POST
@Path("/topologies/{topologyId}/sampling/enable/{pct}")
@Timed
public Response enableSampling(@PathParam("topologyId") Long topologyId, @PathParam("pct") Integer pct, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, READ, EXECUTE);
    Topology topology = catalogService.getTopology(topologyId);
    ensureValidSamplingPct(pct);
    if (topology != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        boolean success = samplingService.enableSampling(topology, pct, asUser);
        return WSUtils.respondEntity(SamplingResponse.of(topologyId).pct(pct).success(success).build(), 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 30 with Topology

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

the class TopologyEventSamplingResource method samplingStatus.

@GET
@Path("/topologies/{topologyId}/sampling")
@Timed
public Response samplingStatus(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, READ, EXECUTE);
    Topology topology = catalogService.getTopology(topologyId);
    if (topology != null) {
        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
        TopologySampling.SamplingStatus status = samplingService.samplingStatus(topology, asUser);
        SamplingResponse response;
        if (status == null) {
            response = SamplingResponse.of(topologyId).success(false).build();
        } else {
            response = SamplingResponse.of(topologyId).success(true).enabled(status.getEnabled()).pct(status.getPct()).build();
        }
        return WSUtils.respondEntity(response, OK);
    }
    throw EntityNotFoundException.byId(topologyId.toString());
}
Also used : TopologySampling(com.hortonworks.streamline.streams.sampling.service.TopologySampling) Topology(com.hortonworks.streamline.streams.catalog.Topology) Path(javax.ws.rs.Path) 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