From 958556e61b8106a29c089bcd6501b0f3b76cbf21 Mon Sep 17 00:00:00 2001 From: chgxtony Date: Mon, 29 Apr 2019 14:09:09 +0800 Subject: [PATCH] upgrade spring-boot to 2.1.x and spring to 5.x --- escheduler-alert/pom.xml | 4 - escheduler-api/pom.xml | 11 - .../api/configuration/AppConfiguration.java | 7 +- escheduler-common/pom.xml | 4 - .../cn/escheduler/common/utils/DateUtils.java | 565 ++++++++++-------- .../server/master/MasterServer.java | 1 - pom.xml | 86 ++- 7 files changed, 343 insertions(+), 335 deletions(-) diff --git a/escheduler-alert/pom.xml b/escheduler-alert/pom.xml index da03314ce8..f066bc4b72 100644 --- a/escheduler-alert/pom.xml +++ b/escheduler-alert/pom.xml @@ -90,10 +90,6 @@ commons-io - - org.apache.commons - commons-collections4 - diff --git a/escheduler-api/pom.xml b/escheduler-api/pom.xml index bfa01dba1e..ec94e30b27 100644 --- a/escheduler-api/pom.xml +++ b/escheduler-api/pom.xml @@ -38,13 +38,6 @@ - - org.springframework.boot - spring-boot-starter-parent - ${spring.boot.version} - pom - import - org.springframework.boot @@ -54,10 +47,6 @@ org.springframework.boot spring-boot-starter-tomcat - - org.springframework.boot - spring-boot-starter - diff --git a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java b/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java index 491da0821e..148efc1894 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/configuration/AppConfiguration.java @@ -19,16 +19,13 @@ package cn.escheduler.api.configuration; import cn.escheduler.api.interceptor.LoginHandlerInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.*; /** * application configuration */ @Configuration -public class AppConfiguration extends WebMvcConfigurerAdapter { +public class AppConfiguration implements WebMvcConfigurer { public static final String LOGIN_INTERCEPTOR_PATH_PATTERN = "/**/*"; public static final String LOGIN_PATH_PATTERN = "/login"; diff --git a/escheduler-common/pom.xml b/escheduler-common/pom.xml index f6b8c83028..9703548057 100644 --- a/escheduler-common/pom.xml +++ b/escheduler-common/pom.xml @@ -240,10 +240,6 @@ postgresql - - org.apache.httpcomponents - httpclient - org.apache.hive hive-jdbc diff --git a/escheduler-common/src/main/java/cn/escheduler/common/utils/DateUtils.java b/escheduler-common/src/main/java/cn/escheduler/common/utils/DateUtils.java index 11dc6bfbf6..045db346c6 100644 --- a/escheduler-common/src/main/java/cn/escheduler/common/utils/DateUtils.java +++ b/escheduler-common/src/main/java/cn/escheduler/common/utils/DateUtils.java @@ -20,8 +20,10 @@ import cn.escheduler.common.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; @@ -30,145 +32,182 @@ import java.util.Date; */ public class DateUtils { - private static final Logger logger = LoggerFactory.getLogger(DateUtils.class); - - /** - * @return get the formatted date string for the current time - */ - public static String getCurrentTime() { - return getCurrentTime(Constants.YYYY_MM_DD_HH_MM_SS); - } - - /** - * @param format - * @return get the date string in the specified format of the current time - */ - public static String getCurrentTime(String format) { - return new SimpleDateFormat(format).format(new Date()); - } - - /** - * @param date - * @param format e.g. yyyy-MM-dd HH:mm:ss - * @return get the formatted date string - */ - public static String format(Date date, String format) { - return new SimpleDateFormat(format).format(date); - } - - /** - * @param date - * @return convert time to yyyy-MM-dd HH:mm:ss format - */ - public static String dateToString(Date date){ - return format(date,Constants.YYYY_MM_DD_HH_MM_SS); - } - - - /** - * @param date - * @return convert string to date and time - */ - public static Date parse(String date,String format){ - try { - return new SimpleDateFormat(format).parse(date); - } catch (Exception e) { - logger.error("error while parse date:" + date, e); - } - return null; - } - - /** - * convert date str to yyyy-MM-dd HH:mm:ss format - * @param str - * @return - */ - public static Date stringToDate(String str){ - return parse(str,Constants.YYYY_MM_DD_HH_MM_SS); - } - - /** - * get seconds between two dates - * - * @param d1 - * @param d2 - * @return - */ - public static long differSec(Date d1, Date d2) { - return (long) Math.ceil(differMs(d1, d2) / 1000.0); - } - - /** - * get ms between two dates - * - * @param d1 - * @param d2 - * @return - */ - public static long differMs(Date d1, Date d2) { - return Math.abs(d1.getTime() - d2.getTime()); - } - - - /** - * get hours between two dates - * - * @param d1 - * @param d2 - * @return - */ - public static long diffHours(Date d1, Date d2) { - return (long) Math.ceil(diffMin(d1, d2) / 60.0); - } - - /** - * get minutes between two dates - * - * @param d1 - * @param d2 - * @return - */ - public static long diffMin(Date d1, Date d2) { - return (long) Math.ceil(differSec(d1, d2) / 60.0); - } - - - /** + private static final Logger logger = LoggerFactory.getLogger(DateUtils.class); + + /** + * java.util.Date to java.time.LocalDateTime + * use default zone + * @param date + * @return + */ + private static LocalDateTime date2LocalDateTime(Date date) { + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } + + /** + * java.time.LocalDateTime to java.util.Date + * use default zone + * @param localDateTime + * @return + */ + private static Date localDateTime2Date(LocalDateTime localDateTime) { + Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); + return Date.from(instant); + } + + /** + * @return get the formatted date string for the current time + */ + public static String getCurrentTime() { + return getCurrentTime(Constants.YYYY_MM_DD_HH_MM_SS); + } + + /** + * @param format + * @return get the date string in the specified format of the current time + */ + public static String getCurrentTime(String format) { +// return new SimpleDateFormat(format).format(new Date()); + return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format)); + } + + /** + * @param date + * @param format e.g. yyyy-MM-dd HH:mm:ss + * @return get the formatted date string + */ + public static String format(Date date, String format) { +// return new SimpleDateFormat(format).format(date); + return format(date2LocalDateTime(date), format); + } + + /** + * @param localDateTime + * @param format e.g. yyyy-MM-dd HH:mm:ss + * @return get the formatted date string + */ + public static String format(LocalDateTime localDateTime, String format) { + return localDateTime.format(DateTimeFormatter.ofPattern(format)); + } + + /** + * @param date + * @return convert time to yyyy-MM-dd HH:mm:ss format + */ + public static String dateToString(Date date) { + return format(date, Constants.YYYY_MM_DD_HH_MM_SS); + } + + + /** + * @param date + * @return convert string to date and time + */ + public static Date parse(String date, String format) { + try { + // return new SimpleDateFormat(format).parse(date); + LocalDateTime ldt = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(format)); + return localDateTime2Date(ldt); + } catch (Exception e) { + logger.error("error while parse date:" + date, e); + } + return null; + } + + /** + * convert date str to yyyy-MM-dd HH:mm:ss format + * + * @param str + * @return + */ + public static Date stringToDate(String str) { + return parse(str, Constants.YYYY_MM_DD_HH_MM_SS); + } + + /** + * get seconds between two dates + * + * @param d1 + * @param d2 + * @return + */ + public static long differSec(Date d1, Date d2) { + return (long) Math.ceil(differMs(d1, d2) / 1000.0); + } + + /** + * get ms between two dates + * + * @param d1 + * @param d2 + * @return + */ + public static long differMs(Date d1, Date d2) { + return Math.abs(d1.getTime() - d2.getTime()); + } + + + /** + * get hours between two dates + * + * @param d1 + * @param d2 + * @return + */ + public static long diffHours(Date d1, Date d2) { + return (long) Math.ceil(diffMin(d1, d2) / 60.0); + } + + /** + * get minutes between two dates + * + * @param d1 + * @param d2 + * @return + */ + public static long diffMin(Date d1, Date d2) { + return (long) Math.ceil(differSec(d1, d2) / 60.0); + } + + + /** * get the date of the specified date in the days before and after - * @param date - * @param day - * @return - */ - public static Date getSomeDay(Date date, int day) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.add(Calendar.DATE, day); - return calendar.getTime(); - } - - /** + * + * @param date + * @param day + * @return + */ + public static Date getSomeDay(Date date, int day) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.DATE, day); + return calendar.getTime(); + } + + /** * compare two dates - * - * @param future - * @param old - * @return - */ - public static boolean compare(Date future, Date old) { - return future.getTime() > old.getTime(); - } - - /** - * convert schedule string to date - * @param schedule - * @return - */ - public static Date getScheduleDate(String schedule){ - return stringToDate(schedule); - } + * + * @param future + * @param old + * @return + */ + public static boolean compare(Date future, Date old) { + return future.getTime() > old.getTime(); + } + + /** + * convert schedule string to date + * + * @param schedule + * @return + */ + public static Date getScheduleDate(String schedule) { + return stringToDate(schedule); + } /** * format time to readable - * + * * @param ms * @return */ @@ -183,131 +222,135 @@ public class DateUtils { } - /** - * get monday - * - * note: Set the first day of the week to Monday, the default is Sunday - */ - public static Date getMonday(Date date) { - Calendar cal = Calendar.getInstance(); - - cal.setTime(date); - - cal.setFirstDayOfWeek(Calendar.MONDAY); - cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); - - return cal.getTime(); - } - - /** - * get sunday - * - * note: Set the first day of the week to Monday, the default is Sunday - */ - public static Date getSunday(Date date) { - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - - cal.setFirstDayOfWeek(Calendar.MONDAY); - cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); - - return cal.getTime(); - } - - /** - * get first day of month - */ - public static Date getFirstDayOfMonth(Date date) { - Calendar cal = Calendar.getInstance(); - - cal.setTime(date); - cal.set(Calendar.DAY_OF_MONTH, 1); - - return cal.getTime(); - } - - /** - * get first day of month - */ - public static Date getSomeHourOfDay(Date date, int hours) { - Calendar cal = Calendar.getInstance(); - - cal.setTime(date); - cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - hours); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - - return cal.getTime(); - } - - /** - * get last day of month - */ - public static Date getLastDayOfMonth(Date date) { - Calendar cal = Calendar.getInstance(); - - cal.setTime(date); - - cal.add(Calendar.MONTH, 1); - cal.set(Calendar.DAY_OF_MONTH, 1); - cal.add(Calendar.DAY_OF_MONTH, -1); - - return cal.getTime(); - } - - /** - * return YYYY-MM-DD 00:00:00 - * @param inputDay - * @return - */ - public static Date getStartOfDay(Date inputDay){ - Calendar cal = Calendar.getInstance(); - cal.setTime(inputDay); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - return cal.getTime(); - } - - /** - * return YYYY-MM-DD 23:59:59 - * @param inputDay - * @return - */ - public static Date getEndOfDay(Date inputDay){ - Calendar cal = Calendar.getInstance(); - cal.setTime(inputDay); - cal.set(Calendar.HOUR_OF_DAY, 23); - cal.set(Calendar.MINUTE, 59); - cal.set(Calendar.SECOND, 59); - return cal.getTime(); - } - - /** - * return YYYY-MM-DD 00:00:00 - * @param inputDay - * @return - */ - public static Date getStartOfHour(Date inputDay){ - Calendar cal = Calendar.getInstance(); - cal.setTime(inputDay); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - return cal.getTime(); - } - - /** - * return YYYY-MM-DD 23:59:59 - * @param inputDay - * @return - */ - public static Date getEndOfHour(Date inputDay){ - Calendar cal = Calendar.getInstance(); - cal.setTime(inputDay); - cal.set(Calendar.MINUTE, 59); - cal.set(Calendar.SECOND, 59); - return cal.getTime(); - } + /** + * get monday + *

+ * note: Set the first day of the week to Monday, the default is Sunday + */ + public static Date getMonday(Date date) { + Calendar cal = Calendar.getInstance(); + + cal.setTime(date); + + cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + + return cal.getTime(); + } + + /** + * get sunday + *

+ * note: Set the first day of the week to Monday, the default is Sunday + */ + public static Date getSunday(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + + cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + + return cal.getTime(); + } + + /** + * get first day of month + */ + public static Date getFirstDayOfMonth(Date date) { + Calendar cal = Calendar.getInstance(); + + cal.setTime(date); + cal.set(Calendar.DAY_OF_MONTH, 1); + + return cal.getTime(); + } + + /** + * get first day of month + */ + public static Date getSomeHourOfDay(Date date, int hours) { + Calendar cal = Calendar.getInstance(); + + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - hours); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + + return cal.getTime(); + } + + /** + * get last day of month + */ + public static Date getLastDayOfMonth(Date date) { + Calendar cal = Calendar.getInstance(); + + cal.setTime(date); + + cal.add(Calendar.MONTH, 1); + cal.set(Calendar.DAY_OF_MONTH, 1); + cal.add(Calendar.DAY_OF_MONTH, -1); + + return cal.getTime(); + } + + /** + * return YYYY-MM-DD 00:00:00 + * + * @param inputDay + * @return + */ + public static Date getStartOfDay(Date inputDay) { + Calendar cal = Calendar.getInstance(); + cal.setTime(inputDay); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + return cal.getTime(); + } + + /** + * return YYYY-MM-DD 23:59:59 + * + * @param inputDay + * @return + */ + public static Date getEndOfDay(Date inputDay) { + Calendar cal = Calendar.getInstance(); + cal.setTime(inputDay); + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + return cal.getTime(); + } + + /** + * return YYYY-MM-DD 00:00:00 + * + * @param inputDay + * @return + */ + public static Date getStartOfHour(Date inputDay) { + Calendar cal = Calendar.getInstance(); + cal.setTime(inputDay); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + return cal.getTime(); + } + + /** + * return YYYY-MM-DD 23:59:59 + * + * @param inputDay + * @return + */ + public static Date getEndOfHour(Date inputDay) { + Calendar cal = Calendar.getInstance(); + cal.setTime(inputDay); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + return cal.getTime(); + } } diff --git a/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java b/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java index 95705dd017..f877104cc1 100644 --- a/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java +++ b/escheduler-server/src/main/java/cn/escheduler/server/master/MasterServer.java @@ -189,7 +189,6 @@ public class MasterServer implements CommandLineRunner, IStoppable { public static void main(String[] args) { SpringApplication app = new SpringApplication(MasterServer.class); - app.setWebEnvironment(false); app.run(args); } diff --git a/pom.xml b/pom.xml index 3e5ff0d79d..3847b49fd3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,12 +8,13 @@ escheduler http://maven.apache.org + UTF-8 UTF-8 2.12.0 - 4.3.7.RELEASE - 1.4.5.RELEASE + 5.1.5.RELEASE + 2.1.3.RELEASE 1.8 1.2.3 2.7.3 @@ -23,16 +24,27 @@ + + org.mybatis + mybatis + 3.5.1 + + + org.mybatis + mybatis-spring + 2.0.1 + org.mybatis.spring.boot mybatis-spring-boot-autoconfigure - 1.2.0 + 2.0.1 org.mybatis.spring.boot mybatis-spring-boot-starter - 1.2.0 + 2.0.1 + org.quartz-scheduler @@ -49,36 +61,26 @@ cron-utils 5.0.5 - - org.mybatis - mybatis - 3.4.2 - - - org.mybatis - mybatis-spring - 1.3.1 - - - org.springframework - spring-tx - ${spring.version} - - - org.springframework - spring-jdbc - ${spring.version} - + com.alibaba fastjson 1.2.29 + + com.alibaba + druid + 1.1.14 + + org.springframework.boot - spring-boot-starter-jetty + spring-boot-starter-parent ${spring.boot.version} + pom + import + org.springframework spring-core @@ -96,31 +98,21 @@ org.springframework - spring-test + spring-tx ${spring.version} - org.springframework.boot - spring-boot-starter-parent - ${spring.boot.version} - - - org.springframework.boot - spring-boot-starter-web - ${spring.boot.version} - - - org.springframework.boot - spring-boot-starter-test - ${spring.boot.version} - test + org.springframework + spring-jdbc + ${spring.version} - org.springframework.boot - spring-boot-starter-aop - ${spring.boot.version} + org.springframework + spring-test + ${spring.version} + cn.analysys escheduler-common @@ -146,6 +138,7 @@ escheduler-alert ${project.version} + org.apache.curator curator-framework @@ -249,11 +242,6 @@ - - com.alibaba - druid - 1.1.14 - ch.qos.logback @@ -380,7 +368,7 @@ - + scm:git:https://github.com/analysys/EasyScheduler.git scm:git:https://github.com/analysys/EasyScheduler.git