Browse Source

Fix auto create tennat concurrently will cause the task failed (#15909)

3.2.2-release-bak
Wenjun Ruan 6 months ago committed by GitHub
parent
commit
446f6ba72b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  2. 2
      dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java

17
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,12 +210,11 @@ 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;
}
/**

2
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);
}
}

Loading…
Cancel
Save