Search in sources :

Example 1 with NamespaceServiceClusterMap

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

the class AbstractBundleHintProvider method provide.

@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
    Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
    Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
    for (NamespaceServiceClusterMap mapping : serviceMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException(new ClusterNotFoundException(clusterId));
        }
        BundleHintsResponse response = new BundleHintsResponse(cluster, getHintsOnCluster(cluster, securityContext, subject));
        hintMap.put(clusterId, response);
    }
    return hintMap;
}
Also used : ClusterNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ClusterNotFoundException) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 2 with NamespaceServiceClusterMap

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

the class AbstractSecureBundleHintProvider method provide.

@Override
public Map<Long, BundleHintsResponse> provide(Namespace namespace, SecurityContext securityContext, Subject subject) {
    Map<Long, BundleHintsResponse> hintMap = new HashMap<>();
    Collection<NamespaceServiceClusterMap> serviceMappings = environmentService.listServiceClusterMapping(namespace.getId(), getServiceName());
    for (NamespaceServiceClusterMap mapping : serviceMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException(new ClusterNotFoundException(clusterId));
        }
        BundleHintsResponse response = new SecureBundleHintsResponse(cluster, getSecurity(cluster, securityContext, subject), getHintsOnCluster(cluster, securityContext, subject));
        hintMap.put(clusterId, response);
    }
    return hintMap;
}
Also used : ClusterNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ClusterNotFoundException) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 3 with NamespaceServiceClusterMap

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

the class NamespaceAwareContainer method getServiceForNamespace.

protected Collection<Service> getServiceForNamespace(Namespace namespace, String serviceName) {
    Collection<NamespaceServiceClusterMap> serviceClusterMappings = environmentService.listServiceClusterMapping(namespace.getId(), serviceName);
    if (serviceClusterMappings == null) {
        throw new RuntimeException("Service name " + serviceName + " is not set in namespace " + namespace.getName() + "(" + namespace.getId() + ")");
    }
    Collection<Service> services = new ArrayList<>(serviceClusterMappings.size());
    for (NamespaceServiceClusterMap mapping : serviceClusterMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException("Cluster " + clusterId + " is not found");
        }
        Service service = environmentService.getServiceByName(clusterId, serviceName);
        if (service == null) {
            throw new RuntimeException("Service name " + serviceName + " is not found in Cluster " + clusterId);
        }
        services.add(service);
    }
    return services;
}
Also used : ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 4 with NamespaceServiceClusterMap

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

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

the class NamespaceCatalogResource method listServiceToClusterMappingInNamespace.

@GET
@Path("/namespaces/{id}/mapping")
@Timed
public Response listServiceToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_USER, Namespace.NAMESPACE, namespaceId, READ);
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw EntityNotFoundException.byId(namespaceId.toString());
    }
    Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
    if (existingMappings != null) {
        return WSUtils.respondEntities(existingMappings, OK);
    }
    return WSUtils.respondEntities(Collections.emptyList(), OK);
}
Also used : NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

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