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 37628dd96e..6df3f57407 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 @@ -227,7 +227,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;