47
47
import static org .opensearch .ml .settings .MLCommonsSettings .ML_COMMONS_MAX_REGISTER_MODEL_TASKS_PER_NODE ;
48
48
import static org .opensearch .ml .stats .ActionName .REGISTER ;
49
49
import static org .opensearch .ml .stats .MLActionLevelStat .ML_ACTION_REQUEST_COUNT ;
50
+ import static org .opensearch .ml .utils .MLExceptionUtils .CONTROLLER_DISABLED_ERR_MSG ;
50
51
import static org .opensearch .ml .utils .MLExceptionUtils .logException ;
51
52
import static org .opensearch .ml .utils .MLNodeUtils .checkOpenCircuitBreaker ;
52
53
import static org .opensearch .ml .utils .MLNodeUtils .createXContentParserFromRegistry ;
131
132
import org .opensearch .ml .engine .indices .MLIndicesHandler ;
132
133
import org .opensearch .ml .engine .utils .FileUtils ;
133
134
import org .opensearch .ml .profile .MLModelProfile ;
135
+ import org .opensearch .ml .settings .MLFeatureEnabledSetting ;
134
136
import org .opensearch .ml .stats .ActionName ;
135
137
import org .opensearch .ml .stats .MLActionLevelStat ;
136
138
import org .opensearch .ml .stats .MLNodeLevelStat ;
@@ -178,6 +180,7 @@ public class MLModelManager {
178
180
private final MLTaskManager mlTaskManager ;
179
181
private final MLEngine mlEngine ;
180
182
private final DiscoveryNodeHelper nodeHelper ;
183
+ private final MLFeatureEnabledSetting mlFeatureEnabledSetting ;
181
184
182
185
private volatile Integer maxModelPerNode ;
183
186
private volatile Integer maxRegisterTasksPerNode ;
@@ -208,7 +211,8 @@ public MLModelManager(
208
211
MLTaskManager mlTaskManager ,
209
212
MLModelCacheHelper modelCacheHelper ,
210
213
MLEngine mlEngine ,
211
- DiscoveryNodeHelper nodeHelper
214
+ DiscoveryNodeHelper nodeHelper ,
215
+ MLFeatureEnabledSetting mlFeatureEnabledSetting
212
216
) {
213
217
this .client = client ;
214
218
this .sdkClient = sdkClient ;
@@ -224,6 +228,7 @@ public MLModelManager(
224
228
this .mlTaskManager = mlTaskManager ;
225
229
this .mlEngine = mlEngine ;
226
230
this .nodeHelper = nodeHelper ;
231
+ this .mlFeatureEnabledSetting = mlFeatureEnabledSetting ;
227
232
228
233
this .maxModelPerNode = ML_COMMONS_MAX_MODELS_PER_NODE .get (settings );
229
234
clusterService .getClusterSettings ().addSettingsUpdateConsumer (ML_COMMONS_MAX_MODELS_PER_NODE , it -> maxModelPerNode = it );
@@ -1329,6 +1334,9 @@ public synchronized void updateModelCache(String modelId, ActionListener<String>
1329
1334
*/
1330
1335
public synchronized void deployControllerWithDeployedModel (String modelId , ActionListener <String > listener ) {
1331
1336
try (ThreadContext .StoredContext context = client .threadPool ().getThreadContext ().stashContext ()) {
1337
+ if (!mlFeatureEnabledSetting .isControllerEnabled ()) {
1338
+ throw new IllegalStateException (CONTROLLER_DISABLED_ERR_MSG );
1339
+ }
1332
1340
if (!modelCacheHelper .isModelDeployed (modelId )) {
1333
1341
throw new OpenSearchStatusException (
1334
1342
"The model of this model controller has not deployed yet, please deploy the model first." ,
@@ -1498,6 +1506,9 @@ private synchronized void deployControllerWithDeployingModel(
1498
1506
* @param mlModel ml model
1499
1507
*/
1500
1508
public void deployControllerWithDeployingModel (MLModel mlModel , Integer eligibleNodeCount ) {
1509
+ if (!mlFeatureEnabledSetting .isControllerEnabled ()) {
1510
+ throw new IllegalStateException (CONTROLLER_DISABLED_ERR_MSG );
1511
+ }
1501
1512
if (mlModel .getModelState () != MLModelState .DEPLOYING ) {
1502
1513
throw new OpenSearchStatusException (
1503
1514
"This method should only be called when model is in DEPLOYING state, but the model is in state: " + mlModel .getModelState (),
0 commit comments