Skip to content

Commit 74dcdf4

Browse files
b4sjooaustintlee
authored andcommitted
Add a setting to control the update connector API (opensearch-project#1465)
* Add a setting to control the update connector API Signed-off-by: Sicheng Song <[email protected]> * Enabling the update connnector setting in unit test Signed-off-by: Sicheng Song <[email protected]> * Enabling the update connnector setting in corresponding unit test Signed-off-by: Sicheng Song <[email protected]> --------- Signed-off-by: Sicheng Song <[email protected]>
1 parent 8490558 commit 74dcdf4

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java

+1
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ public List<Setting<?>> getSettings() {
692692
MLCommonsSettings.ML_COMMONS_REMOTE_MODEL_ELIGIBLE_NODE_ROLES,
693693
MLCommonsSettings.ML_COMMONS_LOCAL_MODEL_ELIGIBLE_NODE_ROLES,
694694
MLCommonsSettings.ML_COMMONS_REMOTE_INFERENCE_ENABLED,
695+
MLCommonsSettings.ML_COMMONS_UPDATE_CONNECTOR_ENABLED,
695696
MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED,
696697
MLCommonsSettings.ML_COMMONS_RAG_PIPELINE_FEATURE_ENABLED
697698
);

plugin/src/main/java/org/opensearch/ml/rest/RestMLUpdateConnectorAction.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
99
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI;
1010
import static org.opensearch.ml.utils.MLExceptionUtils.REMOTE_INFERENCE_DISABLED_ERR_MSG;
11+
import static org.opensearch.ml.utils.MLExceptionUtils.UPDATE_CONNECTOR_DISABLED_ERR_MSG;
1112
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_CONNECTOR_ID;
1213
import static org.opensearch.ml.utils.RestActionUtils.getParameterId;
1314

@@ -63,7 +64,9 @@ private MLUpdateConnectorRequest getRequest(RestRequest request) throws IOExcept
6364
if (!mlFeatureEnabledSetting.isRemoteInferenceEnabled()) {
6465
throw new IllegalStateException(REMOTE_INFERENCE_DISABLED_ERR_MSG);
6566
}
66-
67+
if (!mlFeatureEnabledSetting.isUpdateConnectorEnabled()) {
68+
throw new IllegalStateException(UPDATE_CONNECTOR_DISABLED_ERR_MSG);
69+
}
6770
if (!request.hasContent()) {
6871
throw new IOException("Failed to update connector: Request body is empty");
6972
}

plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ private MLCommonsSettings() {}
114114
public static final Setting<Boolean> ML_COMMONS_REMOTE_INFERENCE_ENABLED = Setting
115115
.boolSetting("plugins.ml_commons.remote_inference.enabled", true, Setting.Property.NodeScope, Setting.Property.Dynamic);
116116

117+
public static final Setting<Boolean> ML_COMMONS_UPDATE_CONNECTOR_ENABLED = Setting
118+
.boolSetting("plugins.ml_commons.update_connector.enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
119+
117120
public static final Setting<Boolean> ML_COMMONS_MODEL_ACCESS_CONTROL_ENABLED = Setting
118121
.boolSetting("plugins.ml_commons.model_access_control_enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
119122

plugin/src/main/java/org/opensearch/ml/settings/MLFeatureEnabledSetting.java

+11
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@
88
package org.opensearch.ml.settings;
99

1010
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_REMOTE_INFERENCE_ENABLED;
11+
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_UPDATE_CONNECTOR_ENABLED;
1112

1213
import org.opensearch.cluster.service.ClusterService;
1314
import org.opensearch.common.settings.Settings;
1415

1516
public class MLFeatureEnabledSetting {
1617

1718
private volatile Boolean isRemoteInferenceEnabled;
19+
private volatile Boolean isUpdateConnectorEnabled;
1820

1921
public MLFeatureEnabledSetting(ClusterService clusterService, Settings settings) {
2022
isRemoteInferenceEnabled = ML_COMMONS_REMOTE_INFERENCE_ENABLED.get(settings);
23+
isUpdateConnectorEnabled = ML_COMMONS_UPDATE_CONNECTOR_ENABLED.get(settings);
24+
2125
clusterService
2226
.getClusterSettings()
2327
.addSettingsUpdateConsumer(ML_COMMONS_REMOTE_INFERENCE_ENABLED, it -> isRemoteInferenceEnabled = it);
28+
clusterService
29+
.getClusterSettings()
30+
.addSettingsUpdateConsumer(ML_COMMONS_UPDATE_CONNECTOR_ENABLED, it -> isUpdateConnectorEnabled = it);
2431
}
2532

2633
/**
@@ -31,4 +38,8 @@ public boolean isRemoteInferenceEnabled() {
3138
return isRemoteInferenceEnabled;
3239
}
3340

41+
public boolean isUpdateConnectorEnabled() {
42+
return isUpdateConnectorEnabled;
43+
}
44+
3445
}

plugin/src/main/java/org/opensearch/ml/utils/MLExceptionUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class MLExceptionUtils {
2020
public static final String NOT_SERIALIZABLE_EXCEPTION_WRAPPER = "NotSerializableExceptionWrapper: ";
2121
public static final String REMOTE_INFERENCE_DISABLED_ERR_MSG =
2222
"Remote Inference is currently disabled. To enable it, update the setting \"plugins.ml_commons.remote_inference_enabled\" to true.";
23+
public static final String UPDATE_CONNECTOR_DISABLED_ERR_MSG =
24+
"Update connector API is currently disabled. To enable it, update the setting \"plugins.ml_commons.update_connector_enabled\" to true.";
2325

2426
public static String getRootCauseMessage(final Throwable throwable) {
2527
String message = ExceptionUtils.getRootCauseMessage(throwable);

plugin/src/test/java/org/opensearch/ml/rest/RestMLUpdateConnectorActionTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void setup() {
6767
client = spy(new NodeClient(Settings.EMPTY, threadPool));
6868

6969
when(mlFeatureEnabledSetting.isRemoteInferenceEnabled()).thenReturn(true);
70+
when(mlFeatureEnabledSetting.isUpdateConnectorEnabled()).thenReturn(true);
7071
restMLUpdateConnectorAction = new RestMLUpdateConnectorAction(mlFeatureEnabledSetting);
7172

7273
doAnswer(invocation -> {

0 commit comments

Comments
 (0)