@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(); }
/** * 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); } }
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; }
/** * 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); } }
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(); }
public MockProvisionerService(String id, String serverUrl, int totalCapacity, long taskMs, long msBetweenTasks, int failureRate) { this.id = id; this.totalCapacity = totalCapacity; NettyHttpService.Builder builder = NettyHttpService.builder(); builder.addHttpHandlers(Lists.newArrayList(new MockProvisionerHandler())); builder.setHost("localhost"); builder.setPort(0); builder.setConnectionBacklog(20000); builder.setExecThreadPoolSize(5); builder.setBossThreadPoolSize(1); builder.setWorkerThreadPoolSize(10); this.httpService = builder.build(); this.httpClient = HttpClients.createDefault(); this.heartbeatRequest = new HttpPost(serverUrl + "/provisioners/" + id + "/heartbeat"); this.registerRequest = new HttpPut(serverUrl + "/provisioners/" + id); this.deregisterRequest = new HttpDelete(serverUrl + "/provisioners/" + id); this.workerService = new MockProvisionerWorkerService(id, serverUrl, totalCapacity, taskMs, msBetweenTasks, failureRate); }
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(); }
public StubProvisioner() { NettyHttpService.Builder builder = NettyHttpService.builder(); builder.addHttpHandlers(ImmutableSet.of(new StubTenantHandler())); builder.setHost("localhost"); builder.setPort(0); builder.setConnectionBacklog(20000); builder.setExecThreadPoolSize(1); builder.setBossThreadPoolSize(1); builder.setWorkerThreadPoolSize(1); this.httpService = builder.build(); this.tenantPutCounts = HashMultiset.create(); this.tenantResourcePutCounts = HashMultiset.create(); this.tenantWorkerPutCounts = HashMultiset.create(); this.tenantDeleteCounts = HashMultiset.create(); }
public DummyService(int port, HttpHandler handler) { NettyHttpService.Builder builder = NettyHttpService.builder(); builder.addHttpHandlers(ImmutableSet.of(handler)); builder.setHost("localhost"); builder.setPort(port); builder.setConnectionBacklog(20000); builder.setExecThreadPoolSize(10); builder.setBossThreadPoolSize(1); builder.setWorkerThreadPoolSize(1); this.httpService = builder.build(); }
NettyHttpService.Builder builder = NettyHttpService.builder(program.getName() + "-http") .setHost(host) .setPort(0)
NettyHttpService.Builder builder = NettyHttpService.builder(program.getName() + "-http") .setHost(host) .setPort(0)
@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); } }); }
.setKeyStore(keyStore, ksPass::toCharArray) .enable( NettyHttpService.builder("test") .setHttpHandlers(new PingHandler()) ).build();
NettyHttpService.builder("test") .setHttpHandlers(new PingHandler()) ).build();
@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(); } }
@Test public void testRemoteUGIProvider() throws Exception { final NettyHttpService httpService = NettyHttpService.builder("remoteUGITest") .setHttpHandlers(new UGIProviderTestHandler()) .build();
@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); }