From e8c949fe2bd7b7bfbe22b569c048af4227d8fcc2 Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Mon, 12 Aug 2019 16:31:48 +0800 Subject: [PATCH 1/6] add druid connection provider in order to change quartz default connection pool --- .../quartz/DruidConnectionProvider.java | 203 ++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 escheduler-server/src/main/java/cn/escheduler/server/quartz/DruidConnectionProvider.java diff --git a/escheduler-server/src/main/java/cn/escheduler/server/quartz/DruidConnectionProvider.java b/escheduler-server/src/main/java/cn/escheduler/server/quartz/DruidConnectionProvider.java new file mode 100644 index 0000000000..b58d87ce9d --- /dev/null +++ b/escheduler-server/src/main/java/cn/escheduler/server/quartz/DruidConnectionProvider.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.escheduler.server.quartz; + +import com.alibaba.druid.pool.DruidDataSource; +import org.quartz.SchedulerException; +import java.sql.Connection; +import java.sql.SQLException; +import org.quartz.utils.ConnectionProvider; + +/** + * druid connection provider + */ +public class DruidConnectionProvider implements ConnectionProvider { + + /** + * JDBC driver + */ + public String driver; + + /** + * JDBC URL + */ + public String URL; + + /** + * Database user name + */ + public String user; + + /** + * Database password + */ + public String password; + + /** + * Maximum number of database connections + */ + public int maxConnections; + + /** + * The query that validates the database connection + */ + public String validationQuery; + + /** + * Whether the database sql query to validate connections should be executed every time + * a connection is retrieved from the pool to ensure that it is still valid. If false, + * then validation will occur on check-in. Default is false. + */ + private boolean validateOnCheckout; + + /** + * The number of seconds between tests of idle connections - only enabled + * if the validation query property is set. Default is 50 seconds. + */ + private int idleConnectionValidationSeconds; + + /** + * The maximum number of prepared statements that will be cached per connection in the pool. + * Depending upon your JDBC Driver this may significantly help performance, or may slightly + * hinder performance. + * Default is 120, as Quartz uses over 100 unique statements. 0 disables the feature. + */ + public String maxCachedStatementsPerConnection; + + /** + * Discard connections after they have been idle this many seconds. 0 disables the feature. Default is 0. + */ + private String discardIdleConnectionsSeconds; + + /** + * Default maximum number of database connections in the pool. + */ + public static final int DEFAULT_DB_MAX_CONNECTIONS = 10; + + /** + * The maximum number of prepared statements that will be cached per connection in the pool. + */ + public static final int DEFAULT_DB_MAX_CACHED_STATEMENTS_PER_CONNECTION = 120; + + /** + * Druid connection pool + */ + private DruidDataSource datasource; + + public Connection getConnection() throws SQLException { + return datasource.getConnection(); + } + public void shutdown() throws SQLException { + datasource.close(); + } + public void initialize() throws SQLException{ + if (this.URL == null) { + throw new SQLException("DBPool could not be created: DB URL cannot be null"); + } + if (this.driver == null) { + throw new SQLException("DBPool driver could not be created: DB driver class name cannot be null!"); + } + if (this.maxConnections < 0) { + throw new SQLException("DBPool maxConnectins could not be created: Max connections must be greater than zero!"); + } + datasource = new DruidDataSource(); + try{ + datasource.setDriverClassName(this.driver); + } catch (Exception e) { + try { + throw new SchedulerException("Problem setting driver class name on datasource: " + e.getMessage(), e); + } catch (SchedulerException e1) { + } + } + datasource.setUrl(this.URL); + datasource.setUsername(this.user); + datasource.setPassword(this.password); + datasource.setMaxActive(this.maxConnections); + datasource.setMinIdle(1); + datasource.setMaxWait(0); + datasource.setMaxPoolPreparedStatementPerConnectionSize(DEFAULT_DB_MAX_CONNECTIONS); + if (this.validationQuery != null) { + datasource.setValidationQuery(this.validationQuery); + if(!this.validateOnCheckout) + datasource.setTestOnReturn(true); + else + datasource.setTestOnBorrow(true); + datasource.setValidationQueryTimeout(this.idleConnectionValidationSeconds); + } + } + + public String getDriver() { + return driver; + } + public void setDriver(String driver) { + this.driver = driver; + } + public String getURL() { + return URL; + } + public void setURL(String URL) { + this.URL = URL; + } + public String getUser() { + return user; + } + public void setUser(String user) { + this.user = user; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public int getMaxConnections() { + return maxConnections; + } + public void setMaxConnections(int maxConnections) { + this.maxConnections = maxConnections; + } + public String getValidationQuery() { + return validationQuery; + } + public void setValidationQuery(String validationQuery) { + this.validationQuery = validationQuery; + } + public boolean isValidateOnCheckout() { + return validateOnCheckout; + } + public void setValidateOnCheckout(boolean validateOnCheckout) { + this.validateOnCheckout = validateOnCheckout; + } + public int getIdleConnectionValidationSeconds() { + return idleConnectionValidationSeconds; + } + public void setIdleConnectionValidationSeconds(int idleConnectionValidationSeconds) { + this.idleConnectionValidationSeconds = idleConnectionValidationSeconds; + } + public DruidDataSource getDatasource() { + return datasource; + } + public void setDatasource(DruidDataSource datasource) { + this.datasource = datasource; + } + public String getDiscardIdleConnectionsSeconds() { + return discardIdleConnectionsSeconds; + } + public void setDiscardIdleConnectionsSeconds(String discardIdleConnectionsSeconds) { + this.discardIdleConnectionsSeconds = discardIdleConnectionsSeconds; + } +} From cdeb050fc61574a3f610f97e11c7ea48a5e7d5f7 Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Tue, 13 Aug 2019 17:04:53 +0800 Subject: [PATCH 2/6] remove c3p0 in escheduler-api and escheduler-dao --- escheduler-api/pom.xml | 6 ++++++ escheduler-dao/pom.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/escheduler-api/pom.xml b/escheduler-api/pom.xml index 2ac260f314..766993ca4e 100644 --- a/escheduler-api/pom.xml +++ b/escheduler-api/pom.xml @@ -141,6 +141,12 @@ org.quartz-scheduler quartz + + + c3p0 + c3p0 + + diff --git a/escheduler-dao/pom.xml b/escheduler-dao/pom.xml index 4d8fb6912e..bbd45c0c89 100644 --- a/escheduler-dao/pom.xml +++ b/escheduler-dao/pom.xml @@ -116,6 +116,12 @@ org.quartz-scheduler quartz + + + c3p0 + c3p0 + + From eafe4d8cb087fd3abc99cc55b6a6e8bdd926869f Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Tue, 13 Aug 2019 17:57:44 +0800 Subject: [PATCH 3/6] change method name queryByIdAndIp to queryBySessionId and queryByUserIdAndIp to queryByUserId --- .../cn/escheduler/dao/mapper/SessionMapperProvider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/SessionMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/SessionMapperProvider.java index 07567fd9ea..5dec6b0fcc 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/SessionMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/SessionMapperProvider.java @@ -103,11 +103,11 @@ public class SessionMapperProvider { } /** - * query by session id and ip + * query by session id * @param parameter * @return */ - public String queryByIdAndIp(Map parameter) { + public String queryBySessionId(Map parameter) { return new SQL() {{ SELECT("*"); @@ -118,11 +118,11 @@ public class SessionMapperProvider { } /** - * query by user id and ip + * query by user id * @param parameter * @return */ - public String queryByUserIdAndIp(Map parameter) { + public String queryByUserId(Map parameter) { return new SQL() {{ SELECT("*"); From 450e912b4337bc22526232d6b78e06b0ca3d807d Mon Sep 17 00:00:00 2001 From: ligang Date: Tue, 13 Aug 2019 19:12:10 +0800 Subject: [PATCH 4/6] change connectionProvider.class from c3p0 to druid --- escheduler-common/src/main/resources/quartz.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escheduler-common/src/main/resources/quartz.properties b/escheduler-common/src/main/resources/quartz.properties index 3aa3df5fca..89bf5cf309 100644 --- a/escheduler-common/src/main/resources/quartz.properties +++ b/escheduler-common/src/main/resources/quartz.properties @@ -26,11 +26,11 @@ org.quartz.jobStore.isClustered = true org.quartz.jobStore.misfireThreshold = 60000 org.quartz.jobStore.clusterCheckinInterval = 5000 org.quartz.jobStore.dataSource = myDs +org.quartz.dataSource.myDs.connectionProvider.class = cn.escheduler.server.quartz.DruidConnectionProvider #============================================================================ # Configure Datasources #============================================================================ - org.quartz.dataSource.myDs.driver = com.mysql.jdbc.Driver org.quartz.dataSource.myDs.URL = jdbc:mysql://192.168.xx.xx:3306/escheduler?characterEncoding=utf8 org.quartz.dataSource.myDs.user = xx From 5e6853f483f4dea040e58944430ad3ce71b632a4 Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Tue, 13 Aug 2019 19:23:20 +0800 Subject: [PATCH 5/6] change connectionProvider.class from c3p0 to druid --- escheduler-common/src/main/resources/quartz.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escheduler-common/src/main/resources/quartz.properties b/escheduler-common/src/main/resources/quartz.properties index 89bf5cf309..1f17801b8d 100644 --- a/escheduler-common/src/main/resources/quartz.properties +++ b/escheduler-common/src/main/resources/quartz.properties @@ -26,11 +26,11 @@ org.quartz.jobStore.isClustered = true org.quartz.jobStore.misfireThreshold = 60000 org.quartz.jobStore.clusterCheckinInterval = 5000 org.quartz.jobStore.dataSource = myDs -org.quartz.dataSource.myDs.connectionProvider.class = cn.escheduler.server.quartz.DruidConnectionProvider #============================================================================ # Configure Datasources #============================================================================ +org.quartz.dataSource.myDs.connectionProvider.class = cn.escheduler.server.quartz.DruidConnectionProvider org.quartz.dataSource.myDs.driver = com.mysql.jdbc.Driver org.quartz.dataSource.myDs.URL = jdbc:mysql://192.168.xx.xx:3306/escheduler?characterEncoding=utf8 org.quartz.dataSource.myDs.user = xx From fd14b81ca18300a1582e1b91d6f1e594c247b85f Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Thu, 15 Aug 2019 17:56:09 +0800 Subject: [PATCH 6/6] remove category x what can we not include in an asf project --- escheduler-common/pom.xml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/escheduler-common/pom.xml b/escheduler-common/pom.xml index 35b025b1d8..b71a1dcc6b 100644 --- a/escheduler-common/pom.xml +++ b/escheduler-common/pom.xml @@ -148,6 +148,10 @@ javax.servlet.jsp jsp-api + + jersey-json + com.sun.jersey + @@ -407,6 +411,10 @@ com.fasterxml.jackson.core jackson-databind + + jaxb-api + javax.xml.bind + @@ -415,8 +423,8 @@ mssql-jdbc - com.microsoft.azure - azure-keyvault + azure-keyvault + com.microsoft.azure