This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 446f6ba72b Fix auto create tennat concurrently will cause the task
failed (#15909)
446f6ba72b is described below
commit 446f6ba72b8347ad817d8f62cdd8d258ace7adf4
Author: Wenjun Ruan <[email protected]>
AuthorDate: Thu Apr 25 18:14:48 2024 +0800
Fix auto create tennat concurrently will cause the task failed (#15909)
---
.../dolphinscheduler/common/utils/OSUtils.java | 25 ++++++++++------------
.../worker/utils/TaskExecutionContextUtils.java | 2 +-
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
index beca53c3fd..dbfcea2ed8 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
@@ -183,11 +183,10 @@ public class OSUtils {
*
* @param userName user name
*/
- public static void createUserIfAbsent(String userName) {
+ public static synchronized void createUserIfAbsent(String userName) {
// if not exists this user, then create
if (!getUserList().contains(userName)) {
- boolean isSuccess = createUser(userName);
- log.info("create user {} {}", userName, isSuccess ? "success" :
"fail");
+ createUser(userName);
}
}
@@ -197,13 +196,12 @@ public class OSUtils {
* @param userName user name
* @return true if creation was successful, otherwise false
*/
- public static boolean createUser(String userName) {
+ public static void createUser(String userName) {
try {
String userGroup = getGroup();
if (StringUtils.isEmpty(userGroup)) {
- String errorLog = String.format("%s group does not exist for
this operating system.", userGroup);
- log.error(errorLog);
- return false;
+ throw new UnsupportedOperationException(
+ "There is no userGroup exist cannot create tenant,
please create userGroupFirst");
}
if (SystemUtils.IS_OS_MAC) {
createMacUser(userName, userGroup);
@@ -212,18 +210,17 @@ public class OSUtils {
} else {
createLinuxUser(userName, userGroup);
}
- return true;
+ log.info("Create tenant {} under userGroup: {} success", userName,
userGroup);
} catch (Exception e) {
- log.error(e.getMessage(), e);
+ throw new RuntimeException("Create tenant: {} failed", e);
}
- return false;
}
/**
* create linux user
*
- * @param userName user name
+ * @param userName user name
* @param userGroup user group
* @throws IOException in case of an I/O error
*/
@@ -237,7 +234,7 @@ public class OSUtils {
/**
* create mac user (Supports Mac OSX 10.10+)
*
- * @param userName user name
+ * @param userName user name
* @param userGroup user group
* @throws IOException in case of an I/O error
*/
@@ -256,7 +253,7 @@ public class OSUtils {
/**
* create windows user
*
- * @param userName user name
+ * @param userName user name
* @param userGroup user group
* @throws IOException in case of an I/O error
*/
@@ -304,7 +301,7 @@ public class OSUtils {
* get sudo command
*
* @param tenantCode tenantCode
- * @param command command
+ * @param command command
* @return result of sudo execute command
*/
public static String getSudoCmd(String tenantCode, String command) {
diff --git
a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java
b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java
index 3cda6ac099..f43b19c444 100644
---
a/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java
+++
b/dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java
@@ -78,7 +78,7 @@ public class TaskExecutionContextUtils {
throw ex;
} catch (Exception ex) {
throw new TaskException(
- String.format("TenantCode: %s doesn't exist",
taskExecutionContext.getTenantCode()));
+ String.format("TenantCode: %s doesn't exist",
taskExecutionContext.getTenantCode()), ex);
}
}