From 0fd07f0b843b0bfc14dd3b2d4145eca0ba41568e Mon Sep 17 00:00:00 2001 From: xinyual <74362153+xinyual@users.noreply.github.com> Date: Thu, 1 Feb 2024 05:02:47 +0800 Subject: [PATCH] fix error message (#1967) * fix error message Signed-off-by: xinyual * modify error message Signed-off-by: xinyual --------- Signed-off-by: xinyual --- .../main/java/org/opensearch/ml/engine/ModelHelper.java | 7 ++++++- .../algorithms/text_embedding/ModelHelperTest.java | 9 +++++++++ .../ml/action/deploy/TransportDeployModelAction.java | 2 ++ 3 files changed, 17 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..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 @@ -229,7 +229,12 @@ 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( + "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<>(); 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;