19
19
import org .elasticsearch .common .xcontent .ToXContentObject ;
20
20
import org .elasticsearch .common .xcontent .XContentBuilder ;
21
21
import org .elasticsearch .common .xcontent .XContentParser ;
22
- import org .elasticsearch .xpack .core .rollup .RollupField ;
23
22
import org .elasticsearch .xpack .core .rollup .job .GroupConfig ;
24
23
import org .elasticsearch .xpack .core .rollup .job .MetricConfig ;
25
24
31
30
import java .util .Objects ;
32
31
import java .util .Set ;
33
32
34
- import static org .elasticsearch .common .xcontent .ConstructingObjectParser .constructorArg ;
35
33
import static org .elasticsearch .common .xcontent .ConstructingObjectParser .optionalConstructorArg ;
36
34
37
35
/**
@@ -43,59 +41,41 @@ public class RollupActionConfig implements NamedWriteable, ToXContentObject {
43
41
private static final String NAME = "xpack/rollup/action/config" ;
44
42
private static final TimeValue DEFAULT_TIMEOUT = TimeValue .timeValueSeconds (20 );
45
43
private static final String TIMEOUT = "timeout" ;
46
- private static final String ROLLUP_INDEX = "rollup_index" ;
47
44
48
45
private final GroupConfig groupConfig ;
49
46
private final List <MetricConfig > metricsConfig ;
50
47
private final TimeValue timeout ;
51
- private String rollupIndex ;
52
48
53
49
private static final ConstructingObjectParser <RollupActionConfig , Void > PARSER ;
54
50
static {
55
51
PARSER = new ConstructingObjectParser <>(NAME , false , (args ) -> {
56
- String rollupIndex = (String ) args [0 ];
57
- GroupConfig groupConfig = (GroupConfig ) args [1 ];
52
+ GroupConfig groupConfig = (GroupConfig ) args [0 ];
58
53
@ SuppressWarnings ("unchecked" )
59
- List <MetricConfig > metricsConfig = (List <MetricConfig >) args [2 ];
60
- TimeValue timeout = (TimeValue ) args [3 ];
61
- return new RollupActionConfig (groupConfig , metricsConfig , timeout , rollupIndex );
54
+ List <MetricConfig > metricsConfig = (List <MetricConfig >) args [1 ];
55
+ TimeValue timeout = (TimeValue ) args [2 ];
56
+ return new RollupActionConfig (groupConfig , metricsConfig , timeout );
62
57
});
63
- PARSER .declareString (constructorArg (), new ParseField (ROLLUP_INDEX ));
64
58
PARSER .declareObject (optionalConstructorArg (), (p , c ) -> GroupConfig .fromXContent (p ), new ParseField (GroupConfig .NAME ));
65
59
PARSER .declareObjectArray (optionalConstructorArg (), (p , c ) -> MetricConfig .fromXContent (p ), new ParseField (MetricConfig .NAME ));
66
60
PARSER .declareField (optionalConstructorArg (), (p , c ) -> TimeValue .parseTimeValue (p .textOrNull (), TIMEOUT ),
67
61
new ParseField (TIMEOUT ), ObjectParser .ValueType .STRING_OR_NULL );
68
62
}
69
63
70
- public RollupActionConfig (final GroupConfig groupConfig , final List <MetricConfig > metricsConfig ,
71
- final @ Nullable TimeValue timeout , final String rollupIndex ) {
72
- if (rollupIndex == null || rollupIndex .isEmpty ()) {
73
- throw new IllegalArgumentException ("Rollup index must be a non-null, non-empty string" );
74
- }
64
+ public RollupActionConfig (final GroupConfig groupConfig , final List <MetricConfig > metricsConfig , final @ Nullable TimeValue timeout ) {
75
65
if (groupConfig == null && (metricsConfig == null || metricsConfig .isEmpty ())) {
76
66
throw new IllegalArgumentException ("At least one grouping or metric must be configured" );
77
67
}
78
- this .rollupIndex = rollupIndex ;
79
68
this .groupConfig = groupConfig ;
80
69
this .metricsConfig = metricsConfig != null ? metricsConfig : Collections .emptyList ();
81
70
this .timeout = timeout != null ? timeout : DEFAULT_TIMEOUT ;
82
71
}
83
72
84
73
public RollupActionConfig (final StreamInput in ) throws IOException {
85
- rollupIndex = in .readString ();
86
74
groupConfig = in .readOptionalWriteable (GroupConfig ::new );
87
75
metricsConfig = in .readList (MetricConfig ::new );
88
76
timeout = in .readTimeValue ();
89
77
}
90
78
91
- public String getId () {
92
- return RollupField .NAME + "_" + rollupIndex ;
93
- }
94
-
95
- public void setRollupIndex (String rollupIndex ) {
96
- this .rollupIndex = rollupIndex ;
97
- }
98
-
99
79
public GroupConfig getGroupConfig () {
100
80
return groupConfig ;
101
81
}
@@ -108,10 +88,6 @@ public TimeValue getTimeout() {
108
88
return timeout ;
109
89
}
110
90
111
- public String getRollupIndex () {
112
- return rollupIndex ;
113
- }
114
-
115
91
@ Override
116
92
public String getWriteableName () {
117
93
return NAME ;
@@ -142,7 +118,6 @@ public void validateMappings(final Map<String, Map<String, FieldCapabilities>> f
142
118
public XContentBuilder toXContent (final XContentBuilder builder , final Params params ) throws IOException {
143
119
builder .startObject ();
144
120
{
145
- builder .field (ROLLUP_INDEX , rollupIndex );
146
121
if (groupConfig != null ) {
147
122
builder .field (GroupConfig .NAME , groupConfig );
148
123
}
@@ -163,7 +138,6 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
163
138
164
139
@ Override
165
140
public void writeTo (final StreamOutput out ) throws IOException {
166
- out .writeString (rollupIndex );
167
141
out .writeOptionalWriteable (groupConfig );
168
142
out .writeList (metricsConfig );
169
143
out .writeTimeValue (timeout );
@@ -179,29 +153,21 @@ public boolean equals(Object other) {
179
153
}
180
154
181
155
final RollupActionConfig that = (RollupActionConfig ) other ;
182
- return Objects .equals (this .rollupIndex , that .rollupIndex )
183
- && Objects .equals (this .groupConfig , that .groupConfig )
156
+ return Objects .equals (this .groupConfig , that .groupConfig )
184
157
&& Objects .equals (this .metricsConfig , that .metricsConfig )
185
158
&& Objects .equals (this .timeout , that .timeout );
186
159
}
187
160
188
161
@ Override
189
162
public int hashCode () {
190
- return Objects .hash (rollupIndex , groupConfig , metricsConfig , timeout );
163
+ return Objects .hash (groupConfig , metricsConfig , timeout );
191
164
}
192
165
193
166
@ Override
194
167
public String toString () {
195
168
return Strings .toString (this , true , true );
196
169
}
197
170
198
- /**
199
- * Same as toString() but more explicitly named so the caller knows this is turned into JSON
200
- */
201
- public String toJSONString () {
202
- return toString ();
203
- }
204
-
205
171
public static RollupActionConfig fromXContent (final XContentParser parser ) throws IOException {
206
172
return PARSER .parse (parser , null );
207
173
}
0 commit comments