diff --git a/docs/painless/painless-api-reference/painless-api-reference-score/index.asciidoc b/docs/painless/painless-api-reference/painless-api-reference-score/index.asciidoc index d9cb42f2e8a38..e91b8026dc333 100644 --- a/docs/painless/painless-api-reference/painless-api-reference-score/index.asciidoc +++ b/docs/painless/painless-api-reference/painless-api-reference-score/index.asciidoc @@ -11,9 +11,9 @@ The following specialized API is available in the Score context. The following methods are directly callable without a class/instance qualifier. Note parameters denoted by a (*) are treated as read-only values. * double cosineSimilarity(List *, String *) -* double decayDateExp(String *, String *, String *, double *, JodaCompatibleZonedDateTime) -* double decayDateGauss(String *, String *, String *, double *, JodaCompatibleZonedDateTime) -* double decayDateLinear(String *, String *, String *, double *, JodaCompatibleZonedDateTime) +* double decayDateExp(String *, String *, String *, double *, ZonedDateTime) +* double decayDateGauss(String *, String *, String *, double *, ZonedDateTime) +* double decayDateLinear(String *, String *, String *, double *, ZonedDateTime) * double decayGeoExp(String *, String *, String *, double *, GeoPoint) * double decayGeoGauss(String *, String *, String *, double *, GeoPoint) * double decayGeoLinear(String *, String *, String *, double *, GeoPoint) diff --git a/docs/reference/migration/migrate_8_0.asciidoc b/docs/reference/migration/migrate_8_0.asciidoc index d95e9d556fbb2..dad7b225b936a 100644 --- a/docs/reference/migration/migrate_8_0.asciidoc +++ b/docs/reference/migration/migrate_8_0.asciidoc @@ -31,6 +31,7 @@ coming[8.0.0] * <> * <> * <> +* <> * <> * <> * <> @@ -132,6 +133,7 @@ include::migrate_8_0/packaging.asciidoc[] include::migrate_8_0/reindex.asciidoc[] include::migrate_8_0/api.asciidoc[] include::migrate_8_0/rollup.asciidoc[] +include::migrate_8_0/scripting.asciidoc[] include::migrate_8_0/search.asciidoc[] include::migrate_8_0/security.asciidoc[] include::migrate_8_0/settings.asciidoc[] diff --git a/docs/reference/migration/migrate_8_0/scripting.asciidoc b/docs/reference/migration/migrate_8_0/scripting.asciidoc new file mode 100644 index 0000000000000..f4e9724d04c63 --- /dev/null +++ b/docs/reference/migration/migrate_8_0/scripting.asciidoc @@ -0,0 +1,25 @@ +[discrete] +[[breaking_80_scripting_changes]] +==== Scripting changes + +//NOTE: The notable-breaking-changes tagged regions are re-used in the +//Installation and Upgrade Guide + +//tag::notable-breaking-changes[] +.The `JodaCompatibleDateTime` class has been removed. +[%collapsible] +==== +*Details* + +As a transition from Joda datetime to Java datetime, scripting used +an intermediate class called `JodaCompatibleDateTime`. This class has +been removed and is replaced by `ZonedDateTime`. Any use of casting +to a `JodaCompatibleDateTime` in a script will result in a compilation +error, and may not allow the upgraded node to start. + +*Impact* + +Before upgrading, replace `getDayOfWeek` with `getDayOfWeekEnum().value` in any +scripts. Any use of `getDayOfWeek` expecting a return value of `int` will result +in a compilation error or runtime error and may not allow the upgraded node to +start. +==== +// end::notable-breaking-changes[] \ No newline at end of file diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java index e3beb83a7c482..c3646b86a445b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/AnalyzerCaster.java @@ -11,9 +11,7 @@ import org.elasticsearch.painless.lookup.PainlessCast; import org.elasticsearch.painless.lookup.PainlessLookupUtility; import org.elasticsearch.painless.lookup.def; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; -import java.time.ZonedDateTime; import java.util.Objects; /** @@ -63,19 +61,11 @@ public static PainlessCast getLegalCast(Location location, Class actual, Clas return PainlessCast.originalTypetoTargetType(def.class, Float.class, explicit); } else if (expected == Double.class) { return PainlessCast.originalTypetoTargetType(def.class, Double.class, explicit); - // TODO: remove this when the transition from Joda to Java datetimes is completed - } else if (expected == ZonedDateTime.class) { - return PainlessCast.originalTypetoTargetType(def.class, ZonedDateTime.class, explicit); } } else if (actual == String.class) { if (expected == char.class && explicit) { return PainlessCast.originalTypetoTargetType(String.class, char.class, true); } - // TODO: remove this when the transition from Joda to Java datetimes is completed - } else if (actual == JodaCompatibleZonedDateTime.class) { - if (expected == ZonedDateTime.class) { - return PainlessCast.originalTypetoTargetType(JodaCompatibleZonedDateTime.class, ZonedDateTime.class, explicit); - } } else if (actual == boolean.class) { if (expected == def.class) { return PainlessCast.boxOriginalType(Boolean.class, def.class, explicit, boolean.class); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index d1a97d42bcb79..b6f6c10a3859b 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -12,13 +12,11 @@ import org.elasticsearch.painless.lookup.PainlessLookupUtility; import org.elasticsearch.painless.lookup.PainlessMethod; import org.elasticsearch.painless.symbol.FunctionTable; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import java.lang.invoke.CallSite; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.time.ZonedDateTime; import java.util.BitSet; import java.util.Collections; import java.util.Iterator; @@ -1202,15 +1200,6 @@ public static String defToStringExplicit(final Object value) { } } - // TODO: remove this when the transition from Joda to Java datetimes is completed - public static ZonedDateTime defToZonedDateTime(final Object value) { - if (value instanceof JodaCompatibleZonedDateTime) { - return ((JodaCompatibleZonedDateTime)value).getZonedDateTime(); - } - - return (ZonedDateTime)value; - } - /** * "Normalizes" the index into a {@code Map} by making no change to the index. */ diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java index 237a006293a8d..919543d54f1fd 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/MethodWriter.java @@ -11,7 +11,6 @@ import org.elasticsearch.painless.lookup.PainlessCast; import org.elasticsearch.painless.lookup.PainlessMethod; import org.elasticsearch.painless.lookup.def; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; @@ -20,7 +19,6 @@ import org.objectweb.asm.commons.Method; import java.lang.reflect.Modifier; -import java.time.ZonedDateTime; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; @@ -62,10 +60,8 @@ import static org.elasticsearch.painless.WriterConstants.DEF_TO_P_SHORT_IMPLICIT; import static org.elasticsearch.painless.WriterConstants.DEF_TO_STRING_EXPLICIT; import static org.elasticsearch.painless.WriterConstants.DEF_TO_STRING_IMPLICIT; -import static org.elasticsearch.painless.WriterConstants.DEF_TO_ZONEDDATETIME; import static org.elasticsearch.painless.WriterConstants.DEF_UTIL_TYPE; import static org.elasticsearch.painless.WriterConstants.INDY_STRING_CONCAT_BOOTSTRAP_HANDLE; -import static org.elasticsearch.painless.WriterConstants.JCZDT_TO_ZONEDDATETIME; import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE; import static org.elasticsearch.painless.WriterConstants.MAX_INDY_STRING_CONCAT_ARGS; import static org.elasticsearch.painless.WriterConstants.PAINLESS_ERROR_TYPE; @@ -153,9 +149,6 @@ public void writeCast(PainlessCast cast) { invokeStatic(UTILITY_TYPE, CHAR_TO_STRING); } else if (cast.originalType == String.class && cast.targetType == char.class) { invokeStatic(UTILITY_TYPE, STRING_TO_CHAR); - // TODO: remove this when the transition from Joda to Java datetimes is completed - } else if (cast.originalType == JodaCompatibleZonedDateTime.class && cast.targetType == ZonedDateTime.class) { - invokeStatic(UTILITY_TYPE, JCZDT_TO_ZONEDDATETIME); } else if (cast.unboxOriginalType != null && cast.boxTargetType != null) { unbox(getType(cast.unboxOriginalType)); writeCast(cast.unboxOriginalType, cast.boxTargetType); @@ -191,8 +184,6 @@ public void writeCast(PainlessCast cast) { else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_FLOAT_EXPLICIT); else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_DOUBLE_EXPLICIT); else if (cast.targetType == String.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_STRING_EXPLICIT); - // TODO: remove this when the transition from Joda to Java datetimes is completed - else if (cast.targetType == ZonedDateTime.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_ZONEDDATETIME); else { writeCast(cast.originalType, cast.targetType); } @@ -214,8 +205,6 @@ public void writeCast(PainlessCast cast) { else if (cast.targetType == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_FLOAT_IMPLICIT); else if (cast.targetType == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_B_DOUBLE_IMPLICIT); else if (cast.targetType == String.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_STRING_IMPLICIT); - // TODO: remove this when the transition from Joda to Java datetimes is completed - else if (cast.targetType == ZonedDateTime.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_ZONEDDATETIME); else { writeCast(cast.originalType, cast.targetType); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Utility.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Utility.java index 6e8ebdfe7b5c0..03608224d31e0 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Utility.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Utility.java @@ -8,10 +8,6 @@ package org.elasticsearch.painless; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; - -import java.time.ZonedDateTime; - /** * A set of methods for non-native boxing and non-native * exact math operations used at both compile-time and runtime. @@ -36,10 +32,5 @@ public static char StringTochar(final String value) { return value.charAt(0); } - // TODO: remove this when the transition from Joda to Java datetimes is completed - public static ZonedDateTime JCZDTToZonedDateTime(final JodaCompatibleZonedDateTime jczdt) { - return jczdt.getZonedDateTime(); - } - private Utility() {} } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java index f7ba9a084a9aa..2e211cbfc8c75 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/WriterConstants.java @@ -8,7 +8,6 @@ package org.elasticsearch.painless; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.objectweb.asm.Handle; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -18,7 +17,6 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -58,10 +56,6 @@ public final class WriterConstants { public static final Method STRING_TO_CHAR = getAsmMethod(char.class, "StringTochar", String.class); public static final Method CHAR_TO_STRING = getAsmMethod(String.class, "charToString", char.class); - // TODO: remove this when the transition from Joda to Java datetimes is completed - public static final Method JCZDT_TO_ZONEDDATETIME = - getAsmMethod(ZonedDateTime.class, "JCZDTToZonedDateTime", JodaCompatibleZonedDateTime.class); - /** * A Method instance for {@linkplain Pattern}. This isn't available from PainlessLookup because we intentionally don't add it * there so that the script can't create regexes without this syntax. Essentially, our static regex syntax has a monopoly on building @@ -117,9 +111,6 @@ public final class WriterConstants { public static final Method DEF_TO_STRING_IMPLICIT = getAsmMethod(String.class, "defToStringImplicit", Object.class); public static final Method DEF_TO_STRING_EXPLICIT = getAsmMethod(String.class, "defToStringExplicit", Object.class); - // TODO: remove this when the transition from Joda to Java datetimes is completed - public static final Method DEF_TO_ZONEDDATETIME = getAsmMethod(ZonedDateTime.class, "defToZonedDateTime", Object.class); - /** invokedynamic bootstrap for lambda expression/method references */ public static final MethodType LAMBDA_BOOTSTRAP_TYPE = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Augmentation.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Augmentation.java index b313850d9a3e7..03657f2200a59 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Augmentation.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Augmentation.java @@ -11,7 +11,9 @@ import org.elasticsearch.common.hash.MessageDigests; import java.nio.charset.StandardCharsets; +import java.time.DayOfWeek; import java.time.Instant; +import java.time.ZonedDateTime; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; import java.util.ArrayList; @@ -714,4 +716,8 @@ public static Matcher matcher(Pattern receiver, int limitFactor, CharSequence in public static long toEpochMilli(TemporalAccessor v) { return v.getLong(ChronoField.INSTANT_SECONDS) * 1_000 + v.get(ChronoField.NANO_OF_SECOND) / 1_000_000; } + + public static DayOfWeek getDayOfWeekEnum(ZonedDateTime receiver) { + return receiver.getDayOfWeek(); + } } diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt index 202461f3a27f9..de9780e9a6fc3 100644 --- a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt +++ b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/java.time.txt @@ -474,6 +474,7 @@ class java.time.YearMonth { class java.time.ZonedDateTime { int getDayOfMonth() DayOfWeek getDayOfWeek() + DayOfWeek org.elasticsearch.painless.api.Augmentation getDayOfWeekEnum() int getDayOfYear() int getHour() LocalDate toLocalDate() diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.score.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.score.txt index b77943e0691e5..111cf71d0affa 100644 --- a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.score.txt +++ b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.script.score.txt @@ -24,8 +24,8 @@ static_import { double decayNumericLinear(double, double, double, double, double)bound_to org.elasticsearch.script.ScoreScriptUtils$DecayNumericLinear double decayNumericExp(double, double, double, double, double) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayNumericExp double decayNumericGauss(double, double, double, double, double) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayNumericGauss - double decayDateLinear(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateLinear - double decayDateExp(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateExp - double decayDateGauss(String, String, String, double, JodaCompatibleZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateGauss + double decayDateLinear(String, String, String, double, ZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateLinear + double decayDateExp(String, String, String, double, ZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateExp + double decayDateGauss(String, String, String, double, ZonedDateTime) bound_to org.elasticsearch.script.ScoreScriptUtils$DecayDateGauss } diff --git a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt index 5ff8535c967a1..907a98be5b973 100644 --- a/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt +++ b/modules/lang-painless/src/main/resources/org/elasticsearch/painless/org.elasticsearch.txt @@ -69,84 +69,9 @@ class org.elasticsearch.index.fielddata.ScriptDocValues$Longs { long getValue() } -class org.elasticsearch.script.JodaCompatibleZonedDateTime { - ##### ZonedDateTime methods - int getDayOfMonth() - int getDayOfYear() - int getHour() - LocalDate toLocalDate() - LocalDateTime toLocalDateTime() - int getMinute() - Month getMonth() - int getMonthValue() - int getNano() - int getSecond() - int getYear() - ZonedDateTime minus(TemporalAmount) - ZonedDateTime minus(long,TemporalUnit) - ZonedDateTime minusYears(long) - ZonedDateTime minusMonths(long) - ZonedDateTime minusWeeks(long) - ZonedDateTime minusDays(long) - ZonedDateTime minusHours(long) - ZonedDateTime minusMinutes(long) - ZonedDateTime minusSeconds(long) - ZonedDateTime minusNanos(long) - ZonedDateTime plus(TemporalAmount) - ZonedDateTime plus(long,TemporalUnit) - ZonedDateTime plusDays(long) - ZonedDateTime plusHours(long) - ZonedDateTime plusMinutes(long) - ZonedDateTime plusMonths(long) - ZonedDateTime plusNanos(long) - ZonedDateTime plusSeconds(long) - ZonedDateTime plusWeeks(long) - ZonedDateTime plusYears(long) - OffsetDateTime toOffsetDateTime() - ZonedDateTime truncatedTo(TemporalUnit) - ZonedDateTime with(TemporalAdjuster) - ZonedDateTime with(TemporalField,long) - ZonedDateTime withDayOfMonth(int) - ZonedDateTime withDayOfYear(int) - ZonedDateTime withEarlierOffsetAtOverlap() - ZonedDateTime withFixedOffsetZone() - ZonedDateTime withHour(int) - ZonedDateTime withLaterOffsetAtOverlap() - ZonedDateTime withMinute(int) - ZonedDateTime withMonth(int) - ZonedDateTime withNano(int) - ZonedDateTime withSecond(int) - ZonedDateTime withYear(int) - ZonedDateTime withZoneSameLocal(ZoneId) - ZonedDateTime withZoneSameInstant(ZoneId) - - #### Joda time methods - long getMillis() - int getCenturyOfEra() - int getEra() - int getHourOfDay() - int getMillisOfDay() - int getMillisOfSecond() - int getMinuteOfDay() - int getMinuteOfHour() - int getMonthOfYear() - int getSecondOfDay() - int getSecondOfMinute() - int getWeekOfWeekyear() - int getWeekyear() - int getYearOfCentury() - int getYearOfEra() - String toString(String) - String toString(String,Locale) - - # conflicting methods - DayOfWeek getDayOfWeekEnum() - int getDayOfWeek() -} - class org.elasticsearch.index.fielddata.ScriptDocValues$Dates { - JodaCompatibleZonedDateTime get(int) - JodaCompatibleZonedDateTime getValue() + ZonedDateTime get(int) + ZonedDateTime getValue() } class org.elasticsearch.index.fielddata.ScriptDocValues$Doubles { diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java index 16fc928ad7b9b..28bc3a2cc378b 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/BasicAPITests.java @@ -132,16 +132,6 @@ public void testStatic() { assertEquals(15.5f, exec("staticAddFloatsTest(6.5f, 9.0f)")); } - // TODO: remove this when the transition from Joda to Java datetimes is completed - public void testJCZDTToZonedDateTime() { - assertEquals(0L, exec( - "Instant instant = Instant.ofEpochMilli(434931330000L);" + - "JodaCompatibleZonedDateTime d = new JodaCompatibleZonedDateTime(instant, ZoneId.of('Z'));" + - "ZonedDateTime t = d;" + - "return ChronoUnit.MILLIS.between(d, t);" - )); - } - public void testRandomUUID() { assertTrue( Pattern.compile("\\p{XDigit}{8}(-\\p{XDigit}{4}){3}-\\p{XDigit}{12}").matcher( diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefCastTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefCastTests.java index 8923ae93f63df..d0dd246fd8689 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefCastTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/DefCastTests.java @@ -685,17 +685,4 @@ public void testConstFoldingDefCast() { assertFalse((boolean)exec("def chr = (char)10L; return (chr > (byte)10);")); assertFalse((boolean)exec("def chr = (char)10L; return (chr > (double)(byte)(char)10);")); } - - // TODO: remove this when the transition from Joda to Java datetimes is completed - public void testdefToZonedDateTime() { - assertEquals(0L, exec( - "Instant instant = Instant.ofEpochMilli(434931330000L);" + - "def d = new JodaCompatibleZonedDateTime(instant, ZoneId.of('Z'));" + - "def x = new HashMap(); x.put('dt', d);" + - "ZonedDateTime t = x['dt'];" + - "def y = t;" + - "t = y;" + - "return ChronoUnit.MILLIS.between(d, t);" - )); - } } diff --git a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test index f79e42ceca8cf..d6d81579211a7 100644 --- a/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test +++ b/modules/lang-painless/src/test/resources/org/elasticsearch/painless/org.elasticsearch.painless.test @@ -1,10 +1,5 @@ # whitelist for tests -# TODO: remove this when the transition from Joda to Java datetimes is completed -class org.elasticsearch.script.JodaCompatibleZonedDateTime { - (Instant, ZoneId) -} - # for unit tests only class org.elasticsearch.painless.api.Json { def load(String) diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 20168ef9296f8..c6c20ef9045ac 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -32,7 +32,6 @@ import org.elasticsearch.common.time.DateUtils; import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.joda.time.DateTimeZone; import java.io.EOFException; @@ -812,12 +811,12 @@ private List readArrayList() throws IOException { return list; } - private JodaCompatibleZonedDateTime readDateTime() throws IOException { - // we reuse DateTime to communicate with older nodes that don't know about the joda compat layer, but - // here we are on a new node so we always want a compat datetime + private ZonedDateTime readDateTime() throws IOException { + // any JodaCompatibleZonedDateTime is read from an older version + // so convert this a standard ZonedDateTime final ZoneId zoneId = DateUtils.dateTimeZoneToZoneId(DateTimeZone.forID(readString())); long millis = readLong(); - return new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), zoneId); + return ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), zoneId); } private ZonedDateTime readZonedDateTime() throws IOException { diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java index 61cf0ad0424ad..4da2817ac6c85 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java @@ -31,7 +31,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.joda.time.DateTimeZone; import org.joda.time.ReadableInstant; @@ -791,17 +790,6 @@ public final void writeOptionalInstant(@Nullable Instant instant) throws IOExcep o.writeString(zonedDateTime.getZone().getId()); o.writeLong(zonedDateTime.toInstant().toEpochMilli()); }), - entry( - JodaCompatibleZonedDateTime.class, - (o, v) -> { - // write the joda compatibility datetime as joda datetime - o.writeByte((byte) 13); - final JodaCompatibleZonedDateTime zonedDateTime = (JodaCompatibleZonedDateTime) v; - String zoneId = zonedDateTime.getZonedDateTime().getZone().getId(); - // joda does not understand "Z" for utc, so we must special case - o.writeString(zoneId.equals("Z") ? DateTimeZone.UTC.getID() : zoneId); - o.writeLong(zonedDateTime.toInstant().toEpochMilli()); - }), entry( Set.class, (o, v) -> { diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/XContentElasticsearchExtension.java b/server/src/main/java/org/elasticsearch/common/xcontent/XContentElasticsearchExtension.java index 78f9703cdf5b1..4ee2f199e8527 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/XContentElasticsearchExtension.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/XContentElasticsearchExtension.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Instant; @@ -82,7 +81,6 @@ public Map, XContentBuilder.Writer> getXContentWriters() { writers.put(Year.class, (b, v) -> b.value(v.toString())); writers.put(Duration.class, (b, v) -> b.value(v.toString())); writers.put(Period.class, (b, v) -> b.value(v.toString())); - writers.put(JodaCompatibleZonedDateTime.class, XContentBuilder::timeValue); writers.put(BytesReference.class, (b, v) -> { if (v == null) { @@ -131,8 +129,6 @@ public Map, Function> getDateTransformers() { d -> DEFAULT_FORMATTER.format(ZonedDateTime.ofInstant((java.time.Instant) d, ZoneOffset.UTC))); transformers.put(LocalDate.class, d -> ((LocalDate) d).toString()); transformers.put(LocalTime.class, d -> LOCAL_TIME_FORMATTER.format((LocalTime) d)); - transformers.put(JodaCompatibleZonedDateTime.class, - d -> DEFAULT_FORMATTER.format(((JodaCompatibleZonedDateTime) d).getZonedDateTime())); return transformers; } } diff --git a/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java b/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java index ca7d2f0e5d66f..68d9076cdf310 100644 --- a/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java +++ b/server/src/main/java/org/elasticsearch/index/fielddata/ScriptDocValues.java @@ -26,13 +26,13 @@ import org.elasticsearch.script.field.FieldValues; import org.elasticsearch.script.field.GeoPointField; import org.elasticsearch.script.field.InvalidConversion; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.script.field.LongField; import org.elasticsearch.script.field.StringField; import java.io.IOException; import java.time.Instant; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.AbstractList; import java.util.Arrays; import java.util.Comparator; @@ -171,7 +171,7 @@ public Field toField(String fieldName) { } } - public static final class Dates extends ScriptDocValues { + public static final class Dates extends ScriptDocValues { private final SortedNumericDocValues in; private final boolean isNanos; @@ -179,7 +179,7 @@ public static final class Dates extends ScriptDocValues].size()==0 to check if a document is missing a field!"); @@ -233,13 +233,13 @@ void refreshArray() throws IOException { } if (dates == null || count > dates.length) { // Happens for the document. We delay allocating dates so we can allocate it with a reasonable size. - dates = new JodaCompatibleZonedDateTime[count]; + dates = new ZonedDateTime[count]; } for (int i = 0; i < count; ++i) { if (isNanos) { - dates[i] = new JodaCompatibleZonedDateTime(DateUtils.toInstant(in.nextValue()), ZoneOffset.UTC); + dates[i] = ZonedDateTime.ofInstant(DateUtils.toInstant(in.nextValue()), ZoneOffset.UTC); } else { - dates[i] = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(in.nextValue()), ZoneOffset.UTC); + dates[i] = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.nextValue()), ZoneOffset.UTC); } } } @@ -259,7 +259,7 @@ public double getDoubleValue() { } @Override - public Field toField(String fieldName) { + public Field toField(String fieldName) { if (isNanos) { return new DateNanosField(fieldName, this); } diff --git a/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java b/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java deleted file mode 100644 index f88103ef8a712..0000000000000 --- a/server/src/main/java/org/elasticsearch/script/JodaCompatibleZonedDateTime.java +++ /dev/null @@ -1,516 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.script; - -import org.elasticsearch.core.SuppressForbidden; -import org.elasticsearch.common.SuppressLoggerChecks; -import org.elasticsearch.common.logging.DeprecationCategory; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.common.time.DateFormatter; -import org.elasticsearch.common.time.DateFormatters; -import org.elasticsearch.common.time.DateUtils; -import org.joda.time.DateTime; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.time.DayOfWeek; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.Month; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.chrono.ChronoZonedDateTime; -import java.time.chrono.Chronology; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoField; -import java.time.temporal.Temporal; -import java.time.temporal.TemporalAccessor; -import java.time.temporal.TemporalAdjuster; -import java.time.temporal.TemporalAmount; -import java.time.temporal.TemporalField; -import java.time.temporal.TemporalQuery; -import java.time.temporal.TemporalUnit; -import java.time.temporal.ValueRange; -import java.util.Locale; -import java.util.Objects; - -/** - * A wrapper around ZonedDateTime that exposes joda methods for backcompat. - */ -public class JodaCompatibleZonedDateTime - implements Comparable>, ChronoZonedDateTime, Temporal, TemporalAccessor { - - private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("strict_date_time"); - private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(JodaCompatibleZonedDateTime.class); - - private static void logDeprecated(DeprecationCategory category, String key, String message, Object... params) { - AccessController.doPrivileged(new PrivilegedAction() { - @SuppressLoggerChecks(reason = "safely delegates to logger") - @Override - public Void run() { - deprecationLogger.critical(category, key, message, params); - return null; - } - }); - } - - private static void logDeprecatedMethod(String oldMethod, String newMethod) { - logDeprecated(DeprecationCategory.PARSING, oldMethod, "Use of the joda time method [{}] is deprecated. Use [{}] instead.", - oldMethod, newMethod); - } - - private ZonedDateTime dt; - - public JodaCompatibleZonedDateTime(Instant instant, ZoneId zone) { - this.dt = ZonedDateTime.ofInstant(instant, zone); - } - - // access the underlying ZonedDateTime - public ZonedDateTime getZonedDateTime() { - return dt; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null)return false; - if (o.getClass() == JodaCompatibleZonedDateTime.class) { - JodaCompatibleZonedDateTime that = (JodaCompatibleZonedDateTime) o; - return Objects.equals(dt, that.dt); - } else if (o.getClass() == ZonedDateTime.class) { - ZonedDateTime that = (ZonedDateTime) o; - return Objects.equals(dt, that); - } - return false; - } - - @Override - public int hashCode() { - return dt.hashCode(); - } - - @Override - public String toString() { - return DATE_FORMATTER.format(dt); - } - - @Override - public String format(DateTimeFormatter formatter) { - return dt.format(formatter); - } - - @Override - public ValueRange range(TemporalField field) { - return dt.range(field); - } - - @Override - public int get(TemporalField field) { - return dt.get(field); - } - - @Override - public long getLong(TemporalField field) { - return dt.getLong(field); - } - - @Override - public Chronology getChronology() { - return dt.getChronology(); - } - - @Override - public ZoneOffset getOffset() { - return dt.getOffset(); - } - - @Override - public boolean isSupported(TemporalField field) { - return dt.isSupported(field); - } - - @Override - public boolean isSupported(TemporalUnit unit) { - return dt.isSupported(unit); - } - - @Override - public long toEpochSecond() { - return dt.toEpochSecond(); - } - - @Override - public int compareTo(ChronoZonedDateTime other) { - return dt.compareTo(other); - } - - @Override - public boolean isBefore(ChronoZonedDateTime other) { - return dt.isBefore(other); - } - - @Override - public boolean isAfter(ChronoZonedDateTime other) { - return dt.isAfter(other); - } - - @Override - public boolean isEqual(ChronoZonedDateTime other) { - return dt.isEqual(other); - } - - @Override - public LocalTime toLocalTime() { - return dt.toLocalTime(); - } - - public int getDayOfMonth() { - return dt.getDayOfMonth(); - } - - public int getDayOfYear() { - return dt.getDayOfYear(); - } - - public int getHour() { - return dt.getHour(); - } - - @Override - public LocalDate toLocalDate() { - return dt.toLocalDate(); - } - - @Override - public LocalDateTime toLocalDateTime() { - return dt.toLocalDateTime(); - } - - public int getMinute() { - return dt.getMinute(); - } - - public Month getMonth() { - return dt.getMonth(); - } - - public int getMonthValue() { - return dt.getMonthValue(); - } - - public int getNano() { - return dt.getNano(); - } - - public int getSecond() { - return dt.getSecond(); - } - - public int getYear() { - return dt.getYear(); - } - - @Override - public ZoneId getZone() { - return dt.getZone(); - } - - @Override - public ZonedDateTime minus(TemporalAmount delta) { - return dt.minus(delta); - } - - @Override - public ZonedDateTime minus(long amount, TemporalUnit unit) { - return dt.minus(amount, unit); - } - - @Override - public R query(TemporalQuery query) { - return dt.query(query); - } - - @Override - public long until(Temporal temporal, TemporalUnit temporalUnit) { - return dt.until(temporal, temporalUnit); - } - - public ZonedDateTime minusYears(long amount) { - return dt.minusYears(amount); - } - - public ZonedDateTime minusMonths(long amount) { - return dt.minusMonths(amount); - } - - public ZonedDateTime minusWeeks(long amount) { - return dt.minusWeeks(amount); - } - - public ZonedDateTime minusDays(long amount) { - return dt.minusDays(amount); - } - - public ZonedDateTime minusHours(long amount) { - return dt.minusHours(amount); - } - - public ZonedDateTime minusMinutes(long amount) { - return dt.minusMinutes(amount); - } - - public ZonedDateTime minusSeconds(long amount) { - return dt.minusSeconds(amount); - } - - public ZonedDateTime minusNanos(long amount) { - return dt.minusNanos(amount); - } - - @Override - public ZonedDateTime plus(TemporalAmount amount) { - return dt.plus(amount); - } - - @Override - public ZonedDateTime plus(long amount,TemporalUnit unit) { - return dt.plus(amount, unit); - } - - public ZonedDateTime plusDays(long amount) { - return dt.plusDays(amount); - } - - public ZonedDateTime plusHours(long amount) { - return dt.plusHours(amount); - } - - public ZonedDateTime plusMinutes(long amount) { - return dt.plusMinutes(amount); - } - - public ZonedDateTime plusMonths(long amount) { - return dt.plusMonths(amount); - } - - public ZonedDateTime plusNanos(long amount) { - return dt.plusNanos(amount); - } - - public ZonedDateTime plusSeconds(long amount) { - return dt.plusSeconds(amount); - } - - public ZonedDateTime plusWeeks(long amount) { - return dt.plusWeeks(amount); - } - - public ZonedDateTime plusYears(long amount) { - return dt.plusYears(amount); - } - - @Override - public Instant toInstant() { - return dt.toInstant(); - } - - public OffsetDateTime toOffsetDateTime() { - return dt.toOffsetDateTime(); - } - - @SuppressForbidden(reason = "only exposing the method as a passthrough") - public ZonedDateTime truncatedTo(TemporalUnit unit) { - return dt.truncatedTo(unit); - } - - @Override - public ZonedDateTime with(TemporalAdjuster adjuster) { - return dt.with(adjuster); - } - - @Override - public ZonedDateTime with(TemporalField field, long newValue) { - return dt.with(field, newValue); - } - - public ZonedDateTime withDayOfMonth(int value) { - return dt.withDayOfMonth(value); - } - - public ZonedDateTime withDayOfYear(int value) { - return dt.withDayOfYear(value); - } - - @Override - public ZonedDateTime withEarlierOffsetAtOverlap() { - return dt.withEarlierOffsetAtOverlap(); - } - - public ZonedDateTime withFixedOffsetZone() { - return dt.withFixedOffsetZone(); - } - - public ZonedDateTime withHour(int value) { - return dt.withHour(value); - } - - @Override - public ZonedDateTime withLaterOffsetAtOverlap() { - return dt.withLaterOffsetAtOverlap(); - } - - public ZonedDateTime withMinute(int value) { - return dt.withMinute(value); - } - - public ZonedDateTime withMonth(int value) { - return dt.withMonth(value); - } - - public ZonedDateTime withNano(int value) { - return dt.withNano(value); - } - - public ZonedDateTime withSecond(int value) { - return dt.withSecond(value); - } - - public ZonedDateTime withYear(int value) { - return dt.withYear(value); - } - - @Override - public ZonedDateTime withZoneSameLocal(ZoneId zone) { - return dt.withZoneSameLocal(zone); - } - - @Override - public ZonedDateTime withZoneSameInstant(ZoneId zone) { - return dt.withZoneSameInstant(zone); - } - - @Deprecated - public long getMillis() { - logDeprecatedMethod("getMillis()", "toInstant().toEpochMilli()"); - return dt.toInstant().toEpochMilli(); - } - - @Deprecated - public int getCenturyOfEra() { - logDeprecatedMethod("getCenturyOfEra()", "get(ChronoField.YEAR_OF_ERA) / 100"); - return dt.get(ChronoField.YEAR_OF_ERA) / 100; - } - - @Deprecated - public int getEra() { - logDeprecatedMethod("getEra()", "get(ChronoField.ERA)"); - return dt.get(ChronoField.ERA); - } - - @Deprecated - public int getHourOfDay() { - logDeprecatedMethod("getHourOfDay()", "getHour()"); - return dt.getHour(); - } - - @Deprecated - public int getMillisOfDay() { - logDeprecatedMethod("getMillisOfDay()", "get(ChronoField.MILLI_OF_DAY)"); - return dt.get(ChronoField.MILLI_OF_DAY); - } - - @Deprecated - public int getMillisOfSecond() { - logDeprecatedMethod("getMillisOfSecond()", "get(ChronoField.MILLI_OF_SECOND)"); - return dt.get(ChronoField.MILLI_OF_SECOND); - } - - @Deprecated - public int getMinuteOfDay() { - logDeprecatedMethod("getMinuteOfDay()", "get(ChronoField.MINUTE_OF_DAY)"); - return dt.get(ChronoField.MINUTE_OF_DAY); - } - - @Deprecated - public int getMinuteOfHour() { - logDeprecatedMethod("getMinuteOfHour()", "getMinute()"); - return dt.getMinute(); - } - - @Deprecated - public int getMonthOfYear() { - logDeprecatedMethod("getMonthOfYear()", "getMonthValue()"); - return dt.getMonthValue(); - } - - @Deprecated - public int getSecondOfDay() { - logDeprecatedMethod("getSecondOfDay()", "get(ChronoField.SECOND_OF_DAY)"); - return dt.get(ChronoField.SECOND_OF_DAY); - } - - @Deprecated - public int getSecondOfMinute() { - logDeprecatedMethod("getSecondOfMinute()", "getSecond()"); - return dt.getSecond(); - } - - @Deprecated - public int getWeekOfWeekyear() { - logDeprecatedMethod("getWeekOfWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekOfWeekBasedYear())"); - return dt.get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear()); - } - - @Deprecated - public int getWeekyear() { - logDeprecatedMethod("getWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekBasedYear())"); - return dt.get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear()); - } - - @Deprecated - public int getYearOfCentury() { - logDeprecatedMethod("getYearOfCentury()", "get(ChronoField.YEAR_OF_ERA) % 100"); - return dt.get(ChronoField.YEAR_OF_ERA) % 100; - } - - @Deprecated - public int getYearOfEra() { - logDeprecatedMethod("getYearOfEra()", "get(ChronoField.YEAR_OF_ERA)"); - return dt.get(ChronoField.YEAR_OF_ERA); - } - - @Deprecated - public String toString(String format) { - logDeprecatedMethod("toString(String)", "a DateTimeFormatter"); - // TODO: replace with bwc formatter - return new DateTime(dt.toInstant().toEpochMilli(), DateUtils.zoneIdToDateTimeZone(dt.getZone())).toString(format); - } - - @Deprecated - public String toString(String format, Locale locale) { - logDeprecatedMethod("toString(String,Locale)", "a DateTimeFormatter"); - // TODO: replace with bwc formatter - return new DateTime(dt.toInstant().toEpochMilli(), DateUtils.zoneIdToDateTimeZone(dt.getZone())).toString(format, locale); - } - - public DayOfWeek getDayOfWeekEnum() { - return dt.getDayOfWeek(); - } - - @Deprecated - public int getDayOfWeek() { - logDeprecated(DeprecationCategory.PARSING, "getDayOfWeek()", - "The return type of [getDayOfWeek()] will change to an enum in 7.0. Use getDayOfWeekEnum().getValue()."); - return dt.getDayOfWeek().getValue(); - } -} diff --git a/server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java b/server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java index 841a263dddd1a..d1ddf0bc88c50 100644 --- a/server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java +++ b/server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java @@ -21,6 +21,7 @@ import org.elasticsearch.index.mapper.DateFieldMapper; import java.time.ZoneId; +import java.time.ZonedDateTime; import static com.carrotsearch.hppc.BitMixer.mix32; @@ -231,7 +232,7 @@ public DecayDateLinear(String originStr, String scaleStr, String offsetStr, doub this.scaling = scale / (1.0 - decay); } - public double decayDateLinear(JodaCompatibleZonedDateTime docValueDate) { + public double decayDateLinear(ZonedDateTime docValueDate) { long docValue = docValueDate.toInstant().toEpochMilli(); // as java.lang.Math#abs(long) is a forbidden API, have to use this comparison instead long diff = (docValue >= origin) ? (docValue - origin) : (origin - docValue); @@ -254,7 +255,7 @@ public DecayDateExp(String originStr, String scaleStr, String offsetStr, double this.scaling = Math.log(decay) / scale; } - public double decayDateExp(JodaCompatibleZonedDateTime docValueDate) { + public double decayDateExp(ZonedDateTime docValueDate) { long docValue = docValueDate.toInstant().toEpochMilli(); long diff = (docValue >= origin) ? (docValue - origin) : (origin - docValue); long distance = Math.max(0, diff - offset); @@ -277,7 +278,7 @@ public DecayDateGauss(String originStr, String scaleStr, String offsetStr, doubl this.scaling = 0.5 * Math.pow(scale, 2.0) / Math.log(decay); } - public double decayDateGauss(JodaCompatibleZonedDateTime docValueDate) { + public double decayDateGauss(ZonedDateTime docValueDate) { long docValue = docValueDate.toInstant().toEpochMilli(); long diff = (docValue >= origin) ? (docValue - origin) : (origin - docValue); long distance = Math.max(0, diff - offset); diff --git a/server/src/main/java/org/elasticsearch/script/field/DateMillisField.java b/server/src/main/java/org/elasticsearch/script/field/DateMillisField.java index 19beaa251dbe0..a8f1ccd1dd2d7 100644 --- a/server/src/main/java/org/elasticsearch/script/field/DateMillisField.java +++ b/server/src/main/java/org/elasticsearch/script/field/DateMillisField.java @@ -8,18 +8,17 @@ package org.elasticsearch.script.field; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; - +import java.time.ZonedDateTime; import java.util.List; import java.util.stream.Collectors; -public class DateMillisField extends Field { +public class DateMillisField extends Field { /* ---- Conversion Helpers To Other Fields ---- */ public static LongField toLongField(DateMillisField sourceField) { - FieldValues fv = sourceField.getFieldValues(); - return new LongField(sourceField.getName(), new DelegatingFieldValues(fv) { + FieldValues fv = sourceField.getFieldValues(); + return new LongField(sourceField.getName(), new DelegatingFieldValues(fv) { @Override public List getValues() { return values.getValues().stream().map(dt -> dt.toInstant().toEpochMilli()).collect(Collectors.toList()); @@ -44,13 +43,13 @@ public double getDoubleValue() { /* ---- Conversion Helpers To Other Types ---- */ - public static long toLong(JodaCompatibleZonedDateTime dt) { + public static long toLong(ZonedDateTime dt) { return dt.toInstant().toEpochMilli(); } /* ---- DateMillis Field Members ---- */ - public DateMillisField(String name, FieldValues values) { + public DateMillisField(String name, FieldValues values) { super(name, values); } } diff --git a/server/src/main/java/org/elasticsearch/script/field/DateNanosField.java b/server/src/main/java/org/elasticsearch/script/field/DateNanosField.java index c169e762731ba..23bc4422f7053 100644 --- a/server/src/main/java/org/elasticsearch/script/field/DateNanosField.java +++ b/server/src/main/java/org/elasticsearch/script/field/DateNanosField.java @@ -8,21 +8,20 @@ package org.elasticsearch.script.field; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; - import java.time.Instant; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.List; import java.util.stream.Collectors; -public class DateNanosField extends Field { +public class DateNanosField extends Field { /* ---- Conversion Helpers To Other Fields ---- */ public static LongField toLongField(DateNanosField sourceField) { - FieldValues fv = sourceField.getFieldValues(); - return new LongField(sourceField.getName(), new DelegatingFieldValues(fv) { - protected long nanoLong(JodaCompatibleZonedDateTime dt) { + FieldValues fv = sourceField.getFieldValues(); + return new LongField(sourceField.getName(), new DelegatingFieldValues(fv) { + protected long nanoLong(ZonedDateTime dt) { return ChronoUnit.NANOS.between(Instant.EPOCH, dt.toInstant()); } @@ -50,13 +49,13 @@ public double getDoubleValue() { /* ---- Conversion Helpers To Other Types ---- */ - public static long toLong(JodaCompatibleZonedDateTime dt) { + public static long toLong(ZonedDateTime dt) { return ChronoUnit.NANOS.between(Instant.EPOCH, dt.toInstant()); } /* ---- DateNanos Field Members ---- */ - public DateNanosField(String name, FieldValues values) { + public DateNanosField(String name, FieldValues values) { super(name, values); } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptDoubleValues.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptDoubleValues.java index 97de6e1f47568..f88ec278a8576 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptDoubleValues.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptDoubleValues.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.lucene.ScorerAware; import org.elasticsearch.index.fielddata.SortingNumericDoubleValues; import org.elasticsearch.script.AggregationScript; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.joda.time.ReadableInstant; @@ -85,8 +84,6 @@ private static double toDoubleValue(Object o) { return ((ReadableInstant) o).getMillis(); } else if (o instanceof ZonedDateTime) { return ((ZonedDateTime) o).toInstant().toEpochMilli(); - } else if (o instanceof JodaCompatibleZonedDateTime) { - return ((JodaCompatibleZonedDateTime) o).toInstant().toEpochMilli(); } else if (o instanceof Boolean) { // We do expose boolean fields as boolean in scripts, however aggregations still expect // that scripts return the same internal representation as regular fields, so boolean diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java index 18053c98e7d3d..126794ba6cdb9 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/support/values/ScriptLongValues.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.lucene.ScorerAware; import org.elasticsearch.index.fielddata.AbstractSortingNumericDocValues; import org.elasticsearch.script.AggregationScript; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.joda.time.ReadableInstant; @@ -84,8 +83,6 @@ private static long toLongValue(Object o) { return ((ReadableInstant) o).getMillis(); } else if (o instanceof ZonedDateTime) { return ((ZonedDateTime) o).toInstant().toEpochMilli(); - } else if (o instanceof JodaCompatibleZonedDateTime) { - return ((JodaCompatibleZonedDateTime) o).toInstant().toEpochMilli(); } else if (o instanceof Boolean) { // We do expose boolean fields as boolean in scripts, however aggregations still expect // that scripts return the same internal representation as regular fields, so boolean diff --git a/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java b/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java index 9ceac9ee8a9cd..be4ba4d1b37cd 100644 --- a/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java +++ b/server/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.lucene.BytesRefs; import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.PageCacheRecycler; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -27,6 +26,7 @@ import java.io.IOException; import java.time.OffsetTime; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -337,10 +337,10 @@ public void testSimpleStreams() throws Exception { assertEquals(DateTimeZone.getDefault(), in.readOptionalTimeZone()); assertNull(in.readOptionalTimeZone()); Object dt = in.readGenericValue(); - assertThat(dt, instanceOf(JodaCompatibleZonedDateTime.class)); - JodaCompatibleZonedDateTime jdt = (JodaCompatibleZonedDateTime) dt; - assertThat(jdt.getZonedDateTime().toInstant().toEpochMilli(), equalTo(123456L)); - assertThat(jdt.getZonedDateTime().getZone(), equalTo(ZoneId.of("America/Los_Angeles"))); + assertThat(dt, instanceOf(ZonedDateTime.class)); + ZonedDateTime zdt = (ZonedDateTime)dt; + assertThat(zdt.toInstant().toEpochMilli(), equalTo(123456L)); + assertThat(zdt.getZone(), equalTo(ZoneId.of("America/Los_Angeles"))); assertThat(in.readGenericValue(), equalTo(offsetNow)); assertEquals(0, in.available()); IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> out.writeGenericValue(new Object() { diff --git a/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java b/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java deleted file mode 100644 index 8e035eba0f250..0000000000000 --- a/server/src/test/java/org/elasticsearch/script/JodaCompatibleZonedDateTimeTests.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.script; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AbstractAppender; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.test.ESTestCase; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.Before; - -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PermissionCollection; -import java.security.Permissions; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; -import java.time.DayOfWeek; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.Month; -import java.time.ZoneOffset; -import java.util.Locale; - -import static org.hamcrest.Matchers.equalTo; - -public class JodaCompatibleZonedDateTimeTests extends ESTestCase { - private static final Logger DEPRECATION_LOGGER = - LogManager.getLogger("org.elasticsearch.deprecation.script.JodaCompatibleZonedDateTime"); - - // each call to get or getValue will be run with limited permissions, just as they are in scripts - private static PermissionCollection NO_PERMISSIONS = new Permissions(); - private static AccessControlContext NO_PERMISSIONS_ACC = new AccessControlContext( - new ProtectionDomain[] { - new ProtectionDomain(null, NO_PERMISSIONS) - } - ); - - private JodaCompatibleZonedDateTime javaTime; - private DateTime jodaTime; - - @Before - public void setupTime() { - long millis = randomIntBetween(0, Integer.MAX_VALUE); - javaTime = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7)); - jodaTime = new DateTime(millis, DateTimeZone.forOffsetHours(-7)); - } - - void assertDeprecation(Runnable assertions, String message) { - Appender appender = new AbstractAppender("test", null, null) { - @Override - public void append(LogEvent event) { - /* Create a temporary directory to prove we are running with the - * server's permissions. */ - createTempDir(); - } - }; - appender.start(); - Loggers.addAppender(DEPRECATION_LOGGER, appender); - try { - // the assertions are run with the same reduced privileges scripts run with - AccessController.doPrivileged((PrivilegedAction) () -> { - assertions.run(); - return null; - }, NO_PERMISSIONS_ACC); - } finally { - appender.stop(); - Loggers.removeAppender(DEPRECATION_LOGGER, appender); - } - - assertWarnings(message); - } - - void assertMethodDeprecation(Runnable assertions, String oldMethod, String newMethod) { - assertDeprecation(assertions, "Use of the joda time method [" + oldMethod + "] is deprecated. Use [" + newMethod + "] instead."); - } - - public void testEquals() { - assertThat(javaTime, equalTo(javaTime)); - } - - public void testToString() { - assertThat(javaTime.toString(), equalTo(jodaTime.toString())); - } - - public void testDayOfMonth() { - assertThat(javaTime.getDayOfMonth(), equalTo(jodaTime.getDayOfMonth())); - } - - public void testDayOfYear() { - assertThat(javaTime.getDayOfYear(), equalTo(jodaTime.getDayOfYear())); - } - - public void testHour() { - assertThat(javaTime.getHour(), equalTo(jodaTime.getHourOfDay())); - } - - public void testLocalDate() { - assertThat(javaTime.toLocalDate(), equalTo(LocalDate.of(jodaTime.getYear(), jodaTime.getMonthOfYear(), jodaTime.getDayOfMonth()))); - } - - public void testLocalDateTime() { - LocalDateTime dt = LocalDateTime.of(jodaTime.getYear(), jodaTime.getMonthOfYear(), jodaTime.getDayOfMonth(), - jodaTime.getHourOfDay(), jodaTime.getMinuteOfHour(), jodaTime.getSecondOfMinute(), - jodaTime.getMillisOfSecond() * 1000000); - assertThat(javaTime.toLocalDateTime(), equalTo(dt)); - } - - public void testMinute() { - assertThat(javaTime.getMinute(), equalTo(jodaTime.getMinuteOfHour())); - } - - public void testMonth() { - assertThat(javaTime.getMonth(), equalTo(Month.of(jodaTime.getMonthOfYear()))); - } - - public void testMonthValue() { - assertThat(javaTime.getMonthValue(), equalTo(jodaTime.getMonthOfYear())); - } - - public void testNano() { - assertThat(javaTime.getNano(), equalTo(jodaTime.getMillisOfSecond() * 1000000)); - } - - public void testSecond() { - assertThat(javaTime.getSecond(), equalTo(jodaTime.getSecondOfMinute())); - } - - public void testYear() { - assertThat(javaTime.getYear(), equalTo(jodaTime.getYear())); - } - - public void testZone() { - assertThat(javaTime.getZone().getId(), equalTo(jodaTime.getZone().getID())); - } - - public void testMillis() { - assertMethodDeprecation(() -> assertThat(javaTime.getMillis(), equalTo(jodaTime.getMillis())), - "getMillis()", "toInstant().toEpochMilli()"); - } - - public void testCenturyOfEra() { - assertMethodDeprecation(() -> assertThat(javaTime.getCenturyOfEra(), equalTo(jodaTime.getCenturyOfEra())), - "getCenturyOfEra()", "get(ChronoField.YEAR_OF_ERA) / 100"); - } - - public void testEra() { - assertMethodDeprecation(() -> assertThat(javaTime.getEra(), equalTo(jodaTime.getEra())), - "getEra()", "get(ChronoField.ERA)"); - } - - public void testHourOfDay() { - assertMethodDeprecation(() -> assertThat(javaTime.getHourOfDay(), equalTo(jodaTime.getHourOfDay())), - "getHourOfDay()", "getHour()"); - } - - public void testMillisOfDay() { - assertMethodDeprecation(() -> assertThat(javaTime.getMillisOfDay(), equalTo(jodaTime.getMillisOfDay())), - "getMillisOfDay()", "get(ChronoField.MILLI_OF_DAY)"); - } - - public void testMillisOfSecond() { - assertMethodDeprecation(() -> assertThat(javaTime.getMillisOfSecond(), equalTo(jodaTime.getMillisOfSecond())), - "getMillisOfSecond()", "get(ChronoField.MILLI_OF_SECOND)"); - } - - public void testMinuteOfDay() { - assertMethodDeprecation(() -> assertThat(javaTime.getMinuteOfDay(), equalTo(jodaTime.getMinuteOfDay())), - "getMinuteOfDay()", "get(ChronoField.MINUTE_OF_DAY)"); - } - - public void testMinuteOfHour() { - assertMethodDeprecation(() -> assertThat(javaTime.getMinuteOfHour(), equalTo(jodaTime.getMinuteOfHour())), - "getMinuteOfHour()", "getMinute()"); - } - - public void testMonthOfYear() { - assertMethodDeprecation(() -> assertThat(javaTime.getMonthOfYear(), equalTo(jodaTime.getMonthOfYear())), - "getMonthOfYear()", "getMonthValue()"); - } - - public void testSecondOfDay() { - assertMethodDeprecation(() -> assertThat(javaTime.getSecondOfDay(), equalTo(jodaTime.getSecondOfDay())), - "getSecondOfDay()", "get(ChronoField.SECOND_OF_DAY)"); - } - - public void testSecondOfMinute() { - assertMethodDeprecation(() -> assertThat(javaTime.getSecondOfMinute(), equalTo(jodaTime.getSecondOfMinute())), - "getSecondOfMinute()", "getSecond()"); - } - - public void testWeekOfWeekyear() { - assertMethodDeprecation(() -> assertThat(javaTime.getWeekOfWeekyear(), equalTo(jodaTime.getWeekOfWeekyear())), - "getWeekOfWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekOfWeekBasedYear())"); - } - - public void testWeekyear() { - assertMethodDeprecation(() -> assertThat(javaTime.getWeekyear(), equalTo(jodaTime.getWeekyear())), - "getWeekyear()", "get(DateFormatters.WEEK_FIELDS.weekBasedYear())"); - } - - public void testYearOfCentury() { - assertMethodDeprecation(() -> assertThat(javaTime.getYearOfCentury(), equalTo(jodaTime.getYearOfCentury())), - "getYearOfCentury()", "get(ChronoField.YEAR_OF_ERA) % 100"); - } - - public void testYearOfEra() { - assertMethodDeprecation(() -> assertThat(javaTime.getYearOfEra(), equalTo(jodaTime.getYearOfEra())), - "getYearOfEra()", "get(ChronoField.YEAR_OF_ERA)"); - } - - public void testToString1() { - assertMethodDeprecation(() -> assertThat(javaTime.toString("YYYY/MM/dd HH:mm:ss.SSS"), - equalTo(jodaTime.toString("YYYY/MM/dd HH:mm:ss.SSS"))), "toString(String)", "a DateTimeFormatter"); - } - - public void testToString2() { - assertMethodDeprecation(() -> assertThat(javaTime.toString("EEE", Locale.GERMANY), - equalTo(jodaTime.toString("EEE", Locale.GERMANY))), "toString(String,Locale)", "a DateTimeFormatter"); - } - - public void testDayOfWeek() { - assertDeprecation(() -> assertThat(javaTime.getDayOfWeek(), equalTo(jodaTime.getDayOfWeek())), - "The return type of [getDayOfWeek()] will change to an enum in 7.0. Use getDayOfWeekEnum().getValue()."); - } - - public void testDayOfWeekEnum() { - assertThat(javaTime.getDayOfWeekEnum(), equalTo(DayOfWeek.of(jodaTime.getDayOfWeek()))); - } - - public void testToStringWithLocaleAndZeroOffset() { - JodaCompatibleZonedDateTime dt = new JodaCompatibleZonedDateTime(Instant.EPOCH, ZoneOffset.ofTotalSeconds(0)); - assertMethodDeprecation(() -> dt.toString("yyyy-MM-dd hh:mm", Locale.ROOT), "toString(String,Locale)", "a DateTimeFormatter"); - } - - public void testToStringAndZeroOffset() { - JodaCompatibleZonedDateTime dt = new JodaCompatibleZonedDateTime(Instant.EPOCH, ZoneOffset.ofTotalSeconds(0)); - assertMethodDeprecation(() -> dt.toString("yyyy-MM-dd hh:mm"), "toString(String)", "a DateTimeFormatter"); - } - - public void testIsEqual() { - assertTrue(javaTime.isEqual(javaTime)); - } - - public void testIsAfter() { - long millis = randomLongBetween(0, Integer.MAX_VALUE / 2); - JodaCompatibleZonedDateTime beforeTime = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7)); - millis = randomLongBetween(millis + 1, Integer.MAX_VALUE); - JodaCompatibleZonedDateTime afterTime = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7)); - assertTrue(afterTime.isAfter(beforeTime)); - } - public void testIsBefore() { - long millis = randomLongBetween(0, Integer.MAX_VALUE / 2); - JodaCompatibleZonedDateTime beforeTime = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7)); - millis = randomLongBetween(millis + 1, Integer.MAX_VALUE); - JodaCompatibleZonedDateTime afterTime = new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(millis), ZoneOffset.ofHours(-7)); - assertTrue(beforeTime.isBefore(afterTime)); - } -} diff --git a/server/src/test/java/org/elasticsearch/script/field/ConvertersTestBase.java b/server/src/test/java/org/elasticsearch/script/field/ConvertersTestBase.java index 103180e336f3e..0b1ab21b26e6b 100644 --- a/server/src/test/java/org/elasticsearch/script/field/ConvertersTestBase.java +++ b/server/src/test/java/org/elasticsearch/script/field/ConvertersTestBase.java @@ -9,7 +9,6 @@ package org.elasticsearch.script.field; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -17,6 +16,7 @@ import java.math.BigInteger; import java.time.Instant; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -351,9 +351,9 @@ public double getDoubleValue() { } long[] rawLongMillisValues; - List rawDateMillisValues; - protected FieldValues dateMillisFieldValues; - protected Field dateMillisField; + List rawDateMillisValues; + protected FieldValues dateMillisFieldValues; + protected Field dateMillisField; @Before public void setupDateMillisField() { @@ -365,13 +365,13 @@ public void setupDateMillisField() { }; rawDateMillisValues = List.of( - new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(rawLongMillisValues[0]), ZoneOffset.ofHours(-7)), - new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(rawLongMillisValues[1]), ZoneOffset.ofHours(-6)), - new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(rawLongMillisValues[2]), ZoneOffset.ofHours(0)), - new JodaCompatibleZonedDateTime(Instant.ofEpochMilli(rawLongMillisValues[3]), ZoneOffset.ofHours(-5)) + ZonedDateTime.ofInstant(Instant.ofEpochMilli(rawLongMillisValues[0]), ZoneOffset.ofHours(-7)), + ZonedDateTime.ofInstant(Instant.ofEpochMilli(rawLongMillisValues[1]), ZoneOffset.ofHours(-6)), + ZonedDateTime.ofInstant(Instant.ofEpochMilli(rawLongMillisValues[2]), ZoneOffset.ofHours(0)), + ZonedDateTime.ofInstant(Instant.ofEpochMilli(rawLongMillisValues[3]), ZoneOffset.ofHours(-5)) ); - dateMillisFieldValues = new FieldValues() { + dateMillisFieldValues = new FieldValues() { @Override public boolean isEmpty() { return false; @@ -383,12 +383,12 @@ public int size() { } @Override - public List getValues() { + public List getValues() { return Collections.unmodifiableList(rawDateMillisValues); } @Override - public JodaCompatibleZonedDateTime getNonPrimitiveValue() { + public ZonedDateTime getNonPrimitiveValue() { return rawDateMillisValues.get(0); } @@ -407,9 +407,9 @@ public double getDoubleValue() { } long[] rawLongNanosValues; - List rawDateNanosValues; - protected FieldValues dateNanosFieldValues; - protected Field dateNanosField; + List rawDateNanosValues; + protected FieldValues dateNanosFieldValues; + protected Field dateNanosField; @Before public void setupDateNanosField() { @@ -421,13 +421,13 @@ public void setupDateNanosField() { }; rawDateNanosValues = List.of( - new JodaCompatibleZonedDateTime(Instant.EPOCH.plusNanos(rawLongNanosValues[0]), ZoneOffset.ofHours(-7)), - new JodaCompatibleZonedDateTime(Instant.EPOCH.plusNanos(rawLongNanosValues[1]), ZoneOffset.ofHours(-6)), - new JodaCompatibleZonedDateTime(Instant.EPOCH.plusNanos(rawLongNanosValues[2]), ZoneOffset.ofHours(0)), - new JodaCompatibleZonedDateTime(Instant.EPOCH.plusNanos(rawLongNanosValues[3]), ZoneOffset.ofHours(-5)) + ZonedDateTime.ofInstant(Instant.EPOCH.plusNanos(rawLongNanosValues[0]), ZoneOffset.ofHours(-7)), + ZonedDateTime.ofInstant(Instant.EPOCH.plusNanos(rawLongNanosValues[1]), ZoneOffset.ofHours(-6)), + ZonedDateTime.ofInstant(Instant.EPOCH.plusNanos(rawLongNanosValues[2]), ZoneOffset.ofHours(0)), + ZonedDateTime.ofInstant(Instant.EPOCH.plusNanos(rawLongNanosValues[3]), ZoneOffset.ofHours(-5)) ); - dateNanosFieldValues = new FieldValues() { + dateNanosFieldValues = new FieldValues() { @Override public boolean isEmpty() { return false; @@ -439,12 +439,12 @@ public int size() { } @Override - public List getValues() { + public List getValues() { return Collections.unmodifiableList(rawDateNanosValues); } @Override - public JodaCompatibleZonedDateTime getNonPrimitiveValue() { + public ZonedDateTime getNonPrimitiveValue() { return rawDateNanosValues.get(0); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/ActionWrapper.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/ActionWrapper.java index 97cd6489388f2..0a7aa4288593a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/ActionWrapper.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/ActionWrapper.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.core.watcher.actions.throttler.ActionThrottler; import org.elasticsearch.xpack.core.watcher.actions.throttler.Throttler; import org.elasticsearch.xpack.core.watcher.actions.throttler.ThrottlerField; @@ -235,7 +234,7 @@ private Map toMap(WatchExecutionContext ctx) { Map model = new HashMap<>(); model.put("id", ctx.id().value()); model.put("watch_id", ctx.id().watchId()); - model.put("execution_time", new JodaCompatibleZonedDateTime(ctx.executionTime().toInstant(), ZoneOffset.UTC)); + model.put("execution_time", ZonedDateTime.ofInstant(ctx.executionTime().toInstant(), ZoneOffset.UTC)); model.put("trigger", ctx.triggerEvent().data()); model.put("metadata", ctx.watch().metadata()); model.put("vars", ctx.vars()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherDateTimeUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherDateTimeUtils.java index 6f6392a04be19..01794daee29da 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherDateTimeUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/WatcherDateTimeUtils.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.DateFieldMapper; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import java.io.IOException; import java.time.Clock; @@ -41,9 +40,6 @@ public static ZonedDateTime convertToDate(Object value, Clock clock) { if (value instanceof ZonedDateTime) { return (ZonedDateTime) value; } - if (value instanceof JodaCompatibleZonedDateTime) { - return ((JodaCompatibleZonedDateTime) value).getZonedDateTime(); - } if (value instanceof String) { return parseDateMath((String) value, ZoneOffset.UTC, clock); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/trigger/TriggerEvent.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/trigger/TriggerEvent.java index 56690f0d3e98f..033d650f043d5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/trigger/TriggerEvent.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/trigger/TriggerEvent.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; import java.io.IOException; @@ -28,8 +27,7 @@ public TriggerEvent(String jobName, ZonedDateTime triggeredTime) { this.jobName = jobName; this.triggeredTime = triggeredTime; this.data = new HashMap<>(); - data.put(Field.TRIGGERED_TIME.getPreferredName(), - new JodaCompatibleZonedDateTime(triggeredTime.toInstant(), ZoneOffset.UTC)); + data.put(Field.TRIGGERED_TIME.getPreferredName(), ZonedDateTime.ofInstant(triggeredTime.toInstant(), ZoneOffset.UTC)); } public String jobName() { diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/whitelist/InternalSqlScriptUtils.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/whitelist/InternalSqlScriptUtils.java index 91e63e60bd302..53016c81a862c 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/whitelist/InternalSqlScriptUtils.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/whitelist/InternalSqlScriptUtils.java @@ -8,7 +8,6 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.index.fielddata.ScriptDocValues; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.ql.expression.function.scalar.whitelist.InternalQlScriptUtils; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateAddProcessor; @@ -217,12 +216,12 @@ public static Number sqrt(Number value) { public static Number tan(Number value) { return MathOperation.TAN.apply(value); } - - + + // // Date/Time functions - // + // @Deprecated public static Integer dateTimeChrono(Object dateTime, String tzId, String chronoName) { String extractorName = null; @@ -238,7 +237,7 @@ public static Integer dateTimeChrono(Object dateTime, String tzId, String chrono } return dateTimeExtract(dateTime, tzId, extractorName); } - + public static Integer dateTimeExtract(Object dateTime, String tzId, String extractorName) { if (dateTime == null || tzId == null || extractorName == null) { return null; @@ -335,9 +334,6 @@ private static Object asDateTime(Object dateTime, boolean lenient) { if (dateTime == null) { return null; } - if (dateTime instanceof JodaCompatibleZonedDateTime) { - return ((JodaCompatibleZonedDateTime) dateTime).getZonedDateTime(); - } if (dateTime instanceof ZonedDateTime) { return dateTime; } diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/operator/arithmetic/SqlBinaryArithmeticOperation.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/operator/arithmetic/SqlBinaryArithmeticOperation.java index e6a24b23b434c..35c1412cd54d9 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/operator/arithmetic/SqlBinaryArithmeticOperation.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/operator/arithmetic/SqlBinaryArithmeticOperation.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.ql.QlIllegalArgumentException; import org.elasticsearch.xpack.ql.expression.predicate.operator.arithmetic.Arithmetics; import org.elasticsearch.xpack.ql.expression.predicate.operator.arithmetic.Arithmetics.NumericArithmetic; @@ -38,8 +37,6 @@ public enum SqlBinaryArithmeticOperation implements BinaryArithmeticOperation { if (l instanceof IntervalDayTime && r instanceof IntervalDayTime) { return ((IntervalDayTime) l).add((IntervalDayTime) r); } - l = unwrapJodaTime(l); - r = unwrapJodaTime(r); if ((l instanceof ZonedDateTime || l instanceof OffsetTime) && r instanceof IntervalYearMonth) { return IntervalArithmetics.add((Temporal) l, ((IntervalYearMonth) r).interval()); } @@ -66,8 +63,6 @@ public enum SqlBinaryArithmeticOperation implements BinaryArithmeticOperation { if (l instanceof IntervalDayTime && r instanceof IntervalDayTime) { return ((IntervalDayTime) l).sub((IntervalDayTime) r); } - l = unwrapJodaTime(l); - r = unwrapJodaTime(r); if ((l instanceof ZonedDateTime || l instanceof OffsetTime) && r instanceof IntervalYearMonth) { return IntervalArithmetics.sub((Temporal) l, ((IntervalYearMonth) r).interval()); } @@ -85,8 +80,6 @@ public enum SqlBinaryArithmeticOperation implements BinaryArithmeticOperation { if (l instanceof Number && r instanceof Number) { return Arithmetics.mul((Number) l, (Number) r); } - l = unwrapJodaTime(l); - r = unwrapJodaTime(r); if (l instanceof Number && r instanceof IntervalYearMonth) { return ((IntervalYearMonth) r).mul(((Number) l).intValue()); } @@ -148,8 +141,4 @@ public void writeTo(StreamOutput out) throws IOException { public static SqlBinaryArithmeticOperation read(StreamInput in) throws IOException { return in.readEnum(SqlBinaryArithmeticOperation.class); } - - private static Object unwrapJodaTime(Object o) { - return o instanceof JodaCompatibleZonedDateTime ? ((JodaCompatibleZonedDateTime) o).getZonedDateTime() : o; - } } diff --git a/x-pack/plugin/watcher/qa/rest/build.gradle b/x-pack/plugin/watcher/qa/rest/build.gradle index cfb75b244aa5b..a4bbaa399fccc 100644 --- a/x-pack/plugin/watcher/qa/rest/build.gradle +++ b/x-pack/plugin/watcher/qa/rest/build.gradle @@ -35,6 +35,15 @@ if (BuildParams.inFipsJvm){ tasks.named("yamlRestTest").configure{enabled = false } } +tasks.named("yamlRestTestV7CompatTest").configure { + systemProperty 'tests.rest.blacklist', [ + // remove JodaCompatibleDateTime -- ZonedDateTime doesn't output millis/nanos if they're 0 (#78417) + 'mustache/30_search_input/Test search input mustache integration (using request body and rest_total_hits_as_int)', + 'mustache/30_search_input/Test search input mustache integration (using request body)', + 'mustache/40_search_transform/Test search transform mustache integration (using request body)' + ].join(',') +} + tasks.named("yamlRestTestV7CompatTransform").configure({ task -> task.replaceKeyInDo("watcher.ack_watch", "xpack-watcher.ack_watch") task.replaceKeyInDo("watcher.activate_watch", "xpack-watcher.activate_watch") diff --git a/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/30_search_input.yml b/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/30_search_input.yml index 807071411064a..954f0d3e3f214 100644 --- a/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/30_search_input.yml +++ b/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/30_search_input.yml @@ -92,8 +92,8 @@ setup: - match: { "watch_record.result.input.status": "success" } - match: { "watch_record.result.input.payload.hits.total": 4 } # makes sure that the mustache template snippets have been resolved correctly: - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-3d" } - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00Z||-3d" } + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00Z" } --- "Test search input mustache integration (using request template)": @@ -210,8 +210,8 @@ setup: - match: { "watch_record.result.input.status": "success" } - match: { "watch_record.result.input.payload.hits.total": 4 } # makes sure that the mustache template snippets have been resolved correctly: - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-3d" } - - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00Z||-3d" } + - match: { "watch_record.result.input.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00Z" } --- "Test search input mustache integration (using request template and rest_total_hits_as_int)": diff --git a/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/40_search_transform.yml b/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/40_search_transform.yml index 068de0adb4649..91b76e5c66eae 100644 --- a/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/40_search_transform.yml +++ b/x-pack/plugin/watcher/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/mustache/40_search_transform.yml @@ -99,8 +99,8 @@ setup: - match: { "watch_record.result.transform.payload.hits.total": 1 } - match: { "watch_record.result.transform.payload.hits.hits.0._id": "3" } # makes sure that the mustache template snippets have been resolved correctly: - - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00:00.000Z||-1d" } - - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00:00.000Z" } + - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.gte": "2015-01-04T00:00Z||-1d" } + - match: { "watch_record.result.transform.search.request.body.query.bool.filter.0.range.date.lte": "2015-01-04T00:00Z" } - match: { "watch_record.result.transform.search.request.body.query.bool.filter.1.term.value": "val_3" } --- diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/Variables.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/Variables.java index 71c5054716c47..0d9ec4626c9fd 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/Variables.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/Variables.java @@ -6,11 +6,11 @@ */ package org.elasticsearch.xpack.watcher.support; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.watch.Payload; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.Map; @@ -37,8 +37,7 @@ public static Map createCtx(WatchExecutionContext ctx, Payload p Map ctxModel = new HashMap<>(); ctxModel.put(ID, ctx.id().value()); ctxModel.put(WATCH_ID, ctx.id().watchId()); - ctxModel.put(EXECUTION_TIME, - new JodaCompatibleZonedDateTime(ctx.executionTime().toInstant(), ZoneOffset.UTC)); + ctxModel.put(EXECUTION_TIME, ZonedDateTime.ofInstant(ctx.executionTime().toInstant(), ZoneOffset.UTC)); ctxModel.put(TRIGGER, ctx.triggerEvent().data()); if (payload != null) { ctxModel.put(PAYLOAD, payload.data()); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEvent.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEvent.java index 67d43f6f876a6..b2f552611b599 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEvent.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEvent.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils; import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent; @@ -30,8 +29,7 @@ public ScheduleTriggerEvent(ZonedDateTime triggeredTime, ZonedDateTime scheduled public ScheduleTriggerEvent(String jobName, ZonedDateTime triggeredTime, ZonedDateTime scheduledTime) { super(jobName, triggeredTime); this.scheduledTime = scheduledTime; - data.put(Field.SCHEDULED_TIME.getPreferredName(), - new JodaCompatibleZonedDateTime(scheduledTime.toInstant(), ZoneOffset.UTC)); + data.put(Field.SCHEDULED_TIME.getPreferredName(), ZonedDateTime.ofInstant(scheduledTime.toInstant(), ZoneOffset.UTC)); } @Override diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java index c4b0c9bf18dae..7fe8c83136144 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ssl.SSLService; import org.elasticsearch.xpack.core.watcher.actions.Action; @@ -134,7 +133,6 @@ public void testExecute() throws Exception { Map metadata = MapBuilder.newMapBuilder().put("_key", "_val").map(); ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC); - JodaCompatibleZonedDateTime jodaJavaNow = new JodaCompatibleZonedDateTime(now.toInstant(), ZoneOffset.UTC); Wid wid = new Wid("watch1", now); WatchExecutionContext ctx = mockExecutionContextBuilder("watch1") @@ -145,14 +143,14 @@ public void testExecute() throws Exception { .buildMock(); Map triggerModel = new HashMap<>(); - triggerModel.put("triggered_time", jodaJavaNow); - triggerModel.put("scheduled_time", jodaJavaNow); + triggerModel.put("triggered_time", now); + triggerModel.put("scheduled_time", now); Map ctxModel = new HashMap<>(); ctxModel.put("id", ctx.id().value()); ctxModel.put("watch_id", "watch1"); ctxModel.put("payload", data); ctxModel.put("metadata", metadata); - ctxModel.put("execution_time", jodaJavaNow); + ctxModel.put("execution_time", now); ctxModel.put("trigger", triggerModel); ctxModel.put("vars", emptyMap()); Map expectedModel = singletonMap("ctx", ctxModel); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java index f0a29534a37ca..0e741a10b8ca9 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.SuppressLoggerChecks; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; @@ -57,19 +56,18 @@ public void init() throws IOException { public void testExecute() throws Exception { final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC); - JodaCompatibleZonedDateTime jodaJavaNow = new JodaCompatibleZonedDateTime(now.toInstant(), ZoneOffset.UTC); WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContextBuilder("_watch_id") .time("_watch_id", now) .buildMock(); Map triggerModel = new HashMap<>(); - triggerModel.put("scheduled_time", jodaJavaNow); - triggerModel.put("triggered_time", jodaJavaNow); + triggerModel.put("scheduled_time", now); + triggerModel.put("triggered_time", now); Map ctxModel = new HashMap<>(); ctxModel.put("id", ctx.id().value()); ctxModel.put("watch_id", "_watch_id"); - ctxModel.put("execution_time", jodaJavaNow); + ctxModel.put("execution_time", now); ctxModel.put("payload", emptyMap()); ctxModel.put("metadata", emptyMap()); ctxModel.put("vars", emptyMap()); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java index f70dbfbe43c1a..2f01e1dd06e30 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; @@ -80,7 +79,6 @@ public void testExecute() throws Exception { Map metadata = MapBuilder.newMapBuilder().put("_key", "_val").map(); ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC); - JodaCompatibleZonedDateTime jodaJavaNow = new JodaCompatibleZonedDateTime(now.toInstant(), ZoneOffset.UTC); Wid wid = new Wid(randomAlphaOfLength(5), now); WatchExecutionContext ctx = mockExecutionContextBuilder(wid.watchId()) @@ -95,10 +93,10 @@ public void testExecute() throws Exception { ctxModel.put("watch_id", wid.watchId()); ctxModel.put("payload", data); ctxModel.put("metadata", metadata); - ctxModel.put("execution_time", jodaJavaNow); + ctxModel.put("execution_time", now); Map triggerModel = new HashMap<>(); - triggerModel.put("triggered_time", jodaJavaNow); - triggerModel.put("scheduled_time", jodaJavaNow); + triggerModel.put("triggered_time", now); + triggerModel.put("scheduled_time", now); ctxModel.put("trigger", triggerModel); ctxModel.put("vars", Collections.emptyMap()); Map expectedModel = new HashMap<>(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java index 025574a76cb1d..8abcbebd9d852 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.actions.Action; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; @@ -77,7 +76,6 @@ public void testExecute() throws Exception { Map metadata = MapBuilder.newMapBuilder().put("_key", "_val").map(); ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC); - JodaCompatibleZonedDateTime jodaJavaNow = new JodaCompatibleZonedDateTime(now.toInstant(), ZoneOffset.UTC); Wid wid = new Wid(randomAlphaOfLength(5), now); WatchExecutionContext ctx = mockExecutionContextBuilder(wid.watchId()) @@ -88,14 +86,14 @@ public void testExecute() throws Exception { .buildMock(); Map triggerModel = new HashMap<>(); - triggerModel.put("triggered_time", jodaJavaNow); - triggerModel.put("scheduled_time", jodaJavaNow); + triggerModel.put("triggered_time", now); + triggerModel.put("scheduled_time", now); Map ctxModel = new HashMap<>(); ctxModel.put("id", ctx.id().value()); ctxModel.put("watch_id", wid.watchId()); ctxModel.put("payload", data); ctxModel.put("metadata", metadata); - ctxModel.put("execution_time", jodaJavaNow); + ctxModel.put("execution_time", now); ctxModel.put("trigger", triggerModel); ctxModel.put("vars", emptyMap()); Map expectedModel = singletonMap("ctx", ctxModel); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java index ff69c9b9d07e6..39bdfd1eaa9b8 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/ScriptConditionTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.script.GeneralScriptException; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptException; import org.elasticsearch.script.ScriptMetadata; @@ -62,8 +61,7 @@ public void init() throws IOException { scripts.put("return new Object()", s -> new Object()); scripts.put("ctx.trigger.scheduled_time.toInstant().toEpochMill() < new Date().time", vars -> { - JodaCompatibleZonedDateTime scheduledTime = - (JodaCompatibleZonedDateTime) XContentMapValues.extractValue("ctx.trigger.scheduled_time", vars); + ZonedDateTime scheduledTime = (ZonedDateTime) XContentMapValues.extractValue("ctx.trigger.scheduled_time", vars); return scheduledTime.toInstant().toEpochMilli() < new Date().getTime(); }); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java index 477bf4b48051c..b56b3b1c1f0d0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/VariablesTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.support; import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.script.JodaCompatibleZonedDateTime; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.Wid; @@ -47,8 +46,7 @@ public void testCreateCtxModel() throws Exception { assertThat(model, notNullValue()); assertThat(model.size(), is(1)); - JodaCompatibleZonedDateTime jodaJavaExecutionTime = - new JodaCompatibleZonedDateTime(executionTime.toInstant(), ZoneOffset.UTC); + ZonedDateTime jodaJavaExecutionTime = ZonedDateTime.ofInstant(executionTime.toInstant(), ZoneOffset.UTC); assertThat(ObjectPath.eval("ctx", model), instanceOf(Map.class)); assertThat(ObjectPath.eval("ctx.id", model), is(wid.value())); // NOTE: we use toString() here because two ZonedDateTime are *not* equal, we need to check with isEqual