44
44
import org .elasticsearch .xpack .core .ml .dataframe .DataFrameAnalyticsTaskState ;
45
45
import org .elasticsearch .xpack .core .ml .dataframe .stats .AnalysisStats ;
46
46
import org .elasticsearch .xpack .core .ml .dataframe .stats .Fields ;
47
- import org .elasticsearch .xpack .core .ml .dataframe .stats .common .MemoryUsage ;
48
47
import org .elasticsearch .xpack .core .ml .dataframe .stats .classification .ClassificationStats ;
49
48
import org .elasticsearch .xpack .core .ml .dataframe .stats .common .DataCounts ;
49
+ import org .elasticsearch .xpack .core .ml .dataframe .stats .common .MemoryUsage ;
50
50
import org .elasticsearch .xpack .core .ml .dataframe .stats .outlierdetection .OutlierDetectionStats ;
51
51
import org .elasticsearch .xpack .core .ml .dataframe .stats .regression .RegressionStats ;
52
52
import org .elasticsearch .xpack .core .ml .job .persistence .AnomalyDetectorsIndex ;
55
55
import org .elasticsearch .xpack .ml .dataframe .DataFrameAnalyticsTask ;
56
56
import org .elasticsearch .xpack .ml .dataframe .StoredProgress ;
57
57
import org .elasticsearch .xpack .ml .dataframe .stats .ProgressTracker ;
58
- import org .elasticsearch .xpack .ml .dataframe .stats .StatsHolder ;
59
58
import org .elasticsearch .xpack .ml .utils .persistence .MlParserUtils ;
60
59
61
60
import java .util .ArrayList ;
@@ -105,25 +104,20 @@ protected void taskOperation(GetDataFrameAnalyticsStatsAction.Request request, D
105
104
ActionListener <QueryPage <Stats >> listener ) {
106
105
logger .debug ("Get stats for running task [{}]" , task .getParams ().getId ());
107
106
108
- ActionListener <StatsHolder > statsHolderListener = ActionListener .wrap (
109
- statsHolder -> {
107
+ ActionListener <Void > reindexingProgressListener = ActionListener .wrap (
108
+ aVoid -> {
110
109
Stats stats = buildStats (
111
110
task .getParams ().getId (),
112
- statsHolder .getProgressTracker ().report (),
113
- statsHolder .getDataCountsTracker ().report (task .getParams ().getId ()),
114
- statsHolder .getMemoryUsage (),
115
- statsHolder .getAnalysisStats ()
111
+ task . getStatsHolder () .getProgressTracker ().report (),
112
+ task . getStatsHolder () .getDataCountsTracker ().report (task .getParams ().getId ()),
113
+ task . getStatsHolder () .getMemoryUsage (),
114
+ task . getStatsHolder () .getAnalysisStats ()
116
115
);
117
116
listener .onResponse (new QueryPage <>(Collections .singletonList (stats ), 1 ,
118
117
GetDataFrameAnalyticsAction .Response .RESULTS_FIELD ));
119
118
}, listener ::onFailure
120
119
);
121
120
122
- ActionListener <Void > reindexingProgressListener = ActionListener .wrap (
123
- aVoid -> statsHolderListener .onResponse (task .getStatsHolder ()),
124
- listener ::onFailure
125
- );
126
-
127
121
task .updateReindexTaskProgress (reindexingProgressListener );
128
122
}
129
123
@@ -138,7 +132,7 @@ protected void doExecute(Task task, GetDataFrameAnalyticsStatsAction.Request req
138
132
.collect (Collectors .toList ());
139
133
request .setExpandedIds (expandedIds );
140
134
ActionListener <GetDataFrameAnalyticsStatsAction .Response > runningTasksStatsListener = ActionListener .wrap (
141
- runningTasksStatsResponse -> gatherStatsForStoppedTasks (request . getExpandedIds (), runningTasksStatsResponse ,
135
+ runningTasksStatsResponse -> gatherStatsForStoppedTasks (getResponse . getResources (). results (), runningTasksStatsResponse ,
142
136
ActionListener .wrap (
143
137
finalResponse -> {
144
138
@@ -163,20 +157,20 @@ protected void doExecute(Task task, GetDataFrameAnalyticsStatsAction.Request req
163
157
executeAsyncWithOrigin (client , ML_ORIGIN , GetDataFrameAnalyticsAction .INSTANCE , getRequest , getResponseListener );
164
158
}
165
159
166
- void gatherStatsForStoppedTasks (List <String > expandedIds , GetDataFrameAnalyticsStatsAction .Response runningTasksResponse ,
160
+ void gatherStatsForStoppedTasks (List <DataFrameAnalyticsConfig > configs , GetDataFrameAnalyticsStatsAction .Response runningTasksResponse ,
167
161
ActionListener <GetDataFrameAnalyticsStatsAction .Response > listener ) {
168
- List <String > stoppedTasksIds = determineStoppedTasksIds ( expandedIds , runningTasksResponse .getResponse ().results ());
169
- if (stoppedTasksIds .isEmpty ()) {
162
+ List <DataFrameAnalyticsConfig > stoppedConfigs = determineStoppedConfigs ( configs , runningTasksResponse .getResponse ().results ());
163
+ if (stoppedConfigs .isEmpty ()) {
170
164
listener .onResponse (runningTasksResponse );
171
165
return ;
172
166
}
173
167
174
- AtomicInteger counter = new AtomicInteger (stoppedTasksIds .size ());
175
- AtomicArray <Stats > jobStats = new AtomicArray <>(stoppedTasksIds .size ());
176
- for (int i = 0 ; i < stoppedTasksIds .size (); i ++) {
168
+ AtomicInteger counter = new AtomicInteger (stoppedConfigs .size ());
169
+ AtomicArray <Stats > jobStats = new AtomicArray <>(stoppedConfigs .size ());
170
+ for (int i = 0 ; i < stoppedConfigs .size (); i ++) {
177
171
final int slot = i ;
178
- String jobId = stoppedTasksIds .get (i );
179
- searchStats (jobId , ActionListener .wrap (
172
+ DataFrameAnalyticsConfig config = stoppedConfigs .get (i );
173
+ searchStats (config , ActionListener .wrap (
180
174
stats -> {
181
175
jobStats .set (slot , stats );
182
176
if (counter .decrementAndGet () == 0 ) {
@@ -192,23 +186,24 @@ void gatherStatsForStoppedTasks(List<String> expandedIds, GetDataFrameAnalyticsS
192
186
}
193
187
}
194
188
195
- static List <String > determineStoppedTasksIds (List <String > expandedIds , List <Stats > runningTasksStats ) {
189
+ static List <DataFrameAnalyticsConfig > determineStoppedConfigs (List <DataFrameAnalyticsConfig > configs , List <Stats > runningTasksStats ) {
196
190
Set <String > startedTasksIds = runningTasksStats .stream ().map (Stats ::getId ).collect (Collectors .toSet ());
197
- return expandedIds .stream ().filter (id -> startedTasksIds .contains (id ) == false ).collect (Collectors .toList ());
191
+ return configs .stream ().filter (config -> startedTasksIds .contains (config . getId () ) == false ).collect (Collectors .toList ());
198
192
}
199
193
200
- private void searchStats (String configId , ActionListener <Stats > listener ) {
201
- logger .debug ("[{}] Gathering stats for stopped task" , configId );
194
+ private void searchStats (DataFrameAnalyticsConfig config , ActionListener <Stats > listener ) {
195
+ logger .debug ("[{}] Gathering stats for stopped task" , config . getId () );
202
196
203
- RetrievedStatsHolder retrievedStatsHolder = new RetrievedStatsHolder ();
197
+ RetrievedStatsHolder retrievedStatsHolder = new RetrievedStatsHolder (
198
+ ProgressTracker .fromZeroes (config .getAnalysis ().getProgressPhases ()).report ());
204
199
205
200
MultiSearchRequest multiSearchRequest = new MultiSearchRequest ();
206
- multiSearchRequest .add (buildStoredProgressSearch (configId ));
207
- multiSearchRequest .add (buildStatsDocSearch (configId , DataCounts .TYPE_VALUE ));
208
- multiSearchRequest .add (buildStatsDocSearch (configId , MemoryUsage .TYPE_VALUE ));
209
- multiSearchRequest .add (buildStatsDocSearch (configId , OutlierDetectionStats .TYPE_VALUE ));
210
- multiSearchRequest .add (buildStatsDocSearch (configId , ClassificationStats .TYPE_VALUE ));
211
- multiSearchRequest .add (buildStatsDocSearch (configId , RegressionStats .TYPE_VALUE ));
201
+ multiSearchRequest .add (buildStoredProgressSearch (config . getId () ));
202
+ multiSearchRequest .add (buildStatsDocSearch (config . getId () , DataCounts .TYPE_VALUE ));
203
+ multiSearchRequest .add (buildStatsDocSearch (config . getId () , MemoryUsage .TYPE_VALUE ));
204
+ multiSearchRequest .add (buildStatsDocSearch (config . getId () , OutlierDetectionStats .TYPE_VALUE ));
205
+ multiSearchRequest .add (buildStatsDocSearch (config . getId () , ClassificationStats .TYPE_VALUE ));
206
+ multiSearchRequest .add (buildStatsDocSearch (config . getId () , RegressionStats .TYPE_VALUE ));
212
207
213
208
executeAsyncWithOrigin (client , ML_ORIGIN , MultiSearchAction .INSTANCE , multiSearchRequest , ActionListener .wrap (
214
209
multiSearchResponse -> {
@@ -220,7 +215,7 @@ private void searchStats(String configId, ActionListener<Stats> listener) {
220
215
logger .error (
221
216
new ParameterizedMessage (
222
217
"[{}] Item failure encountered during multi search for request [indices={}, source={}]: {}" ,
223
- configId , itemRequest .indices (), itemRequest .source (), itemResponse .getFailureMessage ()),
218
+ config . getId () , itemRequest .indices (), itemRequest .source (), itemResponse .getFailureMessage ()),
224
219
itemResponse .getFailure ());
225
220
listener .onFailure (ExceptionsHelper .serverError (itemResponse .getFailureMessage (), itemResponse .getFailure ()));
226
221
return ;
@@ -229,13 +224,13 @@ private void searchStats(String configId, ActionListener<Stats> listener) {
229
224
if (hits .length == 0 ) {
230
225
// Not found
231
226
} else if (hits .length == 1 ) {
232
- parseHit (hits [0 ], configId , retrievedStatsHolder );
227
+ parseHit (hits [0 ], config . getId () , retrievedStatsHolder );
233
228
} else {
234
229
throw ExceptionsHelper .serverError ("Found [" + hits .length + "] hits when just one was requested" );
235
230
}
236
231
}
237
232
}
238
- listener .onResponse (buildStats (configId ,
233
+ listener .onResponse (buildStats (config . getId () ,
239
234
retrievedStatsHolder .progress .get (),
240
235
retrievedStatsHolder .dataCounts ,
241
236
retrievedStatsHolder .memoryUsage ,
@@ -322,9 +317,13 @@ private GetDataFrameAnalyticsStatsAction.Response.Stats buildStats(String concre
322
317
323
318
private static class RetrievedStatsHolder {
324
319
325
- private volatile StoredProgress progress = new StoredProgress ( new ProgressTracker (). report ()) ;
320
+ private volatile StoredProgress progress ;
326
321
private volatile DataCounts dataCounts ;
327
322
private volatile MemoryUsage memoryUsage ;
328
323
private volatile AnalysisStats analysisStats ;
324
+
325
+ private RetrievedStatsHolder (List <PhaseProgress > defaultProgress ) {
326
+ progress = new StoredProgress (defaultProgress );
327
+ }
329
328
}
330
329
}
0 commit comments