From fc7622c21ada2b01df0ed326b4f121e66ca1e494 Mon Sep 17 00:00:00 2001 From: Pranay Venkat Battu Date: Thu, 25 Jul 2024 20:28:51 +0530 Subject: [PATCH] chore: remove Joda-Time dependency from maestro-common #25 - Removed Joda-Time dependency from the Defaults class and replaced it with java.time.ZoneId. - Updated TriggerHelper class to use java.time.ZoneId instead of Joda-Time's DateTimeZone. - Simplified TimeZoneValidator to use a static final set of available time zone IDs, ensuring efficient validation. --- maestro-common/build.gradle | 1 - maestro-common/gradle.lockfile | 1 - .../java/com/netflix/maestro/models/Defaults.java | 4 ++-- .../com/netflix/maestro/utils/TriggerHelper.java | 4 ++-- .../maestro/validations/TimeZoneConstraint.java | 12 +++++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/maestro-common/build.gradle b/maestro-common/build.gradle index cb4bcdf..2da59c5 100644 --- a/maestro-common/build.gradle +++ b/maestro-common/build.gradle @@ -4,7 +4,6 @@ dependencies { implementation javaxValidationDep implementation jacksonYamlDep implementation quartzDep - implementation jodaTimeDep implementation(cronutilsDep) { exclude group: 'org.glassfish' } diff --git a/maestro-common/gradle.lockfile b/maestro-common/gradle.lockfile index 15c8dd9..9b0ca5a 100644 --- a/maestro-common/gradle.lockfile +++ b/maestro-common/gradle.lockfile @@ -11,7 +11,6 @@ com.mchange:mchange-commons-java:0.2.15=compileClasspath com.zaxxer:HikariCP-java7:2.4.13=compileClasspath javax.inject:javax.inject:1=compileClasspath javax.validation:validation-api:2.0.1.Final=compileClasspath -joda-time:joda-time:2.10.14=compileClasspath org.projectlombok:lombok:1.18.34=annotationProcessor,compileClasspath org.quartz-scheduler:quartz:2.3.2=compileClasspath org.slf4j:slf4j-api:1.7.30=compileClasspath diff --git a/maestro-common/src/main/java/com/netflix/maestro/models/Defaults.java b/maestro-common/src/main/java/com/netflix/maestro/models/Defaults.java index 0897a7c..0d47580 100644 --- a/maestro-common/src/main/java/com/netflix/maestro/models/Defaults.java +++ b/maestro-common/src/main/java/com/netflix/maestro/models/Defaults.java @@ -19,8 +19,8 @@ import com.netflix.maestro.models.instance.RunPolicy; import com.netflix.maestro.models.instance.StepInstance; import com.netflix.maestro.models.parameter.ParamMode; +import java.time.ZoneId; import java.util.TimeZone; -import org.joda.time.DateTimeZone; /** Class to hold the user facing default values for unset fields. */ public final class Defaults { @@ -103,7 +103,7 @@ private Defaults() {} StepInstance.Status.NOT_CREATED; /** Default Time Zone. * */ - public static final TimeZone DEFAULT_TIMEZONE = DateTimeZone.UTC.toTimeZone(); + public static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone(ZoneId.of("UTC")); /** Default Param Mode. */ public static final ParamMode DEFAULT_PARAM_MODE = ParamMode.MUTABLE; diff --git a/maestro-common/src/main/java/com/netflix/maestro/utils/TriggerHelper.java b/maestro-common/src/main/java/com/netflix/maestro/utils/TriggerHelper.java index 732ccb3..4a3ffbe 100644 --- a/maestro-common/src/main/java/com/netflix/maestro/utils/TriggerHelper.java +++ b/maestro-common/src/main/java/com/netflix/maestro/utils/TriggerHelper.java @@ -23,6 +23,7 @@ import com.netflix.maestro.models.trigger.TimeTrigger; import com.netflix.maestro.models.trigger.TimeTriggerWithJitter; import java.text.ParseException; +import java.time.ZoneId; import java.util.Date; import java.util.Optional; import java.util.Random; @@ -31,7 +32,6 @@ import java.util.concurrent.ThreadLocalRandom; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.joda.time.DateTimeZone; import org.quartz.CronExpression; /** Cron Helper utility class. * */ @@ -60,7 +60,7 @@ public static CronExpression buildCron(String cron) throws ParseException { * @throws ParseException parse error */ public static CronExpression buildCron(String cron, String timezone) throws ParseException { - return buildCron(cron, DateTimeZone.forID(timezone).toTimeZone()); + return buildCron(cron, TimeZone.getTimeZone(ZoneId.of(timezone))); } /** diff --git a/maestro-common/src/main/java/com/netflix/maestro/validations/TimeZoneConstraint.java b/maestro-common/src/main/java/com/netflix/maestro/validations/TimeZoneConstraint.java index 5921432..c9c9853 100644 --- a/maestro-common/src/main/java/com/netflix/maestro/validations/TimeZoneConstraint.java +++ b/maestro-common/src/main/java/com/netflix/maestro/validations/TimeZoneConstraint.java @@ -17,11 +17,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.time.ZoneId; +import java.util.Set; import javax.validation.Constraint; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; import javax.validation.Payload; -import org.joda.time.DateTimeZone; /** Maestro timezone expression validation. */ @Documented @@ -40,6 +41,8 @@ /** Maestro timezone validator. */ class TimeZoneValidator implements ConstraintValidator { + private static final Set AVAILABLE_ZONE_IDS = ZoneId.getAvailableZoneIds(); + @Override public void initialize(TimeZoneConstraint constraint) {} @@ -49,14 +52,13 @@ public boolean isValid(String timezone, ConstraintValidatorContext context) { return true; } - try { - DateTimeZone.forID(timezone); - } catch (IllegalArgumentException e) { + if (!AVAILABLE_ZONE_IDS.contains(timezone)) { context - .buildConstraintViolationWithTemplate("[timezone expression] is not valid: " + e) + .buildConstraintViolationWithTemplate("[timezone expression] is not valid: " + timezone) .addConstraintViolation(); return false; } + return true; } }