Search in sources :

Example 1 with StormNotReachableException

use of com.hortonworks.streamline.streams.storm.common.StormNotReachableException in project streamline by hortonworks.

the class CatalogResourceUtil method enrichTopology.

static TopologyDashboardResponse enrichTopology(Topology topology, String asUser, Integer latencyTopN, EnvironmentService environmentService, TopologyActionsService actionsService, TopologyMetricsService metricsService, StreamCatalogService catalogService) {
    LOG.debug("[START] enrichTopology - topology id: {}", topology.getId());
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        if (latencyTopN == null) {
            latencyTopN = DEFAULT_N_OF_TOP_N_LATENCY;
        }
        TopologyDashboardResponse detailedResponse;
        String namespaceName = null;
        Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
        if (namespace != null) {
            namespaceName = namespace.getName();
        }
        try {
            String runtimeTopologyId = actionsService.getRuntimeTopologyId(topology, asUser);
            TopologyMetrics.TopologyMetric topologyMetric = metricsService.getTopologyMetric(topology, asUser);
            List<Pair<String, Double>> latenciesTopN = metricsService.getTopNAndOtherComponentsLatency(topology, asUser, latencyTopN);
            detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.RUNNING, namespaceName);
            detailedResponse.setRuntime(new TopologyRuntimeResponse(runtimeTopologyId, topologyMetric, latenciesTopN));
        } catch (TopologyNotAliveException e) {
            LOG.debug("Topology {} is not alive", topology.getId());
            detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.NOT_RUNNING, namespaceName);
            catalogService.getTopologyState(topology.getId()).ifPresent(state -> {
                if (TopologyStateFactory.getInstance().getTopologyState(state.getName()) == TopologyStates.TOPOLOGY_STATE_DEPLOYED) {
                    try {
                        LOG.info("Force killing streamline topology since its not alive in the cluster");
                        actionsService.killTopology(topology, asUser);
                    } catch (Exception ex) {
                        LOG.error("Error trying to kill topology", ex);
                    }
                }
            });
        } catch (StormNotReachableException | IOException e) {
            LOG.error("Storm is not reachable or fail to operate", e);
            detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
        } catch (Exception e) {
            LOG.error("Unhandled exception occurs while operate with Storm", e);
            detailedResponse = new TopologyDashboardResponse(topology, TopologyRunningStatus.UNKNOWN, namespaceName);
        }
        LOG.debug("[END] enrichTopology - topology id: {}, elapsed: {} ms", topology.getId(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
        return detailedResponse;
    } finally {
        stopwatch.stop();
    }
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) TopologyStateFactory(com.hortonworks.streamline.streams.actions.topology.state.TopologyStateFactory) Logger(org.slf4j.Logger) TopologyMetricsService(com.hortonworks.streamline.streams.metrics.topology.service.TopologyMetricsService) Stopwatch(com.google.common.base.Stopwatch) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyStates(com.hortonworks.streamline.streams.actions.topology.state.TopologyStates) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) TopologyMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics) Stopwatch(com.google.common.base.Stopwatch) TopologyMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics) IOException(java.io.IOException) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) IOException(java.io.IOException) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with StormNotReachableException

use of com.hortonworks.streamline.streams.storm.common.StormNotReachableException 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)

Aggregations

Topology (com.hortonworks.streamline.streams.catalog.Topology)2 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)2 StormNotReachableException (com.hortonworks.streamline.streams.storm.common.StormNotReachableException)2 IOException (java.io.IOException)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 Stopwatch (com.google.common.base.Stopwatch)1 StreamingEngineNotReachableException (com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException)1 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)1 TopologyStateFactory (com.hortonworks.streamline.streams.actions.topology.state.TopologyStateFactory)1 TopologyStates (com.hortonworks.streamline.streams.actions.topology.state.TopologyStates)1 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)1 Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)1 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)1 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)1 TopologyMetrics (com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics)1 TopologyMetricsService (com.hortonworks.streamline.streams.metrics.topology.service.TopologyMetricsService)1 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1