9
9
import org .elasticsearch .action .ActionListener ;
10
10
import org .elasticsearch .action .support .ActionFilters ;
11
11
import org .elasticsearch .action .support .master .TransportMasterNodeAction ;
12
+ import org .elasticsearch .client .Client ;
12
13
import org .elasticsearch .cluster .ClusterState ;
13
14
import org .elasticsearch .cluster .block .ClusterBlockException ;
14
15
import org .elasticsearch .cluster .block .ClusterBlockLevel ;
15
16
import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
16
17
import org .elasticsearch .cluster .service .ClusterService ;
18
+ import org .elasticsearch .common .CheckedConsumer ;
17
19
import org .elasticsearch .common .inject .Inject ;
18
20
import org .elasticsearch .common .settings .Settings ;
19
21
import org .elasticsearch .license .LicenseUtils ;
23
25
import org .elasticsearch .xpack .ccr .Ccr ;
24
26
import org .elasticsearch .xpack .ccr .CcrLicenseChecker ;
25
27
import org .elasticsearch .xpack .core .ccr .AutoFollowStats ;
26
- import org .elasticsearch .xpack .core .ccr .action .AutoFollowStatsAction ;
28
+ import org .elasticsearch .xpack .core .ccr .action .FollowStatsAction ;
29
+ import org .elasticsearch .xpack .core .ccr .action .StatsAction ;
27
30
28
31
import java .util .Objects ;
29
32
30
- public class TransportAutoFollowStatsAction
31
- extends TransportMasterNodeAction <AutoFollowStatsAction .Request , AutoFollowStatsAction .Response > {
33
+ public class TransportStatsAction extends TransportMasterNodeAction <StatsAction .Request , StatsAction .Response > {
32
34
35
+ private final Client client ;
33
36
private final CcrLicenseChecker ccrLicenseChecker ;
34
37
private final AutoFollowCoordinator autoFollowCoordinator ;
35
38
36
39
@ Inject
37
- public TransportAutoFollowStatsAction (
40
+ public TransportStatsAction (
38
41
Settings settings ,
39
42
TransportService transportService ,
40
43
ClusterService clusterService ,
41
44
ThreadPool threadPool ,
42
45
ActionFilters actionFilters ,
43
46
IndexNameExpressionResolver indexNameExpressionResolver ,
44
47
AutoFollowCoordinator autoFollowCoordinator ,
45
- CcrLicenseChecker ccrLicenseChecker
48
+ CcrLicenseChecker ccrLicenseChecker ,
49
+ Client client
46
50
) {
47
51
super (
48
52
settings ,
49
- AutoFollowStatsAction .NAME ,
53
+ StatsAction .NAME ,
50
54
transportService ,
51
55
clusterService ,
52
56
threadPool ,
53
57
actionFilters ,
54
- AutoFollowStatsAction .Request ::new ,
58
+ StatsAction .Request ::new ,
55
59
indexNameExpressionResolver
56
60
);
61
+ this .client = client ;
57
62
this .ccrLicenseChecker = Objects .requireNonNull (ccrLicenseChecker );
58
63
this .autoFollowCoordinator = Objects .requireNonNull (autoFollowCoordinator );
59
64
}
@@ -64,12 +69,12 @@ protected String executor() {
64
69
}
65
70
66
71
@ Override
67
- protected AutoFollowStatsAction .Response newResponse () {
68
- return new AutoFollowStatsAction .Response ();
72
+ protected StatsAction .Response newResponse () {
73
+ return new StatsAction .Response ();
69
74
}
70
75
71
76
@ Override
72
- protected void doExecute (Task task , AutoFollowStatsAction .Request request , ActionListener <AutoFollowStatsAction .Response > listener ) {
77
+ protected void doExecute (Task task , StatsAction .Request request , ActionListener <StatsAction .Response > listener ) {
73
78
if (ccrLicenseChecker .isCcrAllowed () == false ) {
74
79
listener .onFailure (LicenseUtils .newComplianceException ("ccr" ));
75
80
return ;
@@ -79,16 +84,20 @@ protected void doExecute(Task task, AutoFollowStatsAction.Request request, Actio
79
84
80
85
@ Override
81
86
protected void masterOperation (
82
- AutoFollowStatsAction .Request request ,
87
+ StatsAction .Request request ,
83
88
ClusterState state ,
84
- ActionListener <AutoFollowStatsAction .Response > listener
89
+ ActionListener <StatsAction .Response > listener
85
90
) throws Exception {
86
- AutoFollowStats stats = autoFollowCoordinator .getStats ();
87
- listener .onResponse (new AutoFollowStatsAction .Response (stats ));
91
+ CheckedConsumer <FollowStatsAction .StatsResponses , Exception > handler = statsResponse -> {
92
+ AutoFollowStats stats = autoFollowCoordinator .getStats ();
93
+ listener .onResponse (new StatsAction .Response (stats , statsResponse ));
94
+ };
95
+ FollowStatsAction .StatsRequest statsRequest = new FollowStatsAction .StatsRequest ();
96
+ client .execute (FollowStatsAction .INSTANCE , statsRequest , ActionListener .wrap (handler , listener ::onFailure ));
88
97
}
89
98
90
99
@ Override
91
- protected ClusterBlockException checkBlock (AutoFollowStatsAction .Request request , ClusterState state ) {
100
+ protected ClusterBlockException checkBlock (StatsAction .Request request , ClusterState state ) {
92
101
return state .blocks ().globalBlockedException (ClusterBlockLevel .METADATA_READ );
93
102
}
94
103
}
0 commit comments