Search in sources :

Example 46 with Version

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

the class OpenSearchRestTestCase method expectTranslogRetentionWarning.

protected static void expectTranslogRetentionWarning(Request request) {
    final List<String> expectedWarnings = Collections.singletonList("Translog retention settings [index.translog.retention.age] " + "and [index.translog.retention.size] are deprecated and effectively ignored. They will be removed in a future version.");
    final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
    if (nodeVersions.stream().allMatch(version -> version.onOrAfter(LegacyESVersion.V_7_7_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.equals(expectedWarnings) == false);
        request.setOptions(requestOptions);
    } else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(LegacyESVersion.V_7_7_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
        request.setOptions(requestOptions);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SSLContext(javax.net.ssl.SSLContext) Arrays(java.util.Arrays) WarningsHandler(org.opensearch.client.WarningsHandler) Collections.unmodifiableList(java.util.Collections.unmodifiableList) HttpStatus(org.apache.http.HttpStatus) SnapshotState(org.opensearch.snapshots.SnapshotState) Version(org.opensearch.Version) KeyStoreException(java.security.KeyStoreException) Request(org.opensearch.client.Request) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Header(org.apache.http.Header) EntityUtils(org.apache.http.util.EntityUtils) Strings(org.opensearch.common.Strings) Collections.sort(java.util.Collections.sort) XContentParser(org.opensearch.common.xcontent.XContentParser) SSLIOSessionStrategy(org.apache.http.nio.conn.ssl.SSLIOSessionStrategy) Matchers.everyItem(org.hamcrest.Matchers.everyItem) SSLContexts(org.apache.http.ssl.SSLContexts) After(org.junit.After) Map(java.util.Map) RestClient(org.opensearch.client.RestClient) RestClientBuilder(org.opensearch.client.RestClientBuilder) Path(java.nio.file.Path) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) Predicate(java.util.function.Predicate) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) ObjectPath(org.opensearch.test.rest.yaml.ObjectPath) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) ReplicationTracker(org.opensearch.index.seqno.ReplicationTracker) KeyStore(java.security.KeyStore) KeyManagementException(java.security.KeyManagementException) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CheckedRunnable(org.opensearch.common.CheckedRunnable) IndexSettings(org.opensearch.index.IndexSettings) XContentType(org.opensearch.common.xcontent.XContentType) Pattern(java.util.regex.Pattern) Matchers.anyOf(org.hamcrest.Matchers.anyOf) Response(org.opensearch.client.Response) Matchers.in(org.hamcrest.Matchers.in) PathUtils(org.opensearch.common.io.PathUtils) Builder(org.opensearch.client.RequestOptions.Builder) RequestOptions(org.opensearch.client.RequestOptions) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LegacyESVersion(org.opensearch.LegacyESVersion) Before(org.junit.Before) SetOnce(org.apache.lucene.util.SetOnce) ListTasksAction(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksAction) Files(java.nio.file.Files) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) InputStreamReader(java.io.InputStreamReader) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) IOUtils(org.opensearch.core.internal.io.IOUtils) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) HttpPut(org.apache.http.client.methods.HttpPut) ResponseException(org.opensearch.client.ResponseException) BasicHeader(org.apache.http.message.BasicHeader) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) XContentMapValues(org.opensearch.common.xcontent.support.XContentMapValues) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) BufferedReader(java.io.BufferedReader) HttpHost(org.apache.http.HttpHost) DeprecationHandler(org.opensearch.common.xcontent.DeprecationHandler) Collections(java.util.Collections) InputStream(java.io.InputStream) RestClientBuilder(org.opensearch.client.RestClientBuilder) Builder(org.opensearch.client.RequestOptions.Builder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 47 with Version

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

the class PersistentTasksCustomMetadataTests method testMinVersionSerialization.

public void testMinVersionSerialization() throws IOException {
    PersistentTasksCustomMetadata.Builder tasks = PersistentTasksCustomMetadata.builder();
    Version minVersion = allReleasedVersions().stream().filter(Version::isRelease).findFirst().orElseThrow(NoSuchElementException::new);
    final Version streamVersion = randomVersionBetween(random(), minVersion, getPreviousVersion(Version.CURRENT));
    tasks.addTask("test_compatible_version", TestPersistentTasksExecutor.NAME, new TestParams(null, randomVersionBetween(random(), minVersion, streamVersion), randomBoolean() ? Optional.empty() : Optional.of("test")), randomAssignment());
    tasks.addTask("test_incompatible_version", TestPersistentTasksExecutor.NAME, new TestParams(null, randomVersionBetween(random(), compatibleFutureVersion(streamVersion), Version.CURRENT), randomBoolean() ? Optional.empty() : Optional.of("test")), randomAssignment());
    final BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(streamVersion);
    Set<String> features = new HashSet<>();
    if (randomBoolean()) {
        features.add("test");
    }
    out.setFeatures(features);
    tasks.build().writeTo(out);
    final StreamInput input = out.bytes().streamInput();
    input.setVersion(streamVersion);
    PersistentTasksCustomMetadata read = new PersistentTasksCustomMetadata(new NamedWriteableAwareStreamInput(input, getNamedWriteableRegistry()));
    assertThat(read.taskMap().keySet(), equalTo(Collections.singleton("test_compatible_version")));
}
Also used : VersionUtils.compatibleFutureVersion(org.opensearch.test.VersionUtils.compatibleFutureVersion) Version(org.opensearch.Version) VersionUtils.getPreviousVersion(org.opensearch.test.VersionUtils.getPreviousVersion) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) Builder(org.opensearch.persistent.PersistentTasksCustomMetadata.Builder) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) TestParams(org.opensearch.persistent.TestPersistentTasksPlugin.TestParams) NoSuchElementException(java.util.NoSuchElementException) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) HashSet(java.util.HashSet)

Example 48 with Version

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

the class RepositoryDataTests method testInitIndices.

public void testInitIndices() {
    final int numSnapshots = randomIntBetween(1, 30);
    final Map<String, SnapshotId> snapshotIds = new HashMap<>(numSnapshots);
    final Map<String, SnapshotState> snapshotStates = new HashMap<>(numSnapshots);
    final Map<String, Version> snapshotVersions = new HashMap<>(numSnapshots);
    for (int i = 0; i < numSnapshots; i++) {
        final SnapshotId snapshotId = new SnapshotId(randomAlphaOfLength(8), UUIDs.randomBase64UUID());
        snapshotIds.put(snapshotId.getUUID(), snapshotId);
        snapshotStates.put(snapshotId.getUUID(), randomFrom(SnapshotState.values()));
        snapshotVersions.put(snapshotId.getUUID(), randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()));
    }
    RepositoryData repositoryData = new RepositoryData(EMPTY_REPO_GEN, snapshotIds, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), ShardGenerations.EMPTY, IndexMetaDataGenerations.EMPTY);
    // test that initializing indices works
    Map<IndexId, List<SnapshotId>> indices = randomIndices(snapshotIds);
    RepositoryData newRepoData = new RepositoryData(repositoryData.getGenId(), snapshotIds, snapshotStates, snapshotVersions, indices, ShardGenerations.EMPTY, IndexMetaDataGenerations.EMPTY);
    List<SnapshotId> expected = new ArrayList<>(repositoryData.getSnapshotIds());
    Collections.sort(expected);
    List<SnapshotId> actual = new ArrayList<>(newRepoData.getSnapshotIds());
    Collections.sort(actual);
    assertEquals(expected, actual);
    for (IndexId indexId : indices.keySet()) {
        assertEquals(indices.get(indexId), newRepoData.getSnapshots(indexId));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SnapshotId(org.opensearch.snapshots.SnapshotId) SnapshotState(org.opensearch.snapshots.SnapshotState) Version(org.opensearch.Version) ArrayList(java.util.ArrayList) List(java.util.List)

Example 49 with Version

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

the class RestMainActionTests method testGetResponse.

public void testGetResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAlphaOfLengthBetween(10, 20);
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final boolean prettyPrint = randomBoolean();
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
    XContentBuilder builder = JsonXContent.contentBuilder();
    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertThat(response.status(), equalTo(RestStatus.OK));
    assertThat(response.content().length(), greaterThan(0));
    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = BytesReference.bytes(responseBuilder);
    assertEquals(xcontentBytes, response.content());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) HashMap(java.util.HashMap) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestRequest(org.opensearch.rest.RestRequest) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) Version(org.opensearch.Version) MainResponse(org.opensearch.action.main.MainResponse) Build(org.opensearch.Build) BytesRestResponse(org.opensearch.rest.BytesRestResponse) ClusterName(org.opensearch.cluster.ClusterName) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 50 with Version

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

the class SearchHitTests method testSerializeShardTarget.

public void testSerializeShardTarget() throws Exception {
    String clusterAlias = randomBoolean() ? null : "cluster_alias";
    SearchShardTarget target = new SearchShardTarget("_node_id", new ShardId(new Index("_index", "_na_"), 0), clusterAlias, OriginalIndices.NONE);
    Map<String, SearchHits> innerHits = new HashMap<>();
    SearchHit innerHit1 = new SearchHit(0, "_id", null, null);
    innerHit1.shard(target);
    SearchHit innerInnerHit2 = new SearchHit(0, "_id", null, null);
    innerInnerHit2.shard(target);
    innerHits.put("1", new SearchHits(new SearchHit[] { innerInnerHit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f));
    innerHit1.setInnerHits(innerHits);
    SearchHit innerHit2 = new SearchHit(0, "_id", null, null);
    innerHit2.shard(target);
    SearchHit innerHit3 = new SearchHit(0, "_id", null, null);
    innerHit3.shard(target);
    innerHits = new HashMap<>();
    SearchHit hit1 = new SearchHit(0, "_id", null, null);
    innerHits.put("1", new SearchHits(new SearchHit[] { innerHit1, innerHit2 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f));
    innerHits.put("2", new SearchHits(new SearchHit[] { innerHit3 }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1f));
    hit1.shard(target);
    hit1.setInnerHits(innerHits);
    SearchHit hit2 = new SearchHit(0, "_id", null, null);
    hit2.shard(target);
    SearchHits hits = new SearchHits(new SearchHit[] { hit1, hit2 }, new TotalHits(2, TotalHits.Relation.EQUAL_TO), 1f);
    Version version = VersionUtils.randomVersion(random());
    SearchHits results = copyWriteable(hits, getNamedWriteableRegistry(), SearchHits::new, version);
    SearchShardTarget deserializedTarget = results.getAt(0).getShard();
    assertThat(deserializedTarget, equalTo(target));
    assertThat(results.getAt(0).getInnerHits().get("1").getAt(0).getShard(), notNullValue());
    assertThat(results.getAt(0).getInnerHits().get("1").getAt(0).getInnerHits().get("1").getAt(0).getShard(), notNullValue());
    assertThat(results.getAt(0).getInnerHits().get("1").getAt(1).getShard(), notNullValue());
    assertThat(results.getAt(0).getInnerHits().get("2").getAt(0).getShard(), notNullValue());
    for (SearchHit hit : results) {
        assertEquals(clusterAlias, hit.getClusterAlias());
        if (hit.getInnerHits() != null) {
            for (SearchHits innerhits : hit.getInnerHits().values()) {
                for (SearchHit innerHit : innerhits) {
                    assertEquals(clusterAlias, innerHit.getClusterAlias());
                }
            }
        }
    }
    assertThat(results.getAt(1).getShard(), equalTo(target));
}
Also used : ShardId(org.opensearch.index.shard.ShardId) TotalHits(org.apache.lucene.search.TotalHits) HashMap(java.util.HashMap) Version(org.opensearch.Version) Index(org.opensearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString)

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