Search in sources :

Example 1 with NoOpMetricsCollectionService

use of io.cdap.cdap.common.metrics.NoOpMetricsCollectionService in project cdap by caskdata.

the class TaskWorkerServiceTest method testRestartAfterMultipleExecutions.

@Test
public void testRestartAfterMultipleExecutions() throws IOException {
    CConfiguration cConf = createCConf();
    SConfiguration sConf = createSConf();
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 2);
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 0);
    TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, new NoOpMetricsCollectionService());
    serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
    // start the service
    taskWorkerService.startAndWait();
    InetSocketAddress addr = taskWorkerService.getBindAddress();
    URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
    // Post valid request
    String want = "100";
    RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
    String reqBody = GSON.toJson(req);
    HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
    response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
    TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
    Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpResponse(io.cdap.common.http.HttpResponse) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) URI(java.net.URI) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 2 with NoOpMetricsCollectionService

use of io.cdap.cdap.common.metrics.NoOpMetricsCollectionService in project cdap by caskdata.

the class RemoteConfiguratorTest method init.

@BeforeClass
public static void init() throws Exception {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 0);
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    MasterEnvironments.setMasterEnvironment(new TestMasterEnvironment(discoveryService));
    NamespaceAdmin namespaceAdmin = new InMemoryNamespaceAdmin();
    namespaceAdmin.create(NamespaceMeta.SYSTEM);
    namespaceAdmin.create(NamespaceMeta.DEFAULT);
    remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
    }, new NoOpMetricsCollectionService()), new ArtifactHttpHandlerInternal(new TestArtifactRepository(cConf), namespaceAdmin), new ArtifactLocalizerHttpHandlerInternal(new ArtifactLocalizer(cConf, remoteClientFactory, ((namespaceId, retryStrategy) -> {
        return new NoOpArtifactManager();
    })))).setPort(cConf.getInt(Constants.ArtifactLocalizer.PORT)).setChannelPipelineModifier(new ChannelPipelineModifier() {

        @Override
        public void modify(ChannelPipeline pipeline) {
            pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
        }
    }).build();
    httpService.start();
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService));
    metricsCollectionService = new NoOpMetricsCollectionService();
}
Also used : ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) AccessException(io.cdap.cdap.api.security.AccessException) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) GsonBuilder(com.google.gson.GsonBuilder) ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) MasterEnvironments(io.cdap.cdap.master.environment.MasterEnvironments) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) MasterEnvironmentRunnableContext(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnableContext) NettyHttpService(io.cdap.http.NettyHttpService) After(org.junit.After) Map(java.util.Map) ConfigTestApp(io.cdap.cdap.ConfigTestApp) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) AfterClass(org.junit.AfterClass) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramType(io.cdap.cdap.api.app.ProgramType) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) Configurator(io.cdap.cdap.app.deploy.Configurator) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) NotFoundException(io.cdap.cdap.common.NotFoundException) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) Location(org.apache.twill.filesystem.Location) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) ConfiguratorTask(io.cdap.cdap.internal.app.worker.ConfiguratorTask) TwillRunnerService(org.apache.twill.api.TwillRunnerService) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Nullable(javax.annotation.Nullable) DiscoveryService(org.apache.twill.discovery.DiscoveryService) URIScheme(io.cdap.cdap.common.discovery.URIScheme) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) MasterEnvironmentRunnable(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnable) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) BeforeClass(org.junit.BeforeClass)

Example 3 with NoOpMetricsCollectionService

use of io.cdap.cdap.common.metrics.NoOpMetricsCollectionService in project cdap by caskdata.

the class DataSourceProviderTest method testInstantiate.

@Test
public void testInstantiate() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION, Constants.Dataset.DATA_STORAGE_SQL);
    cConf.set(Constants.Dataset.DATA_STORAGE_SQL_DRIVER_DIRECTORY, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.Dataset.DATA_STORAGE_SQL_JDBC_DRIVER_NAME, NoopDriver.class.getName());
    cConf.set(Constants.Dataset.DATA_STORAGE_SQL_JDBC_CONNECTION_URL, "jdbc:noop://");
    File driverDir = new File(cConf.get(Constants.Dataset.DATA_STORAGE_SQL_DRIVER_DIRECTORY), cConf.get(Constants.Dataset.DATA_STORAGE_IMPLEMENTATION));
    driverDir.mkdirs();
    AppJarHelper.createDeploymentJar(new LocalLocationFactory(driverDir), NoopDriver.class);
    SConfiguration sConf = SConfiguration.create();
    DataSource dataSource = PostgreSqlStorageProvider.createDataSource(cConf, sConf, new NoOpMetricsCollectionService());
    Assert.assertNotNull(dataSource);
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    Driver loadedDriver = null;
    // the DriverManager can contain the postgres driver since we use embedded postgres, the DriverManager will load
    // that driver initially.
    int count = 0;
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        // we will wrap the driver
        if (driver instanceof JDBCDriverShim) {
            loadedDriver = driver;
        }
        count++;
    }
    Assert.assertEquals(2, count);
    Assert.assertNotNull(loadedDriver);
}
Also used : SConfiguration(io.cdap.cdap.common.conf.SConfiguration) Driver(java.sql.Driver) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 4 with NoOpMetricsCollectionService

use of io.cdap.cdap.common.metrics.NoOpMetricsCollectionService in project cdap by caskdata.

the class MessagingHttpServiceTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, InetAddress.getLocalHost().getHostName());
    cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_CONSUME_CHUNK_SIZE, 128);
    // Set max life time to a high value so that dummy tx ids that we create in the tests still work
    cConf.setLong(TxConstants.Manager.CFG_TX_MAX_LIFETIME, 10000000000L);
    // Reduce the buffer size for the http request buffer to test "large" message request
    cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_MAX_REQUEST_SIZE_MB, 1);
    cConf.setBoolean(Constants.MessagingSystem.HTTP_COMPRESS_PAYLOAD, compressPayload);
    Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new AuthenticationContextModules().getNoOpModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).toInstance(new NoOpMetricsCollectionService());
        }
    });
    httpService = injector.getInstance(MessagingHttpService.class);
    httpService.startAndWait();
    client = new ClientMessagingService(injector.getInstance(RemoteClientFactory.class), compressPayload);
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 5 with NoOpMetricsCollectionService

use of io.cdap.cdap.common.metrics.NoOpMetricsCollectionService in project cdap by caskdata.

the class CDAPLogAppenderTest method testCDAPLogAppender.

@Test
public void testCDAPLogAppender() {
    int syncInterval = 1024 * 1024;
    CDAPLogAppender cdapLogAppender = new CDAPLogAppender();
    cdapLogAppender.setSyncIntervalBytes(syncInterval);
    cdapLogAppender.setMaxFileLifetimeMs(TimeUnit.DAYS.toMillis(1));
    cdapLogAppender.setMaxFileSizeInBytes(104857600);
    cdapLogAppender.setDirPermissions("700");
    cdapLogAppender.setFilePermissions("600");
    cdapLogAppender.setFileRetentionDurationDays(1);
    cdapLogAppender.setLogCleanupIntervalMins(10);
    cdapLogAppender.setFileCleanupBatchSize(100);
    AppenderContext context = new LocalAppenderContext(injector.getInstance(TransactionRunner.class), injector.getInstance(LocationFactory.class), new NoOpMetricsCollectionService());
    context.start();
    cdapLogAppender.setContext(context);
    cdapLogAppender.start();
    FileMetaDataReader fileMetaDataReader = injector.getInstance(FileMetaDataReader.class);
    LoggingEvent event = new LoggingEvent("io.cdap.Test", (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME), Level.ERROR, "test message", null, null);
    Map<String, String> properties = new HashMap<>();
    properties.put(NamespaceLoggingContext.TAG_NAMESPACE_ID, "default");
    properties.put(ApplicationLoggingContext.TAG_APPLICATION_ID, "testApp");
    properties.put(UserServiceLoggingContext.TAG_USER_SERVICE_ID, "testService");
    event.setMDCPropertyMap(properties);
    cdapLogAppender.doAppend(event);
    cdapLogAppender.stop();
    context.stop();
    try {
        List<LogLocation> files = fileMetaDataReader.listFiles(cdapLogAppender.getLoggingPath(properties), 0, Long.MAX_VALUE);
        Assert.assertEquals(1, files.size());
        LogLocation logLocation = files.get(0);
        Assert.assertEquals(LogLocation.VERSION_1, logLocation.getFrameworkVersion());
        Assert.assertTrue(logLocation.getLocation().exists());
        CloseableIterator<LogEvent> logEventCloseableIterator = logLocation.readLog(Filter.EMPTY_FILTER, 0, Long.MAX_VALUE, Integer.MAX_VALUE);
        int logCount = 0;
        while (logEventCloseableIterator.hasNext()) {
            logCount++;
            LogEvent logEvent = logEventCloseableIterator.next();
            Assert.assertEquals(event.getMessage(), logEvent.getLoggingEvent().getMessage());
        }
        logEventCloseableIterator.close();
        Assert.assertEquals(1, logCount);
        // checking permission
        String expectedPermissions = "rw-------";
        for (LogLocation file : files) {
            Location location = file.getLocation();
            Assert.assertEquals(expectedPermissions, location.getPermissions());
        }
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : HashMap(java.util.HashMap) LogEvent(io.cdap.cdap.logging.read.LogEvent) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) LocalAppenderContext(io.cdap.cdap.logging.framework.LocalAppenderContext) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) LogLocation(io.cdap.cdap.logging.write.LogLocation) AppenderContext(io.cdap.cdap.api.logging.AppenderContext) LocalAppenderContext(io.cdap.cdap.logging.framework.LocalAppenderContext) FileMetaDataReader(io.cdap.cdap.logging.meta.FileMetaDataReader) Location(org.apache.twill.filesystem.Location) LogLocation(io.cdap.cdap.logging.write.LogLocation) Test(org.junit.Test)

Aggregations

NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)18 Test (org.junit.Test)11 TransactionRunner (io.cdap.cdap.spi.data.transaction.TransactionRunner)7 LocationFactory (org.apache.twill.filesystem.LocationFactory)7 AppenderContext (io.cdap.cdap.api.logging.AppenderContext)6 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)6 LocalAppenderContext (io.cdap.cdap.logging.framework.LocalAppenderContext)6 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)6 AbstractModule (com.google.inject.AbstractModule)5 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)5 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)3 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)3 Injector (com.google.inject.Injector)3 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)3 Location (org.apache.twill.filesystem.Location)3 Logger (org.slf4j.Logger)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2