Search in sources :

Example 91 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

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 logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings));
    logger.info("starting ...");
    // hack around dependency injection problem (for now...)
    injector.getInstance(Discovery.class).setAllocationService(injector.getInstance(AllocationService.class));
    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(RoutingService.class).start();
    injector.getInstance(SearchService.class).start();
    injector.getInstance(MonitorService.class).start();
    final ClusterService clusterService = injector.getInstance(ClusterService.class);
    final NodeConnectionsService nodeConnectionsService = injector.getInstance(NodeConnectionsService.class);
    nodeConnectionsService.start();
    clusterService.setNodeConnectionsService(nodeConnectionsService);
    // TODO hack around circular dependencies problems
    injector.getInstance(GatewayAllocator.class).setReallocation(clusterService, injector.getInstance(RoutingService.class));
    injector.getInstance(ResourceWatcherService.class).start();
    injector.getInstance(GatewayService.class).start();
    Discovery discovery = injector.getInstance(Discovery.class);
    clusterService.setDiscoverySettings(discovery.getDiscoverySettings());
    clusterService.addInitialStateBlock(discovery.getDiscoverySettings().getNoMasterBlock());
    clusterService.setClusterStatePublisher(discovery::publish);
    // start before the cluster service since it adds/removes initial Cluster state blocks
    final TribeService tribeService = injector.getInstance(TribeService.class);
    tribeService.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.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class));
    transportService.start();
    validateNodeBeforeAcceptingRequests(settings, transportService.boundAddress(), pluginsService.filterPlugins(Plugin.class).stream().flatMap(p -> p.getBootstrapChecks().stream()).collect(Collectors.toList()));
    clusterService.addStateApplier(transportService.getTaskManager());
    clusterService.start();
    assert localNodeFactory.getNode() != null;
    assert transportService.getLocalNode().equals(localNodeFactory.getNode()) : "transportService has a different local node than the factory provided";
    assert clusterService.localNode().equals(localNodeFactory.getNode()) : "clusterService has a different local node than the factory provided";
    // start after cluster service so the local disco is known
    discovery.start();
    transportService.acceptIncomingRequests();
    discovery.startInitialJoin();
    // tribe nodes don't have a master so we shouldn't register an observer         s
    final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings);
    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 ElasticsearchTimeoutException("Interrupted while waiting for initial discovery state");
            }
        }
    }
    if (NetworkModule.HTTP_ENABLED.get(settings)) {
        injector.getInstance(HttpServerTransport.class).start();
    }
    // start nodes now, after the http server, because it may take some time
    tribeService.startNodes();
    // starts connecting to remote clusters if any cluster is configured
    SearchTransportService searchTransportService = injector.getInstance(SearchTransportService.class);
    searchTransportService.start();
    if (WRITE_PORTS_FIELD_SETTING.get(settings)) {
        if (NetworkModule.HTTP_ENABLED.get(settings)) {
            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;
}
Also used : TribeService(org.elasticsearch.tribe.TribeService) GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) SnapshotsService(org.elasticsearch.snapshots.SnapshotsService) SnapshotShardsService(org.elasticsearch.snapshots.SnapshotShardsService) NodeConnectionsService(org.elasticsearch.cluster.NodeConnectionsService) MonitorService(org.elasticsearch.monitor.MonitorService) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Logger(org.apache.logging.log4j.Logger) DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) HttpServerTransport(org.elasticsearch.http.HttpServerTransport) IndicesClusterStateService(org.elasticsearch.indices.cluster.IndicesClusterStateService) LifecycleComponent(org.elasticsearch.common.component.LifecycleComponent) SearchService(org.elasticsearch.search.SearchService) SearchTransportService(org.elasticsearch.action.search.SearchTransportService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) TimeValue(org.elasticsearch.common.unit.TimeValue) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) RoutingService(org.elasticsearch.cluster.routing.RoutingService) Discovery(org.elasticsearch.discovery.Discovery) IndicesService(org.elasticsearch.indices.IndicesService) CountDownLatch(java.util.concurrent.CountDownLatch) GatewayService(org.elasticsearch.gateway.GatewayService) ClusterService(org.elasticsearch.cluster.service.ClusterService) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) SearchTransportService(org.elasticsearch.action.search.SearchTransportService) TransportService(org.elasticsearch.transport.TransportService) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService)

Example 92 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class RestListTasksAction method generateListTasksRequest.

public static ListTasksRequest generateListTasksRequest(RestRequest request) {
    boolean detailed = request.paramAsBoolean("detailed", false);
    String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes"));
    String[] actions = Strings.splitStringByCommaToArray(request.param("actions"));
    TaskId parentTaskId = new TaskId(request.param("parent_task_id"));
    boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
    TimeValue timeout = request.paramAsTime("timeout", null);
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setNodes(nodes);
    listTasksRequest.setDetailed(detailed);
    listTasksRequest.setActions(actions);
    listTasksRequest.setParentTaskId(parentTaskId);
    listTasksRequest.setWaitForCompletion(waitForCompletion);
    listTasksRequest.setTimeout(timeout);
    return listTasksRequest;
}
Also used : TaskId(org.elasticsearch.tasks.TaskId) ListTasksRequest(org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 93 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class TcpTransport method openConnection.

@Override
public final NodeChannels openConnection(DiscoveryNode node, ConnectionProfile connectionProfile) throws IOException {
    if (node == null) {
        throw new ConnectTransportException(null, "can't open connection to a null node");
    }
    boolean success = false;
    NodeChannels nodeChannels = null;
    connectionProfile = resolveConnectionProfile(connectionProfile, defaultConnectionProfile);
    // ensure we don't open connections while we are closing
    globalLock.readLock().lock();
    try {
        ensureOpen();
        try {
            nodeChannels = connectToChannels(node, connectionProfile);
            // one channel is guaranteed by the connection profile
            final Channel channel = nodeChannels.getChannels().get(0);
            final TimeValue connectTimeout = connectionProfile.getConnectTimeout() == null ? defaultConnectionProfile.getConnectTimeout() : connectionProfile.getConnectTimeout();
            final TimeValue handshakeTimeout = connectionProfile.getHandshakeTimeout() == null ? connectTimeout : connectionProfile.getHandshakeTimeout();
            final Version version = executeHandshake(node, channel, handshakeTimeout);
            transportServiceAdapter.onConnectionOpened(node);
            // clone the channels - we now have the correct version
            nodeChannels = new NodeChannels(nodeChannels, version);
            success = true;
            return nodeChannels;
        } catch (ConnectTransportException e) {
            throw e;
        } catch (Exception e) {
            // only relevant exceptions are logged on the caller end.. this is the same as in connectToNode
            throw new ConnectTransportException(node, "general node connection failure", e);
        } finally {
            if (success == false) {
                IOUtils.closeWhileHandlingException(nodeChannels);
            }
        }
    } finally {
        globalLock.readLock().unlock();
    }
}
Also used : Version(org.elasticsearch.Version) TimeValue(org.elasticsearch.common.unit.TimeValue) ElasticsearchException(org.elasticsearch.ElasticsearchException) NotCompressedException(org.elasticsearch.common.compress.NotCompressedException) StreamCorruptedException(java.io.StreamCorruptedException) CancelledKeyException(java.nio.channels.CancelledKeyException) NetworkExceptionHelper.isCloseConnectionException(org.elasticsearch.common.transport.NetworkExceptionHelper.isCloseConnectionException) BindException(java.net.BindException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) NetworkExceptionHelper.isConnectException(org.elasticsearch.common.transport.NetworkExceptionHelper.isConnectException)

Example 94 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class SettingTests method testDefault.

public void testDefault() {
    TimeValue defaultValue = TimeValue.timeValueMillis(randomIntBetween(0, 1000000));
    Setting<TimeValue> setting = Setting.positiveTimeSetting("my.time.value", defaultValue, Property.NodeScope);
    assertFalse(setting.isGroupSetting());
    String aDefault = setting.getDefaultRaw(Settings.EMPTY);
    assertEquals(defaultValue.millis() + "ms", aDefault);
    assertEquals(defaultValue.millis(), setting.get(Settings.EMPTY).millis());
    assertEquals(defaultValue, setting.getDefault(Settings.EMPTY));
    Setting<String> secondaryDefault = new Setting<>("foo.bar", (s) -> s.get("old.foo.bar", "some_default"), Function.identity(), Property.NodeScope);
    assertEquals("some_default", secondaryDefault.get(Settings.EMPTY));
    assertEquals("42", secondaryDefault.get(Settings.builder().put("old.foo.bar", 42).build()));
    Setting<String> secondaryDefaultViaSettings = new Setting<>("foo.bar", secondaryDefault, Function.identity(), Property.NodeScope);
    assertEquals("some_default", secondaryDefaultViaSettings.get(Settings.EMPTY));
    assertEquals("42", secondaryDefaultViaSettings.get(Settings.builder().put("old.foo.bar", 42).build()));
    // It gets more complicated when there are two settings objects....
    Settings hasFallback = Settings.builder().put("foo.bar", "o").build();
    Setting<String> fallsback = new Setting<>("foo.baz", secondaryDefault, Function.identity(), Property.NodeScope);
    assertEquals("o", fallsback.get(hasFallback));
    assertEquals("some_default", fallsback.get(Settings.EMPTY));
    assertEquals("some_default", fallsback.get(Settings.EMPTY, Settings.EMPTY));
    assertEquals("o", fallsback.get(Settings.EMPTY, hasFallback));
    assertEquals("o", fallsback.get(hasFallback, Settings.EMPTY));
    assertEquals("a", fallsback.get(Settings.builder().put("foo.bar", "a").build(), Settings.builder().put("foo.bar", "b").build()));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 95 with TimeValue

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue in project elasticsearch by elastic.

the class SettingTests method testTimeValue.

public void testTimeValue() {
    final TimeValue random = TimeValue.parseTimeValue(randomTimeValue(), "test");
    Setting<TimeValue> setting = Setting.timeSetting("foo", random);
    assertThat(setting.get(Settings.EMPTY), equalTo(random));
    final int factor = randomIntBetween(1, 10);
    setting = Setting.timeSetting("foo", (s) -> TimeValue.timeValueMillis(random.getMillis() * factor), TimeValue.ZERO);
    assertThat(setting.get(Settings.builder().put("foo", "12h").build()), equalTo(TimeValue.timeValueHours(12)));
    assertThat(setting.get(Settings.EMPTY).getMillis(), equalTo(random.getMillis() * factor));
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) Arrays(java.util.Arrays) Property(org.elasticsearch.common.settings.Setting.Property) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) TimeValue(org.elasticsearch.common.unit.TimeValue) Map(java.util.Map) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) ESTestCase(org.elasticsearch.test.ESTestCase) Tuple(org.elasticsearch.common.collect.Tuple) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

TimeValue (org.elasticsearch.common.unit.TimeValue)169 SearchResponse (org.elasticsearch.action.search.SearchResponse)37 ArrayList (java.util.ArrayList)28 IOException (java.io.IOException)27 ClusterState (org.elasticsearch.cluster.ClusterState)26 SearchHit (org.elasticsearch.search.SearchHit)26 CountDownLatch (java.util.concurrent.CountDownLatch)18 Settings (org.elasticsearch.common.settings.Settings)18 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)17 Map (java.util.Map)16 Supplier (org.apache.logging.log4j.util.Supplier)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 List (java.util.List)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 TimeUnit (java.util.concurrent.TimeUnit)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 HashMap (java.util.HashMap)10 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)10