Skip to content

Commit 6a38c2b

Browse files
committed
change to a better method
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent eb33bd2 commit 6a38c2b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

plugin/src/main/java/org/opensearch/ml/action/models/DeleteModelTransportAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import org.opensearch.common.inject.Inject;
5353
import org.opensearch.common.settings.Settings;
5454
import org.opensearch.common.util.concurrent.ThreadContext;
55+
import org.opensearch.common.xcontent.XContentHelper;
56+
import org.opensearch.common.xcontent.json.JsonXContent;
5557
import org.opensearch.commons.authuser.User;
5658
import org.opensearch.core.action.ActionListener;
5759
import org.opensearch.core.rest.RestStatus;
@@ -68,7 +70,6 @@
6870
import org.opensearch.ml.common.transport.model.MLModelDeleteAction;
6971
import org.opensearch.ml.common.transport.model.MLModelDeleteRequest;
7072
import org.opensearch.ml.common.transport.model.MLModelGetRequest;
71-
import org.opensearch.ml.common.utils.StringUtils;
7273
import org.opensearch.ml.engine.utils.AgentModelsSearcher;
7374
import org.opensearch.ml.helper.ModelAccessControlHelper;
7475
import org.opensearch.ml.utils.RestActionUtils;
@@ -305,7 +306,7 @@ private void checkPipelineBeforeDeleteModel(
305306
) {
306307
ActionRequest request = requestSupplier.get();
307308
client.execute(actionType, request, ActionListener.wrap(pipelineResponse -> {
308-
Map<String, Object> allConfigMap = StringUtils.fromJson(pipelineResponse.toString(), "");
309+
Map<String, Object> allConfigMap = XContentHelper.convertToMap(JsonXContent.jsonXContent, pipelineResponse.toString(), true);
309310
List<String> allDependentPipelineIds = findDependentPipelinesEasy(allConfigMap, modelId);
310311
if (allDependentPipelineIds.isEmpty()) {
311312
actionListener.onResponse(true);

plugin/src/test/java/org/opensearch/ml/action/models/DeleteModelTransportActionTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void testDeleteModel_BlockedByIngestPipeline() throws IOException {
302302
public void testDeleteModel_BlockedByAgent() throws IOException {
303303
XContentBuilder content = XContentBuilder.builder(XContentType.JSON.xContent());
304304
content.startObject();
305-
content.field(MLAgent.IS_HIDDEN_FIELD, "false");
305+
content.field(MLAgent.IS_HIDDEN_FIELD, false);
306306
content.endObject();
307307
SearchHit hit = new SearchHit(1, "1", null, null).sourceRef(BytesReference.bytes(content));
308308
SearchHits searchHits = new SearchHits(new SearchHit[] { hit }, new TotalHits(1, TotalHits.Relation.EQUAL_TO), 1.0f);

0 commit comments

Comments
 (0)