Search in sources :

Example 16 with Namespace

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

the class AutoCredsServiceConfigurationReader method readAllClusters.

@Override
public Map<Long, Map<String, String>> readAllClusters(String serviceName) {
    Namespace namespace = environmentService.getNamespace(namespaceId);
    if (namespace == null) {
        throw new IllegalArgumentException("Namespace " + namespaceId + " doesn't exist.");
    }
    Long namespaceId = namespace.getId();
    Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
    List<Long> clusters = mappings.stream().map(mapping -> mapping.getClusterId()).collect(Collectors.toList());
    Map<Long, Map<String, String>> retMap = new HashMap<>();
    clusters.forEach(c -> {
        Map<String, String> flattenConfig = read(c, serviceName);
        retMap.put(c, flattenConfig);
    });
    return retMap;
}
Also used : Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Arrays(java.util.Arrays) Collection(java.util.Collection) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) ServiceConfigurationReadable(com.hortonworks.streamline.streams.storm.common.ServiceConfigurationReadable) List(java.util.List) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) HashMap(java.util.HashMap) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) HashMap(java.util.HashMap) Map(java.util.Map) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 17 with Namespace

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

the class AutoCredsServiceConfigurationReader method read.

@Override
public Map<String, String> read(Long clusterId, String serviceName) {
    Cluster cluster = environmentService.getCluster(clusterId);
    if (cluster == null) {
        throw new IllegalArgumentException("Cluster with id " + clusterId + " doesn't exist.");
    }
    Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
    boolean associated = mappings.stream().anyMatch(map -> map.getClusterId().equals(clusterId));
    if (!associated) {
        return Collections.emptyMap();
    }
    Long serviceId = environmentService.getServiceIdByName(clusterId, serviceName);
    if (serviceId == null) {
        throw new IllegalStateException("Cluster " + clusterId + " is associated to the service " + serviceName + " for namespace " + namespaceId + ", but actual service doesn't exist.");
    }
    Collection<ServiceConfiguration> serviceConfigurations = environmentService.listServiceConfigurations(serviceId);
    Map<String, String> flattenConfig = new HashMap<>();
    String[] confNames = AutoCredsServiceConfigurations.valueOf(serviceName).getConfNames();
    // let's forget about optimization here since two lists will be small enough
    Arrays.stream(confNames).forEachOrdered(confName -> {
        Optional<ServiceConfiguration> serviceConfigurationOptional = serviceConfigurations.stream().filter(sc -> sc.getName().equals(confName)).findFirst();
        if (serviceConfigurationOptional.isPresent()) {
            ServiceConfiguration sc = serviceConfigurationOptional.get();
            try {
                Map<String, String> configurationMap = sc.getConfigurationMap();
                flattenConfig.putAll(configurationMap);
            } catch (IOException e) {
                throw new RuntimeException("Can't read configuration from service configuration - ID: " + sc.getId());
            }
        }
    });
    return flattenConfig;
}
Also used : Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Arrays(java.util.Arrays) Collection(java.util.Collection) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) ServiceConfigurationReadable(com.hortonworks.streamline.streams.storm.common.ServiceConfigurationReadable) List(java.util.List) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) IOException(java.io.IOException) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 18 with Namespace

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

the class TopologyLogSearchService method getTopologyLogSearchInstance.

private TopologyLogSearch getTopologyLogSearchInstance(Topology topology) {
    Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
    if (namespace == null) {
        throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
    }
    TopologyLogSearch topologyLogSearch = topologyLogSearchContainer.findInstance(namespace);
    if (topologyLogSearch == null) {
        throw new RuntimeException("Can't find Topology Log Search for such namespace " + topology.getNamespaceId());
    }
    return topologyLogSearch;
}
Also used : TopologyLogSearch(com.hortonworks.streamline.streams.logsearch.TopologyLogSearch) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 19 with Namespace

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

the class TopologyMetricsService method getTopologyMetricsInstance.

private TopologyMetrics getTopologyMetricsInstance(Topology topology) {
    Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
    if (namespace == null) {
        throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
    }
    TopologyMetrics topologyMetrics = topologyMetricsContainer.findInstance(namespace);
    if (topologyMetrics == null) {
        throw new RuntimeException("Can't find Topology Metrics for such namespace " + topology.getNamespaceId());
    }
    return topologyMetrics;
}
Also used : TopologyMetrics(com.hortonworks.streamline.streams.metrics.topology.TopologyMetrics) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 20 with Namespace

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

the class NamespaceCatalogResource method findServicesToClusterMappingInNamespace.

@GET
@Path("/namespaces/{id}/mapping/{serviceName}")
@Timed
public Response findServicesToClusterMappingInNamespace(@PathParam("id") Long namespaceId, @PathParam("serviceName") String serviceName, @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("Namespace: " + namespaceId.toString());
    }
    Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId, serviceName);
    if (mappings != null) {
        return WSUtils.respondEntities(mappings, OK);
    } else {
        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

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