Search in sources :

Example 1 with HttpExceptionHandler

use of io.cdap.cdap.common.HttpExceptionHandler in project cdap by caskdata.

the class FileFetcherHttpHandlerInternalTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new LocalLocationModule());
    FileFetcherHttpHandlerInternal handler = injector.getInstance(FileFetcherHttpHandlerInternal.class);
    httpService = NettyHttpService.builder("FileFetcherHttpHandlerInternalTest").setHttpHandlers(handler).setExceptionHandler(new HttpExceptionHandler()).build();
    httpService.start();
    InetSocketAddress addr = httpService.getBindAddress();
    baseURL = new URL(String.format("http://%s:%d", addr.getHostName(), addr.getPort()));
}
Also used : LocalLocationModule(io.cdap.cdap.common.guice.LocalLocationModule) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) InetSocketAddress(java.net.InetSocketAddress) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) URL(java.net.URL) FileFetcherHttpHandlerInternal(io.cdap.cdap.gateway.handlers.FileFetcherHttpHandlerInternal) BeforeClass(org.junit.BeforeClass)

Example 2 with HttpExceptionHandler

use of io.cdap.cdap.common.HttpExceptionHandler in project cdap by caskdata.

the class LogBufferHandlerTest method testHandler.

@Test
public void testHandler() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    String absolutePath = TMP_FOLDER.newFolder().getAbsolutePath();
    cConf.set(Constants.LogBuffer.LOG_BUFFER_BASE_DIR, absolutePath);
    cConf.setLong(Constants.LogBuffer.LOG_BUFFER_MAX_FILE_SIZE_BYTES, 100000);
    LoggerContext loggerContext = LogPipelineTestUtil.createLoggerContext("WARN", ImmutableMap.of("test.logger", "INFO"), MockAppender.class.getName());
    final MockAppender appender = LogPipelineTestUtil.getAppender(loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME), "Test", MockAppender.class);
    LogBufferProcessorPipeline pipeline = getLogPipeline(loggerContext);
    pipeline.startAndWait();
    ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> {
    });
    NettyHttpService httpService = NettyHttpService.builder("RemoteAppenderTest").setHttpHandlers(new LogBufferHandler(writer)).setExceptionHandler(new HttpExceptionHandler()).build();
    httpService.start();
    RemoteLogAppender remoteLogAppender = getRemoteAppender(cConf, httpService);
    remoteLogAppender.start();
    List<ILoggingEvent> events = getLoggingEvents();
    WorkerLoggingContext loggingContext = new WorkerLoggingContext("default", "app1", "worker1", "run1", "instance1");
    for (int i = 0; i < 1000; i++) {
        remoteLogAppender.append(new LogMessage(events.get(i % events.size()), loggingContext));
    }
    Tasks.waitFor(1000, () -> appender.getEvents().size(), 120, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    remoteLogAppender.stop();
    httpService.stop();
    pipeline.stopAndWait();
    loggerContext.stop();
}
Also used : WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) RemoteLogAppender(io.cdap.cdap.logging.appender.remote.RemoteLogAppender) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggerContext(ch.qos.logback.classic.LoggerContext) MockAppender(io.cdap.cdap.logging.pipeline.MockAppender) LogMessage(io.cdap.cdap.logging.appender.LogMessage) LogBufferProcessorPipeline(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline) NettyHttpService(io.cdap.http.NettyHttpService) ConcurrentLogBufferWriter(io.cdap.cdap.logging.logbuffer.ConcurrentLogBufferWriter) Test(org.junit.Test)

Example 3 with HttpExceptionHandler

use of io.cdap.cdap.common.HttpExceptionHandler in project cdap by caskdata.

the class RemoteSecureStoreTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    CConfiguration conf = CConfiguration.create();
    conf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true);
    conf.set(Constants.Security.Store.FILE_PATH, TEMP_FOLDER.newFolder().getAbsolutePath());
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
    InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin();
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(NAMESPACE1).build();
    namespaceClient.create(namespaceMeta);
    FileSecureStoreService fileSecureStoreService = new FileSecureStoreService(conf, sConf, namespaceClient);
    // Starts a mock server to handle remote secure store requests
    httpService = new HttpsEnabler().configureKeyStore(conf, sConf).enable(NettyHttpService.builder("remoteSecureStoreTest").setHttpHandlers(new SecureStoreHandler(fileSecureStoreService, fileSecureStoreService)).setExceptionHandler(new HttpExceptionHandler())).build();
    httpService.start();
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    discoveryService.register(URIScheme.HTTPS.createDiscoverable(Constants.Service.SECURE_STORE_SERVICE, httpService.getBindAddress()));
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    remoteSecureStore = new RemoteSecureStore(remoteClientFactory);
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) FileSecureStoreService(io.cdap.cdap.security.store.FileSecureStoreService) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) SecureStoreHandler(io.cdap.cdap.security.store.SecureStoreHandler) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass)

Example 4 with HttpExceptionHandler

use of io.cdap.cdap.common.HttpExceptionHandler in project cdap by caskdata.

the class LogBufferService method startUp.

@Override
protected void startUp() throws Exception {
    // load log pipelines
    List<LogBufferProcessorPipeline> bufferPipelines = loadLogPipelines();
    // start all the log pipelines
    validateAllFutures(Iterables.transform(pipelines, Service::start));
    // recovery service and http handler will send log events to log pipelines. In order to avoid deleting file while
    // reading them in recovery service, we will pass in an atomic boolean will be set to true by recovery service
    // when it is done recovering data. So while recovery service is running, cleanup task will be a no-op
    AtomicBoolean startCleanup = new AtomicBoolean(false);
    // start log recovery service to recover all the pending logs.
    recoveryService = new LogBufferRecoveryService(cConf, bufferPipelines, checkpointManagers, startCleanup);
    recoveryService.startAndWait();
    // create concurrent writer
    ConcurrentLogBufferWriter concurrentWriter = new ConcurrentLogBufferWriter(cConf, bufferPipelines, new LogBufferCleaner(cConf, checkpointManagers, startCleanup));
    // create and start http service
    NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.LOG_BUFFER_SERVICE).setHttpHandlers(new LogBufferHandler(concurrentWriter)).setExceptionHandler(new HttpExceptionHandler()).setHost(cConf.get(Constants.LogBuffer.LOG_BUFFER_SERVER_BIND_ADDRESS)).setPort(cConf.getInt(Constants.LogBuffer.LOG_BUFFER_SERVER_BIND_PORT));
    if (cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED)) {
        new HttpsEnabler().configureKeyStore(cConf, sConf).enable(builder);
    }
    httpService = builder.build();
    httpService.start();
    cancellable = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.LOG_BUFFER_SERVICE, httpService)));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogBufferCleaner(io.cdap.cdap.logging.logbuffer.cleaner.LogBufferCleaner) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) LogBufferProcessorPipeline(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline) LogBufferRecoveryService(io.cdap.cdap.logging.logbuffer.recover.LogBufferRecoveryService) LogBufferHandler(io.cdap.cdap.logging.logbuffer.handler.LogBufferHandler) NettyHttpService(io.cdap.http.NettyHttpService) HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler)

Aggregations

HttpExceptionHandler (io.cdap.cdap.common.HttpExceptionHandler)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 HttpsEnabler (io.cdap.cdap.common.security.HttpsEnabler)2 LogBufferProcessorPipeline (io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline)2 NettyHttpService (io.cdap.http.NettyHttpService)2 BeforeClass (org.junit.BeforeClass)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Injector (com.google.inject.Injector)1 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)1 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)1 LocalLocationModule (io.cdap.cdap.common.guice.LocalLocationModule)1 CommonNettyHttpServiceBuilder (io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder)1 DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)1 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)1 InMemoryNamespaceAdmin (io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin)1 FileFetcherHttpHandlerInternal (io.cdap.cdap.gateway.handlers.FileFetcherHttpHandlerInternal)1 LogMessage (io.cdap.cdap.logging.appender.LogMessage)1 RemoteLogAppender (io.cdap.cdap.logging.appender.remote.RemoteLogAppender)1 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)1