Search in sources :

Example 1 with Namespace

use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.

the class TopologySamplingService method getSamplingInstance.

private TopologySampling getSamplingInstance(Topology topology) {
    Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
    if (namespace == null) {
        throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
    }
    TopologySampling topologySampling = topologySamplingContainer.findInstance(namespace);
    if (topologySampling == null) {
        throw new RuntimeException("Can't find Topology sampling for such namespace " + topology.getNamespaceId());
    }
    return topologySampling;
}
Also used : Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 2 with Namespace

use of com.hortonworks.streamline.streams.cluster.catalog.Namespace 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 3 with Namespace

use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.

the class NamespaceCatalogResource method getNamespaceById.

@GET
@Path("/namespaces/{id}")
@Timed
public Response getNamespaceById(@PathParam("id") Long namespaceId, @javax.ws.rs.QueryParam("detail") Boolean detail, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER, Namespace.NAMESPACE, namespaceId, READ);
    Namespace result = environmentService.getNamespace(namespaceId);
    if (result != null) {
        return buildNamespaceGetResponse(result, detail);
    }
    throw EntityNotFoundException.byId(namespaceId.toString());
}
Also used : Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 4 with Namespace

use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.

the class NamespaceCatalogResource method setServicesToClusterInNamespace.

@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw EntityNotFoundException.byId(namespaceId.toString());
    }
    String streamingEngine = namespace.getStreamingEngine();
    String timeSeriesDB = namespace.getTimeSeriesDB();
    Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
    Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
    // indicates that mapping of streaming engine has been changed or removed
    if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
        assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
    }
    // we're OK to just check with new mappings since we will remove existing mappings
    assertServiceIsUnique(mappings, streamingEngine);
    assertServiceIsUnique(mappings, timeSeriesDB);
    // remove any existing mapping for (namespace, service name) pairs
    Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
    if (existingMappings != null) {
        existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
    }
    List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
    return WSUtils.respondEntities(newMappings, CREATED);
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Roles(com.hortonworks.streamline.streams.security.Roles) Produces(javax.ws.rs.Produces) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) StringUtils(org.apache.commons.lang3.StringUtils) BooleanUtils(org.apache.commons.lang.BooleanUtils) MediaType(javax.ws.rs.core.MediaType) WSUtils(com.hortonworks.streamline.common.util.WSUtils) READ(com.hortonworks.streamline.streams.security.Permission.READ) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) EnumSet(java.util.EnumSet) DELETE(javax.ws.rs.DELETE) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Context(javax.ws.rs.core.Context) Permission(com.hortonworks.streamline.streams.security.Permission) DELETE(com.hortonworks.streamline.streams.security.Permission.DELETE) OK(javax.ws.rs.core.Response.Status.OK) AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) Collection(java.util.Collection) Objects(java.util.Objects) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Response(javax.ws.rs.core.Response) ProcessingException(javax.ws.rs.ProcessingException) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) CREATED(javax.ws.rs.core.Response.Status.CREATED) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) GET(javax.ws.rs.GET) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) WRITE(com.hortonworks.streamline.streams.security.Permission.WRITE) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) IOException(java.io.IOException) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Collectors.toList(java.util.stream.Collectors.toList) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Namespace

use of com.hortonworks.streamline.streams.cluster.catalog.Namespace in project streamline by hortonworks.

the class NamespaceCatalogResource method addNamespace.

@Timed
@POST
@Path("/namespaces")
public Response addNamespace(Namespace namespace, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_ADMIN);
    try {
        String namespaceName = namespace.getName();
        Namespace result = environmentService.getNamespaceByName(namespaceName);
        if (result != null) {
            throw new AlreadyExistsException("Namespace entity already exists with name " + namespaceName);
        }
        Namespace created = environmentService.addNamespace(namespace);
        SecurityUtil.addAcl(authorizer, securityContext, Namespace.NAMESPACE, created.getId(), EnumSet.allOf(Permission.class));
        return WSUtils.respondEntity(created, CREATED);
    } catch (ProcessingException ex) {
        throw BadRequestException.of();
    }
}
Also used : AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) Permission(com.hortonworks.streamline.streams.security.Permission) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) ProcessingException(javax.ws.rs.ProcessingException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)34 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)22 Test (org.junit.Test)12 Verifications (mockit.Verifications)11 Timed (com.codahale.metrics.annotation.Timed)10 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)10 Path (javax.ws.rs.Path)10 Expectations (mockit.Expectations)10 Topology (com.hortonworks.streamline.streams.catalog.Topology)8 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)8 IOException (java.io.IOException)7 Collection (java.util.Collection)7 List (java.util.List)7 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)6 GET (javax.ws.rs.GET)6 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)5 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)5 ArrayList (java.util.ArrayList)5 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)4 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)4