Skip to content

Commit a57a6a9

Browse files
committed
fix error message
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 991193c commit a57a6a9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/ModelHelper.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ public void downloadAndSplit(
229229
DownloadUtils.download(url, modelPath, new ProgressBar());
230230
verifyModelZipFile(modelFormat, modelPath, modelName, functionName);
231231
String hash = calculateFileHash(modelZipFile);
232-
if (hash.equals(modelContentHash)) {
232+
if (modelContentHash == null) {
233+
log.error("Hash code need to be provided when register via url.");
234+
throw (new IllegalArgumentException("Hash code need to be provided when register via url."));
235+
} else if (hash.equals(modelContentHash)) {
233236
List<String> chunkFiles = splitFileIntoChunks(modelZipFile, modelPartsPath, CHUNK_SIZE);
234237
Map<String, Object> result = new HashMap<>();
235238
result.put(CHUNK_FILES, chunkFiles);

ml-algorithms/src/test/java/org/opensearch/ml/engine/algorithms/text_embedding/ModelHelperTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ public void testDownloadAndSplit() throws URISyntaxException {
8585
assertNotEquals(0, argumentCaptor.getValue().size());
8686
}
8787

88+
@Test
89+
public void testDownloadAndSplit_nullHashCode() throws URISyntaxException {
90+
String modelUrl = getClass().getResource("traced_small_model.zip").toURI().toString();
91+
modelHelper.downloadAndSplit(modelFormat, modelId, "model_name", "1", modelUrl, null, FunctionName.TEXT_EMBEDDING, actionListener);
92+
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
93+
verify(actionListener).onFailure(argumentCaptor.capture());
94+
assertEquals(IllegalArgumentException.class, argumentCaptor.getValue().getClass());
95+
}
96+
8897
@Test
8998
public void testDownloadAndSplit_HashFailure() throws URISyntaxException {
9099
String modelUrl = getClass().getResource("traced_small_model.zip").toURI().toString();

plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java

+2
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ private void deployModel(
226226
"Model already deployed to these nodes: "
227227
+ Arrays.toString(difference.toArray(new String[0]))
228228
+ ", but they are not included in target node ids. Undeploy model from these nodes if don't need them any more."
229+
+ "Undeploy from old nodes before try to deploy model on new nodes. Or include all old nodes on your target nodes."
230+
229231
)
230232
);
231233
return;

0 commit comments

Comments
 (0)