|
|
@ -33,8 +33,13 @@ import org.apache.commons.lang3.SystemUtils; |
|
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.nio.file.FileSystems; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Files; |
|
|
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.Paths; |
|
|
|
|
|
|
|
import java.nio.file.attribute.UserPrincipal; |
|
|
|
|
|
|
|
import java.nio.file.attribute.UserPrincipalLookupService; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
@ -45,23 +50,24 @@ public class TaskExecutionCheckerUtils { |
|
|
|
|
|
|
|
|
|
|
|
public static void checkTenantExist(WorkerConfig workerConfig, TaskExecutionContext taskExecutionContext) { |
|
|
|
public static void checkTenantExist(WorkerConfig workerConfig, TaskExecutionContext taskExecutionContext) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
String tenantCode = taskExecutionContext.getTenantCode(); |
|
|
|
boolean osUserExistFlag; |
|
|
|
boolean osUserExistFlag; |
|
|
|
// if Using distributed is true and Currently supported systems are linux,Should not let it
|
|
|
|
// if Using distributed is true and Currently supported systems are linux,Should not let it
|
|
|
|
// automatically
|
|
|
|
// automatically
|
|
|
|
// create tenants,so TenantAutoCreate has no effect
|
|
|
|
// create tenants,so TenantAutoCreate has no effect
|
|
|
|
if (workerConfig.isTenantDistributedUser() && SystemUtils.IS_OS_LINUX) { |
|
|
|
if (workerConfig.isTenantDistributedUser() && SystemUtils.IS_OS_LINUX) { |
|
|
|
// use the id command to judge in linux
|
|
|
|
// use the id command to judge in linux
|
|
|
|
osUserExistFlag = OSUtils.existTenantCodeInLinux(taskExecutionContext.getTenantCode()); |
|
|
|
osUserExistFlag = OSUtils.existTenantCodeInLinux(tenantCode); |
|
|
|
} else if (OSUtils.isSudoEnable() && workerConfig.isTenantAutoCreate()) { |
|
|
|
} else if (OSUtils.isSudoEnable() && workerConfig.isTenantAutoCreate()) { |
|
|
|
// if not exists this user, then create
|
|
|
|
// if not exists this user, then create
|
|
|
|
OSUtils.createUserIfAbsent(taskExecutionContext.getTenantCode()); |
|
|
|
OSUtils.createUserIfAbsent(tenantCode); |
|
|
|
osUserExistFlag = OSUtils.getUserList().contains(taskExecutionContext.getTenantCode()); |
|
|
|
osUserExistFlag = OSUtils.getUserList().contains(tenantCode); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
osUserExistFlag = OSUtils.getUserList().contains(taskExecutionContext.getTenantCode()); |
|
|
|
osUserExistFlag = OSUtils.getUserList().contains(tenantCode); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!osUserExistFlag) { |
|
|
|
if (!osUserExistFlag) { |
|
|
|
throw new TaskException( |
|
|
|
throw new TaskException( |
|
|
|
String.format("TenantCode: %s doesn't exist", taskExecutionContext.getTenantCode())); |
|
|
|
String.format("TenantCode: %s doesn't exist", tenantCode)); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (TaskException ex) { |
|
|
|
} catch (TaskException ex) { |
|
|
|
throw ex; |
|
|
|
throw ex; |
|
|
@ -75,13 +81,14 @@ public class TaskExecutionCheckerUtils { |
|
|
|
try { |
|
|
|
try { |
|
|
|
// local execute path
|
|
|
|
// local execute path
|
|
|
|
String execLocalPath = FileUtils.getProcessExecDir( |
|
|
|
String execLocalPath = FileUtils.getProcessExecDir( |
|
|
|
|
|
|
|
taskExecutionContext.getTenantCode(), |
|
|
|
taskExecutionContext.getProjectCode(), |
|
|
|
taskExecutionContext.getProjectCode(), |
|
|
|
taskExecutionContext.getProcessDefineCode(), |
|
|
|
taskExecutionContext.getProcessDefineCode(), |
|
|
|
taskExecutionContext.getProcessDefineVersion(), |
|
|
|
taskExecutionContext.getProcessDefineVersion(), |
|
|
|
taskExecutionContext.getProcessInstanceId(), |
|
|
|
taskExecutionContext.getProcessInstanceId(), |
|
|
|
taskExecutionContext.getTaskInstanceId()); |
|
|
|
taskExecutionContext.getTaskInstanceId()); |
|
|
|
taskExecutionContext.setExecutePath(execLocalPath); |
|
|
|
taskExecutionContext.setExecutePath(execLocalPath); |
|
|
|
FileUtils.createWorkDirIfAbsent(execLocalPath); |
|
|
|
createDirectoryWithOwner(Paths.get(execLocalPath), taskExecutionContext.getTenantCode()); |
|
|
|
} catch (Throwable ex) { |
|
|
|
} catch (Throwable ex) { |
|
|
|
throw new TaskException("Cannot create process execute dir", ex); |
|
|
|
throw new TaskException("Cannot create process execute dir", ex); |
|
|
|
} |
|
|
|
} |
|
|
@ -131,4 +138,23 @@ public class TaskExecutionCheckerUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void createDirectoryWithOwner(Path filePath, String tenant) { |
|
|
|
|
|
|
|
if (Files.exists(filePath)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Files.createDirectories(filePath); |
|
|
|
|
|
|
|
if (!OSUtils.isSudoEnable()) { |
|
|
|
|
|
|
|
// we need to open sudo, then we can change the owner.
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
UserPrincipalLookupService userPrincipalLookupService = |
|
|
|
|
|
|
|
FileSystems.getDefault().getUserPrincipalLookupService(); |
|
|
|
|
|
|
|
UserPrincipal tenantPrincipal = userPrincipalLookupService.lookupPrincipalByName(tenant); |
|
|
|
|
|
|
|
Files.setOwner(filePath, tenantPrincipal); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
throw new TaskException("Set tenant directory permission failed, tenant: " + tenant, e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|