Skip to content

Commit

Permalink
Switching to a hardcoded version field for BWC purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts195 committed Sep 27, 2023
1 parent 104c49a commit c99dae1
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 28 deletions.
8 changes: 0 additions & 8 deletions server/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,6 @@ public String qualifiedVersion() {
return version;
}

/**
* Get the build version without any suffices like "-SNAPSHOT" or "-rc1".
* @return the build version with no suffix
*/
public String unqualifiedVersion() {
return version.replaceFirst("-.*", "");
}

public boolean isProductionRelease() {
return isSnapshot() == false && version.matches(".*(-alpha\\d+)|(-beta\\d+)|(-rc\\d+)") == false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
package org.elasticsearch.xpack.core.ml;

import org.elasticsearch.Build;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.template.TemplateUtils;

import java.util.Map;
Expand All @@ -34,7 +34,7 @@ public static String indexName() {
public static String mapping() {
return TemplateUtils.loadTemplate(
"/ml/config_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(CONFIG_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
package org.elasticsearch.xpack.core.ml;

import org.elasticsearch.Build;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.template.TemplateUtils;

import java.util.Map;
Expand All @@ -32,7 +32,7 @@ public static String indexName() {
public static String mapping() {
return TemplateUtils.loadTemplate(
"/ml/meta_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(META_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.core.ml;

import org.elasticsearch.Build;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterState;
Expand Down Expand Up @@ -40,7 +39,7 @@ public static String wrappedMapping() {
public static String mapping() {
return TemplateUtils.loadTemplate(
"/ml/stats_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(STATS_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Build;
import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
Expand All @@ -28,6 +27,7 @@
import org.elasticsearch.xpack.core.ml.MlMetadata;
import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings;
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.template.TemplateUtils;

import java.util.List;
Expand Down Expand Up @@ -213,7 +213,7 @@ public static void createAnnotationsIndexIfNecessary(
public static String annotationsMapping() {
return TemplateUtils.loadTemplate(
"/ml/annotations_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(ANNOTATION_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
package org.elasticsearch.xpack.core.ml.inference.persistence;

import org.elasticsearch.Build;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.template.TemplateUtils;

import java.util.Map;
Expand Down Expand Up @@ -51,7 +51,7 @@ public final class InferenceIndexConstants {
public static String mapping() {
return TemplateUtils.loadTemplate(
"/ml/inference_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(INFERENCE_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.core.ml.job.persistence;

import org.elasticsearch.Build;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
Expand Down Expand Up @@ -137,7 +136,7 @@ public static String wrappedResultsMapping() {
public static String resultsMapping() {
return TemplateUtils.loadTemplate(
RESOURCE_PATH + "results_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
RESULTS_MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(RESULTS_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
package org.elasticsearch.xpack.core.ml.notifications;

import org.elasticsearch.Build;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.template.TemplateUtils;

import java.util.Map;
Expand All @@ -24,7 +24,7 @@ private NotificationsIndex() {}
public static String mapping() {
return TemplateUtils.loadTemplate(
RESOURCE_PATH + "notifications_index_mappings.json",
Build.current().unqualifiedVersion(), // Only needed for BWC with pre-8.10.0 nodes
MlIndexAndAlias.BWC_MAPPINGS_VERSION, // Only needed for BWC with pre-8.10.0 nodes
MAPPINGS_VERSION_VARIABLE,
Map.of("xpack.ml.managed.index.version", Integer.toString(NOTIFICATIONS_INDEX_MAPPINGS_VERSION))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
*/
public final class MlIndexAndAlias {

public static final String BWC_MAPPINGS_VERSION = "8.11.0";

private static final Logger logger = LogManager.getLogger(MlIndexAndAlias.class);

// Visible for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.core.ml.job.persistence;

import org.elasticsearch.Build;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
Expand Down Expand Up @@ -41,6 +40,7 @@
import org.elasticsearch.xpack.core.ml.job.results.CategoryDefinition;
import org.elasticsearch.xpack.core.ml.job.results.ReservedFieldNames;
import org.elasticsearch.xpack.core.ml.job.results.Result;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.junit.Assert;
import org.mockito.ArgumentCaptor;

Expand Down Expand Up @@ -154,7 +154,7 @@ public void testMappingRequiresUpdateOnlyProductVersion() {
int newVersion = randomIntBetween(1, 100);
{
ClusterState cs = getClusterStateWithMappingsWithMetadata(
Collections.singletonMap("product_version_only", Build.current().unqualifiedVersion())
Collections.singletonMap("product_version_only", MlIndexAndAlias.BWC_MAPPINGS_VERSION)
);
String[] indices = new String[] { "product_version_only" };
assertArrayEquals(indices, ElasticsearchMappings.mappingRequiresUpdate(cs, indices, newVersion));
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testMappingRequiresUpdateGivenProductVersionAndMappingsVersion() {
int newVersion = currentVersion + randomIntBetween(1, 100);
{
ClusterState cs = getClusterStateWithMappingsWithMetadata(
Collections.singletonMap("both", Build.current().unqualifiedVersion()),
Collections.singletonMap("both", MlIndexAndAlias.BWC_MAPPINGS_VERSION),
Collections.singletonMap(SystemIndexDescriptor.VERSION_META_KEY, currentVersion)
);
String[] indices = new String[] { "both" };
Expand All @@ -213,7 +213,7 @@ public void testMappingRequiresUpdateGivenProductVersionAndMappingsVersion() {
}
{
ClusterState cs = getClusterStateWithMappingsWithMetadata(
Collections.singletonMap("both", Build.current().unqualifiedVersion()),
Collections.singletonMap("both", MlIndexAndAlias.BWC_MAPPINGS_VERSION),
Collections.singletonMap(SystemIndexDescriptor.VERSION_META_KEY, currentVersion)
);
String[] indices = new String[] { "both" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.elasticsearch.xpack.ml.integration;

import org.elasticsearch.Build;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
Expand Down Expand Up @@ -64,6 +63,7 @@
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot;
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles;
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.TimingStats;
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
import org.elasticsearch.xpack.core.ml.utils.ToXContentParams;
import org.elasticsearch.xpack.ml.MlSingleNodeTestCase;
import org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor;
Expand Down Expand Up @@ -519,7 +519,7 @@ private Map<String, Object> getIndexMappingProperties(String index) {
@SuppressWarnings("unchecked")
Map<String, Object> meta = (Map<String, Object>) mappings.get("_meta");
assertThat(meta.keySet(), hasItem("version"));
assertThat(meta.get("version"), equalTo(Build.current().unqualifiedVersion()));
assertThat(meta.get("version"), equalTo(MlIndexAndAlias.BWC_MAPPINGS_VERSION));
assertThat(meta.get("managed_index_mappings_version"), equalTo(AnomalyDetectorsIndex.RESULTS_INDEX_MAPPINGS_VERSION));

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit c99dae1

Please sign in to comment.