org.elasticsearch.http.HttpServerTransport Java Examples
The following examples show how to use
org.elasticsearch.http.HttpServerTransport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrateMonitor.java From crate with Apache License 2.0 | 6 votes |
@Inject public CrateMonitor(JobsLogs jobsLogs, PostgresNetty postgresNetty, @Nullable HttpServerTransport httpServerTransport, TransportService transportService, SQLOperations sqlOperations, ClusterService clusterService, ThreadPool threadPool, CircuitBreakerService breakerService) { logger = LogManager.getLogger(CrateMonitor.class); registerMBean(QueryStats.NAME, new QueryStats(jobsLogs)); registerMBean(NodeStatus.NAME, new NodeStatus(sqlOperations::isEnabled)); registerMBean(NodeInfo.NAME, new NodeInfo(clusterService::localNode, () -> clusterService.state().version())); registerMBean(Connections.NAME, new Connections( () -> httpServerTransport == null ? null : httpServerTransport.stats(), () -> new ConnectionStats(postgresNetty.openConnections(), postgresNetty.totalConnections()), () -> transportService.stats().serverOpen() )); registerMBean(ThreadPools.NAME, new ThreadPools(threadPool)); registerMBean(CircuitBreakers.NAME, new CircuitBreakers(breakerService)); }
Example #2
Source File: LocalElasticSearch.java From core-ng-project with Apache License 2.0 | 6 votes |
public HttpHost start() { var watch = new StopWatch(); this.dataPath = Files.tempDir(); try { Settings.Builder settings = Settings.builder(); settings.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), "test") .put(Node.NODE_NAME_SETTING.getKey(), "test") .put(Environment.PATH_HOME_SETTING.getKey(), dataPath) .put(NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.getKey(), "_local_") .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE); node = new LocalNode(settings.build()); node.start(); // on same local server, there may be multiple es started, e.g. multiple test jobs on shared build server, this is to retrieve actual http port return new HttpHost("localhost", node.injector().getInstance(HttpServerTransport.class).boundAddress().publishAddress().getPort()); } catch (NodeValidationException e) { throw new Error(e); } finally { logger.info("create local elasticsearch node, dataPath={}, elapsed={}", dataPath, watch.elapsed()); } }
Example #3
Source File: Netty4Plugin.java From crate with Apache License 2.0 | 6 votes |
@Override public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, NodeClient nodeClient) { return Collections.singletonMap( NETTY_HTTP_TRANSPORT_NAME, () -> new Netty4HttpServerTransport( settings, networkService, bigArrays, threadPool, xContentRegistry, pipelineRegistry, nodeClient ) ); }
Example #4
Source File: OpenDistroSecuritySSLPlugin.java From deprecated-security-ssl with Apache License 2.0 | 6 votes |
@Override public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, Dispatcher dispatcher) { final Map<String, Supplier<HttpServerTransport>> httpTransports = new HashMap<String, Supplier<HttpServerTransport>>(1); if (!client && httpSSLEnabled) { final ValidatingDispatcher validatingDispatcher = new ValidatingDispatcher(threadPool.getThreadContext(), dispatcher, settings, configPath, NOOP_SSL_EXCEPTION_HANDLER); final OpenDistroSecuritySSLNettyHttpServerTransport sgsnht = new OpenDistroSecuritySSLNettyHttpServerTransport(settings, networkService, bigArrays, threadPool, odsks, xContentRegistry, validatingDispatcher, NOOP_SSL_EXCEPTION_HANDLER); httpTransports.put("com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyHttpServerTransport", () -> sgsnht); } return httpTransports; }
Example #5
Source File: NetworkPlugin.java From crate with Apache License 2.0 | 5 votes |
/** * Returns a map of {@link HttpServerTransport} suppliers. * See {@link org.elasticsearch.common.network.NetworkModule#HTTP_TYPE_SETTING} to configure a specific implementation. */ default Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, NodeClient nodeClient) { return Collections.emptyMap(); }
Example #6
Source File: AuthenticationIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Test public void testOptionsRequestDoesNotRequireAuth() throws Exception { HttpServerTransport httpTransport = internalCluster().getInstance(HttpServerTransport.class); InetSocketAddress address = httpTransport.boundAddress().publishAddress().address(); String uri = String.format(Locale.ENGLISH, "http://%s:%s/", address.getHostName(), address.getPort()); HttpOptions request = new HttpOptions(uri); request.setHeader(HttpHeaderNames.AUTHORIZATION.toString(), "Basic QXJ0aHVyOkV4Y2FsaWJ1cg=="); request.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://example.com"); request.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), "GET"); CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse resp = httpClient.execute(request); assertThat(resp.getStatusLine().getReasonPhrase(), is("OK")); }
Example #7
Source File: BlobPathITest.java From crate with Apache License 2.0 | 5 votes |
private void launchNodeAndInitClient(Settings settings) throws Exception { // using numDataNodes = 1 to launch the node doesn't work: // if globalBlobPath is created within nodeSetting it is sometimes not available for the tests internalCluster().startNode(settings); blobAdminClient = internalCluster().getInstance(BlobAdminClient.class); HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class); InetSocketAddress address = httpServerTransport.boundAddress().publishAddress().address(); client = new BlobHttpClient(address); }
Example #8
Source File: SQLHttpIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Before public void setup() { HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class); address = httpServerTransport.boundAddress().publishAddress().address(); httpPost = new HttpPost(String.format(Locale.ENGLISH, "%s://%s:%s/_sql?error_trace", usesSSL ? "https" : "http", address.getHostName(), address.getPort())); }
Example #9
Source File: BlobHttpIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Before public void setup() throws ExecutionException, InterruptedException { randomNode = internalCluster().getInstances(HttpServerTransport.class) .iterator().next().boundAddress().publishAddress().address(); Iterable<HttpServerTransport> transports = internalCluster().getDataNodeInstances(HttpServerTransport.class); Iterator<HttpServerTransport> httpTransports = transports.iterator(); dataNode1 = httpTransports.next().boundAddress().publishAddress().address(); dataNode2 = httpTransports.next().boundAddress().publishAddress().address(); BlobAdminClient blobAdminClient = internalCluster().getInstance(BlobAdminClient.class); Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2) // SETTING_AUTO_EXPAND_REPLICAS is enabled by default // but for this test it needs to be disabled so we can have 0 replicas .put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "false") .build(); blobAdminClient.createBlobTable("test", indexSettings).get(); blobAdminClient.createBlobTable("test_blobs2", indexSettings).get(); client().admin().indices().prepareCreate("test_no_blobs") .setSettings( Settings.builder() .put("number_of_shards", 2) .put("number_of_replicas", 0).build()).execute().actionGet(); ensureGreen(); }
Example #10
Source File: AdminUIHttpIntegrationTest.java From crate with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { Iterable<HttpServerTransport> transports = internalCluster().getInstances(HttpServerTransport.class); Iterator<HttpServerTransport> httpTransports = transports.iterator(); address = httpTransports.next().boundAddress().publishAddress().address(); // place index file final Path indexDirectory = internalCluster().getInstance(Environment.class).libFile().resolve("site"); Files.createDirectories(indexDirectory); final Path indexFile = indexDirectory.resolve("index.html"); Files.write(indexFile, Collections.singletonList("<h1>Crate Admin</h1>"), Charset.forName("UTF-8")); }
Example #11
Source File: MockNode.java From crate with Apache License 2.0 | 5 votes |
@Override protected HttpServerTransport newHttpTransport(NetworkModule networkModule) { if (getPluginsService().filterPlugins(MockHttpTransport.TestPlugin.class).isEmpty()) { return super.newHttpTransport(networkModule); } else { return new MockHttpTransport(); } }
Example #12
Source File: InternalTestCluster.java From crate with Apache License 2.0 | 5 votes |
@Override public InetSocketAddress[] httpAddresses() { List<InetSocketAddress> addresses = new ArrayList<>(); for (HttpServerTransport httpServerTransport : getInstances(HttpServerTransport.class)) { addresses.add(httpServerTransport.boundAddress().publishAddress().address()); } return addresses.toArray(new InetSocketAddress[addresses.size()]); }
Example #13
Source File: NodeStatsContextFieldResolver.java From crate with Apache License 2.0 | 5 votes |
@Inject @SuppressWarnings("unused") public NodeStatsContextFieldResolver(ClusterService clusterService, NodeService nodeService, @Nullable HttpServerTransport httpServerTransport, TransportService transportService, ThreadPool threadPool, ExtendedNodeInfo extendedNodeInfo, PostgresNetty postgresNetty) { this( clusterService::localNode, nodeService.getMonitorService(), () -> httpServerTransport == null ? null : httpServerTransport.info().getAddress().publishAddress(), () -> httpServerTransport == null ? null : httpServerTransport.stats(), threadPool, extendedNodeInfo, () -> new ConnectionStats(postgresNetty.openConnections(), postgresNetty.totalConnections()), () -> { BoundTransportAddress boundTransportAddress = postgresNetty.boundAddress(); if (boundTransportAddress == null) { return null; } return boundTransportAddress.publishAddress(); }, () -> transportService.stats().getServerOpen(), () -> clusterService.state().version() ); }
Example #14
Source File: Node.java From crate with Apache License 2.0 | 5 votes |
private Node stop() { if (!lifecycle.moveToStopped()) { return this; } logger.info("stopping ..."); injector.getInstance(HttpServerTransport.class).stop(); injector.getInstance(SnapshotsService.class).stop(); injector.getInstance(SnapshotShardsService.class).stop(); // stop any changes happening as a result of cluster state changes injector.getInstance(IndicesClusterStateService.class).stop(); // close discovery early to not react to pings anymore. // This can confuse other nodes and delay things - mostly if we're the master and we're running tests. injector.getInstance(Discovery.class).stop(); // we close indices first, so operations won't be allowed on it injector.getInstance(RoutingService.class).stop(); injector.getInstance(ClusterService.class).stop(); injector.getInstance(NodeConnectionsService.class).stop(); nodeService.getMonitorService().stop(); injector.getInstance(GatewayService.class).stop(); injector.getInstance(TransportService.class).stop(); pluginLifecycleComponents.forEach(LifecycleComponent::stop); // we should stop this last since it waits for resources to get released // if we had scroll searchers etc or recovery going on we wait for to finish. injector.getInstance(IndicesService.class).stop(); logger.info("stopped"); return this; }
Example #15
Source File: NetworkModule.java From crate with Apache License 2.0 | 5 votes |
public Supplier<HttpServerTransport> getHttpServerTransportSupplier() { final String name; if (HTTP_TYPE_SETTING.exists(settings)) { name = HTTP_TYPE_SETTING.get(settings); } else { name = HTTP_DEFAULT_TYPE_SETTING.get(settings); } final Supplier<HttpServerTransport> factory = transportHttpFactories.get(name); if (factory == null) { throw new IllegalStateException("Unsupported http.type [" + name + "]"); } return factory; }
Example #16
Source File: NetworkModule.java From crate with Apache License 2.0 | 5 votes |
/** Adds an http transport implementation that can be selected by setting {@link #HTTP_TYPE_KEY}. */ // TODO: we need another name than "http transport"....so confusing with transportClient... private void registerHttpTransport(String key, Supplier<HttpServerTransport> factory) { if (transportHttpFactories.putIfAbsent(key, factory) != null) { throw new IllegalArgumentException("transport for name: " + key + " is already registered"); } }
Example #17
Source File: OpenShiftElasticSearchPlugin.java From openshift-elasticsearch-plugin with Apache License 2.0 | 5 votes |
@Override public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry namedXContentRegistry, NetworkService networkService, Dispatcher dispatcher) { Map<String, Supplier<HttpServerTransport>> transports = sgPlugin.getHttpTransports(settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, namedXContentRegistry, networkService, dispatcher); return transports; }
Example #18
Source File: Node.java From crate with Apache License 2.0 | 4 votes |
/** Constructs a {@link org.elasticsearch.http.HttpServerTransport} which may be mocked for tests. */ protected HttpServerTransport newHttpTransport(NetworkModule networkModule) { return networkModule.getHttpServerTransportSupplier().get(); }
Example #19
Source File: Node.java From crate with Apache License 2.0 | 4 votes |
@Override public synchronized void close() throws IOException { if (lifecycle.started()) { stop(); } if (!lifecycle.moveToClosed()) { return; } logger.info("closing ..."); List<Closeable> toClose = new ArrayList<>(); StopWatch stopWatch = new StopWatch("node_close"); toClose.add(() -> stopWatch.start("node_service")); toClose.add(nodeService); toClose.add(() -> stopWatch.stop().start("http")); toClose.add(injector.getInstance(HttpServerTransport.class)); toClose.add(() -> stopWatch.stop().start("snapshot_service")); toClose.add(injector.getInstance(SnapshotsService.class)); toClose.add(injector.getInstance(SnapshotShardsService.class)); toClose.add(() -> stopWatch.stop().start("client")); Releasables.close(injector.getInstance(Client.class)); toClose.add(() -> stopWatch.stop().start("indices_cluster")); toClose.add(injector.getInstance(IndicesClusterStateService.class)); toClose.add(() -> stopWatch.stop().start("indices")); toClose.add(injector.getInstance(IndicesService.class)); // close filter/fielddata caches after indices toClose.add(injector.getInstance(IndicesStore.class)); toClose.add(() -> stopWatch.stop().start("routing")); toClose.add(injector.getInstance(RoutingService.class)); toClose.add(() -> stopWatch.stop().start("cluster")); toClose.add(injector.getInstance(ClusterService.class)); toClose.add(() -> stopWatch.stop().start("node_connections_service")); toClose.add(injector.getInstance(NodeConnectionsService.class)); toClose.add(() -> stopWatch.stop().start("discovery")); toClose.add(injector.getInstance(Discovery.class)); toClose.add(() -> stopWatch.stop().start("monitor")); toClose.add(nodeService.getMonitorService()); toClose.add(() -> stopWatch.stop().start("gateway")); toClose.add(injector.getInstance(GatewayService.class)); toClose.add(() -> stopWatch.stop().start("transport")); toClose.add(injector.getInstance(TransportService.class)); for (LifecycleComponent plugin : pluginLifecycleComponents) { toClose.add(() -> stopWatch.stop().start("plugin(" + plugin.getClass().getName() + ")")); toClose.add(plugin); } toClose.addAll(pluginsService.filterPlugins(Plugin.class)); toClose.add(() -> stopWatch.stop().start("thread_pool")); // TODO this should really use ThreadPool.terminate() toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown()); toClose.add(() -> { try { injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { // ignore } }); toClose.add(() -> stopWatch.stop().start("thread_pool_force_shutdown")); toClose.add(() -> injector.getInstance(ThreadPool.class).shutdownNow()); toClose.add(() -> stopWatch.stop()); toClose.add(injector.getInstance(NodeEnvironment.class)); toClose.add(injector.getInstance(PageCacheRecycler.class)); if (logger.isTraceEnabled()) { logger.trace("Close times for each service:\n{}", stopWatch.prettyPrint()); } IOUtils.close(toClose); logger.info("closed"); }
Example #20
Source File: Node.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Start the node. If the node is already started, this method is no-op. */ public Node start() { if (!lifecycle.moveToStarted()) { return this; } ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); logger.info("starting ..."); // hack around dependency injection problem (for now...) injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class)); for (Class<? extends LifecycleComponent> plugin : pluginsService.nodeServices()) { injector.getInstance(plugin).start(); } injector.getInstance(MappingUpdatedAction.class).setClient(client); injector.getInstance(IndicesService.class).start(); injector.getInstance(IndexingMemoryController.class).start(); injector.getInstance(IndicesClusterStateService.class).start(); injector.getInstance(IndicesTTLService.class).start(); injector.getInstance(SnapshotsService.class).start(); injector.getInstance(SnapshotShardsService.class).start(); injector.getInstance(RoutingService.class).start(); injector.getInstance(SearchService.class).start(); injector.getInstance(MonitorService.class).start(); injector.getInstance(RestController.class).start(); // TODO hack around circular dependencies problems injector.getInstance(GatewayAllocator.class).setReallocation(injector.getInstance(ClusterService.class), injector.getInstance(RoutingService.class)); injector.getInstance(ResourceWatcherService.class).start(); injector.getInstance(GatewayService.class).start(); injector.getInstance(TenantManagementService.class).start(); // Start the transport service now so the publish address will be added to the local disco node in ClusterService TransportService transportService = injector.getInstance(TransportService.class); transportService.start(); injector.getInstance(ClusterService.class).start(); // start after cluster service so the local disco is known DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start(); transportService.acceptIncomingRequests(); discoService.joinClusterAndWaitForInitialState(); if (settings.getAsBoolean("http.enabled", true)) { injector.getInstance(HttpServer.class).start(); } injector.getInstance(TribeService.class).start(); if (settings.getAsBoolean("node.portsfile", false)) { if (settings.getAsBoolean("http.enabled", true)) { HttpServerTransport http = injector.getInstance(HttpServerTransport.class); writePortsFile("http", http.boundAddress()); } TransportService transport = injector.getInstance(TransportService.class); writePortsFile("transport", transport.boundAddress()); } logger.info("started"); return this; }