Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation info for joda-java migration #41956

Merged
merged 54 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8f99fc7
initial work
pgomulka May 7, 2019
dbc725c
init version
pgomulka May 8, 2019
937fe06
draft working version
pgomulka May 8, 2019
92dd79f
cleanup
pgomulka May 9, 2019
0ab2a6e
commented code remove
pgomulka May 9, 2019
353af6a
joda deprecation keys
pgomulka May 9, 2019
21255e1
generic deprecation key
pgomulka May 9, 2019
6e85a05
empty lines
pgomulka May 9, 2019
8ca0fee
message fix, prefix8 suggestion
pgomulka May 9, 2019
c94bbe7
fixing test for warnings in headers
pgomulka May 10, 2019
5e7bdb3
do not report deprecation when format starts with 8
pgomulka May 11, 2019
ba913f5
unused improt
pgomulka May 14, 2019
7bc3ea7
remove ignore annotation
pgomulka May 14, 2019
837dea3
field extraction
pgomulka May 20, 2019
23f11f4
changes to support defined format names
pgomulka May 21, 2019
a758afb
change imports
pgomulka May 21, 2019
c282f14
compile fix
pgomulka May 22, 2019
1c1e5bd
disable warning comment change
pgomulka May 22, 2019
160a697
Joda is using format names
pgomulka May 22, 2019
f6776a4
snake case
pgomulka May 22, 2019
9edcc0a
missing snake case name
pgomulka May 22, 2019
f57e855
all names in a set
pgomulka May 22, 2019
03bce11
code style
pgomulka May 22, 2019
e582d38
typo
pgomulka May 22, 2019
8860748
fix failing RangeQueryBuilderTest
pgomulka May 23, 2019
73a19ad
fixing docs tests failing due to joda-java warning
pgomulka May 23, 2019
7461c0f
cleanup
pgomulka May 23, 2019
beaf55b
failing tests
pgomulka May 23, 2019
6f9c402
cleanup and javadoc
pgomulka May 23, 2019
ecc304e
Merge branch '6.8' into feature/deprecation_info_joda
pgomulka May 23, 2019
adf2c49
disable warning check
pgomulka May 23, 2019
3afeae8
warning failing tests
pgomulka May 23, 2019
d61eb70
boostrap file revert
pgomulka May 24, 2019
a23e6e8
old assertion on warning message change
pgomulka May 24, 2019
a64c61b
testing combined patterns and removing duplicates
pgomulka May 24, 2019
c853b72
test failures
pgomulka May 24, 2019
56bc22d
space after ; when combined pattern suggestion
pgomulka May 24, 2019
c4632c8
failing tests
pgomulka May 24, 2019
55a233f
unused import
pgomulka May 24, 2019
9e77047
Update x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpac…
pgomulka May 25, 2019
9b98a79
remove intellij instructions
pgomulka May 25, 2019
aa36731
pipelines support
pgomulka May 26, 2019
3e3c106
failing tests
pgomulka May 26, 2019
f7ee788
checkstyle
pgomulka May 27, 2019
eeaf96c
deprecation issue message change
pgomulka May 27, 2019
0dd1ae1
disable joda deprecation checks by default
pgomulka May 27, 2019
0afb36d
remove failing test cases
pgomulka May 27, 2019
40509ec
use constant instead of string for usePrefix8
pgomulka May 28, 2019
7d3de05
fix tests with warning assertions
pgomulka May 28, 2019
8b82383
remove warning assertion
pgomulka May 28, 2019
85fd30e
IT test failing fix
pgomulka May 28, 2019
fe2f17d
Update x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpac…
pgomulka May 29, 2019
edd0aa1
unused comment and message change
pgomulka May 29, 2019
84608c2
revert resetDeprecationLogger method access
pgomulka May 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/reference/indices/templates.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ PUT _template/template_1
}
--------------------------------------------------
// CONSOLE
// TESTSETUP
// TEST[setup:name]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to figure out how to fix Docs tests. At the moment they fail because of warnings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we would update the docs to not use deprecated functionality. Is that possible here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would - actually it would be much easier if I just use a new pattern with 8 prefix. But should this be done across all the docs?
That change is to fix the DocsClientYamlTestSuiteIT. The options is to prefix with8, assert about warnings, disable warning checks alltogether?

// TEST[warning:'y' year becomes 'u'. Use 'y' for year-of-era.; 'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. Prefix your date format with '8' to use the new specifier.]


NOTE: Index templates provide C-style /* */ block comments. Comments are allowed
everywhere in the JSON document except before the initial opening curly bracket.
Expand Down
48 changes: 26 additions & 22 deletions server/src/main/java/org/elasticsearch/common/joda/Joda.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
import java.util.Locale;
import java.util.regex.Pattern;

import static org.elasticsearch.common.time.FormatNames.BASICDATE;
import static org.elasticsearch.common.time.FormatNames.BASICDATETIME;
import static org.elasticsearch.common.time.FormatNames.BASICDATETIMENOMILLIS;
import static org.elasticsearch.common.time.FormatNames.BASICORDINALDATE;
import static org.elasticsearch.common.time.FormatNames.BASICORDINALDATETIME;
import static org.elasticsearch.common.time.FormatNames.BASICORDINALDATETIMENOMILLIS;
import static org.elasticsearch.common.time.FormatNames.BASICTIME;
import static org.elasticsearch.common.time.FormatNames.BASICTIMENOMILLIS;
import static org.elasticsearch.common.time.FormatNames.BASICTTIME;
import static org.elasticsearch.common.time.FormatNames.BASICTTIMENOMILLIS;

public class Joda {

private static DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(Joda.class));
Expand All @@ -65,25 +76,25 @@ public static JodaDateFormatter forPattern(String input) {
}

DateTimeFormatter formatter;
if ("basicDate".equals(input) || "basic_date".equals(input)) {
pgomulka marked this conversation as resolved.
Show resolved Hide resolved
if (BASICDATE.matches(input)) {
formatter = ISODateTimeFormat.basicDate();
} else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) {
} else if (BASICDATETIME.matches(input) ) {
formatter = ISODateTimeFormat.basicDateTime();
} else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) {
} else if (BASICDATETIMENOMILLIS.matches(input) ) {
formatter = ISODateTimeFormat.basicDateTimeNoMillis();
} else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) {
} else if (BASICORDINALDATE.matches(input) ) {
formatter = ISODateTimeFormat.basicOrdinalDate();
} else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) {
} else if (BASICORDINALDATETIME.matches(input) ) {
formatter = ISODateTimeFormat.basicOrdinalDateTime();
} else if ("basicOrdinalDateTimeNoMillis".equals(input) || "basic_ordinal_date_time_no_millis".equals(input)) {
} else if (BASICORDINALDATETIMENOMILLIS.matches(input) ) {
formatter = ISODateTimeFormat.basicOrdinalDateTimeNoMillis();
} else if ("basicTime".equals(input) || "basic_time".equals(input)) {
} else if (BASICTIME.matches(input) ) {
formatter = ISODateTimeFormat.basicTime();
} else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) {
} else if (BASICTIMENOMILLIS.matches(input) ) {
formatter = ISODateTimeFormat.basicTimeNoMillis();
} else if ("basicTTime".equals(input) || "basic_t_time".equals(input)) {
} else if (BASICTTIME.matches(input) ) {
formatter = ISODateTimeFormat.basicTTime();
} else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) {
} else if (BASICTTIMENOMILLIS.matches(input) ) {
formatter = ISODateTimeFormat.basicTTimeNoMillis();
} else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) {
formatter = ISODateTimeFormat.basicWeekDate();
Expand Down Expand Up @@ -267,18 +278,11 @@ public static JodaDateFormatter forPattern(String input) {
return new JodaDateFormatter(input, formatter, formatter);
}

private static void maybeLogJodaDeprecation(String input) {
if (input.contains("CC")) {
deprecationLogger.deprecatedAndMaybeLog("joda-century-of-era-format",
"Use of 'C' (century-of-era) is deprecated and will not be supported in the next major version of Elasticsearch.");
}
if (input.contains("YY")) {
deprecationLogger.deprecatedAndMaybeLog("joda-year-of-era-format", "Use of 'Y' (year-of-era) will change to 'y' in the" +
" next major version of Elasticsearch. Prefix your date format with '8' to use the new specifier.");
}
if (input.contains("xx")) {
deprecationLogger.deprecatedAndMaybeLog("joda-week-based-year-format","Use of 'x' (week-based-year) will change" +
" to 'Y' in the next major version of Elasticsearch. Prefix your date format with '8' to use the new specifier.");
private static void maybeLogJodaDeprecation(String format) {
if (JodaDeprecationPatterns.isDeprecatedFormat(format)) {
String suggestion = JodaDeprecationPatterns.formatSuggestion(format);
deprecationLogger.deprecatedAndMaybeLog("joda-pattern-deprecation",
suggestion + " " + JodaDeprecationPatterns.USE_PREFIX_8_WARNING);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class JodaDeprecationPatterns {
private static Map<String, String> JODA_PATTERNS_DEPRECATIONS = new LinkedHashMap<>();

static {
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era becomes 'y'. Use 'Y' for week-based-year.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this a bit clearer as to what we're recommending be done. Something like this:

Suggested change
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era becomes 'y'. Use 'Y' for week-based-year.");
JODA_PATTERNS_DEPRECATIONS.put("Y", "'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year.");

And similar for the rest of these.

JODA_PATTERNS_DEPRECATIONS.put("y", "'y' year becomes '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 becomes '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.");
}

public static final String USE_PREFIX_8_WARNING = "Prefix your date format with '8' to use the new specifier.";

/**
* Returns true if pattern is deprecated. That is 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->y
* @param format
* @return
*/
public static boolean isDeprecatedFormat(String format) {
List<String> patterns = DateFormatter.splitCombinedPatterns(format);

for (String pattern : patterns) {
boolean isDeprecated = pattern.startsWith("8") == false && FormatNames.exist(pattern) == false &&
JODA_PATTERNS_DEPRECATIONS.keySet().stream()
.filter(s -> pattern.contains(s))
.findAny()
.isPresent();
if (isDeprecated)
return true;
}
return false;
}

public static String formatSuggestion(String format) {
List<String> patterns = DateFormatter.splitCombinedPatterns(format);

StringJoiner joiner = new StringJoiner("; ");
for (String pattern : patterns) {
if (isDeprecatedFormat(pattern)) {

String suggestion = JODA_PATTERNS_DEPRECATIONS.entrySet().stream()
.filter(s -> pattern.contains(s.getKey()))
.map(s -> s.getValue())
.collect(Collectors.joining("; "));
joiner.add(suggestion);
}
}
return joiner.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public interface DateFormatter {

Expand Down Expand Up @@ -138,18 +139,26 @@ static DateFormatter forPattern(String input) {
// dates starting with 8 will not be using joda but java time formatters
input = input.substring(1);

List<DateFormatter> formatters = new ArrayList<>();
for (String pattern : Strings.delimitedListToStringArray(input, "||")) {
if (Strings.hasLength(pattern) == false) {
throw new IllegalArgumentException("Cannot have empty element in multi date format pattern: " + input);
}
formatters.add(DateFormatters.forPattern(pattern));
}
List<String> patterns = splitCombinedPatterns(input);
List<DateFormatter> formatters = patterns.stream()
.map(DateFormatters::forPattern)
.collect(Collectors.toList());

if (formatters.size() == 1) {
return formatters.get(0);
}

return DateFormatters.merge(input, formatters);
}

public static List<String> splitCombinedPatterns(String input) {
List<String> formatters = new ArrayList<>();
for (String pattern : Strings.delimitedListToStringArray(input, "||")) {
if (Strings.hasLength(pattern) == false) {
throw new IllegalArgumentException("Cannot have empty element in multi date format pattern: " + input);
}
formatters.add(pattern);
}
return formatters;
}
}
Loading