Search in sources :

Example 11 with Namespace

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

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

the class NamespaceCatalogResourceTest method testOverwriteSameStreamingEngineMappingViaMapServiceToClusterInNamespace.

@Test
public void testOverwriteSameStreamingEngineMappingViaMapServiceToClusterInNamespace() 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;
        }
    };
    NamespaceServiceClusterMap existingStreamingEngineMapping = existingMappings.stream().filter(m -> m.getServiceName().equals(TEST_STREAMING_ENGINE)).findAny().get();
    namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, existingStreamingEngineMapping, securityContext);
    new Verifications() {

        {
            environmentService.addOrUpdateServiceClusterMapping(withAny(new NamespaceServiceClusterMap()));
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 13 with Namespace

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

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

the class EnvironmentService method removeNamespace.

public Namespace removeNamespace(Long namespaceId) {
    assertEnvironmentIsNotInternal(namespaceId);
    Namespace namespace = new Namespace();
    namespace.setId(namespaceId);
    Namespace ret = this.dao.remove(new StorableKey(NAMESPACE_NAMESPACE, namespace.getPrimaryKey()));
    invalidateTopologyActionsMetricsInstances(namespaceId);
    return ret;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 15 with Namespace

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

the class EnvironmentService method getNamespace.

public Namespace getNamespace(Long namespaceId) {
    Namespace namespace = new Namespace();
    namespace.setId(namespaceId);
    return this.dao.get(new StorableKey(NAMESPACE_NAMESPACE, namespace.getPrimaryKey()));
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

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