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()));
}
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();
}
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);
}
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)));
}
Aggregations