Search in sources :

Example 21 with NamespaceServiceClusterMap

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

the class AbstractBundleHintProviderTest method testProvide.

@Test
public void testProvide() throws Exception {
    Cluster cluster1 = createDummyCluster(1L, "cluster1");
    Cluster cluster2 = createDummyCluster(2L, "cluster2");
    Cluster cluster3 = createDummyCluster(3L, "cluster3");
    List<NamespaceServiceClusterMap> testServiceClusterMappings = createDummyServiceClusterMappings(Lists.newArrayList(cluster1, cluster2, cluster3));
    new Expectations() {

        {
            environmentService.getCluster(1L);
            result = cluster1;
            environmentService.getCluster(2L);
            result = cluster2;
            environmentService.getCluster(3L);
            result = cluster3;
            environmentService.listServiceClusterMapping(TEST_NAMESPACE_ID, TEST_SERVICE_NAME);
            result = testServiceClusterMappings;
        }
    };
    Namespace namespace = new Namespace();
    namespace.setId(TEST_NAMESPACE_ID);
    Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, null, null);
    Assert.assertEquals(3, hints.size());
    Assert.assertEquals(cluster1, hints.get(cluster1.getId()).getCluster());
    Assert.assertEquals(TEST_HINTS, hints.get(cluster1.getId()).getHints());
    Assert.assertEquals(cluster2, hints.get(cluster2.getId()).getCluster());
    Assert.assertEquals(TEST_HINTS, hints.get(cluster2.getId()).getHints());
    Assert.assertEquals(cluster3, hints.get(cluster3.getId()).getCluster());
    Assert.assertEquals(TEST_HINTS, hints.get(cluster3.getId()).getHints());
}
Also used : Expectations(mockit.Expectations) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) Test(org.junit.Test)

Example 22 with NamespaceServiceClusterMap

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

the class TopologyActionsService method setUpClusterArtifacts.

public void setUpClusterArtifacts(Topology topology, TopologyActions topologyActions) throws IOException {
    Namespace namespace = environmentService.getNamespace(topology.getNamespaceId());
    if (namespace == null) {
        throw new RuntimeException("Corresponding namespace not found: " + topology.getNamespaceId());
    }
    ObjectMapper objectMapper = new ObjectMapper();
    Path artifactsDir = topologyActions.getArtifactsLocation(CatalogToLayoutConverter.getTopologyLayout(topology));
    makeEmptyDir(artifactsDir);
    Collection<NamespaceServiceClusterMap> serviceClusterMappings = environmentService.listServiceClusterMapping(namespace.getId());
    for (NamespaceServiceClusterMap serviceClusterMapping : serviceClusterMappings) {
        Service service = environmentService.getServiceByName(serviceClusterMapping.getClusterId(), serviceClusterMapping.getServiceName());
        if (service != null) {
            Collection<ServiceConfiguration> serviceConfigurations = environmentService.listServiceConfigurations(service.getId());
            if (serviceConfigurations != null) {
                for (ServiceConfiguration serviceConfiguration : serviceConfigurations) {
                    writeConfigurationFile(objectMapper, artifactsDir, serviceConfiguration);
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with NamespaceServiceClusterMap

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

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

Example 25 with NamespaceServiceClusterMap

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

the class NamespaceCatalogResourceTest method testAddStreamingEngineWhenStreamingEngineAlreadyExistsViaMapServiceToClusterInNamespace.

@Test
public void testAddStreamingEngineWhenStreamingEngineAlreadyExistsViaMapServiceToClusterInNamespace() 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_STREAMING_ENGINE, 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)

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