Skip to content

Commit 0aa08cf

Browse files
change only run on ml node setting default value to true (#686) (#688)
* change only run on ml node setting default value to true Signed-off-by: Yaliang Wu <[email protected]> * format code Signed-off-by: Yaliang Wu <[email protected]> Signed-off-by: Yaliang Wu <[email protected]> (cherry picked from commit 9420c91) Co-authored-by: Yaliang Wu <[email protected]>
1 parent 4e6f8a9 commit 0aa08cf

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private MLCommonsSettings() {}
2323
public static final Setting<Integer> ML_COMMONS_MAX_ML_TASK_PER_NODE = Setting
2424
.intSetting("plugins.ml_commons.max_ml_task_per_node", 10, 0, 10000, Setting.Property.NodeScope, Setting.Property.Dynamic);
2525
public static final Setting<Boolean> ML_COMMONS_ONLY_RUN_ON_ML_NODE = Setting
26-
.boolSetting("plugins.ml_commons.only_run_on_ml_node", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
26+
.boolSetting("plugins.ml_commons.only_run_on_ml_node", true, Setting.Property.NodeScope, Setting.Property.Dynamic);
2727
public static final Setting<Integer> ML_COMMONS_SYNC_UP_JOB_INTERVAL_IN_SECONDS = Setting
2828
.intSetting(
2929
"plugins.ml_commons.sync_up_job_interval_in_seconds",

plugin/src/main/java/org/opensearch/ml/task/MLTaskDispatcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.opensearch.ml.action.stats.MLStatsNodesAction;
2727
import org.opensearch.ml.action.stats.MLStatsNodesRequest;
2828
import org.opensearch.ml.cluster.DiscoveryNodeHelper;
29+
import org.opensearch.ml.common.exception.MLResourceNotFoundException;
2930
import org.opensearch.ml.stats.MLNodeLevelStat;
3031

3132
import com.google.common.collect.ImmutableSet;
@@ -165,6 +166,9 @@ private void dispatchTaskWithLeastLoad(ActionListener<DiscoveryNode> listener) {
165166

166167
private void dispatchTaskWithRoundRobin(ActionListener<DiscoveryNode> listener) {
167168
DiscoveryNode[] eligibleNodes = nodeHelper.getEligibleNodes();
169+
if (eligibleNodes == null || eligibleNodes.length == 0) {
170+
throw new MLResourceNotFoundException("no eligible node found, ml node is required to run this request");
171+
}
168172
dispatchTaskWithRoundRobin(eligibleNodes, listener);
169173
}
170174

plugin/src/test/java/org/opensearch/ml/action/MLCommonsIntegTestCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.ml.action;
77

88
import static org.opensearch.ml.common.input.parameter.regression.LogisticRegressionParams.ObjectiveType.LOGMULTICLASS;
9+
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_ONLY_RUN_ON_ML_NODE;
910
import static org.opensearch.ml.utils.RestActionUtils.getAllNodes;
1011
import static org.opensearch.ml.utils.TestData.TARGET_FIELD;
1112
import static org.opensearch.ml.utils.TestData.TIME_FIELD;
@@ -24,6 +25,7 @@
2425
import org.opensearch.action.support.WriteRequest;
2526
import org.opensearch.cluster.node.DiscoveryNode;
2627
import org.opensearch.cluster.node.DiscoveryNodes;
28+
import org.opensearch.common.settings.Settings;
2729
import org.opensearch.common.xcontent.XContentType;
2830
import org.opensearch.index.query.QueryBuilder;
2931
import org.opensearch.index.query.QueryBuilders;
@@ -409,4 +411,9 @@ public MLSyncUpNodesResponse syncUp_Clear() {
409411
MLSyncUpNodesResponse syncUpResponse = client().execute(MLSyncUpAction.INSTANCE, syncUpRequest).actionGet(5000);
410412
return syncUpResponse;
411413
}
414+
415+
@Override
416+
protected Settings nodeSettings(int ordinal) {
417+
return Settings.builder().put(super.nodeSettings(ordinal)).put(ML_COMMONS_ONLY_RUN_ON_ML_NODE.getKey(), false).build();
418+
}
412419
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.http.ssl.SSLContextBuilder;
5050
import org.apache.http.util.EntityUtils;
5151
import org.junit.After;
52+
import org.junit.Before;
5253
import org.opensearch.client.Request;
5354
import org.opensearch.client.Response;
5455
import org.opensearch.client.RestClient;
@@ -103,6 +104,20 @@ protected boolean isHttps() {
103104
return isHttps;
104105
}
105106

107+
@Before
108+
public void setupSettings() throws IOException {
109+
Response response = TestHelper
110+
.makeRequest(
111+
client(),
112+
"PUT",
113+
"_cluster/settings",
114+
null,
115+
"{\"persistent\":{\"plugins.ml_commons.only_run_on_ml_node\":false}}",
116+
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, ""))
117+
);
118+
assertEquals(200, response.getStatusLine().getStatusCode());
119+
}
120+
106121
@Override
107122
protected String getProtocol() {
108123
return isHttps() ? "https" : "http";

0 commit comments

Comments
 (0)