Skip to content

Commit ef68097

Browse files
committed
rename and remove useless method
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent de464e9 commit ef68097

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/tools/AgentModelsSearcher.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import static org.opensearch.ml.common.CommonValue.ML_AGENT_INDEX;
44
import static org.opensearch.ml.common.CommonValue.TOOL_MODEL_RELATED_FIELD_PREFIX;
55

6-
import java.util.ArrayList;
76
import java.util.HashSet;
8-
import java.util.List;
97
import java.util.Map;
108
import java.util.Set;
119

@@ -28,20 +26,12 @@ public AgentModelsSearcher(Map<String, Tool.Factory> toolFactories) {
2826

2927
public SearchRequest constructQueryRequest(String candidateModelId) {
3028
SearchRequest searchRequest = new SearchRequest(ML_AGENT_INDEX);
31-
List<String> allKeyFields = collectAllKeys();
3229
BoolQueryBuilder shouldQuery = QueryBuilders.boolQuery();
33-
for (String keyField : allKeyFields) {
30+
for (String keyField : relatedModelIdSet) {
3431
shouldQuery.should(QueryBuilders.termsQuery(TOOL_MODEL_RELATED_FIELD_PREFIX + keyField, candidateModelId));
3532
}
3633
searchRequest.source(new SearchSourceBuilder().query(shouldQuery));
3734
return searchRequest;
3835
}
3936

40-
private List<String> collectAllKeys() {
41-
Set<String> keys = new HashSet<>();
42-
for (String modelKey : relatedModelIdSet) {
43-
keys.add(modelKey);
44-
}
45-
return new ArrayList<>(keys);
46-
}
4737
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class DeleteModelTransportAction extends HandledTransportAction<ActionReq
8282
static final String BULK_FAILURE_MSG = "Bulk failure while deleting model of ";
8383
static final String SEARCH_FAILURE_MSG = "Search failure while deleting model of ";
8484
static final String OS_STATUS_EXCEPTION_MESSAGE = "Failed to delete all model chunks";
85+
static final String PIPELINE_TARGET_MODEL_KEY = "model_id";
8586
Client client;
8687
NamedXContentRegistry xContentRegistry;
8788
ClusterService clusterService;
@@ -497,13 +498,15 @@ private <T> Boolean isPipelineContainsModel(
497498
return false;
498499
}
499500

500-
private Boolean searchThroughConfig(Object searchCandidate, String candidateId, String prefixKey) {
501+
private Boolean searchThroughConfig(Object searchCandidate, String candidateId, String targetModelKey) {
501502
Boolean flag = false;
502-
if (searchCandidate instanceof String && Objects.equals(prefixKey, "model_id") && Objects.equals(candidateId, searchCandidate)) {
503+
if (searchCandidate instanceof String
504+
&& Objects.equals(targetModelKey, PIPELINE_TARGET_MODEL_KEY)
505+
&& Objects.equals(candidateId, searchCandidate)) {
503506
return true;
504507
} else if (searchCandidate instanceof List<?>) {
505508
for (Object v : (List<?>) searchCandidate) {
506-
flag = flag || searchThroughConfig(v, candidateId, prefixKey);
509+
flag = flag || searchThroughConfig(v, candidateId, targetModelKey);
507510
}
508511
} else if (searchCandidate instanceof Map<?, ?>) {
509512
for (Map.Entry<String, Object> entry : ((Map<String, Object>) searchCandidate).entrySet()) {

0 commit comments

Comments
 (0)