diff --git a/plugin/src/main/java/org/opensearch/ml/task/MLPredictTaskRunner.java b/plugin/src/main/java/org/opensearch/ml/task/MLPredictTaskRunner.java index a6d82e979f..f6d734ecee 100644 --- a/plugin/src/main/java/org/opensearch/ml/task/MLPredictTaskRunner.java +++ b/plugin/src/main/java/org/opensearch/ml/task/MLPredictTaskRunner.java @@ -148,6 +148,16 @@ public void dispatchTask( if (FunctionName.isAutoDeployEnabled(autoDeploymentEnabled, functionName)) { try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { mlModelManager.getModel(modelId, ActionListener.runBefore(ActionListener.wrap(model -> { + if (!checkModelAutoDeployEnabled(model)) { + log.info("Auto deployment disabled for model {}, please deploy model first", modelId); + listener + .onFailure( + new IllegalArgumentException( + "Model not ready yet. Please run this first: POST /_plugins/_ml/models/" + modelId + "/_deploy" + ) + ); + return; + } String[] planningWorkerNodes = model.getPlanningWorkerNodes(); MLModel modelBeingAutoDeployed = mlModelManager.addModelToAutoDeployCache(modelId, model); if (modelBeingAutoDeployed == model) { @@ -241,6 +251,13 @@ protected void executeTask(MLPredictionTaskRequest request, ActionListener