|
16 | 16 | import org.opensearch.OpenSearchStatusException; |
17 | 17 | import org.opensearch.action.ActionRequest; |
18 | 18 | import org.opensearch.action.bulk.BulkRequest; |
| 19 | +import org.opensearch.action.bulk.BulkResponse; |
19 | 20 | import org.opensearch.action.search.SearchRequest; |
20 | 21 | import org.opensearch.action.search.SearchResponse; |
21 | 22 | import org.opensearch.action.support.ActionFilters; |
@@ -229,13 +230,22 @@ private void bulkSetModelIndexToUndeploy( |
229 | 230 | bulkUpdateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); |
230 | 231 | log.info("No nodes service: {}", Arrays.toString(modelIds)); |
231 | 232 |
|
232 | | - client.bulk(bulkUpdateRequest, ActionListener.wrap(br -> { |
233 | | - log.debug("Successfully set modelIds to UNDEPLOY in index"); |
234 | | - listener.onResponse(new MLUndeployModelsResponse(response)); |
235 | | - }, e -> { |
236 | | - log.error("Failed to set modelIds to UNDEPLOY in index", e); |
| 233 | + try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { |
| 234 | + ActionListener<MLUndeployModelsResponse> listenerWithContextRestoration = ActionListener.runBefore(listener, () -> threadContext.restore()); |
| 235 | + ActionListener<BulkResponse> bulkResponseListener = ActionListener.wrap(br -> { |
| 236 | + log.debug("Successfully set modelIds to UNDEPLOY in index"); |
| 237 | + listenerWithContextRestoration.onResponse(new MLUndeployModelsResponse(response)); |
| 238 | + }, e -> { |
| 239 | + log.error("Failed to set modelIds to UNDEPLOY in index", e); |
| 240 | + listenerWithContextRestoration.onFailure(e); |
| 241 | + }); |
| 242 | + |
| 243 | + client.bulk(bulkUpdateRequest, bulkResponseListener); |
| 244 | + } catch (Exception e) { |
| 245 | + log.error("Unexpected error while setting modelIds to UNDEPLOY status to index", e); |
237 | 246 | listener.onFailure(e); |
238 | | - })); |
| 247 | + } |
| 248 | + |
239 | 249 | } |
240 | 250 |
|
241 | 251 | private void validateAccess(String modelId, String tenantId, ActionListener<Boolean> listener) { |
|
0 commit comments