From 7aba355c7103cefd7f2f4a5ed43d5d8dfd18a9fc Mon Sep 17 00:00:00 2001 From: Bhavana Ramaram Date: Tue, 3 Sep 2024 19:21:23 -0500 Subject: [PATCH] address comments Signed-off-by: Bhavana Ramaram --- .../org/opensearch/ml/common/CommonValue.java | 1 + .../org/opensearch/ml/common/MLConfig.java | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/CommonValue.java b/common/src/main/java/org/opensearch/ml/common/CommonValue.java index 933f00b5ad..06f917ee9d 100644 --- a/common/src/main/java/org/opensearch/ml/common/CommonValue.java +++ b/common/src/main/java/org/opensearch/ml/common/CommonValue.java @@ -575,6 +575,7 @@ public class CommonValue { public static final Version VERSION_2_12_0 = Version.fromString("2.12.0"); public static final Version VERSION_2_13_0 = Version.fromString("2.13.0"); public static final Version VERSION_2_14_0 = Version.fromString("2.14.0"); + public static final Version VERSION_2_15_0 = Version.fromString("2.15.0"); public static final Version VERSION_2_16_0 = Version.fromString("2.16.0"); public static final Version VERSION_2_17_0 = Version.fromString("2.17.0"); } diff --git a/common/src/main/java/org/opensearch/ml/common/MLConfig.java b/common/src/main/java/org/opensearch/ml/common/MLConfig.java index 39dd250f95..67f5467cbc 100644 --- a/common/src/main/java/org/opensearch/ml/common/MLConfig.java +++ b/common/src/main/java/org/opensearch/ml/common/MLConfig.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.time.Instant; +import org.opensearch.Version; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.common.io.stream.Writeable; @@ -28,17 +29,23 @@ public class MLConfig implements ToXContentObject, Writeable { public static final String TYPE_FIELD = "type"; - public static final String CONFIG_TYPE_FIELD = "config_type"; - public static final String CONFIGURATION_FIELD = "configuration"; - public static final String ML_CONFIGURATION_FIELD = "ml_configuration"; - public static final String CREATE_TIME_FIELD = "create_time"; public static final String LAST_UPDATE_TIME_FIELD = "last_update_time"; + // Adding below three new fields since the original fields, type, configuration, and last_update_time + // are not created with correct data types in config index due to missing schema version bump. + // Starting 2.15, it is suggested that below fields be used for creating new documents in config index + + public static final String CONFIG_TYPE_FIELD = "config_type"; + + public static final String ML_CONFIGURATION_FIELD = "ml_configuration"; + public static final String LAST_UPDATED_TIME_FIELD = "last_updated_time"; + private static final Version MINIMAL_SUPPORTED_VERSION_FOR_NEW_CONFIG_FIELDS = CommonValue.VERSION_2_15_0; + @Setter private String type; @@ -71,37 +78,43 @@ public MLConfig( } public MLConfig(StreamInput input) throws IOException { + Version streamInputVersion = input.getVersion(); this.type = input.readOptionalString(); - this.configType = input.readOptionalString(); if (input.readBoolean()) { configuration = new Configuration(input); } - if (input.readBoolean()) { - mlConfiguration = new Configuration(input); - } createTime = input.readOptionalInstant(); lastUpdateTime = input.readOptionalInstant(); - lastUpdatedTime = input.readOptionalInstant(); + if (streamInputVersion.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_NEW_CONFIG_FIELDS)) { + this.configType = input.readOptionalString(); + if (input.readBoolean()) { + mlConfiguration = new Configuration(input); + } + lastUpdatedTime = input.readOptionalInstant(); + } } @Override public void writeTo(StreamOutput out) throws IOException { + Version streamOutputVersion = out.getVersion(); out.writeOptionalString(type); - out.writeOptionalString(configType); if (configuration != null) { out.writeBoolean(true); configuration.writeTo(out); } else { out.writeBoolean(false); } - if (mlConfiguration != null) { - out.writeBoolean(true); - mlConfiguration.writeTo(out); - } else { - out.writeBoolean(false); - } out.writeOptionalInstant(createTime); out.writeOptionalInstant(lastUpdateTime); + if (streamOutputVersion.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_NEW_CONFIG_FIELDS)) { + out.writeOptionalString(configType); + if (mlConfiguration != null) { + out.writeBoolean(true); + mlConfiguration.writeTo(out); + } else { + out.writeBoolean(false); + } + } out.writeOptionalInstant(lastUpdatedTime); }