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();
}
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;
}
}
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()));
}
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()));
}
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;
}
};
}
Aggregations