Search in sources :

Example 1 with BadRequestException

use of com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace.

@Test
public void testChangeMappingOfStreamingEngineViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    setupExpectationForSimulatingTopologyIsRunning(testNamespaceId, testNamespace, existingMappings);
    List<NamespaceServiceClusterMap> mappingsToApply = existingMappings.stream().filter(m -> !m.getServiceName().equals(TEST_STREAMING_ENGINE)).collect(toList());
    // change the mapping of streaming engine to cluster id 2
    mappingsToApply.add(new NamespaceServiceClusterMap(testNamespaceId, TEST_STREAMING_ENGINE, 2L));
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) RunWith(org.junit.runner.RunWith) SecurityContext(javax.ws.rs.core.SecurityContext) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Lists(com.google.common.collect.Lists) JMockit(mockit.integration.junit4.JMockit) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Tested(mockit.Tested) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) Collection(java.util.Collection) Test(org.junit.Test) IOException(java.io.IOException) NoopAuthorizer(com.hortonworks.streamline.streams.security.impl.NoopAuthorizer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) Injectable(mockit.Injectable) Assert(org.junit.Assert) Verifications(mockit.Verifications) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 2 with BadRequestException

use of com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException 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 3 with BadRequestException

use of com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException 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 4 with BadRequestException

use of com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testAddTimeSeriesDBWhenTimeSeriesDBAlreadyExistsViaMapServiceToClusterInNamespace.

@Test
public void testAddTimeSeriesDBWhenTimeSeriesDBAlreadyExistsViaMapServiceToClusterInNamespace() 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 newMapping = new NamespaceServiceClusterMap(testNamespaceId, TEST_TIME_SERIES_DB, 2L);
    try {
        namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, newMapping, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

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

Example 5 with BadRequestException

use of com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException in project streamline by hortonworks.

the class NamespaceCatalogResourceTest method testExcludeStreamingEngineViaSetServicesToClusterInNamespace.

@Test
public void testExcludeStreamingEngineViaSetServicesToClusterInNamespace() throws Exception {
    Long testNamespaceId = 1L;
    Namespace testNamespace = createTestNamespace(testNamespaceId, TEST_STREAMING_ENGINE, TEST_TIME_SERIES_DB);
    Collection<NamespaceServiceClusterMap> existingMappings = createTestMappingsForExisting(testNamespaceId);
    setupExpectationForSimulatingTopologyIsRunning(testNamespaceId, testNamespace, existingMappings);
    List<NamespaceServiceClusterMap> mappingsToApply = existingMappings.stream().filter(m -> !m.getServiceName().equals(TEST_STREAMING_ENGINE)).collect(toList());
    try {
        namespaceCatalogResource.setServicesToClusterInNamespace(testNamespaceId, mappingsToApply, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            // request fails before removing existing mappings
            environmentService.removeServiceClusterMapping(testNamespaceId, anyString, anyLong);
            times = 0;
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Expectations(mockit.Expectations) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) RunWith(org.junit.runner.RunWith) SecurityContext(javax.ws.rs.core.SecurityContext) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) Lists(com.google.common.collect.Lists) JMockit(mockit.integration.junit4.JMockit) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Tested(mockit.Tested) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) Collection(java.util.Collection) Test(org.junit.Test) IOException(java.io.IOException) NoopAuthorizer(com.hortonworks.streamline.streams.security.impl.NoopAuthorizer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) Injectable(mockit.Injectable) Assert(org.junit.Assert) Verifications(mockit.Verifications) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) Verifications(mockit.Verifications) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Aggregations

BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)8 Namespace (com.hortonworks.streamline.streams.cluster.catalog.Namespace)8 NamespaceServiceClusterMap (com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)8 Verifications (mockit.Verifications)8 Test (org.junit.Test)8 Expectations (mockit.Expectations)6 Topology (com.hortonworks.streamline.streams.catalog.Topology)4 Lists (com.google.common.collect.Lists)2 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)2 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)2 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)2 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)2 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)2 NoopAuthorizer (com.hortonworks.streamline.streams.security.impl.NoopAuthorizer)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 SecurityContext (javax.ws.rs.core.SecurityContext)2