/** * Add HttpHandlers that service the request. * * @param handlers a list of {@link HttpHandler}s to add * @return instance of {@code Builder}. */ public Builder setHttpHandlers(HttpHandler... handlers) { return setHttpHandlers(Arrays.asList(handlers)); }
/** * Validates the given set of user service handlers. * * @param handlers set of service handlers to validate. * @param <T> type of the handler * @throws IllegalArgumentException if any of the service handler is not valid */ public <T> void validateHttpHandler(Iterable<T> handlers) { List<HttpHandler> httpHandlers = new ArrayList<>(); NoopMetricsContext metricsContext = new NoopMetricsContext(); for (T handler : handlers) { try { @SuppressWarnings("unchecked") TypeToken<T> type = (TypeToken<T>) TypeToken.of(handler.getClass()); httpHandlers.add(createHttpHandler(type, new VerificationDelegateContext<>(handler), metricsContext)); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler class " + handler.getClass().getName()); } } try { // Constructs a NettyHttpService, to verify that the handlers passed in by the user are valid. NettyHttpService.builder("service-configurer") .setHttpHandlers(httpHandlers) .build(); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler", e); } }
/** * Validates the given set of user service handlers. * * @param handlers set of service handlers to validate. * @param <T> type of the handler * @throws IllegalArgumentException if any of the service handler is not valid */ public <T> void validateHttpHandler(Iterable<T> handlers) { List<HttpHandler> httpHandlers = new ArrayList<>(); NoopMetricsContext metricsContext = new NoopMetricsContext(); for (T handler : handlers) { try { @SuppressWarnings("unchecked") TypeToken<T> type = (TypeToken<T>) TypeToken.of(handler.getClass()); httpHandlers.add(createHttpHandler(type, new VerificationDelegateContext<>(handler), metricsContext)); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler class " + handler.getClass().getName()); } } try { // Constructs a NettyHttpService, to verify that the handlers passed in by the user are valid. NettyHttpService.builder("service-configurer") .setHttpHandlers(httpHandlers) .build(); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler", e); } }
.setHttpHandlers(new PingHandler()) ).build();
.setHttpHandlers(handlers) .build(); httpService.start();
.enable( NettyHttpService.builder("test") .setHttpHandlers(new PingHandler()) ).build();
.setHttpHandlers(handlers) .build(); httpService.start();
@Inject public MetricsQueryService(CConfiguration cConf, @Named(Constants.Service.METRICS) Set<HttpHandler> handlers, DiscoveryService discoveryService, @Nullable MetricsCollectionService metricsCollectionService) { // netty http server config String address = cConf.get(Constants.Metrics.ADDRESS); int backlogcnxs = cConf.getInt(Constants.Metrics.BACKLOG_CONNECTIONS, 20000); int execthreads = cConf.getInt(Constants.Metrics.EXEC_THREADS, 20); int bossthreads = cConf.getInt(Constants.Metrics.BOSS_THREADS, 1); int workerthreads = cConf.getInt(Constants.Metrics.WORKER_THREADS, 10); NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.METRICS); builder.setHttpHandlers(handlers); builder.setHandlerHooks(ImmutableList.of(new MetricsReporterHook(metricsCollectionService, Constants.Service.METRICS))); builder.setHost(address); builder.setConnectionBacklog(backlogcnxs); builder.setExecThreadPoolSize(execthreads); builder.setBossThreadPoolSize(bossthreads); builder.setWorkerThreadPoolSize(workerthreads); this.httpService = builder.build(); this.discoveryService = discoveryService; LOG.info("Configuring MetricsService " + ", address: " + address + ", backlog connections: " + backlogcnxs + ", execthreads: " + execthreads + ", bossthreads: " + bossthreads + ", workerthreads: " + workerthreads); }
@Inject public MetricsQueryService(CConfiguration cConf, @Named(Constants.Service.METRICS) Set<HttpHandler> handlers, DiscoveryService discoveryService, @Nullable MetricsCollectionService metricsCollectionService) { // netty http server config String address = cConf.get(Constants.Metrics.ADDRESS); int backlogcnxs = cConf.getInt(Constants.Metrics.BACKLOG_CONNECTIONS, 20000); int execthreads = cConf.getInt(Constants.Metrics.EXEC_THREADS, 20); int bossthreads = cConf.getInt(Constants.Metrics.BOSS_THREADS, 1); int workerthreads = cConf.getInt(Constants.Metrics.WORKER_THREADS, 10); NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.METRICS); builder.setHttpHandlers(handlers); builder.setHandlerHooks(ImmutableList.of(new MetricsReporterHook(metricsCollectionService, Constants.Service.METRICS))); builder.setHost(address); builder.setConnectionBacklog(backlogcnxs); builder.setExecThreadPoolSize(execthreads); builder.setBossThreadPoolSize(bossthreads); builder.setWorkerThreadPoolSize(workerthreads); this.httpService = builder.build(); this.discoveryService = discoveryService; LOG.info("Configuring MetricsService " + ", address: " + address + ", backlog connections: " + backlogcnxs + ", execthreads: " + execthreads + ", bossthreads: " + bossthreads + ", workerthreads: " + workerthreads); }
@Test public void testContentConsumer() throws Exception { HttpHandlerFactory factory = new HttpHandlerFactory("/content", TransactionControl.IMPLICIT); // Create the file upload handler and starts a netty server with it final File outputDir = TEMP_FOLDER.newFolder(); HttpHandler httpHandler = factory.createHttpHandler( TypeToken.of(FileHandler.class), new AbstractDelegatorContext<FileHandler>() { @Override protected FileHandler createHandler() { return new FileHandler(outputDir); } }, new NoopMetricsContext()); // Creates a Netty http server with 1K request buffer NettyHttpService service = NettyHttpService.builder("test-content-consumer") .setHttpHandlers(httpHandler) .setHttpChunkLimit(1024) .build(); service.start(); try { InetSocketAddress bindAddress = service.getBindAddress(); testUpload(outputDir, bindAddress, ""); testUpload(outputDir, bindAddress, "-no-tx"); } finally { service.stop(); } }
@Before public void beforeTest() throws Exception { httpService = NettyHttpService.builder("test") .setHttpHandlers(new TestHandler()) .build(); httpService.start(); sshSession = new TestSSHSession(getSSHConfig()); proxyServer = new MonitorSocksProxy(CConfiguration.create(), host -> Optional.ofNullable(sshSession).orElseThrow(() -> new IllegalArgumentException("No SSH session available for " + host))); proxyServer.startAndWait(); Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyServer.getBindAddress()); defaultProxySelector = ProxySelector.getDefault(); // Set the proxy for URLConnection ProxySelector.setDefault(new ProxySelector() { @Override public List<Proxy> select(URI uri) { return Collections.singletonList(proxy); } @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { LOG.error("Connect failed {} {}", uri, sa, ioe); } }); }
@BeforeClass public static void setUp() throws Exception { CConfiguration conf = CConfiguration.create(); 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 = NettyHttpService.builder("remoteSecureStoreTest") .setHttpHandlers(new SecureStoreHandler(fileSecureStoreService, fileSecureStoreService)) .setExceptionHandler(new HttpExceptionHandler()) .build(); httpService.start(); InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService(); discoveryService.register(new Discoverable(Constants.Service.SECURE_STORE_SERVICE, httpService.getBindAddress())); remoteSecureStore = new RemoteSecureStore(discoveryService); }
@Inject public TransactionHttpService(CConfiguration cConf, @Named(Constants.Service.TRANSACTION_HTTP) Set<HttpHandler> handlers, DiscoveryService discoveryService, MetricsCollectionService metricsCollectionService) { // netty http server config String address = cConf.get(Constants.Transaction.Container.ADDRESS); NettyHttpService.Builder builder = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.TRANSACTION_HTTP); builder.setHandlerHooks(ImmutableList.of(new MetricsReporterHook(metricsCollectionService, Constants.Service.TRANSACTION_HTTP))); builder.setHttpHandlers(handlers); builder.setHost(address); this.httpService = builder.build(); this.discoveryService = discoveryService; }
public SparkExecutionService(LocationFactory locationFactory, String host, ProgramRunId programRunId, @Nullable WorkflowToken workflowToken) { this.locationFactory = locationFactory; this.httpServer = NettyHttpService.builder(programRunId.getProgram() + "-spark-exec-service") .setHttpHandlers(Collections.singletonList(new SparkControllerHandler())) .setHost(host) .setExceptionHandler(new HttpExceptionHandler()) .build(); this.stopping = new AtomicBoolean(); this.stopLatch = new CountDownLatch(1); this.programRunId = programRunId; this.workflowToken = workflowToken; }
public SparkExecutionService(LocationFactory locationFactory, String host, ProgramRunId programRunId, @Nullable WorkflowToken workflowToken) { this.locationFactory = locationFactory; this.httpServer = NettyHttpService.builder(programRunId.getProgram() + "-spark-exec-service") .setHttpHandlers(Collections.singletonList(new SparkControllerHandler())) .setHost(host) .setExceptionHandler(new HttpExceptionHandler()) .build(); this.stopping = new AtomicBoolean(); this.stopLatch = new CountDownLatch(1); this.programRunId = programRunId; this.workflowToken = workflowToken; }
public SparkExecutionService(LocationFactory locationFactory, String host, ProgramRunId programRunId, @Nullable WorkflowToken workflowToken) { this.locationFactory = locationFactory; this.httpServer = NettyHttpService.builder(programRunId.getProgram() + "-spark-exec-service") .setHttpHandlers(Collections.singletonList(new SparkControllerHandler())) .setHost(host) .setExceptionHandler(new HttpExceptionHandler()) .build(); this.stopping = new AtomicBoolean(); this.stopLatch = new CountDownLatch(1); this.programRunId = programRunId; this.workflowToken = workflowToken; }
SparkDriverHttpService(String programName, String hostname, HttpHandler...handlers) { this.httpServer = NettyHttpService.builder(programName + "-http-service") .setHttpHandlers(handlers) .setExceptionHandler(new HttpExceptionHandler()) .setHost(hostname) .build(); }
@Inject public LogSaverStatusService(CConfiguration cConf, DiscoveryService discoveryService, @Named(Constants.LogSaver.LOG_SAVER_STATUS_HANDLER) Set<HttpHandler> handlers, MetricsCollectionService metricsCollectionService) { this.discoveryService = discoveryService; this.httpService = NettyHttpService.builder(LogSaverStatusService.class.getName()) .setHttpHandlers(handlers) .setHandlerHooks(ImmutableList.of(new MetricsReporterHook(metricsCollectionService, Constants.LogSaver.LOG_SAVER_STATUS_HANDLER))) .setHost(cConf.get(Constants.LogSaver.ADDRESS)) .build(); }
SparkDriverHttpService(String programName, String hostname, HttpHandler...handlers) { this.httpServer = NettyHttpService.builder(programName + "-http-service") .setHttpHandlers(handlers) .setExceptionHandler(new HttpExceptionHandler()) .setHost(hostname) .build(); }
SparkDriverHttpService(String programName, String hostname, HttpHandler...handlers) { this.httpServer = NettyHttpService.builder(programName + "-http-service") .setHttpHandlers(handlers) .setExceptionHandler(new HttpExceptionHandler()) .setHost(hostname) .build(); }