Skip to content

Commit

Permalink
add prefix to show the error is from remote service (opensearch-proje…
Browse files Browse the repository at this point in the history
…ct#1499) (opensearch-project#1515)

Signed-off-by: Yaliang Wu <[email protected]>
(cherry picked from commit 3897ad1)

Co-authored-by: Yaliang Wu <[email protected]>
  • Loading branch information
2 people authored and austintlee committed Feb 29, 2024
1 parent 7b76e78 commit dc1ae1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class CommonValue {

public static Integer NO_SCHEMA_VERSION = 0;
public static final String REMOTE_SERVICE_ERROR = "Error from remote service: ";
public static final String USER = "user";
public static final String META = "_meta";
public static final String SCHEMA_VERSION_FIELD = "schema_version";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

package org.opensearch.ml.engine.algorithms.remote;

import static org.opensearch.ml.common.connector.ConnectorProtocols.AWS_SIGV4;
import static org.opensearch.ml.engine.algorithms.remote.ConnectorUtils.processOutput;
import static software.amazon.awssdk.http.SdkHttpMethod.POST;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
Expand Down Expand Up @@ -39,6 +35,11 @@
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.SdkHttpFullRequest;

import static org.opensearch.ml.common.CommonValue.REMOTE_SERVICE_ERROR;
import static org.opensearch.ml.common.connector.ConnectorProtocols.AWS_SIGV4;
import static org.opensearch.ml.engine.algorithms.remote.ConnectorUtils.processOutput;
import static software.amazon.awssdk.http.SdkHttpMethod.POST;

@Log4j2
@ConnectorExecutor(AWS_SIGV4)
public class AwsConnectorExecutor implements RemoteConnectorExecutor {
Expand Down Expand Up @@ -106,7 +107,7 @@ public void invokeRemoteModel(MLInput mlInput, Map<String, String> parameters, S
}
String modelResponse = responseBuilder.toString();
if (statusCode < 200 || statusCode >= 300) {
throw new OpenSearchStatusException(modelResponse, RestStatus.fromCode(statusCode));
throw new OpenSearchStatusException(REMOTE_SERVICE_ERROR + modelResponse, RestStatus.fromCode(statusCode));
}

ModelTensors tensors = processOutput(modelResponse, connector, scriptService, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

package org.opensearch.ml.engine.algorithms.remote;

import static org.opensearch.ml.common.connector.ConnectorProtocols.HTTP;
import static org.opensearch.ml.engine.algorithms.remote.ConnectorUtils.processOutput;

import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.List;
Expand Down Expand Up @@ -38,6 +35,10 @@
import lombok.Setter;
import lombok.extern.log4j.Log4j2;

import static org.opensearch.ml.common.CommonValue.REMOTE_SERVICE_ERROR;
import static org.opensearch.ml.common.connector.ConnectorProtocols.HTTP;
import static org.opensearch.ml.engine.algorithms.remote.ConnectorUtils.processOutput;

@Log4j2
@ConnectorExecutor(HTTP)
public class HttpJsonConnectorExecutor implements RemoteConnectorExecutor {
Expand Down Expand Up @@ -108,7 +109,7 @@ public void invokeRemoteModel(MLInput mlInput, Map<String, String> parameters, S
String modelResponse = responseRef.get();
Integer statusCode = statusCodeRef.get();
if (statusCode < 200 || statusCode >= 300) {
throw new OpenSearchStatusException(modelResponse, RestStatus.fromCode(statusCode));
throw new OpenSearchStatusException(REMOTE_SERVICE_ERROR + modelResponse, RestStatus.fromCode(statusCode));
}

ModelTensors tensors = processOutput(modelResponse, connector, scriptService, parameters);
Expand Down

0 comments on commit dc1ae1c

Please sign in to comment.