From bdf7c154877ce72dad3df71078a9259459ae9b3b Mon Sep 17 00:00:00 2001 From: duanguoqiang Date: Tue, 25 Feb 2025 11:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8D=87portal=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=98=93=E7=94=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ops/HostUserController.java | 12 ++++ .../system/service/ops/IHostUserService.java | 8 +++ .../service/ops/impl/HostUserServiceImpl.java | 18 +++++ ...tionToolPortalDownloadInfoServiceImpl.java | 72 +++++++++++++------ 4 files changed, 89 insertions(+), 21 deletions(-) diff --git a/openGauss-datakit/visualtool-api/src/main/java/org/opengauss/admin/web/controller/ops/HostUserController.java b/openGauss-datakit/visualtool-api/src/main/java/org/opengauss/admin/web/controller/ops/HostUserController.java index 888b21d23..a550fa933 100644 --- a/openGauss-datakit/visualtool-api/src/main/java/org/opengauss/admin/web/controller/ops/HostUserController.java +++ b/openGauss-datakit/visualtool-api/src/main/java/org/opengauss/admin/web/controller/ops/HostUserController.java @@ -89,4 +89,16 @@ public class HostUserController extends BaseController { hostUserService.del(hostUserId); return AjaxResult.success(); } + + /** + * check if the user has root permission + * + * @param userId user ID + * @return has root permission or not + */ + @GetMapping("/hasRootPermission/{userId}") + public AjaxResult hasRootPermission(@PathVariable("userId") String userId) { + boolean hasPermission = hostUserService.hasRootPermission(userId); + return AjaxResult.success(hasPermission); + } } diff --git a/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/IHostUserService.java b/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/IHostUserService.java index 147ce9fab..b1a746f89 100644 --- a/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/IHostUserService.java +++ b/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/IHostUserService.java @@ -63,4 +63,12 @@ public interface IHostUserService extends IService { void cleanPassword(String hostUserId); OpsHostUserEntity getHostUserByUsername(String hostId, String sshUsername); + + /** + * check if the user has root permission + * + * @param userId user ID + * @return has root permission or not + */ + boolean hasRootPermission(String userId); } diff --git a/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/impl/HostUserServiceImpl.java b/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/impl/HostUserServiceImpl.java index 09b83a5fc..4d0612746 100644 --- a/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/impl/HostUserServiceImpl.java +++ b/openGauss-datakit/visualtool-service/src/main/java/org/opengauss/admin/system/service/ops/impl/HostUserServiceImpl.java @@ -304,4 +304,22 @@ public class HostUserServiceImpl extends ServiceImpl implements MigrationToolPortalDownloadInfoService { + private static final List SUPPORT_SYSTEM_INFO_LIST = Collections.unmodifiableList( + Arrays.asList( + "centos7_x86_64", + "openEuler20.03_x86_64", + "openEuler20.03_aarch64", + "openEuler22.03_x86_64", + "openEuler22.03_aarch64" + ) + ); + @Autowired @AutowiredType(AutowiredType.Type.PLUGIN_MAIN) private IHostService hostService; /** - * get portal download information list + * get portal installation package download information list * - * @author duanguoqiang * @param hostId the host ID - * @return java.util.List - * @since 0.0 + * @return package download information list */ @Override public List getPortalDownloadInfoList(String hostId) { - OpsHostEntity opsHostEntity = hostService.getMappedHostEntityById(hostId); - if (StringUtils.isEmpty(opsHostEntity.getOsVersion())) { - hostService.updateHostOsVersion(opsHostEntity); - } - String osVersion = opsHostEntity.getOsVersion(); - String os = opsHostEntity.getOs(); - String cpuArch = opsHostEntity.getCpuArch(); - + OpsHostEntity opsHostEntity = checkHost(hostId); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(MigrationToolPortalDownloadInfo::getHostOs, os).eq(MigrationToolPortalDownloadInfo::getHostCpuArch, cpuArch).eq(MigrationToolPortalDownloadInfo::getHostOsVersion, osVersion); - List portalDownloadInfos = list(queryWrapper); + queryWrapper.eq(MigrationToolPortalDownloadInfo::getHostOs, opsHostEntity.getOs()) + .eq(MigrationToolPortalDownloadInfo::getHostCpuArch, opsHostEntity.getCpuArch()) + .eq(MigrationToolPortalDownloadInfo::getHostOsVersion, opsHostEntity.getOsVersion()); + List portalDownloadInfos = list(queryWrapper); if (ObjectUtils.isEmpty(portalDownloadInfos)) { - queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(MigrationToolPortalDownloadInfo::getHostOs, "centos") - .eq(MigrationToolPortalDownloadInfo::getHostCpuArch, "x86_64") - .eq(MigrationToolPortalDownloadInfo::getHostOsVersion, "7"); - portalDownloadInfos = list(queryWrapper); + throw new PortalInstallException("The online installation package information list is empty"); } - return portalDownloadInfos; } + + private OpsHostEntity checkHost(String hostId) { + OpsHostEntity opsHost = hostService.getById(hostId); + if (ObjectUtils.isEmpty(opsHost)) { + log.error("Cannot get host information by host id: {}", hostId); + throw new PortalInstallException("Host does not exist"); + } + + String os = opsHost.getOs(); + String osVersion = opsHost.getOsVersion(); + String cpuArch = opsHost.getCpuArch(); + if (ObjectUtils.isEmpty(os)) { + throw new PortalInstallException("Failed to get the host os information"); + } + if (ObjectUtils.isEmpty(osVersion)) { + throw new PortalInstallException("Failed to get the host os version"); + } + if (ObjectUtils.isEmpty(cpuArch)) { + throw new PortalInstallException("Failed to get the host cpu architecture"); + } + + String sysInfo = os + osVersion + "_" + cpuArch; + if (SUPPORT_SYSTEM_INFO_LIST.stream().noneMatch(item -> item.equalsIgnoreCase(sysInfo))) { + throw new PortalInstallException( + "No matching installation package for this system architecture: " + os + osVersion + "_" + cpuArch); + } + return opsHost; + } } -- Gitee