Search in sources :

Example 31 with StreamAdmin

use of co.cask.cdap.data2.transaction.stream.StreamAdmin in project cdap by caskdata.

the class StreamCoordinatorTestBase method testDeleteStream.

@Test
public void testDeleteStream() throws Exception {
    final StreamId streamId = NamespaceId.DEFAULT.stream("test");
    StreamAdmin streamAdmin = getStreamAdmin();
    streamAdmin.create(streamId);
    Assert.assertTrue(streamAdmin.exists(streamId));
    StreamCoordinatorClient streamCoordinator = getStreamCoordinator();
    final CountDownLatch latch = new CountDownLatch(1);
    streamCoordinator.addListener(streamId, new StreamPropertyListener() {

        @Override
        public void deleted(StreamId id) {
            if (id.equals(streamId)) {
                latch.countDown();
            }
        }
    });
    streamAdmin.drop(streamId);
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with StreamAdmin

use of co.cask.cdap.data2.transaction.stream.StreamAdmin in project cdap by caskdata.

the class StreamCoordinatorTestBase method testConfig.

@Test
public void testConfig() throws Exception {
    final StreamAdmin streamAdmin = getStreamAdmin();
    final String streamName = "testConfig";
    final StreamId streamId = NamespaceId.DEFAULT.stream(streamName);
    streamAdmin.create(streamId);
    StreamCoordinatorClient coordinator = getStreamCoordinator();
    final BlockingDeque<Integer> thresholds = new LinkedBlockingDeque<>();
    final BlockingDeque<Long> ttls = new LinkedBlockingDeque<>();
    coordinator.addListener(streamId, new StreamPropertyListener() {

        @Override
        public void thresholdChanged(StreamId streamId, int threshold) {
            thresholds.add(threshold);
        }

        @Override
        public void ttlChanged(StreamId streamId, long ttl) {
            ttls.add(ttl);
        }
    });
    // Have two threads, one update the threshold, one update the ttl
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final CountDownLatch completeLatch = new CountDownLatch(2);
    for (int i = 0; i < 2; i++) {
        final int threadId = i;
        Thread t = new Thread() {

            @Override
            public void run() {
                try {
                    barrier.await();
                    for (int i = 0; i < 100; i++) {
                        Long ttl = (threadId == 0) ? (long) (i * 1000) : null;
                        Integer threshold = (threadId == 1) ? i : null;
                        streamAdmin.updateConfig(streamId, new StreamProperties(ttl, null, threshold));
                    }
                    completeLatch.countDown();
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
            }
        };
        t.start();
    }
    Assert.assertTrue(completeLatch.await(60, TimeUnit.SECONDS));
    // Check the last threshold and ttl are correct. We don't check if the listener gets every update as it's
    // possible that it doesn't see every updates, but only the latest value (that's what ZK watch guarantees).
    Assert.assertTrue(validateLastElement(thresholds, 99));
    Assert.assertTrue(validateLastElement(ttls, 99000L));
    // Verify the config is right
    StreamConfig config = streamAdmin.getConfig(streamId);
    Assert.assertEquals(99, config.getNotificationThresholdMB());
    Assert.assertEquals(99000L, config.getTTL());
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) StreamProperties(co.cask.cdap.proto.StreamProperties) StreamConfig(co.cask.cdap.data2.transaction.stream.StreamConfig) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) CyclicBarrier(java.util.concurrent.CyclicBarrier) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) Test(org.junit.Test)

Example 33 with StreamAdmin

use of co.cask.cdap.data2.transaction.stream.StreamAdmin in project cdap by caskdata.

the class StreamFileJanitorTestBase method testCleanupDeletedStream.

@Test
public void testCleanupDeletedStream() throws Exception {
    StreamId streamId = NamespaceId.DEFAULT.stream("cleanupDelete");
    StreamAdmin streamAdmin = getStreamAdmin();
    StreamFileJanitor janitor = new StreamFileJanitor(getCConfiguration(), streamAdmin, getNamespacedLocationFactory(), getNamespaceAdmin(), impersonator);
    streamAdmin.create(streamId);
    // Write some data
    try (FileWriter<StreamEvent> writer = createWriter(streamId)) {
        for (int i = 0; i < 10; i++) {
            writer.append(StreamFileTestUtils.createEvent(i * 1000, "Testing " + i));
        }
    }
    // Delete the stream
    streamAdmin.drop(streamId);
    // Run janitor. Should be running fine without exception.
    janitor.cleanAll();
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) StreamEvent(co.cask.cdap.api.flow.flowlet.StreamEvent) Test(org.junit.Test)

Example 34 with StreamAdmin

use of co.cask.cdap.data2.transaction.stream.StreamAdmin in project cdap by caskdata.

the class StreamFileJanitorTestBase method testCleanupTTL.

@Test
public void testCleanupTTL() throws Exception {
    // Create a stream with 5 seconds TTL, partition duration of 2 seconds
    String streamName = "testCleanupTTL";
    StreamId streamId = NamespaceId.DEFAULT.stream(streamName);
    StreamAdmin streamAdmin = getStreamAdmin();
    StreamFileJanitor janitor = new StreamFileJanitor(getCConfiguration(), getStreamAdmin(), getNamespacedLocationFactory(), getNamespaceAdmin(), impersonator);
    Properties properties = new Properties();
    properties.setProperty(Constants.Stream.PARTITION_DURATION, "2000");
    properties.setProperty(Constants.Stream.TTL, "5000");
    streamAdmin.create(streamId, properties);
    // Truncate to increment generation to 1. This make verification condition easier (won't affect correctness).
    streamAdmin.truncate(streamId);
    StreamConfig config = streamAdmin.getConfig(streamId);
    // Write data with different timestamps that spans across 5 partitions
    FileWriter<StreamEvent> writer = createWriter(streamId);
    for (int i = 0; i < 10; i++) {
        writer.append(StreamFileTestUtils.createEvent(i * 1000, "Testing " + i));
    }
    writer.close();
    // Should see 5 partitions
    Location generationLocation = StreamUtils.createGenerationLocation(config.getLocation(), 1);
    Assert.assertEquals(5, generationLocation.list().size());
    // Perform clean with current time = 10000 (10 seconds since epoch).
    // Since TTL = 5 seconds, 2 partitions will be remove (Ends at 2000 and ends at 4000).
    janitor.clean(config.getLocation(), config.getTTL(), 10000);
    Assert.assertEquals(3, generationLocation.list().size());
    // Cleanup again with current time = 16000, all partitions should be deleted.
    janitor.clean(config.getLocation(), config.getTTL(), 16000);
    Assert.assertTrue(generationLocation.list().isEmpty());
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) StreamEvent(co.cask.cdap.api.flow.flowlet.StreamEvent) StreamConfig(co.cask.cdap.data2.transaction.stream.StreamConfig) Properties(java.util.Properties) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 35 with StreamAdmin

use of co.cask.cdap.data2.transaction.stream.StreamAdmin in project cdap by caskdata.

the class BaseHiveExploreServiceTest method initialize.

protected static void initialize(CConfiguration cConf, TemporaryFolder tmpFolder, boolean useStandalone, boolean enableAuthorization) throws Exception {
    if (!runBefore) {
        return;
    }
    Configuration hConf = new Configuration();
    if (enableAuthorization) {
        LocationFactory locationFactory = new LocalLocationFactory(tmpFolder.newFolder());
        Location authExtensionJar = AppJarHelper.createDeploymentJar(locationFactory, InMemoryAuthorizer.class);
        cConf.setBoolean(Constants.Security.ENABLED, true);
        cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
        cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, authExtensionJar.toURI().getPath());
        cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
        cConf.setInt(Constants.Security.Authorization.CACHE_MAX_ENTRIES, 0);
    }
    List<Module> modules = useStandalone ? createStandaloneModules(cConf, hConf, tmpFolder) : createInMemoryModules(cConf, hConf, tmpFolder);
    injector = Guice.createInjector(modules);
    if (enableAuthorization) {
        injector.getInstance(AuthorizationBootstrapper.class).run();
    }
    transactionManager = injector.getInstance(TransactionManager.class);
    transactionManager.startAndWait();
    transactionSystemClient = injector.getInstance(TransactionSystemClient.class);
    dsOpService = injector.getInstance(DatasetOpExecutor.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    exploreExecutorService = injector.getInstance(ExploreExecutorService.class);
    exploreExecutorService.startAndWait();
    datasetFramework = injector.getInstance(DatasetFramework.class);
    exploreClient = injector.getInstance(DiscoveryExploreClient.class);
    exploreService = injector.getInstance(ExploreService.class);
    exploreClient.ping();
    notificationService = injector.getInstance(NotificationService.class);
    notificationService.startAndWait();
    streamService = injector.getInstance(StreamService.class);
    streamService.startAndWait();
    streamHttpService = injector.getInstance(StreamHttpService.class);
    streamHttpService.startAndWait();
    exploreTableManager = injector.getInstance(ExploreTableManager.class);
    streamAdmin = injector.getInstance(StreamAdmin.class);
    streamMetaStore = injector.getInstance(StreamMetaStore.class);
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    namespacedLocationFactory = injector.getInstance(NamespacedLocationFactory.class);
    // create namespaces
    // This happens when you create a namespace via REST APIs. However, since we do not start AppFabricServer in
    // Explore tests, simulating that scenario by explicitly calling DatasetFramework APIs.
    createNamespace(NamespaceId.DEFAULT);
    createNamespace(NAMESPACE_ID);
    createNamespace(OTHER_NAMESPACE_ID);
}
Also used : StreamService(co.cask.cdap.data.stream.service.StreamService) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) NotificationService(co.cask.cdap.notifications.service.NotificationService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) StreamHttpService(co.cask.cdap.data.stream.service.StreamHttpService) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) DiscoveryExploreClient(co.cask.cdap.explore.client.DiscoveryExploreClient) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) AuthorizationBootstrapper(co.cask.cdap.security.authorization.AuthorizationBootstrapper) TransactionManager(org.apache.tephra.TransactionManager) ExploreExecutorService(co.cask.cdap.explore.executor.ExploreExecutorService) StreamMetaStore(co.cask.cdap.data.stream.service.StreamMetaStore) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) ExploreRuntimeModule(co.cask.cdap.explore.guice.ExploreRuntimeModule) ExploreClientModule(co.cask.cdap.explore.guice.ExploreClientModule) MetricsClientRuntimeModule(co.cask.cdap.metrics.guice.MetricsClientRuntimeModule) NamespaceClientRuntimeModule(co.cask.cdap.common.namespace.guice.NamespaceClientRuntimeModule) ConfigModule(co.cask.cdap.common.guice.ConfigModule) AbstractModule(com.google.inject.AbstractModule) Module(com.google.inject.Module) NotificationServiceRuntimeModule(co.cask.cdap.notifications.guice.NotificationServiceRuntimeModule) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) NamespaceClientUnitTestModule(co.cask.cdap.common.guice.NamespaceClientUnitTestModule) StreamServiceRuntimeModule(co.cask.cdap.data.stream.service.StreamServiceRuntimeModule) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) IOModule(co.cask.cdap.common.guice.IOModule) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location)

Aggregations

StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)25 StreamId (co.cask.cdap.proto.id.StreamId)18 Test (org.junit.Test)16 NamespacedLocationFactory (co.cask.cdap.common.namespace.NamespacedLocationFactory)14 Injector (com.google.inject.Injector)14 ConfigModule (co.cask.cdap.common.guice.ConfigModule)13 ExploreClientModule (co.cask.cdap.explore.guice.ExploreClientModule)13 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)13 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)12 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)12 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)12 ViewAdminModules (co.cask.cdap.data.view.ViewAdminModules)12 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)12 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)12 AbstractModule (com.google.inject.AbstractModule)12 BeforeClass (org.junit.BeforeClass)12 CConfiguration (co.cask.cdap.common.conf.CConfiguration)11 StreamMetaStore (co.cask.cdap.data.stream.service.StreamMetaStore)11 DefaultOwnerAdmin (co.cask.cdap.security.impersonation.DefaultOwnerAdmin)11 Configuration (org.apache.hadoop.conf.Configuration)11