Search in sources :

Example 31 with Namespace

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

the class NamespaceCatalogResourceTest method testOverwriteSameTimeSeriesDBMappingViaMapServiceToClusterInNamespace.

@Test
public void testOverwriteSameTimeSeriesDBMappingViaMapServiceToClusterInNamespace() 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 existingTimeSeriesDBMapping = existingMappings.stream().filter(m -> m.getServiceName().equals(TEST_TIME_SERIES_DB)).findAny().get();
    namespaceCatalogResource.mapServiceToClusterInNamespace(testNamespaceId, existingTimeSeriesDBMapping, 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 32 with Namespace

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

the class NamespaceCatalogResourceTest method testUnmapStreamingEngineWhenTopologyIsRunningViaUnmapServiceToClusterInNamespace.

@Test
public void testUnmapStreamingEngineWhenTopologyIsRunningViaUnmapServiceToClusterInNamespace() 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);
    try {
        namespaceCatalogResource.unmapServiceToClusterInNamespace(testNamespaceId, TEST_STREAMING_ENGINE, 1L, securityContext);
        Assert.fail("Should throw BadRequestException");
    } catch (BadRequestException e) {
    // passed
    }
    new Verifications() {

        {
            environmentService.removeServiceClusterMapping(testNamespaceId, TEST_STREAMING_ENGINE, 1L);
            times = 0;
        }
    };
}
Also used : 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 33 with Namespace

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

the class StreamsModule method setupPlaceholderTestNamespace.

private void setupPlaceholderTestNamespace(EnvironmentService environmentService) {
    if (transactionManager == null) {
        throw new RuntimeException("TransactionManager is not initialized");
    }
    // it's one time setup hence just use it as local variable
    ManagedTransaction mt = new ManagedTransaction(transactionManager, TransactionIsolation.DEFAULT);
    try {
        mt.executeConsumer(() -> {
            Namespace testNamespace = environmentService.getNamespace(EnvironmentService.PLACEHOLDER_ID);
            if (testNamespace == null) {
                testNamespace = new Namespace();
                testNamespace.setId(EnvironmentService.PLACEHOLDER_ID);
                testNamespace.setName("Test Environment");
                testNamespace.setStreamingEngine(MappedTopologyActionsImpl.STORM.name());
                // no metric service, no log search service
                testNamespace.setDescription("Empty environment to test the topology which doesn't require external service.");
                testNamespace.setInternal(true);
                testNamespace.setTimestamp(System.currentTimeMillis());
                environmentService.addOrUpdateNamespace(EnvironmentService.PLACEHOLDER_ID, testNamespace);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ManagedTransaction(com.hortonworks.registries.storage.transaction.ManagedTransaction) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 34 with Namespace

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

the class TopologyComponentBundleResource method getFieldHints.

@GET
@Path("/componentbundles/{component}/{id}/hints/namespaces/{namespaceId}")
@Timed
public Response getFieldHints(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @PathParam("namespaceId") Long namespaceId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
    TopologyComponentBundle bundle = catalogService.getTopologyComponentBundle(id);
    if (bundle == null || !bundle.getType().equals(componentType)) {
        throw EntityNotFoundException.byId("component bundle id: " + id + " with type: " + componentType);
    }
    String providerClass = bundle.getFieldHintProviderClass();
    if (StringUtils.isNotEmpty(providerClass)) {
        ComponentBundleHintProvider provider;
        if (bundle.getBuiltin()) {
            Class<ComponentBundleHintProvider> clazz = (Class<ComponentBundleHintProvider>) Class.forName(providerClass);
            provider = clazz.newInstance();
        } else {
            provider = hintProviderProxyUtil.loadClassFromJar(bundle.getBundleJar(), providerClass);
        }
        provider.init(environmentService);
        Namespace namespace = environmentService.getNamespace(namespaceId);
        if (namespace == null) {
            throw EntityNotFoundException.byId("namespace id: " + namespaceId);
        }
        Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, securityContext, subject);
        return WSUtils.respondEntity(hints, OK);
    } else {
        return WSUtils.respondEntity(Collections.emptyMap(), OK);
    }
}
Also used : ComponentBundleHintProvider(com.hortonworks.streamline.streams.cluster.bundle.ComponentBundleHintProvider) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) 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