From 0d70e065bade8de30a5fa6743dd82a86ed59746c Mon Sep 17 00:00:00 2001
From: break60 <790061044@qq.com>
Date: Tue, 24 Mar 2020 17:40:09 +0800
Subject: [PATCH 1/9] Change normalize.scss import method and animation.scss
license modification (#2295)
* Change DOM label
* Change name to lowercase
* Limit customization file content to no more than 3000 lines
* dd branch flow node verification
* datax
* datax add custom
* Change normalize.scss import method and animation.scss license modification
---
dolphinscheduler-ui/package.json | 1 +
dolphinscheduler-ui/src/js/conf/home/index.js | 1 +
.../src/sass/common/_animation.scss | 23 +-
.../src/sass/common/_normalize.scss | 303 ------------------
.../src/sass/common/index.scss | 1 -
5 files changed, 17 insertions(+), 312 deletions(-)
delete mode 100644 dolphinscheduler-ui/src/sass/common/_normalize.scss
diff --git a/dolphinscheduler-ui/package.json b/dolphinscheduler-ui/package.json
index da15b722fc..b8a288ec07 100644
--- a/dolphinscheduler-ui/package.json
+++ b/dolphinscheduler-ui/package.json
@@ -26,6 +26,7 @@
"js-cookie": "^2.2.1",
"jsplumb": "^2.8.6",
"lodash": "^4.17.11",
+ "normalize.css": "^8.0.1",
"vue": "^2.5.17",
"vue-router": "2.7.0",
"vuex": "^3.0.0",
diff --git a/dolphinscheduler-ui/src/js/conf/home/index.js b/dolphinscheduler-ui/src/js/conf/home/index.js
index 33fc63d8b0..1913088eca 100644
--- a/dolphinscheduler-ui/src/js/conf/home/index.js
+++ b/dolphinscheduler-ui/src/js/conf/home/index.js
@@ -31,6 +31,7 @@ import Permissions from '@/module/permissions'
import 'ans-ui/lib/ans-ui.min.css'
import ans from 'ans-ui/lib/ans-ui.min'
import en_US from 'ans-ui/lib/locale/en' // eslint-disable-line
+import'normalize.css/normalize.css'
import 'sass/conf/home/index.scss'
import'bootstrap/dist/css/bootstrap.min.css'
diff --git a/dolphinscheduler-ui/src/sass/common/_animation.scss b/dolphinscheduler-ui/src/sass/common/_animation.scss
index 5e5fb12f76..d9870cf49a 100644
--- a/dolphinscheduler-ui/src/sass/common/_animation.scss
+++ b/dolphinscheduler-ui/src/sass/common/_animation.scss
@@ -1,13 +1,20 @@
-/* stylelint-disable */
-@charset "UTF-8";
-/*!
- * animate.css -http://daneden.me/animate
- * Version - 3.7.0
- * Licensed under the MIT license - http://opensource.org/licenses/MIT
+/*
+ * 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
*
- * Copyright (c) 2018 Daniel Eden
+ * 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.
*/
-
+@charset "UTF-8";
@-webkit-keyframes bounce {
from,
20%,
diff --git a/dolphinscheduler-ui/src/sass/common/_normalize.scss b/dolphinscheduler-ui/src/sass/common/_normalize.scss
deleted file mode 100644
index e95dc60c9c..0000000000
--- a/dolphinscheduler-ui/src/sass/common/_normalize.scss
+++ /dev/null
@@ -1,303 +0,0 @@
-/* stylelint-disable */
-/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */
-/* Document
- ========================================================================== */
-/**
- * 1. Correct the line height in all browsers.
- * 2. Prevent adjustments of font size after orientation changes in iOS.
- */
-
-html {
- line-height: 1.15; /* 1 */
- -webkit-text-size-adjust: 100%; /* 2 */
-}
-/* Sections
- ========================================================================== */
-/**
- * Remove the margin in all browsers.
- */
-
-body {
- margin: 0;
-}
-/**
- * Correct the font size and margin on `h1` elements within `section` and
- * `article` contexts in Chrome, Firefox, and Safari.
- */
-
-h1 {
- font-size: 2em;
- margin: .67em 0;
-}
-/* Grouping content
- ========================================================================== */
-/**
- * 1. Add the correct box sizing in Firefox.
- * 2. Show the overflow in Edge and IE.
- */
-
-hr {
- box-sizing: content-box; /* 1 */
- height: 0; /* 1 */
- overflow: visible; /* 2 */
-}
-/**
- * 1. Correct the inheritance and scaling of font size in all browsers.
- * 2. Correct the odd `em` font sizing in all browsers.
- */
-
-pre {
- font-family: monospace, monospace; /* 1 */
- font-size: 1em; /* 2 */
-}
-/* Text-level semantics
- ========================================================================== */
-/**
- * Remove the gray background on active links in IE 10.
- */
-
-a {
- background-color: transparent;
-}
-/**
- * 1. Remove the bottom border in Chrome 57-
- * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
- */
-
-abbr[title] {
- border-bottom: none; /* 1 */
- text-decoration: underline; /* 2 */
- text-decoration: underline dotted; /* 2 */
-}
-/**
- * Add the correct font weight in Chrome, Edge, and Safari.
- */
-
-b,
-strong {
- font-weight: bolder;
-}
-/**
- * 1. Correct the inheritance and scaling of font size in all browsers.
- * 2. Correct the odd `em` font sizing in all browsers.
- */
-
-code,
-kbd,
-samp {
- font-family: monospace, monospace; /* 1 */
- font-size: 1em; /* 2 */
-}
-/**
- * Add the correct font size in all browsers.
- */
-
-small {
- font-size: 80%;
-}
-/**
- * Prevent `sub` and `sup` elements from affecting the line height in
- * all browsers.
- */
-
-sub,
-sup {
- font-size: 75%;
- line-height: 0;
- position: relative;
- vertical-align: baseline;
-}
-
-sub {
- bottom: -.25em;
-}
-
-sup {
- top: -.5em;
-}
-/* Embedded content
- ========================================================================== */
-/**
- * Remove the border on images inside links in IE 10.
- */
-
-img {
- border-style: none;
-}
-/* Forms
- ========================================================================== */
-/**
- * 1. Change the font styles in all browsers.
- * 2. Remove the margin in Firefox and Safari.
- */
-
-button,
-input,
-optgroup,
-select,
-textarea {
- font-family: inherit; /* 1 */
- font-size: 100%; /* 1 */
- line-height: 1.15; /* 1 */
- margin: 0; /* 2 */
-}
-/**
- * Show the overflow in IE.
- * 1. Show the overflow in Edge.
- */
-
-button,
-input { /* 1 */
- overflow: visible;
-}
-/**
- * Remove the inheritance of text transform in Edge, Firefox, and IE.
- * 1. Remove the inheritance of text transform in Firefox.
- */
-
-button,
-select { /* 1 */
- text-transform: none;
-}
-/**
- * Correct the inability to style clickable types in iOS and Safari.
- */
-
-button,
-[type="button"],
-[type="reset"],
-[type="submit"] {
- -webkit-appearance: button;
-}
-/**
- * Remove the inner border and padding in Firefox.
- */
-
-button::-moz-focus-inner,
-[type="button"]::-moz-focus-inner,
-[type="reset"]::-moz-focus-inner,
-[type="submit"]::-moz-focus-inner {
- border-style: none;
- padding: 0;
-}
-/**
- * Restore the focus styles unset by the previous rule.
- */
-
-button:-moz-focusring,
-[type="button"]:-moz-focusring,
-[type="reset"]:-moz-focusring,
-[type="submit"]:-moz-focusring {
- outline: 1px dotted ButtonText;
-}
-/**
- * Correct the padding in Firefox.
- */
-
-fieldset {
- padding: .35em .75em .625em;
-}
-/**
- * 1. Correct the text wrapping in Edge and IE.
- * 2. Correct the color inheritance from `fieldset` elements in IE.
- * 3. Remove the padding so developers are not caught out when they zero out
- * `fieldset` elements in all browsers.
- */
-
-legend {
- box-sizing: border-box; /* 1 */
- color: inherit; /* 2 */
- display: table; /* 1 */
- max-width: 100%; /* 1 */
- padding: 0; /* 3 */
- white-space: normal; /* 1 */
-}
-/**
- * Add the correct vertical alignment in Chrome, Firefox, and Opera.
- */
-
-progress {
- vertical-align: baseline;
-}
-/**
- * Remove the default vertical scrollbar in IE 10+.
- */
-
-textarea {
- overflow: auto;
-}
-/**
- * 1. Add the correct box sizing in IE 10.
- * 2. Remove the padding in IE 10.
- */
-
-[type="checkbox"],
-[type="radio"] {
- box-sizing: border-box; /* 1 */
- padding: 0; /* 2 */
-}
-/**
- * Correct the cursor style of increment and decrement buttons in Chrome.
- */
-
-[type="number"]::-webkit-inner-spin-button,
-[type="number"]::-webkit-outer-spin-button {
- height: auto;
-}
-/**
- * 1. Correct the odd appearance in Chrome and Safari.
- * 2. Correct the outline style in Safari.
- */
-
-[type="search"] {
- -webkit-appearance: textfield; /* 1 */
- outline-offset: -2px; /* 2 */
-}
-/**
- * Remove the inner padding in Chrome and Safari on macOS.
- */
-
-[type="search"]::-webkit-search-decoration {
- -webkit-appearance: none;
-}
-/**
- * 1. Correct the inability to style clickable types in iOS and Safari.
- * 2. Change font properties to `inherit` in Safari.
- */
-
-::-webkit-file-upload-button {
- -webkit-appearance: button; /* 1 */
- font: inherit; /* 2 */
-}
-/* Interactive
- ========================================================================== */
-/*
- * Add the correct display in Edge, IE 10+, and Firefox.
- */
-
-details {
- display: block;
-}
-/*
- * Add the correct display in all browsers.
- */
-
-summary {
- display: list-item;
-}
-/* Misc
- ========================================================================== */
-/**
- * Add the correct display in IE 10+.
- */
-
-template {
- display: none;
-}
-/**
- * Add the correct display in IE 10.
- */
-
-[hidden] {
- display: none;
-}
diff --git a/dolphinscheduler-ui/src/sass/common/index.scss b/dolphinscheduler-ui/src/sass/common/index.scss
index a957e71f44..403f3c6980 100644
--- a/dolphinscheduler-ui/src/sass/common/index.scss
+++ b/dolphinscheduler-ui/src/sass/common/index.scss
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-@import "normalize";
@import "mixin";
@import "animation";
@import "scrollbar";
From 5edc2af3119909f26350301a4de7f857f2066017 Mon Sep 17 00:00:00 2001
From: xingchun-chen <55787491+xingchun-chen@users.noreply.github.com>
Date: Wed, 25 Mar 2020 22:27:41 +0800
Subject: [PATCH 2/9] e2e add project and workflow case (#2309)
* add LoginTest license
* Delete useless packages
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
* e2e add project and workflow case
Co-authored-by: chenxingchun <438044805@qq.com>
---
.../constant/TestConstant.java | 8 ++--
.../dolphinscheduler/util/RedisUtil.java | 4 +-
.../dolphinscheduler/base/BaseDriver.java | 16 +++----
.../common/BrowserCommon.java | 34 ++++++++++----
.../data/project/CreatWorkflowData.java | 46 -------------------
.../data/project/CreateProjectData.java | 2 +-
.../data/project/CreateWorkflowData.java | 8 +++-
.../data/security/TenantManageData.java | 8 ++--
.../data/security/UserManageData.java | 2 +-
.../locator/project/CreateProjectLocator.java | 15 +++++-
.../project/CreateWorkflowLocator.java | 11 +++++
.../locator/security/TenantManageLocator.java | 2 +
.../dolphinscheduler/page/LoginPage.java | 3 --
.../page/project/CreateProjectPage.java | 33 +++++++++----
.../page/project/CreateWorkflowPage.java | 41 ++++++++++-------
.../page/security/TenantManagePage.java | 28 +++++------
.../page/security/UserManagePage.java | 6 +--
.../dolphinscheduler/testcase/LoginTest.java | 1 -
.../deleteData/DeleteProjectTest.java | 39 ++++++++++++++++
.../testcase/deleteData/DeleteTenantTest.java | 7 +--
.../testcase/deleteData/DeleteUserTest.java | 8 +++-
.../deleteData/DeleteWorkflowTest.java | 43 +++++++++++++++++
.../testcase/project/CreateProjectTest.java | 3 +-
.../testcase/project/CreateWorkflowTest.java | 6 ++-
.../testcase/security/TenantManageTest.java | 5 +-
.../testcase/security/UserManageTest.java | 2 +-
e2e/testng.xml | 10 ++--
27 files changed, 247 insertions(+), 144 deletions(-)
delete mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreatWorkflowData.java
create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteProjectTest.java
create mode 100644 e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteWorkflowTest.java
diff --git a/e2e/src/main/java/org/apache/dolphinscheduler/constant/TestConstant.java b/e2e/src/main/java/org/apache/dolphinscheduler/constant/TestConstant.java
index 8a3b8eb6b3..2cc78d58a4 100644
--- a/e2e/src/main/java/org/apache/dolphinscheduler/constant/TestConstant.java
+++ b/e2e/src/main/java/org/apache/dolphinscheduler/constant/TestConstant.java
@@ -20,18 +20,16 @@ public class TestConstant {
/**
* 1000
*/
- public static final int ONE_THOUSANG = 1000;
-
-
+ public static final int ONE_THOUSAND = 1000;
/**
* 3000
*/
- public static final int THREE_THOUSANG = 3000;
+ public static final int THREE_THOUSAND = 3000;
/**
* 10000
*/
- public static final int TEN_THOUSANG = 10000;
+ public static final int TEN_THOUSAND = 10000;
}
diff --git a/e2e/src/main/java/org/apache/dolphinscheduler/util/RedisUtil.java b/e2e/src/main/java/org/apache/dolphinscheduler/util/RedisUtil.java
index 7f9340f0ca..14261a5505 100644
--- a/e2e/src/main/java/org/apache/dolphinscheduler/util/RedisUtil.java
+++ b/e2e/src/main/java/org/apache/dolphinscheduler/util/RedisUtil.java
@@ -115,9 +115,9 @@ public class RedisUtil {
try {
System.out.println("redis init");
if (redisPwd.isEmpty())
- jedisPool = new JedisPool(jedisPoolConfig, redisIp, redisPort, TestConstant.THREE_THOUSANG);
+ jedisPool = new JedisPool(jedisPoolConfig, redisIp, redisPort, TestConstant.THREE_THOUSAND);
else {
- jedisPool = new JedisPool(jedisPoolConfig, redisIp, redisPort, TestConstant.TEN_THOUSANG, redisPwd);
+ jedisPool = new JedisPool(jedisPoolConfig, redisIp, redisPort, TestConstant.TEN_THOUSAND, redisPwd);
}
} catch (Exception e) {
e.printStackTrace();
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/base/BaseDriver.java b/e2e/src/test/java/org/apache/dolphinscheduler/base/BaseDriver.java
index 044e28f082..23c98b4e46 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/base/BaseDriver.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/base/BaseDriver.java
@@ -19,14 +19,14 @@ package org.apache.dolphinscheduler.base;
import org.apache.dolphinscheduler.constant.TestConstant;
import org.apache.dolphinscheduler.util.PropertiesReader;
-import org.openqa.selenium.Cookie;
-import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.remote.CapabilityType;
+
import java.io.IOException;
import java.util.concurrent.TimeUnit;
-import org.openqa.selenium.PageLoadStrategy;
/**
@@ -83,6 +83,7 @@ public class BaseDriver {
* start chrome browser
*/
public void startBrowser() throws Exception {
+ System.out.println("===================test start===================");
// set chrome driver
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions chromeOptions = new ChromeOptions();
@@ -104,9 +105,6 @@ public class BaseDriver {
// page load timeout
driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
- // page load timeout
- driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
-
// script timeout
driver.manage().timeouts().setScriptTimeout(setScriptTimeout, TimeUnit.SECONDS);
@@ -141,12 +139,10 @@ public class BaseDriver {
* close browser
*/
public void closeBrowser() throws InterruptedException {
- // JS Show a pop-up box to indicate the end of the test
- Thread.sleep(TestConstant.ONE_THOUSANG);
-// ((JavascriptExecutor) driver).executeScript("alert('Test completed, browser closes after 3s')");
- Thread.sleep(TestConstant.THREE_THOUSANG);
+ Thread.sleep(TestConstant.THREE_THOUSAND);
if (driver != null) {
driver.quit();
+ System.out.println("===================test end===================");
}
}
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/common/BrowserCommon.java b/e2e/src/test/java/org/apache/dolphinscheduler/common/BrowserCommon.java
index 072ccb652e..5ad085a137 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/common/BrowserCommon.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/common/BrowserCommon.java
@@ -126,6 +126,18 @@ public class BrowserCommon {
return buttonElement;
}
+ /**
+ * Click Navigation Bar element
+ * @param locator By
+ * @return clickButton
+ */
+ public void clickTopElement(By locator) {
+ WebElement element = driver.findElement(locator);
+ JavascriptExecutor executor = (JavascriptExecutor)driver;
+ executor.executeScript("arguments[0].click();", element);
+ }
+
+
/**
* Click element
*
@@ -138,6 +150,7 @@ public class BrowserCommon {
return clickElement;
}
+
/**
* input element
*
@@ -236,12 +249,16 @@ public class BrowserCommon {
return driver;
}
- /**
- * Multi-window switch handle, according to the handle number passed in
- *
- * @param num Number starts from 1
- * @return driver
- */
+
+
+
+
+ /**
+ * Multi-window switch handle, according to the handle number passed in
+ *
+ * @param num Number starts from 1
+ * @return driver
+ */
public WebDriver switchHandle(int num) {
// current handle
String currentHandle = driver.getWindowHandle();
@@ -314,9 +331,8 @@ public class BrowserCommon {
executeScript("window.scrollTo(0, document.body.scrollHeight)");
}
- public void scrollToElementBottom() {
-
- WebElement webElement = driver.findElement(By.xpath("/html/body/div[4]/div/div[2]/div/div[2]/div/div[7]/div[3]"));
+ public void scrollToElementBottom(By locator) {
+ WebElement webElement = locateElement(locator);
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", webElement);
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreatWorkflowData.java b/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreatWorkflowData.java
deleted file mode 100644
index 70f4238610..0000000000
--- a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreatWorkflowData.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 org.apache.dolphinscheduler.data.project;
-
-public class CreatWorkflowData {
- //input shell task name
- public static final String SHELL_TASK_NAME = "shell task description test1";
-
- //input shell task description
- public static final String SHELL_TASK_DESCRIPTION = "shell task description test";
-
- //input timeout
- public static final String INPUT_TIMEOUT = "60";
-
- //input shell script
- public static final String SHELL_SCRIPT = "echo 1111111";
-
- //input custom parameters
- public static final String INPUT_CUSTOM_PARAMETERS = "selenium_parameter";
-
- //input custom parameters value
- public static final String INPUT_CUSTOM_PARAMETERS_VALUE = "selenium_parameter_123";
-
- //input add custom parameters
- public static final String INPUT_ADD_CUSTOM_PARAMETERS = "selenium_parameter_delete";
-
- //input add custom parameters value
- public static final String INPUT_ADD_CUSTOM_PARAMETERS_VALUE = "selenium_parameter_delete_456";
-
- //create workflow title
- public static final String WORKFLOW_TITLE = "创建流程定义 - DolphinScheduler";
-}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateProjectData.java b/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateProjectData.java
index 57d79e87d7..004004c54f 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateProjectData.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateProjectData.java
@@ -18,7 +18,7 @@ package org.apache.dolphinscheduler.data.project;
public class CreateProjectData {
// create project name
- public static final String PROJECT_NAME = "selenium_project_3";
+ public static final String PROJECT_NAME = "selenium_project_1";
// create project description
public static final String DESCRIPTION = "test create project description";
// project page title
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateWorkflowData.java b/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateWorkflowData.java
index 31b5bdd1e0..0ec5f05834 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateWorkflowData.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/data/project/CreateWorkflowData.java
@@ -21,7 +21,7 @@ public class CreateWorkflowData {
* create workflow data
*/
//input shell task name
- public static final String SHELL_TASK_NAME = "shell_task_selenium_5";
+ public static final String SHELL_TASK_NAME = "shell_task_selenium_1";
//input shell task description
public static final String SHELL_TASK_DESCRIPTION = "shell task description test";
@@ -44,8 +44,12 @@ public class CreateWorkflowData {
//input add custom parameters value
public static final String INPUT_ADD_CUSTOM_PARAMETERS_VALUE = "selenium_parameter_delete_456";
+ //workflow define title
+ public static final String WORKFLOW_TITLE = "工作流定义 - DolphinScheduler";
+
//create workflow title
- public static final String WORKFLOW_TITLE = "创建流程定义 - DolphinScheduler";
+ public static final String CREATE_WORKFLOW_TITLE = "创建流程定义 - DolphinScheduler";
+
/**
* save workflow data
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/data/security/TenantManageData.java b/e2e/src/test/java/org/apache/dolphinscheduler/data/security/TenantManageData.java
index 100351b600..71e50e7150 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/data/security/TenantManageData.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/data/security/TenantManageData.java
@@ -25,12 +25,12 @@ public class TenantManageData {
/**
* Tenant Code
*/
- public static final String TENANAT_CODE = "dolphinscheduler_tenant_code15";
+ public static final String TENANT_CODE = "selenium_tenant_code_1";
/**
* Tenant Name
*/
- public static final String TENANAT_NAME = "dolphinscheduler_tenant_Name";
+ public static final String TENANT_NAME = "selenium_tenant_Name";
/**
* Queue
@@ -40,9 +40,9 @@ public class TenantManageData {
/**
* Description
*/
- public static final String DESCRIPTION = "creat tenant test";
+ public static final String DESCRIPTION = "create tenant test";
- public static final String TENANAT_MANAGE = "租户管理 - DolphinScheduler";
+ public static final String TENANT_MANAGE = "租户管理 - DolphinScheduler";
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/data/security/UserManageData.java b/e2e/src/test/java/org/apache/dolphinscheduler/data/security/UserManageData.java
index 6fcd923c53..080172d297 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/data/security/UserManageData.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/data/security/UserManageData.java
@@ -18,7 +18,7 @@ package org.apache.dolphinscheduler.data.security;
public class UserManageData {
- public static final String USERNAME = "selenium_5";
+ public static final String USERNAME = "selenium_user_1";
public static final String PASSWORD = "123456qwe";
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateProjectLocator.java b/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateProjectLocator.java
index d2c0d8412c..3d96f24288 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateProjectLocator.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateProjectLocator.java
@@ -20,10 +20,15 @@ import org.openqa.selenium.By;
public class CreateProjectLocator {
//click project manage
- public static final By PROJECT_MANAGE = By.xpath("//div[2]/div/a/span");
+// public static final By PROJECT_MANAGE = By.xpath("//div[@class='clearfix list'][2]");
+ public static final By PROJECT_MANAGE = By.xpath("//div[2]/div[2]/div/a/span");
+
+ // public static final By SECURITY_MANAGE = By.xpath("//div[@class='m-top']/div/div[2]/dev[@class='clearfix list'][6]");
+ public static final By SECURITY_MANAGE = By.xpath("//div[2]/div[6]/div/a/span");
+
//click create project button
- public static final By CREATE_PROJECT_BUTTON = By.xpath("//button/span");
+ public static final By CREATE_PROJECT_BUTTON = By.xpath("//div[2]/div/div[1]/button/span");
//input project name
public static final By PROJECT_NAME = By.xpath("//div[2]/div/div/div[2]/div/input");
@@ -33,4 +38,10 @@ public class CreateProjectLocator {
//submit button
public static final By SUBMIT_BUTTON = By.xpath("//div[3]/button[2]/span");
+
+ //delete project button
+ public static final By DELETE_PROJECT_BUTTON = By.xpath("//div[3]/div[1]/div/table/tr[2]/td[9]/span/button");
+
+ //confirm delete project button
+ public static final By CONFIRM_DELETE_PROJECT_BUTTON = By.xpath("//div[2]/div/button[2]/span");
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateWorkflowLocator.java b/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateWorkflowLocator.java
index 25defcf53f..496bbc4863 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateWorkflowLocator.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/locator/project/CreateWorkflowLocator.java
@@ -169,4 +169,15 @@ public class CreateWorkflowLocator {
//click add button
public static final By CLICK_ADD_BUTTON = By.xpath("//button[2]/span");
+ //scroll to element bottom
+ public static final By SCROLL_BOTTOM = By.xpath("//span/a/em");
+
+ /**
+ * delete workflow
+ */
+ //click delete workflow button
+ public static final By DELETE_WORKFLOW_BOTTOM = By.xpath("//span/button/i");
+
+ //click confirm delete workflow button
+ public static final By CONFIRM_DELETE_WORKFLOW_BOTTOM = By.xpath("//div[2]/div/button[2]/span");
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java b/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java
index d95265cf0b..7db883615c 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/locator/security/TenantManageLocator.java
@@ -19,6 +19,8 @@ package org.apache.dolphinscheduler.locator.security;
import org.openqa.selenium.By;
public class TenantManageLocator{
+ public static final By SECURITY_CENTER = By.xpath("//div[2]/div[6]/div/a/span/em");
+
public static final By TENANT_MANAGE = By.xpath("//div[2]/div/a/div/a/span");
public static final By CREATE_TENANT_BUTTON = By.xpath("//button/span");
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/page/LoginPage.java b/e2e/src/test/java/org/apache/dolphinscheduler/page/LoginPage.java
index 14970bead5..39bd152d0a 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/page/LoginPage.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/page/LoginPage.java
@@ -17,10 +17,8 @@
package org.apache.dolphinscheduler.page;
import org.apache.dolphinscheduler.common.PageCommon;
-import org.apache.dolphinscheduler.constant.TestConstant;
import org.apache.dolphinscheduler.data.LoginData;
import org.apache.dolphinscheduler.locator.LoginLocator;
-import org.apache.dolphinscheduler.util.RedisUtil;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
@@ -49,7 +47,6 @@ public class LoginPage extends PageCommon {
public void jumpPageChinese() {
super.jumpPage(LoginData.URL);
Cookie cookie = new Cookie("language", "zh_CN", "/", null);
-
driver.manage().addCookie(cookie);
}
/**
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateProjectPage.java b/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateProjectPage.java
index d8e1ef655d..52bfcc661d 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateProjectPage.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateProjectPage.java
@@ -28,23 +28,22 @@ public class CreateProjectPage extends PageCommon {
}
/**
- * jump page
+ * jump to ProjectManagePage
*/
- public void jumpProjectManagePage() throws InterruptedException {
- Thread.sleep(TestConstant.ONE_THOUSANG);
- clickElement(CreateProjectLocator.PROJECT_MANAGE);
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ public boolean jumpProjectManagePage() throws InterruptedException {
+ Thread.sleep(TestConstant.THREE_THOUSAND);
+ clickTopElement(CreateProjectLocator.PROJECT_MANAGE);
+ Thread.sleep(TestConstant.ONE_THOUSAND);
+ return ifTitleContains(CreateProjectData.PROJECT_TITLE);
}
/**
- * createTenant
+ * create project
*
- * @return Whether to enter the specified page after creat tenant
+ * @return Whether to enter the specified page after create project
*/
public boolean createProject() throws InterruptedException {
- //click create project
clickElement(CreateProjectLocator.CREATE_PROJECT_BUTTON);
- Thread.sleep(TestConstant.ONE_THOUSANG);
// input create project data
sendInput(CreateProjectLocator.PROJECT_NAME, CreateProjectData.PROJECT_NAME);
@@ -56,4 +55,20 @@ public class CreateProjectPage extends PageCommon {
// Whether to enter the specified page after submit
return ifTitleContains(CreateProjectData.PROJECT_TITLE);
}
+
+ /**
+ * delete project
+ *
+ * @return Whether to enter the specified page after delete project
+ */
+ public boolean deleteProject() throws InterruptedException {
+ //click delete project
+ clickElement(CreateProjectLocator.DELETE_PROJECT_BUTTON);
+
+ //click confirm delete project
+ clickElement(CreateProjectLocator.CONFIRM_DELETE_PROJECT_BUTTON);
+
+ // Whether to enter the specified page after submit
+ return ifTitleContains(CreateProjectData.PROJECT_TITLE);
+ }
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateWorkflowPage.java b/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateWorkflowPage.java
index d115124d8f..a529e76f44 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateWorkflowPage.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/page/project/CreateWorkflowPage.java
@@ -30,22 +30,23 @@ public class CreateWorkflowPage extends PageCommon {
/**
* jump create workflow page
*/
- public boolean createWorkflow() throws InterruptedException {
- System.out.println("Click on the project name to jump to the project homepage");
+
+ public boolean jumpWorkflowPage() throws InterruptedException {
// click project name
clickElement(CreateWorkflowLocator.CLICK_PROJECT_NAME);
- Thread.sleep(TestConstant.ONE_THOUSANG);
-
+ Thread.sleep(TestConstant.ONE_THOUSAND);
- System.out.println("Click on workflow define");
+ System.out.println("Click on workflow define to jump to workflow define page");
// click workflow define
clickElement(CreateWorkflowLocator.CLICK_WORKFLOW_DEFINE);
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ return ifTitleContains(CreateWorkflowData.WORKFLOW_TITLE);
+ }
+
+ public boolean createWorkflow() throws InterruptedException {
System.out.println("Click create workflow button");
// click create workflow button
clickElement(CreateWorkflowLocator.CLICK_CREATE_WORKFLOW_BUTTON);
- Thread.sleep(TestConstant.ONE_THOUSANG);
System.out.println("drag shell task");
//drag shell_task
@@ -98,8 +99,7 @@ public class CreateWorkflowPage extends PageCommon {
//click codeMirror and input script
inputCodeMirror(CreateWorkflowLocator.CLICK_CODE_MIRROR, CreateWorkflowLocator.INPUT_SCRIPT, CreateWorkflowData.SHELL_SCRIPT);
- scrollToElementBottom();
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ scrollToElementBottom(CreateWorkflowLocator.SCROLL_BOTTOM);
//click custom parameters
clickElement(CreateWorkflowLocator.CLICK_CUSTOM_PARAMETERS);
@@ -113,8 +113,7 @@ public class CreateWorkflowPage extends PageCommon {
//click add custom parameters
clickElement(CreateWorkflowLocator.CLICK_ADD_CUSTOM_PARAMETERS);
- scrollToElementBottom();
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ scrollToElementBottom(CreateWorkflowLocator.SCROLL_BOTTOM);
//input add custom parameters
sendInput(CreateWorkflowLocator.INPUT_ADD_CUSTOM_PARAMETERS, CreateWorkflowData.INPUT_ADD_CUSTOM_PARAMETERS);
@@ -124,16 +123,15 @@ public class CreateWorkflowPage extends PageCommon {
//click delete custom parameters
clickElement(CreateWorkflowLocator.CLICK_DELETE_CUSTOM_PARAMETERS);
- Thread.sleep(TestConstant.ONE_THOUSANG);
//click submit button
clickElement(CreateWorkflowLocator.CLICK_SUBMIT_BUTTON);
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ Thread.sleep(TestConstant.ONE_THOUSAND);
System.out.println("Task node set up successfully");
System.out.println("move to Dag Element ");
moveToDragElement(CreateWorkflowLocator.MOUSE_MOVE_SHELL_AT_DAG,-300,-100);
- return ifTitleContains(CreateWorkflowData.WORKFLOW_TITLE);
+ return ifTitleContains(CreateWorkflowData.CREATE_WORKFLOW_TITLE);
}
/**
@@ -182,11 +180,22 @@ public class CreateWorkflowPage extends PageCommon {
//delete workflow global parameters value
clickElement(CreateWorkflowLocator.CLICK_DELETE_WORKFLOW_GLOBAL_PARAMETERS);
- Thread.sleep(TestConstant.ONE_THOUSANG);
+ Thread.sleep(TestConstant.ONE_THOUSAND);
//click add button
- clickElement(CreateWorkflowLocator.CLICK_ADD_BUTTON);
+ clickButton(CreateWorkflowLocator.CLICK_ADD_BUTTON);
System.out.println("submit workflow");
+ return ifTitleContains(CreateWorkflowData.CREATE_WORKFLOW_TITLE);
+ }
+
+ public boolean deleteWorkflow() throws InterruptedException {
+ //click delete project
+ clickButton(CreateWorkflowLocator.DELETE_WORKFLOW_BOTTOM);
+
+ //click confirm delete project
+ clickButton(CreateWorkflowLocator.CONFIRM_DELETE_WORKFLOW_BOTTOM);
+
+ // Whether to enter the specified page after submit
return ifTitleContains(CreateWorkflowData.WORKFLOW_TITLE);
}
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/page/security/TenantManagePage.java b/e2e/src/test/java/org/apache/dolphinscheduler/page/security/TenantManagePage.java
index 618e1bc213..085bfa93a3 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/page/security/TenantManagePage.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/page/security/TenantManagePage.java
@@ -17,12 +17,8 @@
package org.apache.dolphinscheduler.page.security;
import org.apache.dolphinscheduler.common.PageCommon;
-import org.apache.dolphinscheduler.constant.TestConstant;
-import org.apache.dolphinscheduler.data.LoginData;
import org.apache.dolphinscheduler.data.security.TenantManageData;
-import org.apache.dolphinscheduler.locator.LoginLocator;
import org.apache.dolphinscheduler.locator.security.TenantManageLocator;
-import org.apache.dolphinscheduler.util.RedisUtil;
import org.openqa.selenium.WebDriver;
public class TenantManagePage extends PageCommon {
@@ -34,21 +30,30 @@ public class TenantManagePage extends PageCommon {
super(driver);
}
+ /**
+ * jump security page
+ *
+ * @return Whether to enter the specified page after create tenant
+ */
+ public boolean jumpSecurity() throws InterruptedException {
+ clickTopElement(TenantManageLocator.SECURITY_CENTER);
+ return ifTitleContains(TenantManageData.TENANT_MANAGE);
+ }
+
/**
* createTenant
*
- * @return Whether to enter the specified page after creat tenant
+ * @return Whether to enter the specified page after create tenant
*/
public boolean createTenant() throws InterruptedException {
- Thread.sleep(TestConstant.ONE_THOUSANG);
clickButton(TenantManageLocator.TENANT_MANAGE);
//create tenant
clickButton(TenantManageLocator.CREATE_TENANT_BUTTON);
// tenant data
- sendInput(TenantManageLocator.TENANT_INPUT_CODE, TenantManageData.TENANAT_CODE);
- sendInput(TenantManageLocator.TENANT_INPUT_NAME, TenantManageData.TENANAT_NAME);
+ sendInput(TenantManageLocator.TENANT_INPUT_CODE, TenantManageData.TENANT_CODE);
+ sendInput(TenantManageLocator.TENANT_INPUT_NAME, TenantManageData.TENANT_NAME);
sendInput(TenantManageLocator.QUEUE, TenantManageData.QUEUE);
sendInput(TenantManageLocator.DESCRIPTION, TenantManageData.DESCRIPTION);
@@ -56,22 +61,19 @@ public class TenantManagePage extends PageCommon {
clickButton(TenantManageLocator.SUBMIT_BUTTON);
// Whether to enter the specified page after submit
- return ifTitleContains(TenantManageData.TENANAT_MANAGE);
+ return ifTitleContains(TenantManageData.TENANT_MANAGE);
}
public boolean deleteTenant() throws InterruptedException {
- Thread.sleep(TestConstant.ONE_THOUSANG);
clickButton(TenantManageLocator.TENANT_MANAGE);
- Thread.sleep(TestConstant.ONE_THOUSANG);
// click delete button
clickButton(TenantManageLocator.DELETE_TENANT_BUTTON);
- Thread.sleep(TestConstant.ONE_THOUSANG);
//click confirm delete button
clickButton(TenantManageLocator.CONFIRM_DELETE_TENANT_BUTTON);
// Whether to enter the specified page after submit
- return ifTitleContains(TenantManageData.TENANAT_MANAGE);
+ return ifTitleContains(TenantManageData.TENANT_MANAGE);
}
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/page/security/UserManagePage.java b/e2e/src/test/java/org/apache/dolphinscheduler/page/security/UserManagePage.java
index 70311f129e..21dd4ca294 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/page/security/UserManagePage.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/page/security/UserManagePage.java
@@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.page.security;
import org.apache.dolphinscheduler.common.PageCommon;
-import org.apache.dolphinscheduler.constant.TestConstant;
import org.apache.dolphinscheduler.data.security.UserManageData;
import org.apache.dolphinscheduler.locator.security.UserManageLocator;
import org.openqa.selenium.WebDriver;
@@ -33,10 +32,8 @@ public class UserManagePage extends PageCommon {
* @return Whether to enter the specified page after creat tenant
*/
public boolean createUser() throws InterruptedException {
- Thread.sleep(TestConstant.ONE_THOUSANG);
// click user manage
clickElement(UserManageLocator.CLICK_USER_MANAGE);
- Thread.sleep(TestConstant.ONE_THOUSANG);
// click create user button
clickButton(UserManageLocator.CLICK_CREATE_USER_BUTTON);
@@ -59,10 +56,9 @@ public class UserManagePage extends PageCommon {
}
public boolean deleteUser() throws InterruptedException {
- Thread.sleep(TestConstant.ONE_THOUSANG);
+
// click user manage
clickElement(UserManageLocator.CLICK_USER_MANAGE);
- Thread.sleep(TestConstant.ONE_THOUSANG);
// click delete user button
clickButton(UserManageLocator.DELETE_USER_BUTTON );
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/LoginTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/LoginTest.java
index 024ffcdc8a..d1af921077 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/LoginTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/LoginTest.java
@@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.testcase;
import org.apache.dolphinscheduler.page.LoginPage;
-import org.testng.Assert;
import org.testng.annotations.Test;
import static org.apache.dolphinscheduler.base.BaseTest.driver;
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteProjectTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteProjectTest.java
new file mode 100644
index 0000000000..dc45b6e573
--- /dev/null
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteProjectTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.dolphinscheduler.testcase.deleteData;
+
+import org.apache.dolphinscheduler.base.BaseTest;
+import org.apache.dolphinscheduler.page.project.CreateProjectPage;
+import org.testng.annotations.Test;
+
+public class DeleteProjectTest extends BaseTest {
+ private CreateProjectPage createProjectPage;
+
+ @Test(groups={"functionTests"},dependsOnGroups = { "login","project"},description = "DeleteProjectTest",priority=7)
+ public void testDeleteProject() throws InterruptedException {
+ createProjectPage = new CreateProjectPage(driver);
+ //jump to project manage page
+ System.out.println("jump to the project manage page to delete project");
+ createProjectPage.jumpProjectManagePage();
+
+ //assert tenant manage page
+ System.out.println("start delete project");
+ assert createProjectPage.deleteProject();
+ System.out.println("end delete project");
+ System.out.println("===================================");
+ }
+}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteTenantTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteTenantTest.java
index ddbc9d603b..067bc4a973 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteTenantTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteTenantTest.java
@@ -23,15 +23,16 @@ import org.testng.annotations.Test;
public class DeleteTenantTest extends BaseTest {
private TenantManagePage tenantManagePage;
- @Test(groups={"functionTests"},dependsOnGroups = { "login","createTenant"},description = "DeleteTenantTest")
+ @Test(groups={"functionTests"},dependsOnGroups = { "login","createTenant"},description = "DeleteTenantTest",priority=9)
public void testDeleteTenant() throws InterruptedException {
tenantManagePage = new TenantManagePage(driver);
//assert tenant manage page
+ System.out.println("jump to security to delete tenant");
+ tenantManagePage.jumpSecurity();
+
System.out.println("start delete tenant");
assert tenantManagePage.deleteTenant();
System.out.println("end delete tenant");
System.out.println("===================================");
}
-
-
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteUserTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteUserTest.java
index 770fae077d..4507192217 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteUserTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteUserTest.java
@@ -17,14 +17,20 @@
package org.apache.dolphinscheduler.testcase.deleteData;
import org.apache.dolphinscheduler.base.BaseTest;
+import org.apache.dolphinscheduler.page.security.TenantManagePage;
import org.apache.dolphinscheduler.page.security.UserManagePage;
import org.testng.annotations.Test;
public class DeleteUserTest extends BaseTest {
private UserManagePage userManagePage;
+ private TenantManagePage tenantManagePage;
- @Test(groups={"functionTests"},dependsOnGroups = { "login","user" },description = "DeleteUserTest")
+ @Test(groups={"functionTests"},dependsOnGroups = { "login","user" },description = "DeleteUserTest",priority=8)
public void testDeleteUser() throws InterruptedException {
+ tenantManagePage = new TenantManagePage(driver);
+ System.out.println("jump to security to delete user");
+ tenantManagePage.jumpSecurity();
+
userManagePage = new UserManagePage(driver);
//assert user manage page
System.out.println("start delete user");
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteWorkflowTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteWorkflowTest.java
new file mode 100644
index 0000000000..48eb0912fe
--- /dev/null
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/deleteData/DeleteWorkflowTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.dolphinscheduler.testcase.deleteData;
+
+import org.apache.dolphinscheduler.base.BaseTest;
+import org.apache.dolphinscheduler.page.project.CreateProjectPage;
+import org.apache.dolphinscheduler.page.project.CreateWorkflowPage;
+import org.testng.annotations.Test;
+
+public class DeleteWorkflowTest extends BaseTest {
+ private CreateWorkflowPage createWorkflowPage;
+ private CreateProjectPage createProjectPage;
+
+ @Test(groups={"functionTests"},dependsOnGroups = { "login","workflow"},description = "DeleteWorkflowTest",priority=6)
+ public void testDeleteWorkflow() throws InterruptedException {
+ createProjectPage = new CreateProjectPage(driver);
+ //jump to project manage page
+ System.out.println("jump to the project manage page to delete workflow");
+ createProjectPage.jumpProjectManagePage();
+
+ createWorkflowPage = new CreateWorkflowPage(driver);
+ createWorkflowPage.jumpWorkflowPage();
+ //assert tenant manage page
+ System.out.println("start delete workflow");
+ assert createWorkflowPage.deleteWorkflow();
+ System.out.println("end delete workflow");
+ System.out.println("===================================");
+ }
+}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateProjectTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateProjectTest.java
index 546792f0d8..8f7594b05c 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateProjectTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateProjectTest.java
@@ -23,10 +23,11 @@ import org.testng.annotations.Test;
public class CreateProjectTest extends BaseTest {
private CreateProjectPage createProjectPage;
- @Test(groups={"functionTests"},dependsOnGroups = { "login" },description = "CreateProjectTest",priority=4)
+ @Test(groups={"functionTests","project"},dependsOnGroups = { "login" },description = "CreateProjectTest",priority=4)
public void testCreateProject() throws InterruptedException {
createProjectPage = new CreateProjectPage(driver);
// enter user manage page
+ System.out.println("jump to the projectManage page to create project ");
createProjectPage.jumpProjectManagePage();
//assert user manage page
System.out.println("start create project");
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateWorkflowTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateWorkflowTest.java
index ea87f48529..61aadf7a17 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateWorkflowTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/project/CreateWorkflowTest.java
@@ -26,12 +26,16 @@ public class CreateWorkflowTest extends BaseTest {
private CreateProjectPage createProjectPage;
- @Test(groups={"functionTests"},dependsOnGroups = { "login" },description = "CreateWorkflowTest",priority=5)
+ @Test(groups={"functionTests","workflow"},dependsOnGroups = { "login" },description = "CreateWorkflowTest",priority=5)
public void testCreateWorkflow() throws InterruptedException {
createProjectPage = new CreateProjectPage(driver);
+ System.out.println("jump to the projectManage page to create workflow");
createProjectPage.jumpProjectManagePage();
createWorkflowPage = new CreateWorkflowPage(driver);
+ System.out.println("Click on the project name to jump to the project homepage");
+ createWorkflowPage.jumpWorkflowPage();
+
System.out.println("start create workflow");
assert createWorkflowPage.createWorkflow();
assert createWorkflowPage.saveWorkflow();
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/TenantManageTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/TenantManageTest.java
index 8b21d3bb61..721af36d06 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/TenantManageTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/TenantManageTest.java
@@ -24,7 +24,7 @@ import org.testng.annotations.Test;
public class TenantManageTest extends BaseTest {
private TenantManagePage tenantManagePage;
- @Test(groups={"functionTests","createTenant"},dependsOnGroups = { "login" },description = "TenantManageTest")
+ @Test(groups={"functionTests","createTenant"},dependsOnGroups = { "login" },description = "TenantManageTest",priority=2)
public void testTenantManage() throws InterruptedException {
tenantManagePage = new TenantManagePage(driver);
//assert tenant manage page
@@ -32,8 +32,5 @@ public class TenantManageTest extends BaseTest {
assert tenantManagePage.createTenant();
System.out.println("end create tenant");
System.out.println("===================================");
-
}
-
-
}
diff --git a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/UserManageTest.java b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/UserManageTest.java
index 9381b68c75..fdcec1a5c6 100644
--- a/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/UserManageTest.java
+++ b/e2e/src/test/java/org/apache/dolphinscheduler/testcase/security/UserManageTest.java
@@ -23,7 +23,7 @@ import org.testng.annotations.Test;
public class UserManageTest extends BaseTest {
private UserManagePage userManagePage;
- @Test(groups={"functionTests","user"},dependsOnGroups = { "login" },description = "UserManageTest")
+ @Test(groups={"functionTests","user"},dependsOnGroups = { "login" },description = "UserManageTest",priority=3)
public void testUserManage() throws InterruptedException {
userManagePage = new UserManagePage(driver);
//assert user manage page
diff --git a/e2e/testng.xml b/e2e/testng.xml
index 539d383a5a..eb4f21e9d8 100644
--- a/e2e/testng.xml
+++ b/e2e/testng.xml
@@ -20,7 +20,7 @@
-
+
@@ -28,10 +28,12 @@
-
-
-
+
+
+
+
+
From a1b8386c8cf94ad9270b2eb8a146e346f94075b1 Mon Sep 17 00:00:00 2001
From: WeiYe <33245094+WeiYe-Jing@users.noreply.github.com>
Date: Thu, 26 Mar 2020 20:03:44 +0800
Subject: [PATCH 3/9] Update test code logger class name (#2303)
---
.../dolphinscheduler/api/controller/LoginControllerTest.java | 2 +-
.../api/controller/TaskRecordControllerTest.java | 2 +-
.../dolphinscheduler/api/controller/UsersControllerTest.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java
index f5a28d01ae..5be7b0711c 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/LoginControllerTest.java
@@ -36,7 +36,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* login controller test
*/
public class LoginControllerTest extends AbstractControllerTest{
- private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class);
+ private static Logger logger = LoggerFactory.getLogger(LoginControllerTest.class);
@Test
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskRecordControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskRecordControllerTest.java
index 943e14607b..ad4a165ca1 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskRecordControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TaskRecordControllerTest.java
@@ -33,7 +33,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class TaskRecordControllerTest extends AbstractControllerTest {
- private static final Logger logger = LoggerFactory.getLogger(TaskInstanceController.class);
+ private static final Logger logger = LoggerFactory.getLogger(TaskRecordControllerTest.class);
@Test
public void testQueryTaskRecordListPaging() throws Exception {
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java
index d1be6cb382..0798151299 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/UsersControllerTest.java
@@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* users controller test
*/
public class UsersControllerTest extends AbstractControllerTest{
- private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class);
+ private static Logger logger = LoggerFactory.getLogger(UsersControllerTest.class);
@Test
public void testCreateUser() throws Exception {
From 42f9385ee4e98eaf7fd0a2c013c179f7718c05f0 Mon Sep 17 00:00:00 2001
From: "gabry.wu"
Date: Thu, 26 Mar 2020 20:04:30 +0800
Subject: [PATCH 4/9] Adapting partial code(file name start with W) to the
sonar cloud rule (#2287)
---
.../api/service/WorkerGroupService.java | 2 +-
.../dao/mapper/WorkerGroupMapperTest.java | 4 ++--
.../server/worker/WorkerServer.java | 18 +++++++-----------
3 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java
index c44c446d5c..7d47a8fb0d 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/WorkerGroupService.java
@@ -111,7 +111,7 @@ public class WorkerGroupService extends BaseService {
List workerGroupList = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName());
- if(workerGroupList.size() > 0 ){
+ if(CollectionUtils.isNotEmpty(workerGroupList)){
// new group has same name..
if(workerGroup.getId() == 0){
return true;
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java
index ea05f1bf11..dfa2a5de8e 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java
@@ -65,7 +65,7 @@ public class WorkerGroupMapperTest {
workerGroup.setName("workerGroup11");
int update = workerGroupMapper.updateById(workerGroup);
workerGroupMapper.deleteById(workerGroup.getId());
- Assert.assertEquals(update, 1);
+ Assert.assertEquals(1, update);
}
/**
@@ -77,7 +77,7 @@ public class WorkerGroupMapperTest {
WorkerGroup workerGroup = insertOne();
//delete
int delete = workerGroupMapper.deleteById(workerGroup.getId());
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java
index 86bb7d3e07..868b80960f 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/WorkerServer.java
@@ -52,7 +52,6 @@ import org.springframework.context.annotation.FilterType;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Set;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -255,7 +254,7 @@ public class WorkerServer implements IStoppable {
*/
private Runnable heartBeatThread(){
logger.info("start worker heart beat thread...");
- Runnable heartBeatThread = new Runnable() {
+ return new Runnable() {
@Override
public void run() {
// send heartbeat to zk
@@ -266,7 +265,6 @@ public class WorkerServer implements IStoppable {
zkWorkerClient.heartBeatForZk(zkWorkerClient.getWorkerZNode() , Constants.WORKER_PREFIX);
}
};
- return heartBeatThread;
}
@@ -276,7 +274,7 @@ public class WorkerServer implements IStoppable {
* @return kill process thread
*/
private Runnable getKillProcessThread(){
- Runnable killProcessThread = new Runnable() {
+ return new Runnable() {
@Override
public void run() {
logger.info("start listening kill process thread...");
@@ -297,7 +295,6 @@ public class WorkerServer implements IStoppable {
}
}
};
- return killProcessThread;
}
/**
@@ -307,17 +304,17 @@ public class WorkerServer implements IStoppable {
* @param pd process dao
*/
private void killTask(String taskInfo, ProcessService pd) {
- logger.info("get one kill command from tasks kill queue: " + taskInfo);
+ logger.info("get one kill command from tasks kill queue: {}" , taskInfo);
String[] taskInfoArray = taskInfo.split("-");
if(taskInfoArray.length != 2){
- logger.error("error format kill info: " + taskInfo);
+ logger.error("error format kill info: {}", taskInfo);
return ;
}
String host = taskInfoArray[0];
int taskInstanceId = Integer.parseInt(taskInfoArray[1]);
TaskInstance taskInstance = pd.getTaskInstanceDetailByTaskId(taskInstanceId);
if(taskInstance == null){
- logger.error("cannot find the kill task :" + taskInfo);
+ logger.error("cannot find the kill task : {}", taskInfo);
return;
}
@@ -332,8 +329,7 @@ public class WorkerServer implements IStoppable {
}else if(!taskInstance.getState().typeIsFinished()){
ProcessUtils.kill(taskInstance);
}else{
- logger.info("the task aleady finish: task id: " + taskInstance.getId()
- + " state: " + taskInstance.getState().toString());
+ logger.info("the task aleady finish: task id: {} state: {}", taskInstance.getId(), taskInstance.getState());
}
}
}
@@ -347,7 +343,7 @@ public class WorkerServer implements IStoppable {
private void deleteTaskFromQueue(TaskInstance taskInstance, ProcessService pd){
// creating distributed locks, lock path /dolphinscheduler/lock/worker
InterProcessMutex mutex = null;
- logger.info("delete task from tasks queue: " + taskInstance.getId());
+ logger.info("delete task from tasks queue: {}", taskInstance.getId());
try {
mutex = zkWorkerClient.acquireZkLock(zkWorkerClient.getZkClient(),
From 74525c28b5f8eb69d4ffb134e41c340fcc102585 Mon Sep 17 00:00:00 2001
From: tswstarplanet
Date: Thu, 26 Mar 2020 20:07:52 +0800
Subject: [PATCH 5/9] Decouple DruidDataSource in ConnectionFactory and cache
DataSource instance (#2232)
* Decouple DruidDataSource in ConnectionFactory and cache DataSource
instance
* init dataSource first
* fix code smell
* add unit test
* add unit test
* add unit test
* add unit test
* fix unit test
* delete useless logger
---
.../apache/dolphinscheduler/dao/AlertDao.java | 8 ++++-
.../dao/datasource/ConnectionFactory.java | 14 +++++---
.../dao/upgrade/UpgradeDao.java | 12 +++----
.../dolphinscheduler/dao/AlertDaoTest.java | 35 +++++++++++++++----
.../dao/mapper/ConnectionFactoryTest.java | 2 +-
5 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java
index 8546f01aad..d61a181564 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java
@@ -169,5 +169,11 @@ public class AlertDao extends AbstractBaseDao {
return userAlertGroupMapper.listUserByAlertgroupId(alertgroupId);
}
-
+ /**
+ * for test
+ * @return
+ */
+ public AlertMapper getAlertMapper() {
+ return alertMapper;
+ }
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java
index 199fed0ce6..51c56fd29e 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ConnectionFactory.java
@@ -51,6 +51,7 @@ public class ConnectionFactory extends SpringConnectionFactory {
private ConnectionFactory() {
try {
+ dataSource = buildDataSource();
sqlSessionFactory = getSqlSessionFactory();
sqlSessionTemplate = getSqlSessionTemplate();
} catch (Exception e) {
@@ -69,12 +70,18 @@ public class ConnectionFactory extends SpringConnectionFactory {
*/
private SqlSessionTemplate sqlSessionTemplate;
+ private DataSource dataSource;
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
/**
* get the data source
*
* @return druid dataSource
*/
- public DruidDataSource getDataSource() {
+ private DataSource buildDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
@@ -112,10 +119,9 @@ public class ConnectionFactory extends SpringConnectionFactory {
* @throws Exception sqlSessionFactory exception
*/
private SqlSessionFactory getSqlSessionFactory() throws Exception {
- DataSource dataSource = getDataSource();
TransactionFactory transactionFactory = new JdbcTransactionFactory();
- Environment environment = new Environment("development", transactionFactory, dataSource);
+ Environment environment = new Environment("development", transactionFactory, getDataSource());
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setEnvironment(environment);
@@ -125,7 +131,7 @@ public class ConnectionFactory extends SpringConnectionFactory {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setConfiguration(configuration);
- sqlSessionFactoryBean.setDataSource(dataSource);
+ sqlSessionFactoryBean.setDataSource(getDataSource());
sqlSessionFactoryBean.setTypeEnumsPackage("org.apache.dolphinscheduler.*.enums");
sqlSessionFactory = sqlSessionFactoryBean.getObject();
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
index 384c3604c4..3552d4e9b3 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
@@ -27,6 +27,7 @@ import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.sql.DataSource;
import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -40,7 +41,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
private static final String T_VERSION_NAME = "t_escheduler_version";
private static final String T_NEW_VERSION_NAME = "t_ds_version";
private static final String rootDir = System.getProperty("user.dir");
- protected static final DruidDataSource dataSource = getDataSource();
+ protected static final DataSource dataSource = getDataSource();
private static final DbType dbType = getCurrentDbType();
@Override
@@ -52,13 +53,8 @@ public abstract class UpgradeDao extends AbstractBaseDao {
* get datasource
* @return DruidDataSource
*/
- public static DruidDataSource getDataSource(){
- DruidDataSource dataSource = ConnectionFactory.getInstance().getDataSource();
- dataSource.setInitialSize(2);
- dataSource.setMinIdle(2);
- dataSource.setMaxActive(2);
-
- return dataSource;
+ public static DataSource getDataSource(){
+ return ConnectionFactory.getInstance().getDataSource();
}
/**
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java
index b4f197adc9..b94162c563 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/AlertDaoTest.java
@@ -16,19 +16,42 @@
*/
package org.apache.dolphinscheduler.dao;
+import org.apache.dolphinscheduler.common.enums.AlertStatus;
+import org.apache.dolphinscheduler.common.enums.AlertType;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.dao.entity.Alert;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class AlertDaoTest {
- private static final Logger logger = LoggerFactory.getLogger(AlertDaoTest.class);
+import java.util.Arrays;
+import java.util.List;
+public class AlertDaoTest {
@Test
- public void testGetAlertDao() {
- logger.info("testGetAlertDao start");
+ public void testAlertDao(){
AlertDao alertDao = DaoFactory.getDaoInstance(AlertDao.class);
- Assert.assertNotNull(alertDao);
- logger.info("testGetAlertDao end");
+ Alert alert = new Alert();
+ alert.setTitle("Mysql Exception");
+ alert.setShowType(ShowType.TEXT);
+ alert.setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", " +
+ "\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]");
+ alert.setAlertType(AlertType.EMAIL);
+ alert.setAlertGroupId(1);
+ alert.setAlertStatus(AlertStatus.WAIT_EXECUTION);
+ alertDao.addAlert(alert);
+
+
+ List alerts = alertDao.listWaitExecutionAlert();
+ Assert.assertNotNull(alerts);
+ Assert.assertNotEquals(0, alerts.size());
+ int id = alerts.get(0).getId();
+ AlertStatus alertStatus = alerts.get(0).getAlertStatus();
+ alertDao.updateAlert(AlertStatus.EXECUTION_SUCCESS, "", id);
+
+ alerts = alertDao.listWaitExecutionAlert();
+ Assert.assertEquals(0, alerts.size());
+ alertDao.getAlertMapper().deleteById(id);
}
}
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ConnectionFactoryTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ConnectionFactoryTest.java
index f4139444f5..1d419a83d8 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ConnectionFactoryTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ConnectionFactoryTest.java
@@ -31,7 +31,7 @@ public class ConnectionFactoryTest {
*/
@Test
public void testConnection()throws Exception{
- Connection connection = ConnectionFactory.getInstance().getDataSource().getPooledConnection().getConnection();
+ Connection connection = ConnectionFactory.getInstance().getDataSource().getConnection();
Assert.assertTrue(connection != null);
}
}
\ No newline at end of file
From d83a94a305c9858c07d0d08b567e4293fb903235 Mon Sep 17 00:00:00 2001
From: "gabry.wu"
Date: Thu, 26 Mar 2020 23:17:28 +0800
Subject: [PATCH 6/9] Adapting partial code(file name start with T) to the
sonar cloud rule (#2271)
---
.../api/dto/TaskCountDto.java | 36 +++++++++----------
.../api/service/TaskInstanceService.java | 4 ---
.../api/service/TaskRecordService.java | 4 ---
.../api/service/TenantService.java | 4 +--
.../common/enums/TaskStateType.java | 2 +-
.../common/model/TaskNode.java | 6 ++--
.../common/thread/ThreadPoolExecutors.java | 36 +++++++++----------
.../placeholder/TimePlaceholderUtils.java | 8 ++---
.../dolphinscheduler/dao/TaskRecordDao.java | 4 +--
.../dao/mapper/TaskInstanceMapperTest.java | 4 +--
.../dao/mapper/TenantMapperTest.java | 4 +--
.../worker/runner/TaskScheduleThread.java | 2 +-
.../service/queue/TaskQueueZkImpl.java | 6 ++--
.../service/queue/TaskQueueZKImplTest.java | 24 ++++++-------
14 files changed, 68 insertions(+), 76 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java
index e7b182076d..6b0391f111 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java
@@ -43,36 +43,36 @@ public class TaskCountDto {
}
private void countTaskDtos(List taskInstanceStateCounts){
- int submitted_success = 0;
- int running_exeution = 0;
- int ready_pause = 0;
+ int submittedSuccess = 0;
+ int runningExeution = 0;
+ int readyPause = 0;
int pause = 0;
- int ready_stop = 0;
+ int readyStop = 0;
int stop = 0;
int failure = 0;
int success = 0;
- int need_fault_tolerance = 0;
+ int needFaultTolerance = 0;
int kill = 0;
- int waitting_thread = 0;
+ int waittingThread = 0;
for(ExecuteStatusCount taskInstanceStateCount : taskInstanceStateCounts){
ExecutionStatus status = taskInstanceStateCount.getExecutionStatus();
totalCount += taskInstanceStateCount.getCount();
switch (status){
case SUBMITTED_SUCCESS:
- submitted_success += taskInstanceStateCount.getCount();
+ submittedSuccess += taskInstanceStateCount.getCount();
break;
case RUNNING_EXEUTION:
- running_exeution += taskInstanceStateCount.getCount();
+ runningExeution += taskInstanceStateCount.getCount();
break;
case READY_PAUSE:
- ready_pause += taskInstanceStateCount.getCount();
+ readyPause += taskInstanceStateCount.getCount();
break;
case PAUSE:
pause += taskInstanceStateCount.getCount();
break;
case READY_STOP:
- ready_stop += taskInstanceStateCount.getCount();
+ readyStop += taskInstanceStateCount.getCount();
break;
case STOP:
stop += taskInstanceStateCount.getCount();
@@ -84,13 +84,13 @@ public class TaskCountDto {
success += taskInstanceStateCount.getCount();
break;
case NEED_FAULT_TOLERANCE:
- need_fault_tolerance += taskInstanceStateCount.getCount();
+ needFaultTolerance += taskInstanceStateCount.getCount();
break;
case KILL:
kill += taskInstanceStateCount.getCount();
break;
case WAITTING_THREAD:
- waitting_thread += taskInstanceStateCount.getCount();
+ waittingThread += taskInstanceStateCount.getCount();
break;
default:
@@ -98,17 +98,17 @@ public class TaskCountDto {
}
}
this.taskCountDtos = new ArrayList<>();
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submitted_success));
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, running_exeution));
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, ready_pause));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submittedSuccess));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, runningExeution));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, readyPause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.PAUSE, pause));
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, ready_stop));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, readyStop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.STOP, stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.FAILURE, failure));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUCCESS, success));
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, need_fault_tolerance));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, needFaultTolerance));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.KILL, kill));
- this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waitting_thread));
+ this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waittingThread));
}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
index e4fec54395..170278e02f 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
@@ -32,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.service.process.ProcessService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -46,8 +44,6 @@ import java.util.*;
@Service
public class TaskInstanceService extends BaseService {
- private static final Logger logger = LoggerFactory.getLogger(TaskInstanceService.class);
-
@Autowired
ProjectMapper projectMapper;
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java
index 54b6a1889c..54eba5c2d6 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java
@@ -21,8 +21,6 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.dao.TaskRecordDao;
import org.apache.dolphinscheduler.dao.entity.TaskRecord;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -37,8 +35,6 @@ import static org.apache.dolphinscheduler.common.Constants.*;
@Service
public class TaskRecordService extends BaseService{
- private static final Logger logger = LoggerFactory.getLogger(TaskRecordService.class);
-
/**
* query task record list paging
*
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
index 12b4656a40..2fded4d32f 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
@@ -310,7 +310,7 @@ public class TenantService extends BaseService{
Map result = new HashMap<>(5);
List resourceList = tenantMapper.queryByTenantCode(tenantCode);
- if (resourceList != null && resourceList.size() > 0) {
+ if (CollectionUtils.isNotEmpty(resourceList)) {
result.put(Constants.DATA_LIST, resourceList);
putMsg(result, Status.SUCCESS);
} else {
@@ -346,6 +346,6 @@ public class TenantService extends BaseService{
*/
private boolean checkTenantExists(String tenantCode) {
List tenants = tenantMapper.queryByTenantCode(tenantCode);
- return (tenants != null && tenants.size() > 0);
+ return CollectionUtils.isNotEmpty(tenants);
}
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java
index 695f0fd880..200f90709a 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java
@@ -60,7 +60,7 @@ public enum TaskStateType {
default:
break;
}
- return null;
+ return new int[0];
}
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
index c0ad907dca..1ed398a693 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
@@ -293,14 +293,14 @@ public class TaskNode {
public TaskTimeoutParameter getTaskTimeoutParameter() {
if(StringUtils.isNotEmpty(this.getTimeout())){
String formatStr = String.format("%s,%s", TaskTimeoutStrategy.WARN.name(), TaskTimeoutStrategy.FAILED.name());
- String timeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
- return JSON.parseObject(timeout,TaskTimeoutParameter.class);
+ String taskTimeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
+ return JSON.parseObject(taskTimeout,TaskTimeoutParameter.class);
}
return new TaskTimeoutParameter(false);
}
public boolean isConditionsTask(){
- return this.getType().toUpperCase().equals(TaskType.CONDITIONS.toString());
+ return TaskType.CONDITIONS.toString().equalsIgnoreCase(this.getType());
}
@Override
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java
index f88ea6d127..2744803f21 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java
@@ -74,21 +74,21 @@ public class ThreadPoolExecutors {
* @param event
*/
public void execute(final Runnable event) {
- Executor executor = getExecutor();
- if (executor == null) {
- logger.error("Cannot execute [" + event + "] because the executor is missing.");
+ Executor eventExecutor = getExecutor();
+ if (eventExecutor == null) {
+ logger.error("Cannot execute [{}}] because the executor is missing.", event);
} else {
- executor.execute(event);
+ eventExecutor.execute(event);
}
}
public Future> submit(Runnable event) {
- Executor executor = getExecutor();
- if (executor == null) {
- logger.error("Cannot submit [" + event + "] because the executor is missing.");
+ Executor eventExecutor = getExecutor();
+ if (eventExecutor == null) {
+ logger.error("Cannot submit [{}}] because the executor is missing.", event);
} else {
- return executor.submit(event);
+ return eventExecutor.submit(event);
}
return null;
@@ -97,11 +97,11 @@ public class ThreadPoolExecutors {
public Future> submit(Callable> task) {
- Executor executor = getExecutor();
- if (executor == null) {
- logger.error("Cannot submit [" + task + "] because the executor is missing.");
+ Executor taskExecutor = getExecutor();
+ if (taskExecutor == null) {
+ logger.error("Cannot submit [{}] because the executor is missing.", task);
} else {
- return executor.submit(task);
+ return taskExecutor.submit(task);
}
return null;
@@ -110,8 +110,8 @@ public class ThreadPoolExecutors {
public void printStatus() {
- Executor executor = getExecutor();
- executor.getStatus().dumpInfo();
+ Executor printExecutor = getExecutor();
+ printExecutor.getStatus().dumpInfo();
}
@@ -125,7 +125,7 @@ public class ThreadPoolExecutors {
List wasRunning = executor.threadPoolExecutor
.shutdownNow();
if (!wasRunning.isEmpty()) {
- logger.info(executor + " had " + wasRunning + " on shutdown");
+ logger.info("{} had {} on shutdown", executor, wasRunning);
}
}
}
@@ -138,7 +138,7 @@ public class ThreadPoolExecutors {
/**
* how long to retain excess threads
*/
- final long keepAliveTimeInMillis = 1000;
+ static final long KEEP_ALIVE_TIME_IN_MILLIS = 1000;
/**
* the thread pool executor that services the requests
*/
@@ -146,7 +146,7 @@ public class ThreadPoolExecutors {
/**
* work queue to use - unbounded queue
*/
- final BlockingQueue q = new LinkedBlockingQueue();
+ final BlockingQueue q = new LinkedBlockingQueue<>();
private final String name;
private static final AtomicLong seqids = new AtomicLong(0);
private final long id;
@@ -156,7 +156,7 @@ public class ThreadPoolExecutors {
this.name = name;
//create the thread pool executor
this.threadPoolExecutor = new TrackingThreadPoolExecutor(
- maxThreads, maxThreads, keepAliveTimeInMillis,
+ maxThreads, maxThreads, KEEP_ALIVE_TIME_IN_MILLIS,
TimeUnit.MILLISECONDS, q);
// name the threads for this threadpool
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
index 15e3282d38..35cb018399 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
@@ -35,12 +35,12 @@ public class TimePlaceholderUtils {
/**
* Prefix of the position to be replaced
*/
- public static final String placeholderPrefix = "$[";
+ public static final String PLACEHOLDER_PREFIX = "$[";
/**
* The suffix of the position to be replaced
*/
- public static final String placeholderSuffix = "]";
+ public static final String PLACEHOLDER_SUFFIX = "]";
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
@@ -66,7 +66,7 @@ public class TimePlaceholderUtils {
* be ignored ({@code true}) or cause an exception ({@code false})
*/
private static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {
- return new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, null, ignoreUnresolvablePlaceholders);
+ return new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, null, ignoreUnresolvablePlaceholders);
}
/**
@@ -503,7 +503,7 @@ public class TimePlaceholderUtils {
* @return calculate need minutes
*/
public static Integer calcMinutes(String minuteExpression) {
- int index = minuteExpression.indexOf("/");
+ int index = minuteExpression.indexOf('/');
String calcExpression;
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
index f89002ebdc..e16890149b 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
@@ -84,9 +84,9 @@ public class TaskRecordDao {
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
- logger.error("Exception ", e);
+ logger.error("Class not found Exception ", e);
} catch (SQLException e) {
- logger.error("Exception ", e);
+ logger.error("SQL Exception ", e);
}
return conn;
}
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
index 51a22b756e..ffd49b4f0d 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
@@ -78,7 +78,7 @@ public class TaskInstanceMapperTest {
TaskInstance taskInstance = insertOne();
//update
int update = taskInstanceMapper.updateById(taskInstance);
- Assert.assertEquals(update, 1);
+ Assert.assertEquals(1, update);
taskInstanceMapper.deleteById(taskInstance.getId());
}
@@ -89,7 +89,7 @@ public class TaskInstanceMapperTest {
public void testDelete(){
TaskInstance taskInstance = insertOne();
int delete = taskInstanceMapper.deleteById(taskInstance.getId());
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java
index f5cb8fca12..dc6a7d1710 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java
@@ -64,7 +64,7 @@ public class TenantMapperTest {
tenant.setUpdateTime(new Date());
//update
int update = tenantMapper.updateById(tenant);
- Assert.assertEquals(update, 1);
+ Assert.assertEquals(1, update);
tenantMapper.deleteById(tenant.getId());
}
@@ -75,7 +75,7 @@ public class TenantMapperTest {
public void testDelete(){
Tenant tenant = insertOne();
int delete = tenantMapper.deleteById(tenant.getId());
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java
index d36d4de5b4..48048e7eba 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java
@@ -230,7 +230,7 @@ public class TaskScheduleThread implements Runnable {
taskInstance.getId() + ".log";
}
}catch (Exception e){
- logger.error("logger" + e);
+ logger.error("logger {}", e.getMessage(), e);
logPath = "";
}
return logPath;
diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java
index 9c1d318ea5..5ac3ece663 100644
--- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java
+++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java
@@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.service.queue;
import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.IpUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.service.zk.ZookeeperOperator;
@@ -67,8 +68,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
@Override
public List getAllTasks(String key) {
try {
- List list = zookeeperOperator.getChildrenKeys(getTasksPath(key));
- return list;
+ return zookeeperOperator.getChildrenKeys(getTasksPath(key));
} catch (Exception e) {
logger.error("get all tasks from tasks queue exception",e);
}
@@ -141,7 +141,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
try{
List list = zookeeperOperator.getChildrenKeys(getTasksPath(key));
- if(list != null && list.size() > 0){
+ if(CollectionUtils.isNotEmpty(list)){
String workerIp = OSUtils.getHost();
String workerIpLongStr = String.valueOf(IpUtils.ipToLong(workerIp));
diff --git a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java
index 5d464ac3c9..a630c494c5 100644
--- a/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java
+++ b/dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java
@@ -58,11 +58,11 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
init();
// get all
List allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
- assertEquals(allTasks.size(),2);
+ assertEquals(2, allTasks.size());
//delete all
tasksQueue.delete();
allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
- assertEquals(allTasks.size(),0);
+ assertEquals(0, allTasks.size());
}
@Test
public void hasTask(){
@@ -126,10 +126,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
//add
init();
List taskList = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 2);
- assertEquals(taskList.size(),2);
+ assertEquals(2, taskList.size());
- assertEquals(taskList.get(0),"0_1_1_1_-1");
- assertEquals(taskList.get(1),"1_0_1_1_-1");
+ assertEquals("0_1_1_1_-1", taskList.get(0));
+ assertEquals("1_0_1_1_-1", taskList.get(1));
}
/**
@@ -153,7 +153,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
+ assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
@@ -166,10 +166,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
+ assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//remove and get size
tasksQueue.srem(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0);
+ assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
/**
@@ -179,17 +179,17 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
public void smembers(){
//first init
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0);
+ assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
+ assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add
task = "0_1_1_1_";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
- assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),2);
+ assertEquals(2, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
@@ -222,7 +222,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
}
String node1 = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 1).get(0);
- assertEquals(node1,"0");
+ assertEquals("0", node1);
}
From efde8fd4e71cf8b17f3f25bbf09395c00e09b1a3 Mon Sep 17 00:00:00 2001
From: t1mon <178317391@qq.com>
Date: Thu, 26 Mar 2020 23:23:19 +0800
Subject: [PATCH 7/9] Refactor BaseDataSource and unified handling of JDBC
resource releases. (#2184)
* Refactor BaseDataSource.isConnectable().
* Add BaseDataSource test.
* Unified handling of JDBC resource releases.
* Fix sonar check error.
* Remove useless logger.
* Refactor BaseDataSource.getJdbcUrl().
* Modify ConnectionUtils.releaseResource().
* Add javadoc
* Remove useless method.
* Add BaseDataSourceTest UT
---
.../common/utils/ConnectionUtils.java | 103 ++++------------
.../dolphinscheduler/dao/MonitorDBDao.java | 10 +-
.../dolphinscheduler/dao/TaskRecordDao.java | 35 +-----
.../dao/datasource/BaseDataSource.java | 109 ++++++++++++++++-
.../dao/datasource/ClickHouseDataSource.java | 47 ++-----
.../dao/datasource/DB2ServerDataSource.java | 46 ++-----
.../dao/datasource/HiveDataSource.java | 51 ++------
.../dao/datasource/MySQLDataSource.java | 44 ++-----
.../dao/datasource/OracleDataSource.java | 47 ++-----
.../dao/datasource/PostgreDataSource.java | 49 ++------
.../dao/datasource/SQLServerDataSource.java | 61 +++-------
.../dao/datasource/SparkDataSource.java | 52 ++------
.../dao/upgrade/MysqlUpgradeDao.java | 4 +-
.../dao/upgrade/PostgresqlUpgradeDao.java | 4 +-
.../dao/upgrade/UpgradeDao.java | 12 +-
.../dao/datasource/BaseDataSourceTest.java | 115 ++++++++++++++++++
.../server/worker/task/sql/SqlTask.java | 22 +---
pom.xml | 1 +
18 files changed, 333 insertions(+), 479 deletions(-)
create mode 100644 dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSourceTest.java
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ConnectionUtils.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ConnectionUtils.java
index c1c3ff5d57..f8ea0e7188 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ConnectionUtils.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ConnectionUtils.java
@@ -16,86 +16,35 @@
*/
package org.apache.dolphinscheduler.common.utils;
+import java.util.Arrays;
+import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.*;
-
public class ConnectionUtils {
- public static final Logger logger = LoggerFactory.getLogger(ConnectionUtils.class);
-
- private static ConnectionUtils instance;
-
- ConnectionUtils() {
- }
-
- public static ConnectionUtils getInstance() {
- if (null == instance) {
- syncInit();
- }
- return instance;
- }
-
- private static synchronized void syncInit() {
- if (instance == null) {
- instance = new ConnectionUtils();
- }
- }
-
- public void release(ResultSet rs, Statement stmt, Connection conn) {
- try {
- if (rs != null) {
- rs.close();
- rs = null;
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- } finally {
- try {
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- } finally {
- try {
- if (conn != null) {
- conn.close();
- conn = null;
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- }
- }
- }
- }
-
- public static void releaseResource(ResultSet rs, PreparedStatement ps, Connection conn) {
- ConnectionUtils.getInstance().release(rs,ps,conn);
- if (null != rs) {
- try {
- rs.close();
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- }
- }
-
- if (null != ps) {
- try {
- ps.close();
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- }
- }
-
- if (null != conn) {
- try {
- conn.close();
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- }
- }
- }
+ public static final Logger logger = LoggerFactory.getLogger(ConnectionUtils.class);
+
+ private ConnectionUtils() {
+ throw new IllegalStateException("ConnectionUtils class");
+ }
+
+ /**
+ * release resource
+ * @param resources resources
+ */
+ public static void releaseResource(AutoCloseable... resources) {
+
+ if (resources == null || resources.length == 0) {
+ return;
+ }
+ Arrays.stream(resources).filter(Objects::nonNull)
+ .forEach(resource -> {
+ try {
+ resource.close();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ });
+ }
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java
index 5ea5966238..53366777f7 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java
@@ -18,10 +18,10 @@ package org.apache.dolphinscheduler.dao;
import com.alibaba.druid.pool.DruidDataSource;
import java.sql.Connection;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.dolphinscheduler.common.enums.DbType;
+import org.apache.dolphinscheduler.common.utils.ConnectionUtils;
import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
import org.apache.dolphinscheduler.dao.utils.MysqlPerformance;
import org.apache.dolphinscheduler.dao.utils.PostgrePerformance;
@@ -63,13 +63,7 @@ public class MonitorDBDao {
}catch (Exception e) {
logger.error("SQLException: {}", e.getMessage(), e);
}finally {
- try {
- if (conn != null) {
- conn.close();
- }
- } catch (SQLException e) {
- logger.error("SQLException ", e);
- }
+ ConnectionUtils.releaseResource(conn);
}
return monitorRecord;
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
index e16890149b..7cf9159e98 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.TaskRecordStatus;
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
+import org.apache.dolphinscheduler.common.utils.ConnectionUtils;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.dao.entity.TaskRecord;
@@ -163,14 +164,14 @@ public class TaskRecordDao {
sql += getWhereString(filterMap);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
- while (rs.next()) {
+ while (rs.next()){
count = rs.getInt("count");
break;
}
} catch (SQLException e) {
logger.error("Exception ", e);
- } finally {
- closeResource(rs, pstmt, conn);
+ }finally {
+ ConnectionUtils.releaseResource(rs, pstmt, conn);
}
return count;
}
@@ -254,8 +255,8 @@ public class TaskRecordDao {
}
} catch (SQLException e) {
logger.error("Exception ", e);
- } finally {
- closeResource(rs, pstmt, conn);
+ }finally {
+ ConnectionUtils.releaseResource(rs, pstmt, conn);
}
return recordList;
}
@@ -292,28 +293,4 @@ public class TaskRecordDao {
}
}
-
- private static void closeResource(ResultSet rs, PreparedStatement pstmt, Connection conn) {
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException e) {
- logger.error("Exception ", e);
- }
- }
- if (pstmt != null) {
- try {
- pstmt.close();
- } catch (SQLException e) {
- logger.error("Exception ", e);
- }
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException e) {
- logger.error("Exception ", e);
- }
- }
- }
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSource.java
index a46e5aabcc..6f95026759 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSource.java
@@ -16,10 +16,21 @@
*/
package org.apache.dolphinscheduler.dao.datasource;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* data source base class
*/
public abstract class BaseDataSource {
+
+ private static final Logger logger = LoggerFactory.getLogger(BaseDataSource.class);
+
/**
* user name
*/
@@ -57,17 +68,105 @@ public abstract class BaseDataSource {
public void setPrincipal(String principal) {
this.principal = principal;
}
+
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return driver class
+ */
+ public abstract String driverClassSelector();
+
+ /**
+ * @return db type
*/
- public abstract void isConnectable() throws Exception;
+ public abstract DbType dbTypeSelector();
/**
* gets the JDBC url for the data source connection
- * @return
*/
- public abstract String getJdbcUrl();
+ public String getJdbcUrl() {
+ StringBuilder jdbcUrl = new StringBuilder(getAddress());
+
+ appendDatabase(jdbcUrl);
+ appendPrincipal(jdbcUrl);
+ appendOther(jdbcUrl);
+
+ return jdbcUrl.toString();
+ }
+
+ /**
+ * append database
+ * @param jdbcUrl jdbc url
+ */
+ private void appendDatabase(StringBuilder jdbcUrl) {
+ if (dbTypeSelector() == DbType.SQLSERVER) {
+ jdbcUrl.append(";databaseName=").append(getDatabase());
+ } else {
+ if (getAddress().lastIndexOf('/') != (jdbcUrl.length() - 1)) {
+ jdbcUrl.append("/");
+ }
+ jdbcUrl.append(getDatabase());
+ }
+ }
+
+ /**
+ * append principal
+ * @param jdbcUrl jdbc url
+ */
+ private void appendPrincipal(StringBuilder jdbcUrl) {
+ boolean tag = dbTypeSelector() == DbType.HIVE || dbTypeSelector() == DbType.SPARK;
+ if (tag && StringUtils.isNotEmpty(getPrincipal())) {
+ jdbcUrl.append(";principal=").append(getPrincipal());
+ }
+ }
+
+ /**
+ * append other
+ * @param jdbcUrl jdbc url
+ */
+ private void appendOther(StringBuilder jdbcUrl) {
+ if (StringUtils.isNotEmpty(getOther())) {
+ String separator = "";
+ switch (dbTypeSelector()) {
+ case CLICKHOUSE:
+ case MYSQL:
+ case ORACLE:
+ case POSTGRESQL:
+ separator = "?";
+ break;
+ case DB2:
+ separator = ":";
+ break;
+ case HIVE:
+ case SPARK:
+ case SQLSERVER:
+ separator = ";";
+ break;
+ default:
+ logger.error("Db type mismatch!");
+ }
+ jdbcUrl.append(separator).append(getOther());
+ }
+ }
+
+ /**
+ * test whether the data source can be connected successfully
+ */
+ public void isConnectable() {
+ Connection con = null;
+ try {
+ Class.forName(driverClassSelector());
+ con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
+ } catch (ClassNotFoundException | SQLException e) {
+ logger.error("Get connection error: {}", e.getMessage());
+ } finally {
+ if (con != null) {
+ try {
+ con.close();
+ } catch (SQLException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
public String getUser() {
return user;
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ClickHouseDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ClickHouseDataSource.java
index e159f81d2e..ba34ff82d6 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ClickHouseDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/ClickHouseDataSource.java
@@ -17,59 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of ClickHouse
*/
public class ClickHouseDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(ClickHouseDataSource.class);
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf('/') != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += "?" + getOther();
- }
-
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.COM_CLICKHOUSE_JDBC_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.COM_CLICKHOUSE_JDBC_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("ClickHouse datasource try conn close conn error", e);
- }
- }
- }
-
+ public DbType dbTypeSelector() {
+ return DbType.CLICKHOUSE;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/DB2ServerDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/DB2ServerDataSource.java
index 3c2366b5b0..4b524b8b81 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/DB2ServerDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/DB2ServerDataSource.java
@@ -17,58 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of DB2 Server
*/
public class DB2ServerDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(DB2ServerDataSource.class);
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += ":" + getOther();
- }
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.COM_DB2_JDBC_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.COM_DB2_JDBC_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("DB2 Server datasource try conn close conn error", e);
- }
- }
- }
-
+ public DbType dbTypeSelector() {
+ return DbType.DB2;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/HiveDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/HiveDataSource.java
index 4dfb8817a8..2616c5add6 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/HiveDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/HiveDataSource.java
@@ -17,63 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of hive
*/
public class HiveDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(HiveDataSource.class);
-
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf('/') != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getPrincipal())){
- jdbcUrl += ";principal=" + getPrincipal();
- }
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += ";" + getOther();
- }
-
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), "");
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("hive datasource try conn close conn error", e);
- }
- }
- }
+ public DbType dbTypeSelector() {
+ return DbType.HIVE;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java
index 969c17b54d..459cf946f1 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java
@@ -17,57 +17,27 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of mySQL
*/
public class MySQLDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(MySQLDataSource.class);
-
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String address = getAddress();
- if (address.lastIndexOf('/') != (address.length() - 1)) {
- address += "/";
- }
- String jdbcUrl = address + getDatabase();
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += "?" + getOther();
- }
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.COM_MYSQL_JDBC_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.COM_MYSQL_JDBC_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("Mysql datasource try conn close conn error", e);
- }
- }
- }
+ public DbType dbTypeSelector() {
+ return DbType.MYSQL;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/OracleDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/OracleDataSource.java
index cefaf879b5..0ebecb49f7 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/OracleDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/OracleDataSource.java
@@ -17,59 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of Oracle
*/
public class OracleDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(OracleDataSource.class);
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += "?" + getOther();
- }
-
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.COM_ORACLE_JDBC_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.COM_ORACLE_JDBC_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("Oracle datasource try conn close conn error", e);
- }
- }
- }
-
+ public DbType dbTypeSelector() {
+ return DbType.ORACLE;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/PostgreDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/PostgreDataSource.java
index c01dfa4dc0..03a2b5c7b6 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/PostgreDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/PostgreDataSource.java
@@ -17,61 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of postgreSQL
*/
public class PostgreDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(PostgreDataSource.class);
-
-
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf('/') != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += "?" + getOther();
- }
-
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.ORG_POSTGRESQL_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.ORG_POSTGRESQL_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("Postgre datasource try conn close conn error", e);
- }
- }
- }
-
+ public DbType dbTypeSelector() {
+ return DbType.POSTGRESQL;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SQLServerDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SQLServerDataSource.java
index 07770c06a7..c692de8dcc 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SQLServerDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SQLServerDataSource.java
@@ -17,55 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of SQL Server
*/
public class SQLServerDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(SQLServerDataSource.class);
-
- /**
- * gets the JDBC url for the data source connection
- * @return
- */
- @Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- jdbcUrl += ";databaseName=" + getDatabase();
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += ";" + getOther();
- }
-
- return jdbcUrl;
- }
-
- /**
- * test whether the data source can be connected successfully
- * @throws Exception
- */
- @Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.COM_SQLSERVER_JDBC_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("SQL Server datasource try conn close conn error", e);
- }
- }
- }
- }
+ /**
+ * @return driver class
+ */
+ @Override
+ public String driverClassSelector() {
+ return Constants.COM_SQLSERVER_JDBC_DRIVER;
+ }
+
+ /**
+ * @return db type
+ */
+ @Override
+ public DbType dbTypeSelector() {
+ return DbType.SQLSERVER;
+ }
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SparkDataSource.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SparkDataSource.java
index 81a5ac6f04..d8794651d8 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SparkDataSource.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SparkDataSource.java
@@ -17,64 +17,26 @@
package org.apache.dolphinscheduler.dao.datasource;
import org.apache.dolphinscheduler.common.Constants;
-import org.apache.dolphinscheduler.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
+import org.apache.dolphinscheduler.common.enums.DbType;
/**
* data source of spark
*/
public class SparkDataSource extends BaseDataSource {
- private static final Logger logger = LoggerFactory.getLogger(SparkDataSource.class);
-
/**
- * gets the JDBC url for the data source connection
- * @return
+ * @return driver class
*/
@Override
- public String getJdbcUrl() {
- String jdbcUrl = getAddress();
- if (jdbcUrl.lastIndexOf("/") != (jdbcUrl.length() - 1)) {
- jdbcUrl += "/";
- }
-
- jdbcUrl += getDatabase();
-
- if (StringUtils.isNotEmpty(getPrincipal())){
- jdbcUrl += ";principal=" + getPrincipal();
- }
-
- if (StringUtils.isNotEmpty(getOther())) {
- jdbcUrl += ";" + getOther();
- }
-
- return jdbcUrl;
+ public String driverClassSelector() {
+ return Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER;
}
/**
- * test whether the data source can be connected successfully
- * @throws Exception
+ * @return db type
*/
@Override
- public void isConnectable() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER);
- con = DriverManager.getConnection(getJdbcUrl(), getUser(), "");
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error("Spark datasource try conn close conn error", e);
- }
- }
- }
-
+ public DbType dbTypeSelector() {
+ return DbType.SPARK;
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java
index a20a3acb95..255f1cf081 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java
@@ -66,7 +66,7 @@ public class MysqlUpgradeDao extends UpgradeDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(rs, null, conn);
+ ConnectionUtils.releaseResource(rs, conn);
}
}
@@ -89,7 +89,7 @@ public class MysqlUpgradeDao extends UpgradeDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(null, null, conn);
+ ConnectionUtils.releaseResource(conn);
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java
index c58521de1d..b4049450ab 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java
@@ -96,7 +96,7 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(rs, null, conn);
+ ConnectionUtils.releaseResource(rs, conn);
}
}
@@ -119,7 +119,7 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(rs, null, conn);
+ ConnectionUtils.releaseResource(rs, conn);
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
index 3552d4e9b3..e708620f8a 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/UpgradeDao.java
@@ -79,7 +79,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
return null;
}finally {
- ConnectionUtils.releaseResource(null, null, conn);
+ ConnectionUtils.releaseResource(conn);
}
}
@@ -160,7 +160,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(null, null, conn);
+ ConnectionUtils.releaseResource(conn);
}
@@ -193,7 +193,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(null, null, conn);
+ ConnectionUtils.releaseResource(conn);
}
@@ -329,7 +329,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(null, pstmt, conn);
+ ConnectionUtils.releaseResource(pstmt, conn);
}
}
@@ -372,7 +372,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e);
} finally {
- ConnectionUtils.releaseResource(null, pstmt, conn);
+ ConnectionUtils.releaseResource(pstmt, conn);
}
}
@@ -401,7 +401,7 @@ public abstract class UpgradeDao extends AbstractBaseDao {
logger.error(e.getMessage(),e);
throw new RuntimeException("sql: " + upgradeSQL, e);
} finally {
- ConnectionUtils.releaseResource(null, pstmt, conn);
+ ConnectionUtils.releaseResource(pstmt, conn);
}
}
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSourceTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSourceTest.java
new file mode 100644
index 0000000000..6c44c3e329
--- /dev/null
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/datasource/BaseDataSourceTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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 org.apache.dolphinscheduler.dao.datasource;
+
+import org.apache.dolphinscheduler.common.Constants;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BaseDataSourceTest {
+
+ @Test
+ public void testDriverClassSelector() {
+ String mysqlDriverClass = new MySQLDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.COM_MYSQL_JDBC_DRIVER, mysqlDriverClass);
+
+ String clickHouseDriverClass = new ClickHouseDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.COM_CLICKHOUSE_JDBC_DRIVER, clickHouseDriverClass);
+
+ String db2ServerDriverClass = new DB2ServerDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.COM_DB2_JDBC_DRIVER, db2ServerDriverClass);
+
+ String oracleDriverClass = new OracleDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.COM_ORACLE_JDBC_DRIVER, oracleDriverClass);
+
+ String postgreDriverClass = new PostgreDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.ORG_POSTGRESQL_DRIVER, postgreDriverClass);
+
+ String sqlServerDriverClass = new SQLServerDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.COM_SQLSERVER_JDBC_DRIVER, sqlServerDriverClass);
+
+ String hiveDriverClass = new HiveDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER, hiveDriverClass);
+
+ String sparkDriverClass = new SparkDataSource().driverClassSelector();
+ Assert.assertEquals(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER, sparkDriverClass);
+ }
+
+ @Test
+ public void testGetJdbcUrl() {
+ BaseDataSource hiveDataSource = new HiveDataSource();
+ hiveDataSource.setAddress("jdbc:hive2://127.0.0.1:10000");
+ hiveDataSource.setDatabase("test");
+ hiveDataSource.setPassword("123456");
+ hiveDataSource.setUser("test");
+ Assert.assertEquals("jdbc:hive2://127.0.0.1:10000/test", hiveDataSource.getJdbcUrl());
+ //set principal
+ hiveDataSource.setPrincipal("hive/test.com@TEST.COM");
+ Assert.assertEquals("jdbc:hive2://127.0.0.1:10000/test;principal=hive/test.com@TEST.COM",
+ hiveDataSource.getJdbcUrl());
+ //set fake other
+ hiveDataSource.setOther("charset=UTF-8");
+ Assert.assertEquals(
+ "jdbc:hive2://127.0.0.1:10000/test;principal=hive/test.com@TEST.COM;charset=UTF-8",
+ hiveDataSource.getJdbcUrl());
+
+ BaseDataSource clickHouseDataSource = new ClickHouseDataSource();
+ clickHouseDataSource.setAddress("jdbc:clickhouse://127.0.0.1:8123");
+ clickHouseDataSource.setDatabase("test");
+ clickHouseDataSource.setPassword("123456");
+ clickHouseDataSource.setUser("test");
+ Assert.assertEquals("jdbc:clickhouse://127.0.0.1:8123/test", clickHouseDataSource.getJdbcUrl());
+ //set fake principal
+ clickHouseDataSource.setPrincipal("fake principal");
+ Assert.assertEquals("jdbc:clickhouse://127.0.0.1:8123/test", clickHouseDataSource.getJdbcUrl());
+ //set fake other
+ clickHouseDataSource.setOther("charset=UTF-8");
+ Assert.assertEquals("jdbc:clickhouse://127.0.0.1:8123/test?charset=UTF-8",
+ clickHouseDataSource.getJdbcUrl());
+
+ BaseDataSource sqlServerDataSource = new SQLServerDataSource();
+ sqlServerDataSource.setAddress("jdbc:sqlserver://127.0.0.1:1433");
+ sqlServerDataSource.setDatabase("test");
+ sqlServerDataSource.setPassword("123456");
+ sqlServerDataSource.setUser("test");
+ Assert.assertEquals("jdbc:sqlserver://127.0.0.1:1433;databaseName=test",
+ sqlServerDataSource.getJdbcUrl());
+ //set fake principal
+ sqlServerDataSource.setPrincipal("fake principal");
+ Assert.assertEquals("jdbc:sqlserver://127.0.0.1:1433;databaseName=test",
+ sqlServerDataSource.getJdbcUrl());
+ //set fake other
+ sqlServerDataSource.setOther("charset=UTF-8");
+ Assert.assertEquals("jdbc:sqlserver://127.0.0.1:1433;databaseName=test;charset=UTF-8",
+ sqlServerDataSource.getJdbcUrl());
+
+ BaseDataSource db2DataSource = new DB2ServerDataSource();
+ db2DataSource.setAddress("jdbc:db2://127.0.0.1:50000");
+ db2DataSource.setDatabase("test");
+ db2DataSource.setPassword("123456");
+ db2DataSource.setUser("test");
+ Assert.assertEquals("jdbc:db2://127.0.0.1:50000/test", db2DataSource.getJdbcUrl());
+ //set fake principal
+ db2DataSource.setPrincipal("fake principal");
+ Assert.assertEquals("jdbc:db2://127.0.0.1:50000/test", db2DataSource.getJdbcUrl());
+ //set fake other
+ db2DataSource.setOther("charset=UTF-8");
+ Assert.assertEquals("jdbc:db2://127.0.0.1:50000/test:charset=UTF-8", db2DataSource.getJdbcUrl());
+
+
+ }
+}
diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
index f7070b1d38..ebc91563b4 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java
@@ -140,7 +140,6 @@ public class SqlTask extends AbstractTask {
dataSource.getUserId(),
dataSource.getConnectionParams());
- Connection con = null;
List createFuncs = null;
try {
// load class
@@ -178,18 +177,10 @@ public class SqlTask extends AbstractTask {
}
// execute sql task
- con = executeFuncAndSql(mainSqlBinds, preStatementSqlBinds, postStatementSqlBinds, createFuncs);
+ executeFuncAndSql(mainSqlBinds, preStatementSqlBinds, postStatementSqlBinds, createFuncs);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
- } finally {
- if (con != null) {
- try {
- con.close();
- } catch (SQLException e) {
- logger.error(e.getMessage(),e);
- }
- }
}
}
@@ -249,9 +240,8 @@ public class SqlTask extends AbstractTask {
* @param preStatementsBinds pre statements binds
* @param postStatementsBinds post statements binds
* @param createFuncs create functions
- * @return Connection
*/
- public Connection executeFuncAndSql(SqlBinds mainSqlBinds,
+ public void executeFuncAndSql(SqlBinds mainSqlBinds,
List preStatementsBinds,
List postStatementsBinds,
List createFuncs){
@@ -343,13 +333,9 @@ public class SqlTask extends AbstractTask {
logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage());
} finally {
- try {
- connection.close();
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
+ ConnectionUtils.releaseResource(connection);
}
- return connection;
+
}
/**
diff --git a/pom.xml b/pom.xml
index d11b3bf1f6..73542921f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -741,6 +741,7 @@
**/server/worker/task/sqoop/SqoopTaskTest.java
**/server/utils/DataxUtilsTest.java
**/service/zk/DefaultEnsembleProviderTest.java
+ **/dao/datasource/BaseDataSourceTest.java
**/alert/utils/MailUtilsTest.java
**/dao/AlertDaoTest.java
From d8cba5ff1ba4be74e99397b80bca521bff60ffb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AD=99=E6=9C=9D=E5=92=8C?= <649790970@qq.com>
Date: Thu, 26 Mar 2020 23:25:15 +0800
Subject: [PATCH 8/9] resolve shell task build command nullpointexception
(#2267)
Co-authored-by: sunchaohe
---
.../server/worker/task/shell/ShellTask.java | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java
index 2c8433aa01..165430b5fd 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/shell/ShellTask.java
@@ -134,7 +134,6 @@ public class ShellTask extends AbstractTask {
String script = shellParameters.getRawScript().replaceAll("\\r\\n", "\n");
-
/**
* combining local and global parameters
*/
@@ -143,13 +142,9 @@ public class ShellTask extends AbstractTask {
shellParameters.getLocalParametersMap(),
taskProps.getCmdTypeIfComplement(),
taskProps.getScheduleTime());
-// if (paramsMap != null){
-// script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap));
-// }
- //new
// replace variable TIME with $[YYYYmmddd...] in shell file when history run job and batch complement job
- if (paramsMap != null) {
+ if(paramsMap != null && taskProps.getScheduleTime()!=null) {
String dateTime = DateUtils.format(taskProps.getScheduleTime(), Constants.PARAMETER_FORMAT_TIME);
Property p = new Property();
p.setValue(dateTime);
@@ -182,6 +177,4 @@ public class ShellTask extends AbstractTask {
return shellParameters;
}
-
-
}
From eef8bf4e6de199313499477ac6f8dbac1512f2da Mon Sep 17 00:00:00 2001
From: "gabry.wu"
Date: Thu, 26 Mar 2020 23:36:17 +0800
Subject: [PATCH 9/9] Adapting partial code(file name start with P #2) to the
sonar cloud rule (#2260)
---
.../controller/ProcessInstanceController.java | 2 +-
.../dolphinscheduler/api/dto/ProcessMeta.java | 3 -
.../api/service/ProcessDefinitionService.java | 13 +-
.../api/service/ProcessInstanceService.java | 15 ++-
.../process/ProcessEnvironmentForWin32.java | 20 ++--
.../utils/process/ProcessImplForWin32.java | 113 +++++++++---------
.../dao/entity/ProcessInstance.java | 2 +-
.../mapper/ProcessInstanceMapMapperTest.java | 6 +-
.../dao/mapper/ProcessInstanceMapperTest.java | 14 +--
.../master/runner/MasterExecThread.java | 2 +-
10 files changed, 94 insertions(+), 96 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
index 102f116575..5faf7a4f14 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
@@ -391,7 +391,7 @@ public class ProcessInstanceController extends BaseController{
}
}
}
- if(deleteFailedIdList.size() > 0){
+ if(!deleteFailedIdList.isEmpty()){
putMsg(result, Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR, String.join(",", deleteFailedIdList));
}else{
putMsg(result, Status.SUCCESS);
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java
index f14d8df097..bdb9e1f576 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/ProcessMeta.java
@@ -106,9 +106,6 @@ public class ProcessMeta {
*/
private String scheduleWorkerGroupName;
- public ProcessMeta() {
- }
-
public String getProjectName() {
return projectName;
}
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
index 22e3593a52..44c2b44ebb 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
@@ -148,7 +148,7 @@ public class ProcessDefinitionService extends BaseDAGService {
//custom global params
List globalParamsList = processData.getGlobalParams();
- if (globalParamsList != null && globalParamsList.size() > 0) {
+ if (CollectionUtils.isNotEmpty(globalParamsList)) {
Set globalParamsSet = new HashSet<>(globalParamsList);
globalParamsList = new ArrayList<>(globalParamsSet);
processDefine.setGlobalParamList(globalParamsList);
@@ -314,7 +314,7 @@ public class ProcessDefinitionService extends BaseDAGService {
//custom global params
List globalParamsList = new ArrayList<>();
- if (processData.getGlobalParams() != null && processData.getGlobalParams().size() > 0) {
+ if (CollectionUtils.isNotEmpty(processData.getGlobalParams())) {
Set userDefParamsSet = new HashSet<>(processData.getGlobalParams());
globalParamsList = new ArrayList<>(userDefParamsSet);
}
@@ -453,12 +453,11 @@ public class ProcessDefinitionService extends BaseDAGService {
ProcessDefinition processDefinition = processDefineMapper.selectById(id);
switch (state) {
- case ONLINE: {
+ case ONLINE:
processDefinition.setReleaseState(state);
processDefineMapper.updateById(processDefinition);
break;
- }
- case OFFLINE: {
+ case OFFLINE:
processDefinition.setReleaseState(state);
processDefineMapper.updateById(processDefinition);
List scheduleList = scheduleMapper.selectAllByProcessDefineArray(
@@ -473,11 +472,9 @@ public class ProcessDefinitionService extends BaseDAGService {
SchedulerService.deleteSchedule(project.getId(), schedule.getId());
}
break;
- }
- default: {
+ default:
putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, "releaseState");
return result;
- }
}
putMsg(result, Status.SUCCESS);
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
index 3530c66ff6..57f839af1b 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
+++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
@@ -239,7 +239,7 @@ public class ProcessInstanceService extends BaseDAGService {
}
ProcessInstance processInstance = processService.findProcessInstanceDetailById(processId);
List taskInstanceList = processService.findValidTaskListByProcessId(processId);
- AddDependResultForTaskList(taskInstanceList);
+ addDependResultForTaskList(taskInstanceList);
Map resultMap = new HashMap<>();
resultMap.put(PROCESS_INSTANCE_STATE, processInstance.getState().toString());
resultMap.put(TASK_LIST, taskInstanceList);
@@ -253,9 +253,9 @@ public class ProcessInstanceService extends BaseDAGService {
* add dependent result for dependent task
* @param taskInstanceList
*/
- private void AddDependResultForTaskList(List taskInstanceList) throws IOException {
+ private void addDependResultForTaskList(List taskInstanceList) throws IOException {
for(TaskInstance taskInstance: taskInstanceList){
- if(taskInstance.getTaskType().toUpperCase().equals(TaskType.DEPENDENT.toString())){
+ if(taskInstance.getTaskType().equalsIgnoreCase(TaskType.DEPENDENT.toString())){
Result logResult = loggerService.queryLog(
taskInstance.getId(), 0, 4098);
if(logResult.getCode() == Status.SUCCESS.ordinal()){
@@ -414,11 +414,10 @@ public class ProcessInstanceService extends BaseDAGService {
processInstance.setProcessInstanceJson(processInstanceJson);
processInstance.setGlobalParams(globalParams);
}
-// int update = processDao.updateProcessInstance(processInstanceId, processInstanceJson,
-// globalParams, schedule, flag, locations, connects);
+
int update = processService.updateProcessInstance(processInstance);
int updateDefine = 1;
- if (syncDefine && StringUtils.isNotEmpty(processInstanceJson)) {
+ if (Boolean.TRUE.equals(syncDefine) && StringUtils.isNotEmpty(processInstanceJson)) {
processDefinition.setProcessDefinitionJson(processInstanceJson);
processDefinition.setGlobalParams(originDefParams);
processDefinition.setLocations(locations);
@@ -544,7 +543,7 @@ public class ProcessInstanceService extends BaseDAGService {
nodeValueSb.append(ipSb);
}
- logger.info("delete task queue node : {}",nodeValueSb.toString());
+ logger.info("delete task queue node : {}",nodeValueSb);
tasksQueue.removeNode(org.apache.dolphinscheduler.common.Constants.DOLPHINSCHEDULER_TASKS_QUEUE, nodeValueSb.toString());
}
@@ -621,7 +620,7 @@ public class ProcessInstanceService extends BaseDAGService {
Map localParamsMap = new HashMap<>();
localParamsMap.put("taskType",taskNode.getType());
localParamsMap.put("localParamsList",localParamsList);
- if (localParamsList.size() > 0) {
+ if (CollectionUtils.isNotEmpty(localParamsList)) {
localUserDefParams.put(taskNode.getName(), localParamsMap);
}
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java
index 3dbe7cb50f..39fddfbad9 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessEnvironmentForWin32.java
@@ -46,22 +46,23 @@ final class ProcessEnvironmentForWin32 extends HashMap {
return (String) o;
}
+ @Override
public String put(String key, String value) {
return super.put(validateName(key), validateValue(value));
}
-
+ @Override
public String get(Object key) {
return super.get(nonNullString(key));
}
-
+ @Override
public boolean containsKey(Object key) {
return super.containsKey(nonNullString(key));
}
-
+ @Override
public boolean containsValue(Object value) {
return super.containsValue(nonNullString(value));
}
-
+ @Override
public String remove(Object key) {
return super.remove(nonNullString(key));
}
@@ -92,6 +93,7 @@ final class ProcessEnvironmentForWin32 extends HashMap {
public Entry next() {
return new CheckedEntry(i.next());
}
+ @Override
public void remove() { i.remove();}
};
}
@@ -110,10 +112,14 @@ final class ProcessEnvironmentForWin32 extends HashMap {
private final Collection c;
public CheckedValues(Collection c) {this.c = c;}
public int size() {return c.size();}
+ @Override
public boolean isEmpty() {return c.isEmpty();}
+ @Override
public void clear() { c.clear();}
public Iterator iterator() {return c.iterator();}
+ @Override
public boolean contains(Object o) {return c.contains(nonNullString(o));}
+ @Override
public boolean remove(Object o) {return c.remove(nonNullString(o));}
}
@@ -127,15 +133,15 @@ final class ProcessEnvironmentForWin32 extends HashMap {
public boolean contains(Object o) {return s.contains(nonNullString(o));}
public boolean remove(Object o) {return s.remove(nonNullString(o));}
}
-
+ @Override
public Set keySet() {
return new CheckedKeySet(super.keySet());
}
-
+ @Override
public Collection values() {
return new CheckedValues(super.values());
}
-
+ @Override
public Set> entrySet() {
return new CheckedEntrySet(super.entrySet());
}
diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java
index bef5bb0ae2..4f6d719ef3 100644
--- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java
+++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessImplForWin32.java
@@ -113,7 +113,7 @@ public class ProcessImplForWin32 extends Process {
// System-dependent portion of ProcessBuilderForWindows.start()
static Process start(String username,
String password,
- String cmdarray[],
+ String[] cmdarray,
java.util.Map environment,
String dir,
ProcessBuilderForWin32.Redirect[] redirects,
@@ -178,10 +178,10 @@ public class ProcessImplForWin32 extends Process {
private static class LazyPattern {
// Escape-support version:
- // "(\")((?:\\\\\\1|.)+?)\\1|([^\\s\"]+)";
+ // "(\")((?:\\\\\\1|.)+?)\\1|([^\\s\"]+)"
private static final Pattern PATTERN =
Pattern.compile("[^\\s\"]+|\"[^\"]*\"");
- };
+ }
/* Parses the command string parameter into the executable name and
* program arguments.
@@ -204,7 +204,7 @@ public class ProcessImplForWin32 extends Process {
private static final int VERIFICATION_LEGACY = 3;
// See Command shell overview for documentation of special characters.
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
- private static final char ESCAPE_VERIFICATION[][] = {
+ private static final char[][] ESCAPE_VERIFICATION = {
// We guarantee the only command file execution for implicit [cmd.exe] run.
// http://technet.microsoft.com/en-us/library/bb490954.aspx
{' ', '\t', '<', '>', '&', '|', '^'},
@@ -215,7 +215,7 @@ public class ProcessImplForWin32 extends Process {
private static String createCommandLine(int verificationType,
final String executablePath,
- final String cmd[])
+ final String[] cmd)
{
StringBuilder cmdbuf = new StringBuilder(80);
@@ -310,7 +310,7 @@ public class ProcessImplForWin32 extends Process {
}
if (!argIsQuoted) {
- char testEscape[] = ESCAPE_VERIFICATION[verificationType];
+ char[] testEscape = ESCAPE_VERIFICATION[verificationType];
for (int i = 0; i < testEscape.length; ++i) {
if (arg.indexOf(testEscape[i]) >= 0) {
return true;
@@ -391,14 +391,14 @@ public class ProcessImplForWin32 extends Process {
private static final char BACKSLASH = '\\';
private WinNT.HANDLE handle;
- private OutputStream stdin_stream;
- private InputStream stdout_stream;
- private InputStream stderr_stream;
+ private OutputStream stdinStream;
+ private InputStream stdoutStream;
+ private InputStream stderrStream;
private ProcessImplForWin32(
String username,
String password,
- String cmd[],
+ String[] cmd,
final String envblock,
final String path,
final long[] stdHandles,
@@ -473,44 +473,44 @@ public class ProcessImplForWin32 extends Process {
new PrivilegedAction() {
public Void run() {
if (stdHandles[0] == -1L)
- stdin_stream = ProcessBuilderForWin32.NullOutputStream.INSTANCE;
+ stdinStream = ProcessBuilderForWin32.NullOutputStream.INSTANCE;
else {
- FileDescriptor stdin_fd = new FileDescriptor();
- setHandle(stdin_fd, stdHandles[0]);
- stdin_stream = new BufferedOutputStream(
- new FileOutputStream(stdin_fd));
+ FileDescriptor stdinFd = new FileDescriptor();
+ setHandle(stdinFd, stdHandles[0]);
+ stdinStream = new BufferedOutputStream(
+ new FileOutputStream(stdinFd));
}
if (stdHandles[1] == -1L)
- stdout_stream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
+ stdoutStream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
else {
- FileDescriptor stdout_fd = new FileDescriptor();
- setHandle(stdout_fd, stdHandles[1]);
- stdout_stream = new BufferedInputStream(
- new FileInputStream(stdout_fd));
+ FileDescriptor stdoutFd = new FileDescriptor();
+ setHandle(stdoutFd, stdHandles[1]);
+ stdoutStream = new BufferedInputStream(
+ new FileInputStream(stdoutFd));
}
if (stdHandles[2] == -1L)
- stderr_stream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
+ stderrStream = ProcessBuilderForWin32.NullInputStream.INSTANCE;
else {
- FileDescriptor stderr_fd = new FileDescriptor();
- setHandle(stderr_fd, stdHandles[2]);
- stderr_stream = new FileInputStream(stderr_fd);
+ FileDescriptor stderrFd = new FileDescriptor();
+ setHandle(stderrFd, stdHandles[2]);
+ stderrStream = new FileInputStream(stderrFd);
}
return null; }});
}
public OutputStream getOutputStream() {
- return stdin_stream;
+ return stdinStream;
}
public InputStream getInputStream() {
- return stdout_stream;
+ return stdoutStream;
}
public InputStream getErrorStream() {
- return stderr_stream;
+ return stderrStream;
}
protected void finalize() {
@@ -558,11 +558,12 @@ public class ProcessImplForWin32 extends Process {
public void destroy() { terminateProcess(handle); }
+ @Override
public Process destroyForcibly() {
destroy();
return this;
}
-
+ @Override
public boolean isAlive() {
return isProcessAlive(handle);
}
@@ -583,7 +584,7 @@ public class ProcessImplForWin32 extends Process {
pjhandles.setValue(thisProcessEnd);
}
}
- Kernel32.INSTANCE.SetHandleInformation(phStd.getValue(), Kernel32.HANDLE_FLAG_INHERIT, Kernel32.HANDLE_FLAG_INHERIT);
+ Kernel32.INSTANCE.SetHandleInformation(phStd.getValue(), WinBase.HANDLE_FLAG_INHERIT, WinBase.HANDLE_FLAG_INHERIT);
return true;
}
@@ -597,17 +598,17 @@ public class ProcessImplForWin32 extends Process {
private static void prepareIOEHandleState(WinNT.HANDLE[] stdIOE, Boolean[] inherit) {
for(int i = 0; i < HANDLE_STORAGE_SIZE; ++i) {
WinNT.HANDLE hstd = stdIOE[i];
- if (!Kernel32.INVALID_HANDLE_VALUE.equals(hstd)) {
+ if (!WinBase.INVALID_HANDLE_VALUE.equals(hstd)) {
inherit[i] = Boolean.TRUE;
- Kernel32.INSTANCE.SetHandleInformation(hstd, Kernel32.HANDLE_FLAG_INHERIT, 0);
+ Kernel32.INSTANCE.SetHandleInformation(hstd, WinBase.HANDLE_FLAG_INHERIT, 0);
}
}
}
private static void restoreIOEHandleState(WinNT.HANDLE[] stdIOE, Boolean[] inherit) {
for (int i = HANDLE_STORAGE_SIZE - 1; i >= 0; --i) {
- if (!Kernel32.INVALID_HANDLE_VALUE.equals(stdIOE[i])) {
- Kernel32.INSTANCE.SetHandleInformation(stdIOE[i], Kernel32.HANDLE_FLAG_INHERIT, inherit[i] ? Kernel32.HANDLE_FLAG_INHERIT : 0);
+ if (!WinBase.INVALID_HANDLE_VALUE.equals(stdIOE[i])) {
+ Kernel32.INSTANCE.SetHandleInformation(stdIOE[i], WinBase.HANDLE_FLAG_INHERIT, Boolean.TRUE.equals(inherit[i]) ? WinBase.HANDLE_FLAG_INHERIT : 0);
}
}
}
@@ -622,12 +623,12 @@ public class ProcessImplForWin32 extends Process {
WinNT.HANDLE ret = new WinNT.HANDLE(Pointer.createConstant(0));
WinNT.HANDLE[] stdIOE = new WinNT.HANDLE[] {
- Kernel32.INVALID_HANDLE_VALUE, Kernel32.INVALID_HANDLE_VALUE, Kernel32.INVALID_HANDLE_VALUE,
+ WinBase.INVALID_HANDLE_VALUE, WinBase.INVALID_HANDLE_VALUE, WinBase.INVALID_HANDLE_VALUE,
stdHandles[0].getValue(), stdHandles[1].getValue(), stdHandles[2].getValue()
};
- stdIOE[0] = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_INPUT_HANDLE);
- stdIOE[1] = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_OUTPUT_HANDLE);
- stdIOE[2] = Kernel32.INSTANCE.GetStdHandle(Kernel32.STD_ERROR_HANDLE);
+ stdIOE[0] = Kernel32.INSTANCE.GetStdHandle(Wincon.STD_INPUT_HANDLE);
+ stdIOE[1] = Kernel32.INSTANCE.GetStdHandle(Wincon.STD_OUTPUT_HANDLE);
+ stdIOE[2] = Kernel32.INSTANCE.GetStdHandle(Wincon.STD_ERROR_HANDLE);
Boolean[] inherit = new Boolean[] {
Boolean.FALSE, Boolean.FALSE, Boolean.FALSE,
@@ -639,17 +640,17 @@ public class ProcessImplForWin32 extends Process {
// input
WinNT.HANDLEByReference hStdInput = new WinNT.HANDLEByReference();
WinNT.HANDLEByReference[] pipeIn = new WinNT.HANDLEByReference[] {
- new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE) };
+ new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE) };
// output
WinNT.HANDLEByReference hStdOutput = new WinNT.HANDLEByReference();
WinNT.HANDLEByReference[] pipeOut = new WinNT.HANDLEByReference[] {
- new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE) };
+ new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE) };
// error
WinNT.HANDLEByReference hStdError = new WinNT.HANDLEByReference();
WinNT.HANDLEByReference[] pipeError = new WinNT.HANDLEByReference[] {
- new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(Kernel32.INVALID_HANDLE_VALUE) };
+ new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE), new WinNT.HANDLEByReference(WinBase.INVALID_HANDLE_VALUE) };
boolean success;
if (initHolder(stdHandles[0], pipeIn, OFFSET_READ, hStdInput)) {
@@ -669,8 +670,8 @@ public class ProcessImplForWin32 extends Process {
if (success) {
WTypes.LPSTR lpEnvironment = envblock == null ? new WTypes.LPSTR() : new WTypes.LPSTR(envblock);
- Kernel32.PROCESS_INFORMATION pi = new WinBase.PROCESS_INFORMATION();
- si.dwFlags = Kernel32.STARTF_USESTDHANDLES;
+ WinBase.PROCESS_INFORMATION pi = new WinBase.PROCESS_INFORMATION();
+ si.dwFlags = WinBase.STARTF_USESTDHANDLES;
if (!Advapi32.INSTANCE.CreateProcessWithLogonW(
username
, null
@@ -678,7 +679,7 @@ public class ProcessImplForWin32 extends Process {
, Advapi32.LOGON_WITH_PROFILE
, null
, cmd
- , Kernel32.CREATE_NO_WINDOW
+ , WinBase.CREATE_NO_WINDOW
, lpEnvironment.getPointer()
, path
, si
@@ -710,13 +711,11 @@ public class ProcessImplForWin32 extends Process {
for (int i = 0; i < stdHandles.length; i++) {
handles[i] = new WinNT.HANDLEByReference(new WinNT.HANDLE(Pointer.createConstant(stdHandles[i])));
}
-
- if (cmd != null) {
- if (username != null && password != null) {
- ret = processCreate(username, password, cmd, envblock, path, handles, redirectErrorStream);
- }
+
+ if (cmd != null && username != null && password != null) {
+ ret = processCreate(username, password, cmd, envblock, path, handles, redirectErrorStream);
}
-
+
for (int i = 0; i < stdHandles.length; i++) {
stdHandles[i] = handles[i].getPointer().getLong(0);
}
@@ -756,15 +755,15 @@ public class ProcessImplForWin32 extends Process {
* @return the native HANDLE
*/
private static long openForAtomicAppend(String path) throws IOException {
- int access = Kernel32.GENERIC_READ | Kernel32.GENERIC_WRITE;
- int sharing = Kernel32.FILE_SHARE_READ | Kernel32.FILE_SHARE_WRITE;
- int disposition = Kernel32.OPEN_ALWAYS;
- int flagsAndAttributes = Kernel32.FILE_ATTRIBUTE_NORMAL;
+ int access = WinNT.GENERIC_READ | WinNT.GENERIC_WRITE;
+ int sharing = WinNT.FILE_SHARE_READ | WinNT.FILE_SHARE_WRITE;
+ int disposition = WinNT.OPEN_ALWAYS;
+ int flagsAndAttributes = WinNT.FILE_ATTRIBUTE_NORMAL;
if (path == null || path.isEmpty()) {
return -1;
} else {
WinNT.HANDLE handle = Kernel32.INSTANCE.CreateFile(path, access, sharing, null, disposition, flagsAndAttributes, null);
- if (handle == Kernel32.INVALID_HANDLE_VALUE) {
+ if (handle == WinBase.INVALID_HANDLE_VALUE) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
return handle.getPointer().getLong(0);
@@ -772,15 +771,15 @@ public class ProcessImplForWin32 extends Process {
}
private static void waitForInterruptibly(WinNT.HANDLE handle) {
- int result = Kernel32.INSTANCE.WaitForMultipleObjects(1, new WinNT.HANDLE[]{handle}, false, Kernel32.INFINITE);
- if (result == Kernel32.WAIT_FAILED) {
+ int result = Kernel32.INSTANCE.WaitForMultipleObjects(1, new WinNT.HANDLE[]{handle}, false, WinBase.INFINITE);
+ if (result == WinBase.WAIT_FAILED) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
}
private static void waitForTimeoutInterruptibly(WinNT.HANDLE handle, long timeout) {
int result = Kernel32.INSTANCE.WaitForMultipleObjects(1, new WinNT.HANDLE[]{handle}, false, (int) timeout);
- if (result == Kernel32.WAIT_FAILED) {
+ if (result == WinBase.WAIT_FAILED) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
}
diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
index fd9653a36c..097bf11238 100644
--- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
+++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessInstance.java
@@ -366,7 +366,7 @@ public class ProcessInstance {
}
- public boolean IsProcessInstanceStop(){
+ public boolean isProcessInstanceStop(){
return this.state.typeIsFinished();
}
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapperTest.java
index 175dd57948..cbc056e63d 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapperTest.java
@@ -60,7 +60,7 @@ public class ProcessInstanceMapMapperTest {
//update
processInstanceMap.setParentProcessInstanceId(1);
int update = processInstanceMapMapper.updateById(processInstanceMap);
- Assert.assertEquals(update, 1);
+ Assert.assertEquals(1, update);
processInstanceMapMapper.deleteById(processInstanceMap.getId());
}
@@ -71,7 +71,7 @@ public class ProcessInstanceMapMapperTest {
public void testDelete(){
ProcessInstanceMap processInstanceMap = insertOne();
int delete = processInstanceMapMapper.deleteById(processInstanceMap.getId());
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
@@ -132,7 +132,7 @@ public class ProcessInstanceMapMapperTest {
int delete = processInstanceMapMapper.deleteByParentProcessId(
processInstanceMap.getParentProcessInstanceId()
);
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java
index 3b307cc2ad..fd4749c4bf 100644
--- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java
+++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java
@@ -74,7 +74,7 @@ public class ProcessInstanceMapperTest {
ProcessInstance processInstanceMap = insertOne();
//update
int update = processInstanceMapper.updateById(processInstanceMap);
- Assert.assertEquals(update, 1);
+ Assert.assertEquals(1, update);
processInstanceMapper.deleteById(processInstanceMap.getId());
}
@@ -85,7 +85,7 @@ public class ProcessInstanceMapperTest {
public void testDelete(){
ProcessInstance processInstanceMap = insertOne();
int delete = processInstanceMapper.deleteById(processInstanceMap.getId());
- Assert.assertEquals(delete, 1);
+ Assert.assertEquals(1, delete);
}
/**
@@ -197,7 +197,7 @@ public class ProcessInstanceMapperTest {
Assert.assertNotEquals(update, 0);
processInstance = processInstanceMapper.selectById(processInstance.getId());
- Assert.assertEquals(processInstance.getHost(), null);
+ Assert.assertNull(processInstance.getHost());
processInstanceMapper.deleteById(processInstance.getId());
}
@@ -217,7 +217,7 @@ public class ProcessInstanceMapperTest {
ProcessInstance processInstance1 = processInstanceMapper.selectById(processInstance.getId());
processInstanceMapper.deleteById(processInstance.getId());
- Assert.assertEquals(processInstance1.getState(), ExecutionStatus.SUCCESS);
+ Assert.assertEquals(ExecutionStatus.SUCCESS, processInstance1.getState());
}
@@ -261,10 +261,10 @@ public class ProcessInstanceMapperTest {
List processInstances = processInstanceMapper.queryByProcessDefineId(processInstance.getProcessDefinitionId(), 1);
- Assert.assertEquals(processInstances.size(), 1);
+ Assert.assertEquals(1, processInstances.size());
processInstances = processInstanceMapper.queryByProcessDefineId(processInstance.getProcessDefinitionId(), 2);
- Assert.assertEquals(processInstances.size(), 2);
+ Assert.assertEquals(2, processInstances.size());
processInstanceMapper.deleteById(processInstance.getId());
processInstanceMapper.deleteById(processInstance1.getId());
@@ -320,7 +320,7 @@ public class ProcessInstanceMapperTest {
start = new Date(2019-1900, 1-1, 01, 1, 0, 0);
processInstance1 = processInstanceMapper.queryLastManualProcess(processInstance.getProcessDefinitionId(),start, end
);
- Assert.assertEquals(processInstance1, null);
+ Assert.assertNull(processInstance1);
processInstanceMapper.deleteById(processInstance.getId());
diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java
index 3ef795938f..d6ee6a3b1d 100644
--- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java
+++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterExecThread.java
@@ -937,7 +937,7 @@ public class MasterExecThread implements Runnable {
// submit start node
submitPostNode(null);
boolean sendTimeWarning = false;
- while(!processInstance.IsProcessInstanceStop()){
+ while(!processInstance.isProcessInstanceStop()){
// send warning email if process time out.
if( !sendTimeWarning && checkProcessTimeOut(processInstance) ){