Search in sources :

Example 21 with Topology

use of com.hortonworks.streamline.streams.catalog.Topology 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 22 with Topology

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

the class NamespaceCatalogResourceTest method testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace.

@Test
public void testOverwriteExistingStreamingEngineMappingViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    new Expectations() {

        {
            environmentService.getNamespace(testNamespaceId);
            result = testNamespace;
            environmentService.listServiceClusterMapping(testNamespaceId);
            result = existingMappings;
        }
    };
    namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, new ArrayList<>(existingMappings), securityContext);
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = existingMappings.size();
            environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
            times = existingMappings.size();
        }
    };
}
Also used : Expectations(mockit.Expectations) Topology(com.hortonworks.streamline.streams.catalog.Topology) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 23 with Topology

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

the class NamespaceCatalogResourceTest method testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace.

@Test
public void testMappingMultipleStreamingEngineViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    new Expectations() {

        {
            environmentService.getNamespace(testNamespaceId);
            result = testNamespace;
            environmentService.listServiceClusterMapping(testNamespaceId);
            result = existingMappings;
        }
    };
    List<NamespaceServiceClusterMap> mappingsToApply = Lists.newArrayList(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 2L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), new NamespaceServiceClusterMap(testNamespaceId, "KAFKA", 1L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) Topology(com.hortonworks.streamline.streams.catalog.Topology) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 24 with Topology

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

the class NamespaceCatalogResourceTest method testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace.

@Test
public void testMappingMultipleTimeSeriesDBViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    new Expectations() {

        {
            environmentService.getNamespace(testNamespaceId);
            result = testNamespace;
            environmentService.listServiceClusterMapping(testNamespaceId);
            result = existingMappings;
        }
    };
    List<NamespaceServiceClusterMap> mappingsToApply = Lists.newArrayList(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 1L), new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 2L), new NamespaceServiceClusterMap(testNamespaceId, "KAFKA", 1L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            catalogService.listTopologies();
            times = 0;
            topologyActionsService.getRuntimeTopologyId(withAny(new Topology()), anyString);
            times = 0;
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) Topology(com.hortonworks.streamline.streams.catalog.Topology) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 25 with Topology

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

the class TopologyCatalogResource method listTopologies.

@GET
@Path("/topologies")
@Timed
public Response listTopologies(@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) {
        response = WSUtils.respondEntities(topologies, 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)

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