From 94c190e29f13862409e699b4827d02ac78e7f014 Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Sat, 30 Oct 2021 21:53:59 -0700 Subject: [PATCH 1/3] Dont throw 500s on null Signed-off-by: John Mazanec --- .../opensearch/knn/plugin/rest/RestTrainModelHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opensearch/knn/plugin/rest/RestTrainModelHandler.java b/src/main/java/org/opensearch/knn/plugin/rest/RestTrainModelHandler.java index bc9283621..a5b2f13e4 100644 --- a/src/main/java/org/opensearch/knn/plugin/rest/RestTrainModelHandler.java +++ b/src/main/java/org/opensearch/knn/plugin/rest/RestTrainModelHandler.java @@ -100,9 +100,9 @@ private TrainingModelRequest createTransportRequest(RestRequest restRequest) thr parser.nextToken(); if (TRAIN_INDEX_PARAMETER.equals(fieldName) && ensureNotSet(fieldName, trainingIndex)) { - trainingIndex = parser.text(); + trainingIndex = parser.textOrNull(); } else if (TRAIN_FIELD_PARAMETER.equals(fieldName) && ensureNotSet(fieldName, trainingField)) { - trainingField = parser.text(); + trainingField = parser.textOrNull(); } else if (KNN_METHOD.equals(fieldName) && ensureNotSet(fieldName, knnMethodContext)) { knnMethodContext = KNNMethodContext.parse(parser.map()); } else if (DIMENSION.equals(fieldName) && ensureNotSet(fieldName, dimension)) { @@ -112,7 +112,7 @@ private TrainingModelRequest createTransportRequest(RestRequest restRequest) thr } else if (SEARCH_SIZE_PARAMETER.equals(fieldName) && ensureNotSet(fieldName, searchSize)) { searchSize = (Integer) NumberFieldMapper.NumberType.INTEGER.parse(parser.objectBytes(), false); } else if (MODEL_DESCRIPTION.equals(fieldName) && ensureNotSet(fieldName, description)) { - description = parser.text(); + description = parser.textOrNull(); } else { throw new IllegalArgumentException("Unable to parse token. \"" + fieldName + "\" is not a valid " + "parameter."); From b3027a1dc2613e186d0851bd95d5f34072685c8a Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Sat, 30 Oct 2021 22:02:24 -0700 Subject: [PATCH 2/3] Throw illegal state exception training rejection Signed-off-by: John Mazanec --- .../java/org/opensearch/knn/training/TrainingJobRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/knn/training/TrainingJobRunner.java b/src/main/java/org/opensearch/knn/training/TrainingJobRunner.java index 3ac130a14..9340cd79b 100644 --- a/src/main/java/org/opensearch/knn/training/TrainingJobRunner.java +++ b/src/main/java/org/opensearch/knn/training/TrainingJobRunner.java @@ -82,7 +82,7 @@ public void execute(TrainingJob trainingJob, ActionListener 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 RejectedExecutionException("Unable to run training job: No training capacity on node."); + throw new IllegalStateException("Unable to run training job: No training capacity on node."); } jobCount.incrementAndGet(); From 5b62017c5b8f73d5b3fbe5a36a7ce52a8fb17b9c Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Sat, 30 Oct 2021 22:37:55 -0700 Subject: [PATCH 3/3] Throw validation exception on train reject Signed-off-by: John Mazanec --- .../plugin/transport/TrainingJobRouterTransportAction.java | 5 ++++- .../java/org/opensearch/knn/training/TrainingJobRunner.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opensearch/knn/plugin/transport/TrainingJobRouterTransportAction.java b/src/main/java/org/opensearch/knn/plugin/transport/TrainingJobRouterTransportAction.java index c939e652a..0a24c0c47 100644 --- a/src/main/java/org/opensearch/knn/plugin/transport/TrainingJobRouterTransportAction.java +++ b/src/main/java/org/opensearch/knn/plugin/transport/TrainingJobRouterTransportAction.java @@ -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; @@ -70,7 +71,9 @@ protected void routeRequest(TrainingModelRequest request, ActionListener 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();