Search in sources :

Example 11 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class NetworkModuleTests method testRegisterHttpTransport.

public void testRegisterHttpTransport() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    NetworkModule module = newNetworkModule(settings, false, new NetworkPlugin() {

        @Override
        public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher) {
            return Collections.singletonMap("custom", custom);
        }
    });
    assertSame(custom, module.getHttpServerTransportSupplier());
    assertFalse(module.isTransportClient());
    assertTrue(module.isHttpEnabled());
    settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
    NetworkModule newModule = newNetworkModule(settings, false);
    assertFalse(newModule.isTransportClient());
    assertFalse(newModule.isHttpEnabled());
    expectThrows(IllegalStateException.class, () -> newModule.getHttpServerTransportSupplier());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) BigArrays(org.elasticsearch.common.util.BigArrays) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) HashMap(java.util.HashMap) Map(java.util.Map) Settings(org.elasticsearch.common.settings.Settings)

Example 12 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class NetworkModuleTests method testDefaultKeys.

public void testDefaultKeys() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "default_custom").build();
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    Supplier<HttpServerTransport> def = FakeHttpTransport::new;
    Supplier<Transport> customTransport = () -> null;
    NetworkModule module = newNetworkModule(settings, false, new NetworkPlugin() {

        @Override
        public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
            return Collections.singletonMap("default_custom", customTransport);
        }

        @Override
        public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher) {
            Map<String, Supplier<HttpServerTransport>> supplierMap = new HashMap<>();
            supplierMap.put("custom", custom);
            supplierMap.put("default_custom", def);
            return supplierMap;
        }
    });
    assertSame(def, module.getHttpServerTransportSupplier());
    assertSame(customTransport, module.getTransportSupplier());
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkPlugin(org.elasticsearch.plugins.NetworkPlugin) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) BigArrays(org.elasticsearch.common.util.BigArrays) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Transport(org.elasticsearch.transport.Transport) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HashMap(java.util.HashMap) Map(java.util.Map) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings)

Example 13 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4HttpRequestSizeLimitIT method testDoesNotLimitExcludedRequests.

public void testDoesNotLimitExcludedRequests() throws Exception {
    ensureGreen();
    @SuppressWarnings("unchecked") Tuple<String, CharSequence>[] requestUris = new Tuple[1500];
    for (int i = 0; i < requestUris.length; i++) {
        requestUris[i] = Tuple.tuple("/_cluster/settings", "{ \"transient\": {\"search.default_search_timeout\": \"40s\" } }");
    }
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress().boundAddresses());
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.put(transportAddress.address(), requestUris);
        assertThat(responses, hasSize(requestUris.length));
        assertAllInExpectedStatus(responses, HttpResponseStatus.OK);
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Tuple(org.elasticsearch.common.collect.Tuple)

Example 14 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project elasticsearch by elastic.

the class Netty4HttpServerPipeliningTests method testThatHttpPipeliningCanBeDisabled.

public void testThatHttpPipeliningCanBeDisabled() throws Exception {
    final Settings settings = Settings.builder().put("http.pipelining", false).put("http.port", "0").build();
    try (HttpServerTransport httpServerTransport = new CustomNettyHttpServerTransport(settings)) {
        httpServerTransport.start();
        final TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());
        final int numberOfRequests = randomIntBetween(4, 16);
        final Set<Integer> slowIds = new HashSet<>();
        final List<String> requests = new ArrayList<>(numberOfRequests);
        for (int i = 0; i < numberOfRequests; i++) {
            if (rarely()) {
                requests.add("/slow/" + i);
                slowIds.add(i);
            } else {
                requests.add("/" + i);
            }
        }
        try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
            Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests.toArray(new String[] {}));
            List<String> responseBodies = new ArrayList<>(Netty4HttpClient.returnHttpResponseBodies(responses));
            // we can not be sure about the order of the responses, but the slow ones should come last
            assertThat(responseBodies, hasSize(numberOfRequests));
            for (int i = 0; i < numberOfRequests - slowIds.size(); i++) {
                assertThat(responseBodies.get(i), matches("/\\d+"));
            }
            final Set<Integer> ids = new HashSet<>();
            for (int i = 0; i < slowIds.size(); i++) {
                final String response = responseBodies.get(numberOfRequests - slowIds.size() + i);
                assertThat(response, matches("/slow/\\d+"));
                assertTrue(ids.add(Integer.parseInt(response.split("/")[2])));
            }
            assertThat(slowIds, equalTo(ids));
        }
    }
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) Settings(org.elasticsearch.common.settings.Settings) HashSet(java.util.HashSet)

Example 15 with HttpServerTransport

use of org.elasticsearch.http.HttpServerTransport in project crate by crate.

the class AdminUIHttpIntegrationTest method setup.

@Before
public void setup() throws ExecutionException, InterruptedException, IOException {
    Iterable<HttpServerTransport> transports = internalCluster().getInstances(HttpServerTransport.class);
    Iterator<HttpServerTransport> httpTransports = transports.iterator();
    address = ((InetSocketTransportAddress) httpTransports.next().boundAddress().publishAddress()).address();
    // place index file
    final Path indexDirectory = internalCluster().getInstance(Environment.class).pluginsFile().resolve("crate-admin").resolve("_site");
    Files.createDirectories(indexDirectory);
    final Path indexFile = indexDirectory.resolve("index.html");
    Files.write(indexFile, Arrays.asList("<h1>Crate Admin</h1>"), Charset.forName("UTF-8"));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) Before(org.junit.Before)

Aggregations

HttpServerTransport (org.elasticsearch.http.HttpServerTransport)18 Settings (org.elasticsearch.common.settings.Settings)7 TransportAddress (org.elasticsearch.common.transport.TransportAddress)7 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)6 ThreadPool (org.elasticsearch.threadpool.ThreadPool)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)3 BlobAdminClient (io.crate.blob.v2.BlobAdminClient)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 InetSocketAddress (java.net.InetSocketAddress)2 Path (java.nio.file.Path)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 ClusterStateObserver (org.elasticsearch.cluster.ClusterStateObserver)2 NodeConnectionsService (org.elasticsearch.cluster.NodeConnectionsService)2 MappingUpdatedAction (org.elasticsearch.cluster.action.index.MappingUpdatedAction)2