From a57a6a9f4b2c6d573332f5f5beef63ca8f031784 Mon Sep 17 00:00:00 2001 From: xinyual Date: Wed, 31 Jan 2024 09:23:20 +0800 Subject: [PATCH 1/2] fix error message Signed-off-by: xinyual --- .../main/java/org/opensearch/ml/engine/ModelHelper.java | 5 ++++- .../algorithms/text_embedding/ModelHelperTest.java | 9 +++++++++ .../ml/action/deploy/TransportDeployModelAction.java | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java index bb810b40d3..3ed2b7c31e 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java @@ -229,7 +229,10 @@ public void downloadAndSplit( DownloadUtils.download(url, modelPath, new ProgressBar()); verifyModelZipFile(modelFormat, modelPath, modelName, functionName); String hash = calculateFileHash(modelZipFile); - if (hash.equals(modelContentHash)) { + if (modelContentHash == null) { + log.error("Hash code need to be provided when register via url."); + throw (new IllegalArgumentException("Hash code need to be provided when register via url.")); + } else if (hash.equals(modelContentHash)) { List chunkFiles = splitFileIntoChunks(modelZipFile, modelPartsPath, CHUNK_SIZE); Map result = new HashMap<>(); result.put(CHUNK_FILES, chunkFiles); diff --git a/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java b/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java index 9b6ef26e8e..3faafcc24f 100644 --- a/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java +++ b/ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java @@ -85,6 +85,15 @@ public void testDownloadAndSplit() throws URISyntaxException { assertNotEquals(0, argumentCaptor.getValue().size()); } + @Test + public void testDownloadAndSplit_nullHashCode() throws URISyntaxException { + String modelUrl = getClass().getResource("traced_small_model.zip").toURI().toString(); + modelHelper.downloadAndSplit(modelFormat, modelId, "model_name", "1", modelUrl, null, FunctionName.TEXT_EMBEDDING, actionListener); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argumentCaptor.capture()); + assertEquals(IllegalArgumentException.class, argumentCaptor.getValue().getClass()); + } + @Test public void testDownloadAndSplit_HashFailure() throws URISyntaxException { String modelUrl = getClass().getResource("traced_small_model.zip").toURI().toString(); diff --git a/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java b/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java index 99e450567a..8d1c4f706e 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java @@ -226,6 +226,8 @@ private void deployModel( "Model already deployed to these nodes: " + Arrays.toString(difference.toArray(new String[0])) + ", but they are not included in target node ids. Undeploy model from these nodes if don't need them any more." + + "Undeploy from old nodes before try to deploy model on new nodes. Or include all old nodes on your target nodes." + ) ); return; From f096160725d94f9b910f51228c2579c2791073c0 Mon Sep 17 00:00:00 2001 From: xinyual Date: Wed, 31 Jan 2024 09:27:23 +0800 Subject: [PATCH 2/2] modify error message Signed-off-by: xinyual --- .../src/main/java/org/opensearch/ml/engine/ModelHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java index 3ed2b7c31e..1090ee15b6 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java @@ -231,7 +231,9 @@ public void downloadAndSplit( String hash = calculateFileHash(modelZipFile); if (modelContentHash == null) { log.error("Hash code need to be provided when register via url."); - throw (new IllegalArgumentException("Hash code need to be provided when register via url.")); + throw (new IllegalArgumentException( + "Model content Hash code need to be provided when register via url. Please calculate sha 256 Hash code." + )); } else if (hash.equals(modelContentHash)) { List chunkFiles = splitFileIntoChunks(modelZipFile, modelPartsPath, CHUNK_SIZE); Map result = new HashMap<>();