Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <[email protected]>
  • Loading branch information
zane-neo committed Apr 27, 2024
1 parent a7a980c commit ea2d860
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
import lombok.AllArgsConstructor;
import lombok.Data;

/**
* This class encapsulates several parameters that are used in a split-batch request case.
* A batch request is that in neural-search side multiple fields are send in one request to ml-commons,
* but the remote model doesn't accept list of string inputs so in ml-commons the request needs split.
* sequence is used to identify the index of the split request.
* countDownLatch is used to wait for all the split requests to finish.
* exceptionHolder is used to hold any exception thrown in a split-batch request.
*/
@Data
@AllArgsConstructor
public class ExecutionContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public class MLSdkAsyncHttpResponseHandler implements SdkAsyncHttpResponseHandle

private final MLGuard mlGuard;

private final static Gson GSON = StringUtils.gson;

public MLSdkAsyncHttpResponseHandler(
ExecutionContext executionContext,
ActionListener<List<ModelTensors>> actionListener,
Expand Down Expand Up @@ -108,28 +106,31 @@ private void processResponse(
) {
if (Strings.isBlank(body)) {
log.error("Remote model response body is empty!");
if (executionContext.getExceptionHolder().get() == null)
if (executionContext.getExceptionHolder().get() == null) {
executionContext
.getExceptionHolder()
.compareAndSet(null, new OpenSearchStatusException("No response from model", RestStatus.BAD_REQUEST));
}
} else {
if (statusCode < HttpStatus.SC_OK || statusCode > HttpStatus.SC_MULTIPLE_CHOICES) {
log.error("Remote server returned error code: {}", statusCode);
if (executionContext.getExceptionHolder().get() == null)
if (executionContext.getExceptionHolder().get() == null) {
executionContext
.getExceptionHolder()
.compareAndSet(null, new OpenSearchStatusException(REMOTE_SERVICE_ERROR + body, RestStatus.fromCode(statusCode)));
}
} else {
try {
ModelTensors tensors = processOutput(body, connector, scriptService, parameters, mlGuard);
tensors.setStatusCode(statusCode);
tensorOutputs.put(executionContext.getSequence(), tensors);
} catch (Exception e) {
log.error("Failed to process response body: {}", body, e);
if (executionContext.getExceptionHolder().get() == null)
if (executionContext.getExceptionHolder().get() == null) {
executionContext
.getExceptionHolder()
.compareAndSet(null, new MLException("Fail to execute predict in aws connector", e));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/src/main/java/org/opensearch/ml/utils/LoggerUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.opensearch.ml.utils;public class LoggerUtil {
}

0 comments on commit ea2d860

Please sign in to comment.