Search in sources :

Example 11 with NamespaceServiceClusterMap

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

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

the class EnvironmentServiceTest method invalidateContainersWhenImportingClusterServices.

@Test
public void invalidateContainersWhenImportingClusterServices() throws Exception {
    Deencapsulation.setField(environmentService, "clusterImporter", clusterImporter);
    long clusterId = 1L;
    Cluster testCluster = new Cluster();
    testCluster.setId(clusterId);
    ArrayList<Long> namespaceIds = Lists.newArrayList(1L, 2L, 3L);
    List<NamespaceServiceClusterMap> mappings = new ArrayList<>();
    mappings.add(new NamespaceServiceClusterMap(1L, "STORM", clusterId));
    mappings.add(new NamespaceServiceClusterMap(2L, "KAFKA", clusterId));
    mappings.add(new NamespaceServiceClusterMap(3L, "HADOOP", clusterId));
    MockedNamespaceAwareContainer container1 = new MockedNamespaceAwareContainer();
    MockedNamespaceAwareContainer container2 = new MockedNamespaceAwareContainer();
    environmentService.addNamespaceAwareContainer(container1);
    environmentService.addNamespaceAwareContainer(container2);
    new Expectations() {

        {
            clusterImporter.importCluster(discoverer, testCluster);
            result = testCluster;
            dao.find(NAMESPACE_SERVICE_CLUSTER_MAP, Collections.singletonList(new QueryParam("clusterId", String.valueOf(clusterId))));
            result = mappings;
        }
    };
    // we're just checking whether it calls invalidation to associated containers properly
    environmentService.importClusterServices(discoverer, testCluster);
    assertEquals(3, container1.getInvalidatedNamespaceIds().size());
    assertTrue(container1.getInvalidatedNamespaceIds().containsAll(namespaceIds));
    assertEquals(3, container2.getInvalidatedNamespaceIds().size());
    assertTrue(container2.getInvalidatedNamespaceIds().containsAll(namespaceIds));
}
Also used : Expectations(mockit.Expectations) QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Test(org.junit.Test)

Example 13 with NamespaceServiceClusterMap

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

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

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

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