Skip to content

Commit

Permalink
chore: remove Joda-Time dependency from maestro-common #25
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Pranay Venkat Battu authored and Pranay Venkat Battu committed Jul 25, 2024
1 parent 3785587 commit fc7622c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion maestro-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencies {
implementation javaxValidationDep
implementation jacksonYamlDep
implementation quartzDep
implementation jodaTimeDep
implementation(cronutilsDep) {
exclude group: 'org.glassfish'
}
Expand Down
1 change: 0 additions & 1 deletion maestro-common/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. * */
Expand Down Expand Up @@ -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)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,6 +41,8 @@

/** Maestro timezone validator. */
class TimeZoneValidator implements ConstraintValidator<TimeZoneConstraint, String> {
private static final Set<String> AVAILABLE_ZONE_IDS = ZoneId.getAvailableZoneIds();

@Override
public void initialize(TimeZoneConstraint constraint) {}

Expand All @@ -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;
}
}
Expand Down

0 comments on commit fc7622c

Please sign in to comment.