Skip to content

Commit b9a49f5

Browse files
[Backport main] Remove strict version dependency to compile minimum compatible version (opensearch-project#2486) (opensearch-project#2523)
* [Feature/multi_tenancy] Remove strict version dependency to compile minimum compatible version (opensearch-project#2485) * Remove strict version dependency to compile minimum compatible version Signed-off-by: Daniel Widdis <widdis@gmail.com> * Only declare version constants once Signed-off-by: Daniel Widdis <widdis@gmail.com> --------- Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Sicheng Song <sicheng.song@outlook.com> * Remove unnecessary dependency Signed-off-by: Sicheng Song <sicheng.song@outlook.com> * remove space Signed-off-by: Sicheng Song <sicheng.song@outlook.com> --------- Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Sicheng Song <sicheng.song@outlook.com> Co-authored-by: Daniel Widdis <widdis@gmail.com> (cherry picked from commit 954e8b3) Co-authored-by: Sicheng Song <sicheng.song@outlook.com>
1 parent 5635972 commit b9a49f5

File tree

9 files changed

+26
-13
lines changed

9 files changed

+26
-13
lines changed

common/src/main/java/org/opensearch/ml/common/CommonValue.java

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package org.opensearch.ml.common;
77

8+
import org.opensearch.Version;
89
import org.opensearch.ml.common.agent.MLAgent;
910
import org.opensearch.ml.common.connector.AbstractConnector;
1011
import org.opensearch.ml.common.controller.MLController;
@@ -527,4 +528,9 @@ public class CommonValue {
527528
+ "\": {\"type\": \"long\"}\n"
528529
+ " }\n"
529530
+ "}";
531+
// Calculate Versions independently of OpenSearch core version
532+
public static final Version VERSION_2_11_0 = Version.fromString("2.11.0");
533+
public static final Version VERSION_2_12_0 = Version.fromString("2.12.0");
534+
public static final Version VERSION_2_13_0 = Version.fromString("2.13.0");
535+
public static final Version VERSION_2_14_0 = Version.fromString("2.14.0");
530536
}

common/src/main/java/org/opensearch/ml/common/agent/MLAgent.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.opensearch.core.xcontent.ToXContentObject;
1616
import org.opensearch.core.xcontent.XContentBuilder;
1717
import org.opensearch.core.xcontent.XContentParser;
18+
import org.opensearch.ml.common.CommonValue;
1819
import org.opensearch.ml.common.MLAgentType;
1920
import org.opensearch.ml.common.MLModel;
2021

@@ -47,7 +48,7 @@ public class MLAgent implements ToXContentObject, Writeable {
4748
public static final String APP_TYPE_FIELD = "app_type";
4849
public static final String IS_HIDDEN_FIELD = "is_hidden";
4950

50-
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_HIDDEN_AGENT = Version.V_2_13_0;
51+
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_HIDDEN_AGENT = CommonValue.VERSION_2_13_0;
5152

5253
private String name;
5354
private String type;

common/src/main/java/org/opensearch/ml/common/dataset/TextDocsInputDataSet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.opensearch.Version;
1313
import org.opensearch.core.common.io.stream.StreamInput;
1414
import org.opensearch.core.common.io.stream.StreamOutput;
15+
import org.opensearch.ml.common.CommonValue;
1516
import org.opensearch.ml.common.annotation.InputDataSet;
1617
import org.opensearch.ml.common.output.model.ModelResultFilter;
1718

@@ -29,7 +30,7 @@ public class TextDocsInputDataSet extends MLInputDataset{
2930

3031
private List<String> docs;
3132

32-
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_MULTI_MODAL = Version.V_2_11_0;
33+
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_MULTI_MODAL = CommonValue.VERSION_2_11_0;
3334

3435
@Builder(toBuilder = true)
3536
public TextDocsInputDataSet(List<String> docs, ModelResultFilter resultFilter) {

common/src/main/java/org/opensearch/ml/common/model/MLDeploySetting.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.opensearch.core.xcontent.ToXContentObject;
1717
import org.opensearch.core.xcontent.XContentBuilder;
1818
import org.opensearch.core.xcontent.XContentParser;
19+
import org.opensearch.ml.common.CommonValue;
1920

2021
import java.io.IOException;
2122

@@ -27,7 +28,7 @@ public class MLDeploySetting implements ToXContentObject, Writeable {
2728
public static final String IS_AUTO_DEPLOY_ENABLED_FIELD = "is_auto_deploy_enabled";
2829
public static final String MODEL_TTL_MINUTES_FIELD = "model_ttl_minutes";
2930
private static final long DEFAULT_TTL_MINUTES = -1;
30-
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_MODEL_TTL = Version.V_2_14_0;
31+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_MODEL_TTL = CommonValue.VERSION_2_14_0;
3132

3233
private Boolean isAutoDeployEnabled;
3334
private Long modelTTLInMinutes; // in minutes

common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.opensearch.core.xcontent.XContentBuilder;
1717
import org.opensearch.core.xcontent.XContentParser;
1818
import org.opensearch.ml.common.AccessMode;
19+
import org.opensearch.ml.common.CommonValue;
1920
import org.opensearch.ml.common.connector.AbstractConnector;
2021
import org.opensearch.ml.common.connector.ConnectorAction;
2122
import org.opensearch.ml.common.connector.ConnectorClientConfig;
@@ -46,7 +47,7 @@ public class MLCreateConnectorInput implements ToXContentObject, Writeable {
4647
public static final String ACCESS_MODE_FIELD = "access_mode";
4748
public static final String DRY_RUN_FIELD = "dry_run";
4849

49-
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_CLIENT_CONFIG = Version.V_2_13_0;
50+
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_CLIENT_CONFIG = CommonValue.VERSION_2_13_0;
5051

5152
public static final String DRY_RUN_CONNECTOR_NAME = "dryRunConnector";
5253

common/src/main/java/org/opensearch/ml/common/transport/register/MLRegisterModelInput.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.opensearch.core.xcontent.XContentBuilder;
1616
import org.opensearch.core.xcontent.XContentParser;
1717
import org.opensearch.ml.common.AccessMode;
18+
import org.opensearch.ml.common.CommonValue;
1819
import org.opensearch.ml.common.FunctionName;
1920
import org.opensearch.ml.common.MLModel;
2021
import org.opensearch.ml.common.connector.Connector;
@@ -69,10 +70,10 @@ public class MLRegisterModelInput implements ToXContentObject, Writeable {
6970
public static final String DOES_VERSION_CREATE_MODEL_GROUP = "does_version_create_model_group";
7071
public static final String GUARDRAILS_FIELD = "guardrails";
7172

72-
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_DOES_VERSION_CREATE_MODEL_GROUP = Version.V_2_11_0;
73-
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_AGENT_FRAMEWORK = Version.V_2_12_0;
74-
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS_AND_AUTO_DEPLOY = Version.V_2_13_0;
75-
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_INTERFACE = Version.V_2_14_0;
73+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_DOES_VERSION_CREATE_MODEL_GROUP = CommonValue.VERSION_2_11_0;
74+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_AGENT_FRAMEWORK = CommonValue.VERSION_2_12_0;
75+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_GUARDRAILS_AND_AUTO_DEPLOY = CommonValue.VERSION_2_13_0;
76+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_INTERFACE = CommonValue.VERSION_2_14_0;
7677

7778
private FunctionName functionName;
7879
private String modelName;

common/src/test/java/org/opensearch/ml/common/agent/MLAgentTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.opensearch.core.xcontent.ToXContent;
1919
import org.opensearch.core.xcontent.XContentBuilder;
2020
import org.opensearch.core.xcontent.XContentParser;
21+
import org.opensearch.ml.common.CommonValue;
2122
import org.opensearch.ml.common.MLAgentType;
2223
import org.opensearch.ml.common.TestHelper;
2324
import org.opensearch.search.SearchModule;
@@ -196,7 +197,7 @@ public void constructor_NonConversationalNoLLM() {
196197
public void writeTo_ReadFrom_HiddenFlag_VersionCompatibility() throws IOException {
197198
MLAgent agent = new MLAgent("test", "FLOW", "test", null, null, null, null, Instant.EPOCH, Instant.EPOCH, "test", true);
198199
BytesStreamOutput output = new BytesStreamOutput();
199-
Version oldVersion = Version.fromString("2.12.0");
200+
Version oldVersion = CommonValue.VERSION_2_12_0;
200201
output.setVersion(oldVersion); // Version before MINIMAL_SUPPORTED_VERSION_FOR_HIDDEN_AGENT
201202
agent.writeTo(output);
202203

@@ -206,10 +207,10 @@ public void writeTo_ReadFrom_HiddenFlag_VersionCompatibility() throws IOExceptio
206207
assertNull(agentOldVersion.getIsHidden()); // Hidden should be null for old versions
207208

208209
output = new BytesStreamOutput();
209-
output.setVersion(Version.V_2_13_0); // Version at or after MINIMAL_SUPPORTED_VERSION_FOR_HIDDEN_AGENT
210+
output.setVersion(CommonValue.VERSION_2_13_0); // Version at or after MINIMAL_SUPPORTED_VERSION_FOR_HIDDEN_AGENT
210211
agent.writeTo(output);
211212
StreamInput streamInput1 = output.bytes().streamInput();
212-
streamInput1.setVersion(Version.V_2_13_0);
213+
streamInput1.setVersion(CommonValue.VERSION_2_13_0);
213214
MLAgent agentNewVersion = new MLAgent(output.bytes().streamInput());
214215
assertEquals(Boolean.TRUE, agentNewVersion.getIsHidden()); // Hidden should be true for new versions
215216
}

common/src/test/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInputTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.opensearch.core.xcontent.XContentBuilder;
2222
import org.opensearch.core.xcontent.XContentParser;
2323
import org.opensearch.ml.common.AccessMode;
24+
import org.opensearch.ml.common.CommonValue;
2425
import org.opensearch.ml.common.connector.ConnectorAction;
2526
import org.opensearch.ml.common.connector.ConnectorClientConfig;
2627
import org.opensearch.ml.common.connector.MLPostProcessFunction;
@@ -256,7 +257,7 @@ public void testWriteToVersionCompatibility() throws IOException {
256257
MLCreateConnectorInput input = mlCreateConnectorInput; // Assuming mlCreateConnectorInput is already initialized
257258

258259
// Simulate an older version of OpenSearch that does not support connectorClientConfig
259-
Version oldVersion = Version.fromString("2.12.0"); // Change this as per your old version
260+
Version oldVersion = CommonValue.VERSION_2_12_0; // Change this as per your old version
260261
BytesStreamOutput output = new BytesStreamOutput();
261262
output.setVersion(oldVersion);
262263

plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ List<String> jacocoExclusions = [
284284
'org.opensearch.ml.profile.MLPredictRequestStats',
285285
'org.opensearch.ml.action.deploy.TransportDeployModelAction',
286286
'org.opensearch.ml.action.deploy.TransportDeployModelOnNodeAction',
287-
'org.opensearch.ml.action.undeploy.TransportUndeployModelsAction',
287+
'org.opensearch.ml.action.undeploy.TransportUndeployModelsAction',
288288
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction',
289289
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction.1',
290290
'org.opensearch.ml.action.tasks.GetTaskTransportAction',

0 commit comments

Comments
 (0)