Skip to content

Commit db031ba

Browse files
committed
Update index calls to directly use index response without parsing
Signed-off-by: Daniel Widdis <[email protected]>
1 parent 686cf8e commit db031ba

File tree

5 files changed

+7
-32
lines changed

5 files changed

+7
-32
lines changed

plugin/src/main/java/org/opensearch/ml/action/agents/TransportRegisterAgentAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void registerAgentToIndex(MLAgent mlAgent, String tenantId, ActionListen
150150
listener.onFailure(cause);
151151
} else {
152152
try {
153-
IndexResponse indexResponse = IndexResponse.fromXContent(r.parser());
153+
IndexResponse indexResponse = r.indexResponse();
154154
log.info("Agent creation result: {}, Agent id: {}", indexResponse.getResult(), indexResponse.getId());
155155
MLRegisterAgentResponse response = new MLRegisterAgentResponse(r.id());
156156
listener.onResponse(response);

plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import static org.opensearch.ml.common.CommonValue.ML_CONNECTOR_INDEX;
1010
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX;
1111

12-
import java.io.IOException;
1312
import java.time.Instant;
1413
import java.util.HashSet;
1514
import java.util.List;
@@ -179,15 +178,15 @@ private void indexConnector(Connector connector, ActionListener<MLCreateConnecto
179178
listener.onFailure(cause);
180179
} else {
181180
try {
182-
IndexResponse indexResponse = IndexResponse.fromXContent(r.parser());
181+
IndexResponse indexResponse = r.indexResponse();
183182
log
184183
.info(
185184
"Connector creation result: {}, connector id: {}",
186185
indexResponse.getResult(),
187186
indexResponse.getId()
188187
);
189188
listener.onResponse(new MLCreateConnectorResponse(indexResponse.getId()));
190-
} catch (IOException e) {
189+
} catch (Exception e) {
191190
listener.onFailure(e);
192191
}
193192
}

plugin/src/main/java/org/opensearch/ml/model/MLModelGroupManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void createModelGroup(MLRegisterModelGroupInput input, ActionListener<Str
145145
wrappedListener.onFailure(cause);
146146
} else {
147147
try {
148-
IndexResponse indexResponse = IndexResponse.fromXContent(r.parser());
148+
IndexResponse indexResponse = r.indexResponse();
149149
log
150150
.info(
151151
"Model group creation result: {}, model group id: {}",

plugin/src/main/java/org/opensearch/ml/model/MLModelManager.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -661,19 +661,7 @@ private void indexRemoteModel(
661661
});
662662

663663
ThreadedActionListener<IndexResponse> putListener = threadedActionListener(REGISTER_THREAD_POOL, indexListener);
664-
sdkClient.putDataObjectAsync(putModelMetaRequest).whenComplete((r, throwable) -> {
665-
if (throwable == null) {
666-
try {
667-
IndexResponse ir = IndexResponse.fromXContent(r.parser());
668-
putListener.onResponse(ir);
669-
} catch (Exception e) {
670-
putListener.onFailure(e);
671-
}
672-
} else {
673-
Exception e = SdkClientUtils.unwrapAndConvertToException(throwable);
674-
putListener.onFailure(e);
675-
}
676-
});
664+
sdkClient.putDataObjectAsync(putModelMetaRequest).whenComplete(SdkClientUtils.wrapPutCompletion(putListener));
677665
}, error -> {
678666
// failed to initialize the model index
679667
log.error("Failed to init model index", error);
@@ -764,19 +752,7 @@ void indexRemoteModel(MLRegisterModelInput registerModelInput, MLTask mlTask, St
764752
});
765753

766754
ThreadedActionListener<IndexResponse> putListener = threadedActionListener(REGISTER_THREAD_POOL, indexListener);
767-
sdkClient.putDataObjectAsync(putModelMetaRequest).whenComplete((r, throwable) -> {
768-
if (throwable == null) {
769-
try {
770-
IndexResponse ir = IndexResponse.fromXContent(r.parser());
771-
putListener.onResponse(ir);
772-
} catch (Exception e) {
773-
putListener.onFailure(e);
774-
}
775-
} else {
776-
Exception e = SdkClientUtils.unwrapAndConvertToException(throwable);
777-
putListener.onFailure(e);
778-
}
779-
});
755+
sdkClient.putDataObjectAsync(putModelMetaRequest).whenComplete(SdkClientUtils.wrapPutCompletion(putListener));
780756

781757
}, e -> {
782758
log.error("Failed to init model index", e);

plugin/src/main/java/org/opensearch/ml/task/MLTaskManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void createMLTask(MLTask mlTask, ActionListener<IndexResponse> listener)
304304
listener.onFailure(cause);
305305
} else {
306306
try {
307-
IndexResponse indexResponse = IndexResponse.fromXContent(r.parser());
307+
IndexResponse indexResponse = r.indexResponse();
308308
log.info("Task creation result: {}, Task id: {}", indexResponse.getResult(), indexResponse.getId());
309309
listener.onResponse(indexResponse);
310310
} catch (Exception e) {

0 commit comments

Comments
 (0)