7
7
*/
8
8
package org .elasticsearch .script ;
9
9
10
+ import org .apache .logging .log4j .LogManager ;
11
+ import org .apache .logging .log4j .Logger ;
10
12
import org .elasticsearch .ResourceNotFoundException ;
11
13
import org .elasticsearch .Version ;
12
14
import org .elasticsearch .cluster .ClusterState ;
18
20
import org .elasticsearch .common .io .stream .StreamInput ;
19
21
import org .elasticsearch .common .io .stream .StreamOutput ;
20
22
import org .elasticsearch .common .io .stream .Writeable ;
21
- import org .elasticsearch .common .logging .DeprecationCategory ;
22
- import org .elasticsearch .common .logging .DeprecationLogger ;
23
23
import org .elasticsearch .common .xcontent .ToXContentFragment ;
24
24
import org .elasticsearch .common .xcontent .XContentBuilder ;
25
25
import org .elasticsearch .common .xcontent .XContentParser ;
38
38
public final class ScriptMetadata implements Metadata .Custom , Writeable , ToXContentFragment {
39
39
40
40
/**
41
- * Standard deprecation logger for used to deprecate allowance of empty templates .
41
+ * Standard logger used to warn about dropped scripts .
42
42
*/
43
- private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (ScriptMetadata .class );
43
+ private static final Logger logger = LogManager .getLogger (ScriptMetadata .class );
44
44
45
45
/**
46
46
* A builder used to modify the currently stored scripts data held within
@@ -162,16 +162,10 @@ static ScriptMetadata deleteStoredScript(ScriptMetadata previous, String id) {
162
162
* ...
163
163
* }
164
164
* }
165
- *
166
- * When loading from a source prior to 6.0, if multiple scripts
167
- * using the old namespace id format of [lang#id] are found to have the
168
- * same id but different languages an error will occur.
169
165
*/
170
166
public static ScriptMetadata fromXContent (XContentParser parser ) throws IOException {
171
167
Map <String , StoredScriptSource > scripts = new HashMap <>();
172
168
String id = null ;
173
- StoredScriptSource source ;
174
- StoredScriptSource exists ;
175
169
176
170
Token token = parser .currentToken ();
177
171
@@ -189,84 +183,28 @@ public static ScriptMetadata fromXContent(XContentParser parser) throws IOExcept
189
183
switch (token ) {
190
184
case FIELD_NAME :
191
185
id = parser .currentName ();
192
- break ;
193
- case VALUE_STRING :
194
- if (id == null ) {
195
- throw new ParsingException (parser .getTokenLocation (),
196
- "unexpected token [" + token + "], expected [<id>, <code>, {]" );
197
- }
198
-
199
- int split = id .indexOf ('#' );
200
- String lang ;
201
-
202
- if (split == -1 ) {
203
- throw new IllegalArgumentException ("illegal stored script id [" + id + "], does not contain lang" );
204
- } else {
205
- lang = id .substring (0 , split );
206
- id = id .substring (split + 1 );
207
- source = new StoredScriptSource (lang , parser .text (), Collections .emptyMap ());
208
-
209
- if (source .getSource ().isEmpty ()) {
210
- if (source .getLang ().equals (Script .DEFAULT_TEMPLATE_LANG )) {
211
- deprecationLogger .critical (
212
- DeprecationCategory .TEMPLATES ,
213
- "empty_templates" ,
214
- "empty templates should no longer be used"
215
- );
216
- } else {
217
- deprecationLogger .critical (
218
- DeprecationCategory .TEMPLATES ,
219
- "empty_scripts" ,
220
- "empty scripts should no longer be used"
221
- );
222
- }
223
- }
224
- }
225
-
226
- exists = scripts .get (id );
227
-
228
- if (exists == null ) {
229
- scripts .put (id , source );
230
- } else if (exists .getLang ().equals (lang ) == false ) {
231
- throw new IllegalArgumentException ("illegal stored script, id [" + id + "] used for multiple scripts with " +
232
- "different languages [" + exists .getLang () + "] and [" + lang + "]; scripts using the old namespace " +
233
- "of [lang#id] as a stored script id will have to be updated to use only the new namespace of [id]" );
234
- }
235
-
236
- id = null ;
237
-
238
186
break ;
239
187
case START_OBJECT :
240
188
if (id == null ) {
241
189
throw new ParsingException (parser .getTokenLocation (),
242
190
"unexpected token [" + token + "], expected [<id>, <code>, {]" );
243
191
}
244
192
245
- exists = scripts . get ( id );
246
- source = StoredScriptSource . fromXContent ( parser , true );
247
-
248
- if ( exists == null ) {
249
- // due to a bug (https://github.com/elastic/elasticsearch/issues/47593)
250
- // scripts may have been retained during upgrade that include the old-style
251
- // id of lang#id; these scripts are unreachable after 7.0, so they are dropped
252
- if ( id . contains ( "#" ) == false ) {
253
- scripts . put ( id , source );
193
+ StoredScriptSource source = StoredScriptSource . fromXContent ( parser , true );
194
+ // as of 8.0 we drop scripts/templates with an empty source
195
+ // this check should be removed for the next upgradable version after 8.0
196
+ // since there is a guarantee no more empty scripts will exist
197
+ if ( source . getSource (). isEmpty ()) {
198
+ if ( Script . DEFAULT_TEMPLATE_LANG . equals ( source . getLang ())) {
199
+ logger . warn ( "empty template [" + id + "] found and dropped" );
200
+ } else {
201
+ logger . warn ( "empty script [" + id + "] found and dropped" );
254
202
}
255
- } else if (exists .getLang ().equals (source .getLang ()) == false ) {
256
- throw new IllegalArgumentException (
257
- "illegal stored script, id ["
258
- + id
259
- + "] used for multiple scripts with different languages ["
260
- + exists .getLang ()
261
- + "] and ["
262
- + source .getLang ()
263
- + "]; scripts using the old namespace of [lang#id] as a stored script id will have to be updated "
264
- + "to use only the new namespace of [id]"
265
- );
203
+ } else {
204
+ scripts .put (id , source );
266
205
}
267
206
268
207
id = null ;
269
-
270
208
break ;
271
209
default :
272
210
throw new ParsingException (parser .getTokenLocation (), "unexpected token [" + token + "], expected [<id>, <code>, {]" );
@@ -318,8 +256,6 @@ public void writeTo(StreamOutput out) throws IOException {
318
256
}
319
257
}
320
258
321
-
322
-
323
259
/**
324
260
* This will write XContent from {@link ScriptMetadata}. The following format will be written:
325
261
*
0 commit comments