private static Map<String, TransportClientFactory> createTransportClientFactories() { return ImmutableMap.<String, TransportClientFactory>builder() .put("http", new HttpClientFactory()) //It won't route to SSL port without this. .put("https", new HttpClientFactory()) .build(); } }
public JobExecutionInfoClient(String serverUri) { this.httpClientFactory = new HttpClientFactory(); Client r2Client = new TransportClientAdapter(this.httpClientFactory.getClient(Collections.<String, String>emptyMap())); this.restClient = new RestClient(r2Client, serverUri); }
@Override public void close() throws IOException { if (_restClient.isPresent()) { _restClient.get().shutdown(new FutureCallback<None>()); } if (_httpClientFactory.isPresent()) { _httpClientFactory.get().shutdown(new FutureCallback<None>()); } } }
private Client newTransportClient(Map<String, ? extends Object> properties) { Client client = new TransportClientAdapter(_clientFactory.getClient(properties)); _transportClients.add(client); return client; }
public CoordinatorAdminClient(RESTClientConfig config) { this.config = config; this.httpClientFactory = new HttpClientFactory(); Map<String, String> properties = Maps.newHashMap(); properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(this.config.getMaxR2ConnectionPoolSize())); this.client = new TransportClientAdapter(httpClientFactory.getClient(properties)); }
private Client createHttpClient(Config config) { boolean isSSLEnabled = config.getBoolean(SSL_ENABLED); SSLContext sslContext = null; SSLParameters sslParameters = null; if (isSSLEnabled) { sslContext = SSLContextFactory.createInstance(config); sslParameters = sslContext.getDefaultSSLParameters(); } Map<String, Object> properties = new HashMap<>(); properties.put(HttpClientFactory.HTTP_SSL_CONTEXT, sslContext); properties.put(HttpClientFactory.HTTP_SSL_PARAMS, sslParameters); if (config.hasPath(PROPERTIES)) { properties.putAll(toMap(config.getConfig(PROPERTIES))); } return new R2HttpClientProxy(new HttpClientFactory(), properties); }
@Override public void close() throws IOException { if (_restClient.isPresent()) { _restClient.get().shutdown(new FutureCallback<None>()); } if (_httpClientFactory.isPresent()) { _httpClientFactory.get().shutdown(new FutureCallback<None>()); } } }
/** * Construct a {@link FlowStatusClient} to communicate with http flow status server at URI serverUri * @param serverUri address and port of the REST server */ public FlowStatusClient(String serverUri) { LOG.debug("FlowConfigClient with serverUri " + serverUri); _httpClientFactory = Optional.of(new HttpClientFactory()); Client r2Client = new TransportClientAdapter(_httpClientFactory.get().getClient(Collections.<String, String>emptyMap())); _restClient = Optional.of(new RestClient(r2Client, serverUri)); _flowstatusesRequestBuilders = new FlowstatusesRequestBuilders(); }
public RESTClientFactory(RESTClientFactoryConfig config) { this.restClientFactoryConfig = config; this.config = new RESTClientConfig(restClientFactoryConfig.getClientConfig()); this.stats = new StoreStats("aggregate.rest-client-factory"); this.rawStoreList = new ArrayList<R2Store>(); // Create the R2 (Netty) Factory object // TODO: Add monitoring for R2 factory this._clientFactory = new HttpClientFactory(); this.RESTClientFactoryStats = new StoreClientFactoryStats(); keySerializerMap = new HashMap<String, SerializerDefinition>(); valueSerializerMap = new HashMap<String, SerializerDefinition>(); }
@Override public void close() throws IOException { if (_restClient.isPresent()) { _restClient.get().shutdown(new FutureCallback<None>()); } if (_httpClientFactory.isPresent()) { _httpClientFactory.get().shutdown(new FutureCallback<None>()); } } }
/** * Construct a {@link FlowConfigV2Client} to communicate with http flow config server at URI serverUri * @param serverUri address and port of the REST server */ public FlowConfigV2Client(String serverUri) { LOG.debug("FlowConfigClient with serverUri " + serverUri); _httpClientFactory = Optional.of(new HttpClientFactory()); Client r2Client = new TransportClientAdapter(_httpClientFactory.get().getClient(Collections.<String, String>emptyMap())); _restClient = Optional.of(new RestClient(r2Client, serverUri)); _flowconfigsV2RequestBuilders = new FlowconfigsV2RequestBuilders(); }
@BeforeClass public void init() throws Exception { _serverScheduler = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() + 1); EngineBuilder serverEngineBuilder = new EngineBuilder(); serverEngineBuilder.setTaskExecutor(_serverScheduler).setTimerScheduler(_serverScheduler) .setPlanDeactivationListener(_batchingSupport); _serverEngine = serverEngineBuilder.build(); _server = RestLiIntTestServer.createServer(_serverEngine, _port, true, 5000, null, FilterChains.empty(), true, false, false); _server.start(); _clientFactory = new HttpClientFactory(); _transportClients = new ArrayList<>(); _restClient = createRestClient(); }
@Override public void close() throws IOException { this.restClient.shutdown(new FutureCallback<None>()); this.httpClientFactory.shutdown(new FutureCallback<None>()); } }
/** * Construct a {@link FlowConfigClient} to communicate with http flow config server at URI serverUri * @param serverUri address and port of the REST server */ public FlowConfigClient(String serverUri) { LOG.debug("FlowConfigClient with serverUri " + serverUri); _httpClientFactory = Optional.of(new HttpClientFactory()); Client r2Client = new TransportClientAdapter(_httpClientFactory.get().getClient(Collections.<String, String>emptyMap())); _restClient = Optional.of(new RestClient(r2Client, serverUri)); _flowconfigsRequestBuilders = new FlowconfigsRequestBuilders(); }
this._clientFactory.shutdown(factoryShutdownCallback, SHUTDOWN_TIMEOUT, TimeUnit.SECONDS); try { factoryShutdownCallback.get();
@Override public SharedResourceFactoryResponse<RestClient> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, SharedRestClientKey> config) throws NotConfiguredException { try { SharedRestClientKey key = config.getKey(); if (!(key instanceof UriRestClientKey)) { return new ResourceCoordinate<>(this, new UriRestClientKey(key.serviceName, resolveUriPrefix(config.getConfig(), key)), config.getScope()); } String uriPrefix = ((UriRestClientKey) key).getUri(); HttpClientFactory http = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(0 /* use default settings */, ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Nio Event Loop-%d"))), true, Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Netty Scheduler"))), true); Client r2Client = new TransportClientAdapter(http.getClient(Collections.<String, String>emptyMap())); return new ResourceInstance<>(new RestClient(r2Client,uriPrefix)); } catch (URISyntaxException use) { throw new RuntimeException("Could not create a rest client for key " + Optional.fromNullable(config.getKey().toConfigurationKey()).or("null")); } }
@AfterClass public void shutdown() throws Exception { if (_server != null) { _server.stop(); } if (_serverEngine != null) { _serverEngine.shutdown(); } if (_serverScheduler != null) { _serverScheduler.shutdownNow(); } for (Client client : _transportClients) { FutureCallback<None> callback = new FutureCallback<>(); client.shutdown(callback); callback.get(); } if (_clientFactory != null) { FutureCallback<None> callback = new FutureCallback<>(); _clientFactory.shutdown(callback); callback.get(); } }
.setTimeoutMs(10000, TimeUnit.MILLISECONDS) .setMaxR2ConnectionPoolSize(100); clientFactory = new HttpClientFactory(); Map<String, String> properties = new HashMap<String, String>(); properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize())); TransportClient transportClient = clientFactory.getClient(properties); R2Store r2Store = new R2Store(STORE_NAME, restClientConfig.getHttpBootstrapURL(),
@BeforeClass public static void oneTimeSetUp() { voldemortConfig = VoldemortConfig.loadFromVoldemortHome("config/single_node_rest_server/"); key = new ByteArray("key1".getBytes()); vectorClock = new VectorClock(); vectorClock.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis()); value = new Versioned<byte[]>("value1".getBytes(), vectorClock); server = new VoldemortServer(voldemortConfig); if(!server.isStarted()) server.start(); logger.info("********************Starting REST Server********************"); restClientConfig = new RESTClientConfig(); restClientConfig.setHttpBootstrapURL("http://localhost:8085") .setTimeoutMs(1500, TimeUnit.MILLISECONDS) .setMaxR2ConnectionPoolSize(100); clientFactory = new HttpClientFactory(); Map<String, String> properties = new HashMap<String, String>(); properties.put(HttpClientFactory.HTTP_POOL_SIZE, Integer.toString(restClientConfig.getMaxR2ConnectionPoolSize())); transportClient = clientFactory.getClient(properties); r2store = new R2Store("test", restClientConfig.getHttpBootstrapURL(), "2", transportClient, restClientConfig, 0); store = r2store; deleteCreatedKeys(key); }
server.awaitRunning(); final HttpClientFactory http = new HttpClientFactory(); final Client r2Client = new TransportClientAdapter(http.getClient(Collections.<String, String>emptyMap()));