Search in sources :

Example 1 with HttpServerTransport

use of org.opensearch.http.HttpServerTransport in project OpenSearch by opensearch-project.

the class Netty4HttpRequestSizeLimitIT method testLimitsInFlightRequests.

public void testLimitsInFlightRequests() throws Exception {
    ensureGreen();
    // we use the limit size as a (very) rough indication on how many requests we should sent to hit the limit
    int numRequests = LIMIT.bytesAsInt() / 100;
    StringBuilder bulkRequest = new StringBuilder();
    for (int i = 0; i < numRequests; i++) {
        bulkRequest.append("{\"index\": {}}");
        bulkRequest.append(System.lineSeparator());
        bulkRequest.append("{ \"field\" : \"value\" }");
        bulkRequest.append(System.lineSeparator());
    }
    List<Tuple<String, CharSequence>> requests = new ArrayList<>();
    for (int i = 0; i < 150; i++) {
        requests.add(Tuple.tuple("/index/_bulk", bulkRequest));
    }
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> singleResponse = nettyHttpClient.post(transportAddress.address(), requests.subList(0, 1));
        try {
            assertThat(singleResponse, hasSize(1));
            assertAtLeastOnceExpectedStatus(singleResponse, HttpResponseStatus.OK);
            Collection<FullHttpResponse> multipleResponses = nettyHttpClient.post(transportAddress.address(), requests);
            try {
                assertThat(multipleResponses, hasSize(requests.size()));
                assertAtLeastOnceExpectedStatus(multipleResponses, HttpResponseStatus.TOO_MANY_REQUESTS);
            } finally {
                multipleResponses.forEach(ReferenceCounted::release);
            }
        } finally {
            singleResponse.forEach(ReferenceCounted::release);
        }
    }
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.opensearch.http.HttpServerTransport) Tuple(org.opensearch.common.collect.Tuple) ReferenceCounted(io.netty.util.ReferenceCounted)

Example 2 with HttpServerTransport

use of org.opensearch.http.HttpServerTransport in project OpenSearch by opensearch-project.

the class Netty4HttpRequestSizeLimitIT method testDoesNotLimitExcludedRequests.

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

Example 3 with HttpServerTransport

use of org.opensearch.http.HttpServerTransport in project OpenSearch by opensearch-project.

the class Netty4PipeliningIT method testThatNettyHttpServerSupportsPipelining.

public void testThatNettyHttpServerSupportsPipelining() throws Exception {
    String[] requests = new String[] { "/", "/_nodes/stats", "/", "/_cluster/state", "/" };
    HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
    TransportAddress[] boundAddresses = httpServerTransport.boundAddress().boundAddresses();
    TransportAddress transportAddress = randomFrom(boundAddresses);
    try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
        Collection<FullHttpResponse> responses = nettyHttpClient.get(transportAddress.address(), requests);
        try {
            assertThat(responses, hasSize(5));
            Collection<String> opaqueIds = Netty4HttpClient.returnOpaqueIds(responses);
            assertOpaqueIdsInOrder(opaqueIds);
        } finally {
            responses.forEach(ReferenceCounted::release);
        }
    }
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) HttpServerTransport(org.opensearch.http.HttpServerTransport) ReferenceCounted(io.netty.util.ReferenceCounted)

Example 4 with HttpServerTransport

use of org.opensearch.http.HttpServerTransport in project OpenSearch by opensearch-project.

the class Node method start.

/**
 * Start the node. If the node is already started, this method is no-op.
 */
public Node start() throws NodeValidationException {
    if (!lifecycle.moveToStarted()) {
        return this;
    }
    logger.info("starting ...");
    pluginLifecycleComponents.forEach(LifecycleComponent::start);
    injector.getInstance(MappingUpdatedAction.class).setClient(client);
    injector.getInstance(IndicesService.class).start();
    injector.getInstance(IndicesClusterStateService.class).start();
    injector.getInstance(SnapshotsService.class).start();
    injector.getInstance(SnapshotShardsService.class).start();
    injector.getInstance(RepositoriesService.class).start();
    injector.getInstance(SearchService.class).start();
    injector.getInstance(FsHealthService.class).start();
    nodeService.getMonitorService().start();
    final ClusterService clusterService = injector.getInstance(ClusterService.class);
    final NodeConnectionsService nodeConnectionsService = injector.getInstance(NodeConnectionsService.class);
    nodeConnectionsService.start();
    clusterService.setNodeConnectionsService(nodeConnectionsService);
    injector.getInstance(GatewayService.class).start();
    Discovery discovery = injector.getInstance(Discovery.class);
    clusterService.getMasterService().setClusterStatePublisher(discovery::publish);
    // 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.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class));
    transportService.getTaskManager().setTaskCancellationService(new TaskCancellationService(transportService));
    transportService.start();
    assert localNodeFactory.getNode() != null;
    assert transportService.getLocalNode().equals(localNodeFactory.getNode()) : "transportService has a different local node than the factory provided";
    injector.getInstance(PeerRecoverySourceService.class).start();
    // Load (and maybe upgrade) the metadata stored on disk
    final GatewayMetaState gatewayMetaState = injector.getInstance(GatewayMetaState.class);
    gatewayMetaState.start(settings(), transportService, clusterService, injector.getInstance(MetaStateService.class), injector.getInstance(MetadataIndexUpgradeService.class), injector.getInstance(MetadataUpgrader.class), injector.getInstance(PersistedClusterStateService.class));
    if (Assertions.ENABLED) {
        try {
            assert injector.getInstance(MetaStateService.class).loadFullState().v1().isEmpty();
            final NodeMetadata nodeMetadata = NodeMetadata.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, nodeEnvironment.nodeDataPaths());
            assert nodeMetadata != null;
            assert nodeMetadata.nodeVersion().equals(Version.CURRENT);
            assert nodeMetadata.nodeId().equals(localNodeFactory.getNode().getId());
        } catch (IOException e) {
            assert false : e;
        }
    }
    // we load the global state here (the persistent part of the cluster state stored on disk) to
    // pass it to the bootstrap checks to allow plugins to enforce certain preconditions based on the recovered state.
    final Metadata onDiskMetadata = gatewayMetaState.getPersistedState().getLastAcceptedState().metadata();
    // this is never null
    assert onDiskMetadata != null : "metadata is null but shouldn't";
    validateNodeBeforeAcceptingRequests(new BootstrapContext(environment, onDiskMetadata), transportService.boundAddress(), pluginsService.filterPlugins(Plugin.class).stream().flatMap(p -> p.getBootstrapChecks().stream()).collect(Collectors.toList()));
    clusterService.addStateApplier(transportService.getTaskManager());
    // start after transport service so the local disco is known
    // start before cluster service so that it can set initial state on ClusterApplierService
    discovery.start();
    clusterService.start();
    assert clusterService.localNode().equals(localNodeFactory.getNode()) : "clusterService has a different local node than the factory provided";
    transportService.acceptIncomingRequests();
    discovery.startInitialJoin();
    final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings());
    configureNodeAndClusterIdStateListener(clusterService);
    if (initialStateTimeout.millis() > 0) {
        final ThreadPool thread = injector.getInstance(ThreadPool.class);
        ClusterState clusterState = clusterService.state();
        ClusterStateObserver observer = new ClusterStateObserver(clusterState, clusterService, null, logger, thread.getThreadContext());
        if (clusterState.nodes().getMasterNodeId() == null) {
            logger.debug("waiting to join the cluster. timeout [{}]", initialStateTimeout);
            final CountDownLatch latch = new CountDownLatch(1);
            observer.waitForNextChange(new ClusterStateObserver.Listener() {

                @Override
                public void onNewClusterState(ClusterState state) {
                    latch.countDown();
                }

                @Override
                public void onClusterServiceClose() {
                    latch.countDown();
                }

                @Override
                public void onTimeout(TimeValue timeout) {
                    logger.warn("timed out while waiting for initial discovery state - timeout: {}", initialStateTimeout);
                    latch.countDown();
                }
            }, state -> state.nodes().getMasterNodeId() != null, initialStateTimeout);
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new OpenSearchTimeoutException("Interrupted while waiting for initial discovery state");
            }
        }
    }
    injector.getInstance(HttpServerTransport.class).start();
    if (WRITE_PORTS_FILE_SETTING.get(settings())) {
        TransportService transport = injector.getInstance(TransportService.class);
        writePortsFile("transport", transport.boundAddress());
        HttpServerTransport http = injector.getInstance(HttpServerTransport.class);
        writePortsFile("http", http.boundAddress());
    }
    logger.info("started");
    pluginsService.filterPlugins(ClusterPlugin.class).forEach(ClusterPlugin::onNodeStarted);
    return this;
}
Also used : OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) SnapshotsService(org.opensearch.snapshots.SnapshotsService) SnapshotShardsService(org.opensearch.snapshots.SnapshotShardsService) NodeConnectionsService(org.opensearch.cluster.NodeConnectionsService) Metadata(org.opensearch.cluster.metadata.Metadata) NodeMetadata(org.opensearch.env.NodeMetadata) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) ThreadPool(org.opensearch.threadpool.ThreadPool) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) BootstrapContext(org.opensearch.bootstrap.BootstrapContext) TaskResultsService(org.opensearch.tasks.TaskResultsService) HttpServerTransport(org.opensearch.http.HttpServerTransport) GatewayMetaState(org.opensearch.gateway.GatewayMetaState) MetaStateService(org.opensearch.gateway.MetaStateService) IndicesClusterStateService(org.opensearch.indices.cluster.IndicesClusterStateService) LifecycleComponent(org.opensearch.common.component.LifecycleComponent) SearchService(org.opensearch.search.SearchService) PeerRecoverySourceService(org.opensearch.indices.recovery.PeerRecoverySourceService) TimeValue(org.opensearch.common.unit.TimeValue) FsHealthService(org.opensearch.monitor.fs.FsHealthService) ClusterState(org.opensearch.cluster.ClusterState) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterPlugin(org.opensearch.plugins.ClusterPlugin) Discovery(org.opensearch.discovery.Discovery) IndicesService(org.opensearch.indices.IndicesService) MetadataIndexUpgradeService(org.opensearch.cluster.metadata.MetadataIndexUpgradeService) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) GatewayService(org.opensearch.gateway.GatewayService) NodeMetadata(org.opensearch.env.NodeMetadata) ClusterService(org.opensearch.cluster.service.ClusterService) PersistentTasksClusterService(org.opensearch.persistent.PersistentTasksClusterService) RemoteClusterService(org.opensearch.transport.RemoteClusterService) TransportService(org.opensearch.transport.TransportService) SearchTransportService(org.opensearch.action.search.SearchTransportService) RepositoriesService(org.opensearch.repositories.RepositoriesService) MappingUpdatedAction(org.opensearch.cluster.action.index.MappingUpdatedAction) PersistedClusterStateService(org.opensearch.gateway.PersistedClusterStateService) TaskCancellationService(org.opensearch.tasks.TaskCancellationService)

Example 5 with HttpServerTransport

use of org.opensearch.http.HttpServerTransport in project OpenSearch by opensearch-project.

the class NetworkModuleTests method testOverrideDefault.

public void testOverrideDefault() {
    Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local").put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom").build();
    // content doesn't matter we check reference equality
    Supplier<Transport> customTransport = () -> null;
    Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
    Supplier<HttpServerTransport> def = FakeHttpTransport::new;
    NetworkModule module = newNetworkModule(settings, new NetworkPlugin() {

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

Aggregations

HttpServerTransport (org.opensearch.http.HttpServerTransport)12 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)6 ClusterSettings (org.opensearch.common.settings.ClusterSettings)6 TransportAddress (org.opensearch.common.transport.TransportAddress)6 ReferenceCounted (io.netty.util.ReferenceCounted)5 Settings (org.opensearch.common.settings.Settings)5 ThreadPool (org.opensearch.threadpool.ThreadPool)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BigArrays (org.opensearch.common.util.BigArrays)3 PageCacheRecycler (org.opensearch.common.util.PageCacheRecycler)3 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)3 CircuitBreakerService (org.opensearch.indices.breaker.CircuitBreakerService)3 NetworkPlugin (org.opensearch.plugins.NetworkPlugin)3 TestThreadPool (org.opensearch.threadpool.TestThreadPool)3 IOException (java.io.IOException)2 Tuple (org.opensearch.common.collect.Tuple)2 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)2 NoOpNodeClient (org.opensearch.test.client.NoOpNodeClient)2