Skip to content

Commit

Permalink
Throw validation exception on train reject
Browse files Browse the repository at this point in the history
Signed-off-by: John Mazanec <[email protected]>
  • Loading branch information
jmazanec15 committed Oct 31, 2021
1 parent b3027a1 commit 5b62017
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Strings;
import org.opensearch.common.ValidationException;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.inject.Inject;
import org.opensearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -70,7 +71,9 @@ protected void routeRequest(TrainingModelRequest request, ActionListener<Trainin
DiscoveryNode node = selectNode(request.getPreferredNodeId(), response);

if (node == null) {
listener.onFailure(new RejectedExecutionException("Cluster does not have capacity to train"));
ValidationException exception = new ValidationException();
exception.addValidationError("Cluster does not have capacity to train");
listener.onFailure(exception);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.ActionListener;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.common.ValidationException;
import org.opensearch.knn.indices.ModelDao;
import org.opensearch.knn.indices.ModelMetadata;
import org.opensearch.knn.indices.ModelState;
Expand Down Expand Up @@ -82,7 +83,9 @@ public void execute(TrainingJob trainingJob, ActionListener<IndexResponse> liste
// the number of training jobs that enter this function. Although the training threadpool size will also prevent
// this, we want to prevent this before we perform any serialization.
if (!semaphore.tryAcquire()) {
throw new IllegalStateException("Unable to run training job: No training capacity on node.");
ValidationException exception = new ValidationException();
exception.addValidationError("Unable to run training job: No training capacity on node.");
throw exception;
}

jobCount.incrementAndGet();
Expand Down

0 comments on commit 5b62017

Please sign in to comment.