Search in sources :

Example 36 with Version

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

the class IndexMetadata method addHumanReadableSettings.

/**
 * Adds human readable version and creation date settings.
 * This method is used to display the settings in a human readable format in REST API
 */
public static Settings addHumanReadableSettings(Settings settings) {
    Settings.Builder builder = Settings.builder().put(settings);
    Version version = SETTING_INDEX_VERSION_CREATED.get(settings);
    if (version != Version.V_EMPTY) {
        builder.put(SETTING_VERSION_CREATED_STRING, version.toString());
    }
    Version versionUpgraded = settings.getAsVersion(SETTING_VERSION_UPGRADED, null);
    if (versionUpgraded != null) {
        builder.put(SETTING_VERSION_UPGRADED_STRING, versionUpgraded.toString());
    }
    Long creationDate = settings.getAsLong(SETTING_CREATION_DATE, null);
    if (creationDate != null) {
        ZonedDateTime creationDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(creationDate), ZoneOffset.UTC);
        builder.put(SETTING_CREATION_DATE_STRING, creationDateTime.toString());
    }
    return builder.build();
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) ZonedDateTime(java.time.ZonedDateTime) Settings(org.opensearch.common.settings.Settings)

Example 37 with Version

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

the class PreConfiguredAnalysisComponent method get.

@Override
public T get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException {
    Version versionCreated = Version.indexCreated(settings);
    synchronized (this) {
        T factory = cache.get(versionCreated);
        if (factory == null) {
            factory = create(versionCreated);
            cache.put(versionCreated, factory);
        }
        return factory;
    }
}
Also used : Version(org.opensearch.Version)

Example 38 with Version

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

the class VersionSensitiveWarningsHandlerTests method testSameVersionCluster.

public void testSameVersionCluster() throws IOException {
    Set<Version> nodeVersions = new HashSet<>();
    nodeVersions.add(Version.CURRENT);
    WarningsHandler handler = expectVersionSpecificWarnings(nodeVersions, (v) -> {
        v.current("expectedCurrent1");
    });
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "unexpected")));
    assertFalse(handler.warningsShouldFailRequest(Collections.emptyList()));
}
Also used : Version(org.opensearch.Version) WarningsHandler(org.opensearch.client.WarningsHandler) VersionSensitiveWarningsHandler(org.opensearch.test.rest.OpenSearchRestTestCase.VersionSensitiveWarningsHandler) HashSet(java.util.HashSet)

Example 39 with Version

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

the class VersionSensitiveWarningsHandlerTests method testMixedVersionCluster.

public void testMixedVersionCluster() throws IOException {
    Set<Version> nodeVersions = new HashSet<>();
    nodeVersions.add(Version.CURRENT);
    nodeVersions.add(Version.CURRENT.minimumIndexCompatibilityVersion());
    WarningsHandler handler = expectVersionSpecificWarnings(nodeVersions, (v) -> {
        v.current("expectedCurrent1");
        v.compatible("Expected legacy warning");
    });
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1")));
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("Expected legacy warning")));
    assertFalse(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "Expected legacy warning")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("expectedCurrent1", "Unexpected legacy warning")));
    assertTrue(handler.warningsShouldFailRequest(Arrays.asList("Unexpected legacy warning")));
    assertFalse(handler.warningsShouldFailRequest(Collections.emptyList()));
}
Also used : Version(org.opensearch.Version) WarningsHandler(org.opensearch.client.WarningsHandler) VersionSensitiveWarningsHandler(org.opensearch.test.rest.OpenSearchRestTestCase.VersionSensitiveWarningsHandler) HashSet(java.util.HashSet)

Example 40 with Version

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

the class DoSection method parseVersionSelector.

private static NodeSelector parseVersionSelector(XContentParser parser) throws IOException {
    if (false == parser.currentToken().isValue()) {
        throw new XContentParseException(parser.getTokenLocation(), "expected [version] to be a value");
    }
    List<VersionRange> skipVersionRanges = SkipSection.parseVersionRanges(parser.text());
    return new NodeSelector() {

        @Override
        public void select(Iterable<Node> nodes) {
            for (Iterator<Node> itr = nodes.iterator(); itr.hasNext(); ) {
                Node node = itr.next();
                if (node.getVersion() == null) {
                    throw new IllegalStateException("expected [version] metadata to be set but got " + node);
                }
                Version version = Version.fromString(node.getVersion());
                boolean skip = skipVersionRanges.stream().anyMatch(v -> v.contains(version));
                if (false == skip) {
                    itr.remove();
                }
            }
        }

        @Override
        public String toString() {
            return "version ranges " + skipVersionRanges;
        }
    };
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Node(org.opensearch.client.Node) HasAttributeNodeSelector(org.opensearch.client.HasAttributeNodeSelector) NodeSelector(org.opensearch.client.NodeSelector) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

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