Search in sources :

Example 41 with Version

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

the class AbstractSimpleTransportTestCase method testHandshakeWithIncompatVersion.

public void testHandshakeWithIncompatVersion() {
    assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
    Version version = LegacyESVersion.fromString("6.0.0");
    try (MockTransportService service = buildService("TS_C", version, Settings.EMPTY)) {
        service.start();
        service.acceptIncomingRequests();
        TransportAddress address = service.boundAddress().publishAddress();
        DiscoveryNode node = new DiscoveryNode("TS_TPC", "TS_TPC", address, emptyMap(), emptySet(), version0);
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1, TransportRequestOptions.Type.BULK, TransportRequestOptions.Type.PING, TransportRequestOptions.Type.RECOVERY, TransportRequestOptions.Type.REG, TransportRequestOptions.Type.STATE);
        expectThrows(ConnectTransportException.class, () -> serviceA.openConnection(node, builder.build()));
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress)

Example 42 with Version

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

the class AbstractSimpleTransportTestCase method testHandshakeUpdatesVersion.

public void testHandshakeUpdatesVersion() throws IOException {
    assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
    Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
    try (MockTransportService service = buildService("TS_C", version, Settings.EMPTY)) {
        service.start();
        service.acceptIncomingRequests();
        TransportAddress address = service.boundAddress().publishAddress();
        DiscoveryNode node = new DiscoveryNode("TS_TPC", "TS_TPC", address, emptyMap(), emptySet(), LegacyESVersion.fromString("2.0.0"));
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1, TransportRequestOptions.Type.BULK, TransportRequestOptions.Type.PING, TransportRequestOptions.Type.RECOVERY, TransportRequestOptions.Type.REG, TransportRequestOptions.Type.STATE);
        try (Transport.Connection connection = serviceA.openConnection(node, builder.build())) {
            // OpenSearch [1.0:3.0) in bwc mode should only "upgrade" to Legacy v7.10.2
            assertEquals(connection.getVersion(), version.onOrAfter(Version.V_1_0_0) && version.before(V_3_0_0) ? LegacyESVersion.V_7_10_2 : version);
        }
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) StubbableTransport(org.opensearch.test.transport.StubbableTransport)

Example 43 with Version

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

the class VersionUtilsTests method testGradleVersionsMatchVersionUtils.

/**
 * Tests that {@link Version#minimumCompatibilityVersion()} and {@link VersionUtils#allReleasedVersions()}
 * agree with the list of wire and index compatible versions we build in gradle.
 */
public void testGradleVersionsMatchVersionUtils() {
    // First check the index compatible versions
    VersionsFromProperty indexCompatible = new VersionsFromProperty("tests.gradle_index_compat_versions");
    List<Version> released = VersionUtils.allReleasedVersions().stream().filter(v -> v.onOrAfter(Version.CURRENT.minimumIndexCompatibilityVersion())).filter(Version::isRelease).collect(toList());
    List<String> releasedIndexCompatible = released.stream().filter(v -> !Version.CURRENT.equals(v)).map(Object::toString).collect(toList());
    assertEquals(releasedIndexCompatible, indexCompatible.released);
    List<String> unreleasedIndexCompatible = new ArrayList<>(VersionUtils.allUnreleasedVersions().stream().filter(v -> v.equals(Version.CURRENT) == false).filter(v -> v.onOrAfter(Version.CURRENT.minimumIndexCompatibilityVersion())).filter(v -> false == v.isAlpha()).map(Object::toString).collect(toCollection(LinkedHashSet::new)));
    assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);
    // Now the wire compatible versions
    VersionsFromProperty wireCompatible = new VersionsFromProperty("tests.gradle_wire_compat_versions");
    Version minimumCompatibleVersion = Version.CURRENT.minimumCompatibilityVersion();
    List<String> releasedWireCompatible = released.stream().filter(v -> !Version.CURRENT.equals(v)).filter(v -> v.onOrAfter(minimumCompatibleVersion)).map(Object::toString).collect(toList());
    assertEquals(releasedWireCompatible, wireCompatible.released);
    List<String> unreleasedWireCompatible = VersionUtils.allUnreleasedVersions().stream().filter(v -> v.equals(Version.CURRENT) == false).filter(v -> v.onOrAfter(minimumCompatibleVersion)).map(Object::toString).collect(toList());
    assertEquals(unreleasedWireCompatible, wireCompatible.unreleased);
}
Also used : Arrays(java.util.Arrays) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Set(java.util.Set) Version(org.opensearch.Version) Tuple(org.opensearch.common.collect.Tuple) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LegacyESVersion(org.opensearch.LegacyESVersion) Booleans(org.opensearch.common.Booleans) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) ArrayList(java.util.ArrayList)

Example 44 with Version

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

the class OpenSearchRestTestCase method minimumNodeVersion.

/**
 * Returns the minimum node version among all nodes of the cluster
 */
protected static Version minimumNodeVersion() throws IOException {
    final Request request = new Request("GET", "_nodes");
    request.addParameter("filter_path", "nodes.*.version");
    final Response response = adminClient().performRequest(request);
    final Map<String, Object> nodes = ObjectPath.createFromResponse(response).evaluate("nodes");
    Version minVersion = null;
    for (Map.Entry<String, Object> node : nodes.entrySet()) {
        @SuppressWarnings("unchecked") Version nodeVersion = Version.fromString((String) ((Map<String, Object>) node.getValue()).get("version"));
        if (minVersion == null || minVersion.after(nodeVersion)) {
            minVersion = nodeVersion;
        }
    }
    assertNotNull(minVersion);
    return minVersion;
}
Also used : Response(org.opensearch.client.Response) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Request(org.opensearch.client.Request) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap)

Example 45 with Version

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

the class OpenSearchRestTestCase method expectSoftDeletesWarning.

protected static void expectSoftDeletesWarning(Request request, String indexName) {
    final List<String> esExpectedWarnings = Collections.singletonList("Creating indices with soft-deletes disabled is deprecated and will be removed in future Elasticsearch versions. " + "Please do not specify value for setting [index.soft_deletes.enabled] of index [" + indexName + "].");
    final List<String> opensearchExpectedWarnings = Collections.singletonList("Creating indices with soft-deletes disabled is deprecated and will be removed in future OpenSearch versions. " + "Please do not specify value for setting [index.soft_deletes.enabled] of index [" + indexName + "].");
    final Builder requestOptions = RequestOptions.DEFAULT.toBuilder();
    if (nodeVersions.stream().allMatch(version -> version.onOrAfter(LegacyESVersion.V_7_6_0) && version.before(Version.V_1_0_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.equals(esExpectedWarnings) == false);
        request.setOptions(requestOptions);
    } else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(LegacyESVersion.V_7_6_0) && version.before(Version.V_1_0_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(esExpectedWarnings) == false);
        request.setOptions(requestOptions);
    }
    if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_1_0_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.equals(opensearchExpectedWarnings) == false);
        request.setOptions(requestOptions);
    } else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(Version.V_1_0_0))) {
        requestOptions.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(opensearchExpectedWarnings) == 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)

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