Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavana Ramaram <[email protected]>
  • Loading branch information
rbhavna committed Sep 4, 2024
1 parent 02b0d56 commit 7aba355
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
45 changes: 29 additions & 16 deletions common/src/main/java/org/opensearch/ml/common/MLConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7aba355

Please sign in to comment.