Skip to content

Commit cd00f21

Browse files
committed
Replace listener::onFailure with handleError after GENERATING status is written
Signed-off-by: shuangli-z <[email protected]>
1 parent 7a5ab95 commit cd00f21

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

common/src/main/java/org/opensearch/ml/common/indexInsight/AbstractIndexInsightTask.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void execute(String tenantId, ActionListener<IndexInsight> listener) {
105105
.whenComplete((r, throwable) -> {
106106
if (throwable != null) {
107107
Exception cause = SdkClientUtils.unwrapAndConvertToException(throwable);
108-
listener.onFailure(cause);
108+
handleError("Failed to search pattern matched documents for index: {}", cause, tenantId, listener, false);
109109
} else {
110110
SearchResponse searchResponse = r.searchResponse();
111111
SearchHit[] hits = searchResponse.getHits().getHits();
@@ -203,9 +203,11 @@ protected void beginGeneration(String tenantId, ActionListener<IndexInsight> lis
203203
.lastUpdatedTime(Instant.now())
204204
.build();
205205

206-
writeIndexInsight(indexInsight, tenantId, ActionListener.wrap(r -> { runWithPrerequisites(tenantId, listener); }, e -> {
207-
saveFailedStatus(tenantId, e, listener);
208-
}));
206+
writeIndexInsight(
207+
indexInsight,
208+
tenantId,
209+
ActionListener.wrap(r -> { runWithPrerequisites(tenantId, listener); }, listener::onFailure)
210+
);
209211
}
210212

211213
protected void runWithPrerequisites(String tenantId, ActionListener<IndexInsight> listener) {
@@ -239,7 +241,7 @@ protected void saveResult(String content, String tenantId, ActionListener<IndexI
239241
.build();
240242

241243
writeIndexInsight(insight, tenantId, ActionListener.wrap(r -> { listener.onResponse(insight); }, e -> {
242-
saveFailedStatus(tenantId, e, listener);
244+
handleError("Failed to save completed result for index: {}", e, tenantId, listener);
243245
}));
244246
}
245247

common/src/main/java/org/opensearch/ml/common/indexInsight/FieldDescriptionTask.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,12 @@ protected void handlePatternResult(Map<String, Object> patternSource, String ten
128128
listener.onResponse(insight);
129129

130130
} catch (Exception e) {
131-
log.error("Failed to process current index mapping for index {}", sourceIndex, e);
132-
listener.onFailure(e);
131+
handleError("Failed to process current index mapping for index: {}", e, tenantId, listener, false);
133132
}
134-
}, e -> {
135-
log.error("Failed to get current index mapping for index {}", sourceIndex, e);
136-
listener.onFailure(e);
137-
}));
133+
}, e -> { handleError("Failed to get current index mapping for index: {}", e, tenantId, listener, false); }));
138134

139135
} catch (Exception e) {
140-
log.error("Failed to filter field descriptions for index {}", sourceIndex, e);
141-
listener.onFailure(e);
136+
handleError("Failed to filter field descriptions for index: {}", e, tenantId, listener, false);
142137
}
143138
}
144139

@@ -233,7 +228,10 @@ private void processBatch(
233228
log.error("Error parsing response for batch in index {}: {}", sourceIndex, e.getMessage());
234229
listener.onFailure(e);
235230
}
236-
}, e -> { listener.onFailure(e); }));
231+
}, e -> {
232+
log.error("Failed to call LLM for batch processing in index {}: {}", sourceIndex, e.getMessage());
233+
listener.onFailure(e);
234+
}));
237235
}
238236

239237
private String generateBatchPrompt(List<String> batchFields, Map<String, Object> statisticalContentMap) {

common/src/main/java/org/opensearch/ml/common/indexInsight/LogRelatedIndexCheckTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void runTask(String tenantId, ActionListener<IndexInsight> listener) {
9898
e -> handleError("Failed to get agent ID from ML config", e, tenantId, listener)
9999
)
100100
);
101-
}, listener::onFailure));
101+
}, e -> handleError("Failed to collect sample documents for index: {}", e, tenantId, listener)));
102102
} catch (Exception e) {
103103
handleError("Failed log related check for index: {}", e, tenantId, listener);
104104
}

common/src/main/java/org/opensearch/ml/common/indexInsight/StatisticalDataTask.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ private void collectStatisticalData(String tenantId, boolean shouldStore, Action
122122
client.admin().indices().getMappings(getMappingsRequest, ActionListener.wrap(getMappingsResponse -> {
123123
Map<String, MappingMetadata> mappings = getMappingsResponse.getMappings();
124124
if (mappings.isEmpty()) {
125-
listener.onFailure(new IllegalArgumentException("No matching mapping with index name: " + sourceIndex));
125+
handleError(
126+
"No matching mapping with index name: {}",
127+
new IllegalArgumentException("No matching mapping with index name: " + sourceIndex),
128+
tenantId,
129+
listener,
130+
shouldStore
131+
);
126132
return;
127133
}
128134

@@ -169,9 +175,9 @@ private void collectStatisticalData(String tenantId, boolean shouldStore, Action
169175
.build();
170176
listener.onResponse(insight);
171177
}
172-
}, listener::onFailure));
178+
}, e -> handleError("Failed to filter important columns by LLM for index: {}", e, tenantId, listener, shouldStore)));
173179
}, e -> handleError("Failed to collect statistical data for index: {}", e, tenantId, listener, shouldStore)));
174-
}, listener::onFailure));
180+
}, e -> handleError("Failed to get mappings for index: {}", e, tenantId, listener, shouldStore)));
175181
}
176182

177183
@Override

0 commit comments

Comments
 (0)