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