|
15 | 15 | import org.opensearch.OpenSearchStatusException; |
16 | 16 | import org.opensearch.action.ActionRequest; |
17 | 17 | import org.opensearch.action.bulk.BulkRequest; |
| 18 | +import org.opensearch.action.bulk.BulkResponse; |
18 | 19 | import org.opensearch.action.search.SearchRequest; |
19 | 20 | import org.opensearch.action.search.SearchResponse; |
20 | 21 | import org.opensearch.action.support.ActionFilters; |
@@ -206,13 +207,22 @@ private void bulkSetModelIndexToUndeploy( |
206 | 207 | bulkUpdateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); |
207 | 208 | log.info("No nodes service: {}", Arrays.toString(modelIds)); |
208 | 209 |
|
209 | | - client.bulk(bulkUpdateRequest, ActionListener.wrap(br -> { |
210 | | - log.debug("Successfully set modelIds to UNDEPLOY in index"); |
211 | | - listener.onResponse(new MLUndeployModelsResponse(response)); |
212 | | - }, e -> { |
213 | | - log.error("Failed to set modelIds to UNDEPLOY in index", e); |
| 210 | + try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { |
| 211 | + ActionListener<MLUndeployModelsResponse> listenerWithContextRestoration = ActionListener.runBefore(listener, () -> threadContext.restore()); |
| 212 | + ActionListener<BulkResponse> bulkResponseListener = ActionListener.wrap(br -> { |
| 213 | + log.debug("Successfully set modelIds to UNDEPLOY in index"); |
| 214 | + listenerWithContextRestoration.onResponse(new MLUndeployModelsResponse(response)); |
| 215 | + }, e -> { |
| 216 | + log.error("Failed to set modelIds to UNDEPLOY in index", e); |
| 217 | + listenerWithContextRestoration.onFailure(e); |
| 218 | + }); |
| 219 | + |
| 220 | + client.bulk(bulkUpdateRequest, bulkResponseListener); |
| 221 | + } catch (Exception e) { |
| 222 | + log.error("Unexpected error while setting modelIds to UNDEPLOY status to index", e); |
214 | 223 | listener.onFailure(e); |
215 | | - })); |
| 224 | + } |
| 225 | + |
216 | 226 | } |
217 | 227 |
|
218 | 228 | private void validateAccess(String modelId, ActionListener<Boolean> listener) { |
|
0 commit comments