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 * @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 not exists this user, then create
if (!getUserList().contains(userName)) { if (!getUserList().contains(userName)) {
boolean isSuccess = createUser(userName); createUser(userName);
log.info("create user {} {}", userName, isSuccess ? "success" : "fail");
} }
} }
@ -197,13 +196,12 @@ public class OSUtils {
* @param userName user name * @param userName user name
* @return true if creation was successful, otherwise false * @return true if creation was successful, otherwise false
*/ */
public static boolean createUser(String userName) { public static void createUser(String userName) {
try { try {
String userGroup = getGroup(); String userGroup = getGroup();
if (StringUtils.isEmpty(userGroup)) { if (StringUtils.isEmpty(userGroup)) {
String errorLog = String.format("%s group does not exist for this operating system.", userGroup); throw new UnsupportedOperationException(
log.error(errorLog); "There is no userGroup exist cannot create tenant, please create userGroupFirst");
return false;
} }
if (SystemUtils.IS_OS_MAC) { if (SystemUtils.IS_OS_MAC) {
createMacUser(userName, userGroup); createMacUser(userName, userGroup);
@ -212,12 +210,11 @@ public class OSUtils {
} else { } else {
createLinuxUser(userName, userGroup); createLinuxUser(userName, userGroup);
} }
return true; log.info("Create tenant {} under userGroup: {} success", userName, userGroup);
} catch (Exception e) { } 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; throw ex;
} catch (Exception ex) { } catch (Exception ex) {
throw new TaskException( 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