@@ -107,15 +107,7 @@ public JobDataDeleter(Client client, String jobId, boolean deleteUserAnnotations
107
107
*/
108
108
public void deleteModelSnapshots (List <ModelSnapshot > modelSnapshots , ActionListener <BulkByScrollResponse > listener ) {
109
109
if (modelSnapshots .isEmpty ()) {
110
- listener .onResponse (
111
- new BulkByScrollResponse (
112
- TimeValue .ZERO ,
113
- new BulkByScrollTask .Status (Collections .emptyList (), null ),
114
- Collections .emptyList (),
115
- Collections .emptyList (),
116
- false
117
- )
118
- );
110
+ listener .onResponse (emptyBulkByScrollResponse ());
119
111
return ;
120
112
}
121
113
@@ -132,7 +124,12 @@ public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListe
132
124
indices .add (AnomalyDetectorsIndex .jobResultsAliasedName (modelSnapshot .getJobId ()));
133
125
}
134
126
135
- String [] indicesToQuery = removeReadOnlyIndices (new ArrayList <>(indices ), listener , "model snapshots" , null );
127
+ String [] indicesToQuery = removeReadOnlyIndices (
128
+ new ArrayList <>(indices ),
129
+ listener ,
130
+ "model snapshots" ,
131
+ () -> listener .onResponse (emptyBulkByScrollResponse ())
132
+ );
136
133
if (indicesToQuery .length == 0 ) return ;
137
134
138
135
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest (indicesToQuery ).setRefresh (true )
@@ -145,6 +142,16 @@ public void deleteModelSnapshots(List<ModelSnapshot> modelSnapshots, ActionListe
145
142
executeAsyncWithOrigin (client , ML_ORIGIN , DeleteByQueryAction .INSTANCE , deleteByQueryRequest , listener );
146
143
}
147
144
145
+ private static BulkByScrollResponse emptyBulkByScrollResponse () {
146
+ return new BulkByScrollResponse (
147
+ TimeValue .ZERO ,
148
+ new BulkByScrollTask .Status (Collections .emptyList (), null ),
149
+ Collections .emptyList (),
150
+ Collections .emptyList (),
151
+ false
152
+ );
153
+ }
154
+
148
155
/**
149
156
* Asynchronously delete the annotations
150
157
* If the deleteUserAnnotations field is set to true then all
@@ -309,7 +316,7 @@ public void deleteDatafeedTimingStats(ActionListener<BulkByScrollResponse> liste
309
316
List .of (AnomalyDetectorsIndex .jobResultsAliasedName (jobId )),
310
317
listener ,
311
318
"datafeed timing stats" ,
312
- null
319
+ () -> listener . onResponse ( emptyBulkByScrollResponse ())
313
320
);
314
321
if (indicesToQuery .length == 0 ) return ;
315
322
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest (indicesToQuery ).setRefresh (true )
@@ -502,7 +509,12 @@ private void deleteResultsByQuery(
502
509
ActionListener <BroadcastResponse > refreshListener = ActionListener .wrap (refreshResponse -> {
503
510
logger .info ("[{}] running delete by query on [{}]" , jobId , String .join (", " , indices ));
504
511
ConstantScoreQueryBuilder query = new ConstantScoreQueryBuilder (new TermQueryBuilder (Job .ID .getPreferredName (), jobId ));
505
- String [] indicesToQuery = removeReadOnlyIndices (List .of (indices ), listener , "results" , null );
512
+ String [] indicesToQuery = removeReadOnlyIndices (
513
+ List .of (indices ),
514
+ listener ,
515
+ "results" ,
516
+ () -> listener .onResponse (emptyBulkByScrollResponse ())
517
+ );
506
518
if (indicesToQuery .length == 0 ) return ;
507
519
DeleteByQueryRequest request = new DeleteByQueryRequest (indicesToQuery ).setQuery (query )
508
520
.setIndicesOptions (MlIndicesUtils .addIgnoreUnavailable (IndicesOptions .lenientExpandOpenHidden ()))
0 commit comments