-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecation info for joda-java migration on 7.x (#42659)
Some clusters might have been already migrated to version 7 without being warned about the joda-java migration changes. Deprecation api on that version will give them guidance on what patterns need to be changed. relates. This change is using the same logic like in 6.8 that is: verifying the pattern is from the incompatible set ('y'-Y', 'C', 'Z' etc), not from predifined set, not prefixed with 8. AND was also created in 6.x. Mappings created in 7.x are considered migrated and should not generate warnings There is no pipeline check (present on 6.8) as it is impossible to verify when the pipeline was created, and therefore to make sure the format is depracated or not #42010
- Loading branch information
Showing
11 changed files
with
725 additions
and
196 deletions.
There are no files selected for viewing
174 changes: 84 additions & 90 deletions
174
server/src/main/java/org/elasticsearch/common/joda/Joda.java
Large diffs are not rendered by default.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
server/src/main/java/org/elasticsearch/common/joda/JodaDeprecationPatterns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.common.joda; | ||
|
||
import org.elasticsearch.common.time.DateFormatter; | ||
import org.elasticsearch.common.time.FormatNames; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class JodaDeprecationPatterns { | ||
public static final String USE_NEW_FORMAT_SPECIFIERS = "Use new java.time date format specifiiers."; | ||
private static Map<String, String> JODA_PATTERNS_DEPRECATIONS = new LinkedHashMap<>(); | ||
|
||
static { | ||
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year."); | ||
JODA_PATTERNS_DEPRECATIONS.put("y", "'y' year should be replaced with 'u'. Use 'y' for year-of-era."); | ||
JODA_PATTERNS_DEPRECATIONS.put("C", "'C' century of era is no longer supported."); | ||
JODA_PATTERNS_DEPRECATIONS.put("x", "'x' weak-year should be replaced with 'Y'. Use 'x' for zone-offset."); | ||
JODA_PATTERNS_DEPRECATIONS.put("Z", | ||
"'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'."); | ||
JODA_PATTERNS_DEPRECATIONS.put("z", | ||
"'z' time zone text. Will print 'Z' for Zulu given UTC timezone."); | ||
} | ||
|
||
/** | ||
* Checks if date parsing pattern is deprecated. | ||
* Deprecated here means: when it was not already prefixed with 8 (meaning already upgraded) | ||
* and it is not a predefined pattern from <code>FormatNames</code> like basic_date_time_no_millis | ||
* and it uses pattern characters which changed meaning from joda to java like Y becomes y. | ||
* @param pattern - a format to be checked | ||
* @return true if format is deprecated, otherwise false | ||
*/ | ||
public static boolean isDeprecatedPattern(String pattern) { | ||
List<String> patterns = DateFormatter.splitCombinedPatterns(pattern); | ||
|
||
for (String subPattern : patterns) { | ||
boolean isDeprecated = subPattern.startsWith("8") == false && FormatNames.exist(subPattern) == false && | ||
JODA_PATTERNS_DEPRECATIONS.keySet().stream() | ||
.filter(s -> subPattern.contains(s)) | ||
.findAny() | ||
.isPresent(); | ||
if (isDeprecated) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Formats deprecation message for suggestion field in a warning header. | ||
* Joins all warnings in a one message. | ||
* @param pattern - a pattern to be formatted | ||
* @return a formatted deprecation message | ||
*/ | ||
public static String formatSuggestion(String pattern) { | ||
List<String> patterns = DateFormatter.splitCombinedPatterns(pattern); | ||
|
||
Set<String> warnings = new LinkedHashSet<>(); | ||
for (String subPattern : patterns) { | ||
if (isDeprecatedPattern(subPattern)) { | ||
String suggestion = JODA_PATTERNS_DEPRECATIONS.entrySet().stream() | ||
.filter(s -> subPattern.contains(s.getKey())) | ||
.map(s -> s.getValue()) | ||
.collect(Collectors.joining("; ")); | ||
warnings.add(suggestion); | ||
} | ||
} | ||
String combinedWarning = warnings.stream() | ||
.collect(Collectors.joining("; ")); | ||
return combinedWarning; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.