Search in sources :

Example 31 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class StreamOutput method writeException.

private void writeException(Throwable rootException, Throwable throwable, int nestedLevel) throws IOException {
    if (throwable == null) {
        writeBoolean(false);
    } else if (nestedLevel > MAX_NESTED_EXCEPTION_LEVEL) {
        assert failOnTooManyNestedExceptions(rootException);
        writeException(new IllegalStateException("too many nested exceptions"));
    } else {
        writeBoolean(true);
        boolean writeCause = true;
        boolean writeMessage = true;
        if (throwable instanceof CorruptIndexException) {
            writeVInt(1);
            writeOptionalString(((CorruptIndexException) throwable).getOriginalMessage());
            writeOptionalString(((CorruptIndexException) throwable).getResourceDescription());
            writeMessage = false;
        } else if (throwable instanceof IndexFormatTooNewException) {
            writeVInt(2);
            writeOptionalString(((IndexFormatTooNewException) throwable).getResourceDescription());
            writeInt(((IndexFormatTooNewException) throwable).getVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMinVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMaxVersion());
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof IndexFormatTooOldException) {
            writeVInt(3);
            IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
            writeOptionalString(t.getResourceDescription());
            if (t.getVersion() == null) {
                writeBoolean(false);
                writeOptionalString(t.getReason());
            } else {
                writeBoolean(true);
                writeInt(t.getVersion());
                writeInt(t.getMinVersion());
                writeInt(t.getMaxVersion());
            }
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof NullPointerException) {
            writeVInt(4);
            writeCause = false;
        } else if (throwable instanceof NumberFormatException) {
            writeVInt(5);
            writeCause = false;
        } else if (throwable instanceof IllegalArgumentException) {
            writeVInt(6);
        } else if (throwable instanceof AlreadyClosedException) {
            writeVInt(7);
        } else if (throwable instanceof EOFException) {
            writeVInt(8);
            writeCause = false;
        } else if (throwable instanceof SecurityException) {
            writeVInt(9);
        } else if (throwable instanceof StringIndexOutOfBoundsException) {
            writeVInt(10);
            writeCause = false;
        } else if (throwable instanceof ArrayIndexOutOfBoundsException) {
            writeVInt(11);
            writeCause = false;
        } else if (throwable instanceof FileNotFoundException) {
            writeVInt(12);
            writeCause = false;
        } else if (throwable instanceof FileSystemException) {
            writeVInt(13);
            if (throwable instanceof NoSuchFileException) {
                writeVInt(0);
            } else if (throwable instanceof NotDirectoryException) {
                writeVInt(1);
            } else if (throwable instanceof DirectoryNotEmptyException) {
                writeVInt(2);
            } else if (throwable instanceof AtomicMoveNotSupportedException) {
                writeVInt(3);
            } else if (throwable instanceof FileAlreadyExistsException) {
                writeVInt(4);
            } else if (throwable instanceof AccessDeniedException) {
                writeVInt(5);
            } else if (throwable instanceof FileSystemLoopException) {
                writeVInt(6);
            } else {
                writeVInt(7);
            }
            writeOptionalString(((FileSystemException) throwable).getFile());
            writeOptionalString(((FileSystemException) throwable).getOtherFile());
            writeOptionalString(((FileSystemException) throwable).getReason());
            writeCause = false;
        } else if (throwable instanceof IllegalStateException) {
            writeVInt(14);
        } else if (throwable instanceof LockObtainFailedException) {
            writeVInt(15);
        } else if (throwable instanceof InterruptedException) {
            writeVInt(16);
            writeCause = false;
        } else if (throwable instanceof IOException) {
            writeVInt(17);
        } else if (throwable instanceof OpenSearchRejectedExecutionException) {
            writeVInt(18);
            writeBoolean(((OpenSearchRejectedExecutionException) throwable).isExecutorShutdown());
            writeCause = false;
        } else {
            final OpenSearchException ex;
            if (throwable instanceof OpenSearchException && OpenSearchException.isRegistered(throwable.getClass(), version)) {
                ex = (OpenSearchException) throwable;
            } else {
                ex = new NotSerializableExceptionWrapper(throwable);
            }
            writeVInt(0);
            writeVInt(OpenSearchException.getId(ex.getClass()));
            ex.writeTo(this);
            return;
        }
        if (writeMessage) {
            writeOptionalString(throwable.getMessage());
        }
        if (writeCause) {
            writeException(rootException, throwable.getCause(), nestedLevel + 1);
        }
        OpenSearchException.writeStackTraces(throwable, this, (o, t) -> o.writeException(rootException, t, nestedLevel + 1));
    }
}
Also used : OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) DateTimeZone(org.joda.time.DateTimeZone) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) Date(java.util.Date) Writer(org.opensearch.common.io.stream.Writeable.Writer) ZonedDateTime(java.time.ZonedDateTime) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Version(org.opensearch.Version) BitUtil(org.apache.lucene.util.BitUtil) OpenSearchException(org.opensearch.OpenSearchException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) Map(java.util.Map) BigInteger(java.math.BigInteger) EnumSet(java.util.EnumSet) TimeValue(org.opensearch.common.unit.TimeValue) JodaCompatibleZonedDateTime(org.opensearch.script.JodaCompatibleZonedDateTime) BytesRef(org.apache.lucene.util.BytesRef) Collection(java.util.Collection) FileSystemException(java.nio.file.FileSystemException) ReadableInstant(org.joda.time.ReadableInstant) Set(java.util.Set) Instant(java.time.Instant) EOFException(java.io.EOFException) Nullable(org.opensearch.common.Nullable) FileNotFoundException(java.io.FileNotFoundException) ZoneId(java.time.ZoneId) List(java.util.List) BytesArray(org.opensearch.common.bytes.BytesArray) AccessDeniedException(java.nio.file.AccessDeniedException) BytesReference(org.opensearch.common.bytes.BytesReference) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ClusterState(org.opensearch.cluster.ClusterState) SecureString(org.opensearch.common.settings.SecureString) FileSystemLoopException(java.nio.file.FileSystemLoopException) LinkedHashSet(java.util.LinkedHashSet) IntFunction(java.util.function.IntFunction) OutputStream(java.io.OutputStream) CharArrays(org.opensearch.common.CharArrays) Iterator(java.util.Iterator) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) GeoPoint(org.opensearch.common.geo.GeoPoint) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) Collections(java.util.Collections) Text(org.opensearch.common.text.Text) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) FileSystemException(java.nio.file.FileSystemException) NotDirectoryException(java.nio.file.NotDirectoryException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) OpenSearchException(org.opensearch.OpenSearchException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 32 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class FullClusterRestartIT method testSystemIndexMetadataIsUpgraded.

@SuppressWarnings("unchecked")
public void testSystemIndexMetadataIsUpgraded() throws Exception {
    final String systemIndexWarning = "this request accesses system indices: [.tasks], but in a future major version, direct " + "access to system indices will be prevented by default";
    if (isRunningAgainstOldCluster()) {
        // create index
        Request createTestIndex = new Request("PUT", "/test_index_old");
        createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0, \"index.number_of_shards\": 1}}");
        client().performRequest(createTestIndex);
        Request bulk = new Request("POST", "/_bulk");
        bulk.addParameter("refresh", "true");
        bulk.setJsonEntity("{\"index\": {\"_index\": \"test_index_old\"}}\n" + "{\"f1\": \"v1\", \"f2\": \"v2\"}\n");
        client().performRequest(bulk);
        // start a async reindex job
        Request reindex = new Request("POST", "/_reindex");
        reindex.setJsonEntity("{\n" + "  \"source\":{\n" + "    \"index\":\"test_index_old\"\n" + "  },\n" + "  \"dest\":{\n" + "    \"index\":\"test_index_reindex\"\n" + "  }\n" + "}");
        reindex.addParameter("wait_for_completion", "false");
        Map<String, Object> response = entityAsMap(client().performRequest(reindex));
        String taskId = (String) response.get("task");
        // wait for task
        Request getTask = new Request("GET", "/_tasks/" + taskId);
        getTask.addParameter("wait_for_completion", "true");
        client().performRequest(getTask);
        // make sure .tasks index exists
        Request getTasksIndex = new Request("GET", "/.tasks");
        getTasksIndex.addParameter("allow_no_indices", "false");
        if (getOldClusterVersion().before(LegacyESVersion.V_7_0_0)) {
            getTasksIndex.addParameter("include_type_name", "false");
        }
        getTasksIndex.setOptions(expectVersionSpecificWarnings(v -> {
            v.current(systemIndexWarning);
            v.compatible(systemIndexWarning);
        }));
        assertBusy(() -> {
            try {
                assertThat(client().performRequest(getTasksIndex).getStatusLine().getStatusCode(), is(200));
            } catch (ResponseException e) {
                throw new AssertionError(".tasks index does not exist yet");
            }
        });
        // upgraded properly. If we're already on 8.x, skip this part of the test.
        if (minimumNodeVersion().before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
            // Create an alias to make sure it gets upgraded properly
            Request putAliasRequest = new Request("POST", "/_aliases");
            putAliasRequest.setJsonEntity("{\n" + "  \"actions\": [\n" + "    {\"add\":  {\"index\":  \".tasks\", \"alias\": \"test-system-alias\"}},\n" + "    {\"add\":  {\"index\":  \"test_index_reindex\", \"alias\": \"test-system-alias\"}}\n" + "  ]\n" + "}");
            assertThat(client().performRequest(putAliasRequest).getStatusLine().getStatusCode(), is(200));
        }
    } else {
        assertBusy(() -> {
            Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata");
            Map<String, Object> indices = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get("metadata.indices");
            // Make sure our non-system index is still non-system
            assertThat(new XContentTestUtils.JsonMapView(indices).get("test_index_old.system"), is(false));
            // Can't get the .tasks index via JsonMapView because it splits on `.`
            assertThat(indices, hasKey(".tasks"));
            XContentTestUtils.JsonMapView tasksIndex = new XContentTestUtils.JsonMapView((Map<String, Object>) indices.get(".tasks"));
            assertThat(tasksIndex.get("system"), is(true));
            // If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
            final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
            assertThat(tasksCreatedVersionString, notNullValue());
            final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
            if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
                // Verify that the alias survived the upgrade
                Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
                getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
                    v.current(systemIndexWarning);
                    v.compatible(systemIndexWarning);
                }));
                Map<String, Object> aliasResponse = entityAsMap(client().performRequest(getAliasRequest));
                assertThat(aliasResponse, hasKey(".tasks"));
                assertThat(aliasResponse, hasKey("test_index_reindex"));
            }
        });
    }
}
Also used : CheckedFunction(org.opensearch.common.CheckedFunction) SETTING_ALLOCATION_MAX_RETRY(org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY) Version(org.opensearch.Version) Request(org.opensearch.client.Request) Matchers.hasKey(org.hamcrest.Matchers.hasKey) EntityUtils(org.apache.http.util.EntityUtils) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) RestClient(org.opensearch.client.RestClient) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) NotEqualMessageBuilder(org.opensearch.test.NotEqualMessageBuilder) Collection(java.util.Collection) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING(org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING) OpenSearchRestTestCase(org.opensearch.test.rest.OpenSearchRestTestCase) Base64(java.util.Base64) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) Pattern(java.util.regex.Pattern) Response(org.opensearch.client.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentFactory.jsonBuilder(org.opensearch.common.xcontent.XContentFactory.jsonBuilder) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LegacyESVersion(org.opensearch.LegacyESVersion) Booleans(org.opensearch.common.Booleans) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Collections.singletonMap(java.util.Collections.singletonMap) MetadataIndexStateService(org.opensearch.cluster.metadata.MetadataIndexStateService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) IOException(java.io.IOException) XContentTestUtils(org.opensearch.test.XContentTestUtils) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) ResponseException(org.opensearch.client.ResponseException) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) SYSTEM_INDEX_ENFORCEMENT_VERSION(org.opensearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION) XContentMapValues(org.opensearch.common.xcontent.support.XContentMapValues) ResponseException(org.opensearch.client.ResponseException) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentTestUtils(org.opensearch.test.XContentTestUtils)

Example 33 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class FullClusterRestartIT method testClusterState.

public void testClusterState() throws Exception {
    if (isRunningAgainstOldCluster()) {
        XContentBuilder mappingsAndSettings = jsonBuilder();
        mappingsAndSettings.startObject();
        mappingsAndSettings.field("index_patterns", index);
        mappingsAndSettings.field("order", "1000");
        {
            mappingsAndSettings.startObject("settings");
            mappingsAndSettings.field("number_of_shards", 1);
            mappingsAndSettings.field("number_of_replicas", 0);
            mappingsAndSettings.endObject();
        }
        mappingsAndSettings.endObject();
        Request createTemplate = new Request("PUT", "/_template/template_1");
        createTemplate.setJsonEntity(Strings.toString(mappingsAndSettings));
        client().performRequest(createTemplate);
        client().performRequest(new Request("PUT", "/" + index));
    }
    // verifying if we can still read some properties from cluster state api:
    Map<String, Object> clusterState = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
    // Check some global properties:
    String numberOfShards = (String) XContentMapValues.extractValue("metadata.templates.template_1.settings.index.number_of_shards", clusterState);
    assertEquals("1", numberOfShards);
    String numberOfReplicas = (String) XContentMapValues.extractValue("metadata.templates.template_1.settings.index.number_of_replicas", clusterState);
    assertEquals("0", numberOfReplicas);
    // Check some index properties:
    numberOfShards = (String) XContentMapValues.extractValue("metadata.indices." + index + ".settings.index.number_of_shards", clusterState);
    assertEquals("1", numberOfShards);
    numberOfReplicas = (String) XContentMapValues.extractValue("metadata.indices." + index + ".settings.index.number_of_replicas", clusterState);
    assertEquals("0", numberOfReplicas);
    Version version = Version.fromId(Integer.valueOf((String) XContentMapValues.extractValue("metadata.indices." + index + ".settings.index.version.created", clusterState)));
    assertEquals(getOldClusterVersion(), version);
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 34 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class AbstractSearchAsyncAction method sendSearchResponse.

@Override
public void sendSearchResponse(InternalSearchResponse internalSearchResponse, AtomicArray<SearchPhaseResult> queryResults) {
    ShardSearchFailure[] failures = buildShardFailures();
    Boolean allowPartialResults = request.allowPartialSearchResults();
    assert allowPartialResults != null : "SearchRequest missing setting for allowPartialSearchResults";
    if (allowPartialResults == false && failures.length > 0) {
        raisePhaseFailure(new SearchPhaseExecutionException("", "Shard failures", null, failures));
    } else {
        final Version minNodeVersion = clusterState.nodes().getMinNodeVersion();
        final String scrollId = request.scroll() != null ? TransportSearchHelper.buildScrollId(queryResults, minNodeVersion) : null;
        final String searchContextId;
        if (buildPointInTimeFromSearchResults()) {
            searchContextId = SearchContextId.encode(queryResults.asList(), aliasFilter, minNodeVersion);
        } else {
            if (request.source() != null && request.source().pointInTimeBuilder() != null) {
                searchContextId = request.source().pointInTimeBuilder().getId();
            } else {
                searchContextId = null;
            }
        }
        listener.onResponse(buildSearchResponse(internalSearchResponse, failures, scrollId, searchContextId));
    }
}
Also used : Version(org.opensearch.Version) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 35 with Version

use of org.opensearch.Version in project OpenSearch by opensearch-project.

the class MetadataCreateIndexService method aggregateIndexSettings.

/**
 * Validates and creates the settings for the new index based on the explicitly configured settings via the
 * {@link CreateIndexClusterStateUpdateRequest}, inherited from templates and, if recovering from another index (ie. split, shrink,
 * clone), the resize settings.
 *
 * The template mappings are applied in the order they are encountered in the list (clients should make sure the lower index, closer
 * to the head of the list, templates have the highest {@link IndexTemplateMetadata#order()})
 *
 * @return the aggregated settings for the new index
 */
static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClusterStateUpdateRequest request, Settings combinedTemplateSettings, @Nullable IndexMetadata sourceMetadata, Settings settings, IndexScopedSettings indexScopedSettings, ShardLimitValidator shardLimitValidator, Set<IndexSettingProvider> indexSettingProviders) {
    // Create builders for the template and request settings. We transform these into builders
    // because we may want settings to be "removed" from these prior to being set on the new
    // index (see more comments below)
    final Settings.Builder templateSettings = Settings.builder().put(combinedTemplateSettings);
    final Settings.Builder requestSettings = Settings.builder().put(request.settings());
    final Settings.Builder indexSettingsBuilder = Settings.builder();
    if (sourceMetadata == null) {
        final Settings.Builder additionalIndexSettings = Settings.builder();
        final Settings templateAndRequestSettings = Settings.builder().put(combinedTemplateSettings).put(request.settings()).build();
        final boolean isDataStreamIndex = request.dataStreamName() != null;
        // additionalIndexSettings map
        for (IndexSettingProvider provider : indexSettingProviders) {
            additionalIndexSettings.put(provider.getAdditionalIndexSettings(request.index(), isDataStreamIndex, templateAndRequestSettings));
        }
        // value).
        for (String explicitSetting : additionalIndexSettings.keys()) {
            if (templateSettings.keys().contains(explicitSetting) && templateSettings.get(explicitSetting) == null) {
                logger.debug("removing default [{}] setting as it in set to null in a template for [{}] creation", explicitSetting, request.index());
                additionalIndexSettings.remove(explicitSetting);
                templateSettings.remove(explicitSetting);
            }
            if (requestSettings.keys().contains(explicitSetting) && requestSettings.get(explicitSetting) == null) {
                logger.debug("removing default [{}] setting as it in set to null in the request for [{}] creation", explicitSetting, request.index());
                additionalIndexSettings.remove(explicitSetting);
                requestSettings.remove(explicitSetting);
            }
        }
        // Finally, we actually add the explicit defaults prior to the template settings and the
        // request settings, so that the precedence goes:
        // Explicit Defaults -> Template -> Request -> Necessary Settings (# of shards, uuid, etc)
        indexSettingsBuilder.put(additionalIndexSettings.build());
        indexSettingsBuilder.put(templateSettings.build());
    }
    // now, put the request settings, so they override templates
    indexSettingsBuilder.put(requestSettings.build());
    if (indexSettingsBuilder.get(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey()) == null) {
        final DiscoveryNodes nodes = currentState.nodes();
        final Version createdVersion = Version.min(Version.CURRENT, nodes.getSmallestNonClientNodeVersion());
        indexSettingsBuilder.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), createdVersion);
    }
    if (INDEX_NUMBER_OF_SHARDS_SETTING.exists(indexSettingsBuilder) == false) {
        final int numberOfShards;
        if (INDEX_NUMBER_OF_SHARDS_SETTING.exists(settings)) {
            numberOfShards = INDEX_NUMBER_OF_SHARDS_SETTING.get(settings);
        } else {
            numberOfShards = getNumberOfShards(indexSettingsBuilder);
        }
        indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards);
    }
    if (INDEX_NUMBER_OF_REPLICAS_SETTING.exists(indexSettingsBuilder) == false) {
        indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, INDEX_NUMBER_OF_REPLICAS_SETTING.get(settings));
    }
    if (settings.get(SETTING_AUTO_EXPAND_REPLICAS) != null && indexSettingsBuilder.get(SETTING_AUTO_EXPAND_REPLICAS) == null) {
        indexSettingsBuilder.put(SETTING_AUTO_EXPAND_REPLICAS, settings.get(SETTING_AUTO_EXPAND_REPLICAS));
    }
    if (indexSettingsBuilder.get(SETTING_CREATION_DATE) == null) {
        indexSettingsBuilder.put(SETTING_CREATION_DATE, Instant.now().toEpochMilli());
    }
    indexSettingsBuilder.put(IndexMetadata.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName());
    indexSettingsBuilder.put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID());
    if (sourceMetadata != null) {
        assert request.resizeType() != null;
        prepareResizeIndexSettings(currentState, indexSettingsBuilder, request.recoverFrom(), request.index(), request.resizeType(), request.copySettings(), indexScopedSettings);
    }
    Settings indexSettings = indexSettingsBuilder.build();
    /*
         * We can not validate settings until we have applied templates, otherwise we do not know the actual settings
         * that will be used to create this index.
         */
    shardLimitValidator.validateShardLimit(indexSettings, currentState);
    if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings) == false && IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings).onOrAfter(Version.V_2_0_0)) {
        throw new IllegalArgumentException("Creating indices with soft-deletes disabled is no longer supported. " + "Please do not specify a value for setting [index.soft_deletes.enabled].");
    }
    validateTranslogRetentionSettings(indexSettings);
    validateStoreTypeSettings(indexSettings);
    return indexSettings;
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IndexSettingProvider(org.opensearch.index.shard.IndexSettingProvider) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Aggregations

Version (org.opensearch.Version)254 Settings (org.opensearch.common.settings.Settings)90 LegacyESVersion (org.opensearch.LegacyESVersion)85 ArrayList (java.util.ArrayList)62 IOException (java.io.IOException)57 List (java.util.List)57 Map (java.util.Map)54 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)48 HashMap (java.util.HashMap)40 TimeValue (org.opensearch.common.unit.TimeValue)40 Collections (java.util.Collections)39 BytesReference (org.opensearch.common.bytes.BytesReference)39 HashSet (java.util.HashSet)38 Set (java.util.Set)38 ClusterState (org.opensearch.cluster.ClusterState)38 Collectors (java.util.stream.Collectors)37 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)37 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)35 StreamInput (org.opensearch.common.io.stream.StreamInput)33 BytesArray (org.opensearch.common.bytes.BytesArray)30