From fb47b8438de77f20cc67c938a4fb38cfa0f1af92 Mon Sep 17 00:00:00 2001 From: zhangboxuan Date: Thu, 25 Apr 2024 20:17:55 +0800 Subject: [PATCH] =?UTF-8?q?fix=20task=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=B0=86?= =?UTF-8?q?=E4=BA=91=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=8C=87=E6=B4=BE=E7=BB=99?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServerVmMoveToPortalGroupParam.java | 12 ++ .../service/CloudOrganizationService.java | 8 + .../impl/CloudOrganizationServiceImpl.java | 25 ++++ .../manage/config/MCConfigProperties.java | 4 + .../KylinHttpResponseServerVmConstants.java | 2 + .../cloud/manage/ctrl/ServerVmCtrl.java | 21 +++ .../mc/resp/KcpServerVmSummaryResp.java | 1 + .../req/servervm/QueryTransferOrgParams.java | 12 ++ .../req/servervm/ServerVmTransferParam.java | 20 +++ .../cloud/manage/service/OrgService.java | 9 ++ .../cloud/manage/service/ServerVmService.java | 23 +++ .../manage/service/impl/OrgServiceImpl.java | 49 ++++++ .../service/impl/ServerVmServiceImpl.java | 141 +++++++++++++++++- 13 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/common/servervm/ServerVmMoveToPortalGroupParam.java create mode 100644 mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/QueryTransferOrgParams.java create mode 100644 mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/ServerVmTransferParam.java diff --git a/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/common/servervm/ServerVmMoveToPortalGroupParam.java b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/common/servervm/ServerVmMoveToPortalGroupParam.java new file mode 100644 index 0000000..e896265 --- /dev/null +++ b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/common/servervm/ServerVmMoveToPortalGroupParam.java @@ -0,0 +1,12 @@ +package com.hnkylin.cloud.core.common.servervm; + +import lombok.Data; + +/** + * Created by kylin-ksvd on 21-7-12. + */ +@Data +public class ServerVmMoveToPortalGroupParam { + private String machineUUid; + private String moveToUser; +} diff --git a/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/CloudOrganizationService.java b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/CloudOrganizationService.java index 41d2fa4..577ad00 100644 --- a/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/CloudOrganizationService.java +++ b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/CloudOrganizationService.java @@ -35,5 +35,13 @@ public interface CloudOrganizationService extends IService */ CloudOrganizationDo getDefaultTopOrg(); + /** + * 根据vdc集合获取组织列表 + * + * @param vdcList + * @return + */ + List getOrgListByVdcList(List vdcList); + } diff --git a/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/impl/CloudOrganizationServiceImpl.java b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/impl/CloudOrganizationServiceImpl.java index b3848c6..7c34226 100644 --- a/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/impl/CloudOrganizationServiceImpl.java +++ b/mcp-cloud-core/src/main/java/com/hnkylin/cloud/core/service/impl/CloudOrganizationServiceImpl.java @@ -4,11 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnkylin.cloud.core.common.KylinCommonConstants; +import com.hnkylin.cloud.core.domain.CloudOrgVdcDo; import com.hnkylin.cloud.core.domain.CloudOrganizationDo; import com.hnkylin.cloud.core.mapper.CloudOrganizationMapper; +import com.hnkylin.cloud.core.service.CloudOrgVdcService; import com.hnkylin.cloud.core.service.CloudOrganizationService; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -16,6 +19,8 @@ import java.util.stream.Collectors; public class CloudOrganizationServiceImpl extends ServiceImpl implements CloudOrganizationService { + @Resource + private CloudOrgVdcService cloudOrgVdcService; @Override public List queryAllOrgList() { CloudOrganizationDo organizationDo = new CloudOrganizationDo(); @@ -77,4 +82,24 @@ public class CloudOrganizationServiceImpl extends ServiceImpl(userOrgDo); return getOne(wrapper); } + + @Override + public List getOrgListByVdcList(List vdcList) { + CloudOrgVdcDo orgVdcDo = new CloudOrgVdcDo(); + orgVdcDo.setDeleteFlag(false); + QueryWrapper orgVdcDoWrapper = + new QueryWrapper<>(orgVdcDo); + orgVdcDoWrapper.in("vdc_id", vdcList); + List orgVdcList = cloudOrgVdcService.getBaseMapper().selectList(orgVdcDoWrapper); + List orgIdList = orgVdcList.stream().map(CloudOrgVdcDo::getOrgId).collect(Collectors.toList()); + if (orgIdList.isEmpty()) { + return new ArrayList<>(); + } + + CloudOrganizationDo organizationDo = new CloudOrganizationDo(); + organizationDo.setDeleteFlag(Boolean.FALSE); + QueryWrapper organizationDoWrapper = new QueryWrapper<>(organizationDo); + organizationDoWrapper.in("id", orgIdList); + return baseMapper.selectList(organizationDoWrapper); + } } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/config/MCConfigProperties.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/config/MCConfigProperties.java index 284d043..43e6802 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/config/MCConfigProperties.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/config/MCConfigProperties.java @@ -161,4 +161,8 @@ public class MCConfigProperties { //已读告警 private String ignoreNotificationsUrl; + //将云服务器移动到自服务分组下 + private String moveMachineToPortalGroup; + + } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/constant/KylinHttpResponseServerVmConstants.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/constant/KylinHttpResponseServerVmConstants.java index 48fda1d..7108cc5 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/constant/KylinHttpResponseServerVmConstants.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/constant/KylinHttpResponseServerVmConstants.java @@ -24,5 +24,7 @@ public interface KylinHttpResponseServerVmConstants { String BATCH_OPERATE_ERR = "批量操作失败"; + String TRANSFER_ERR = "转移失败,超出转移用户所在组资源限制"; + } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/ctrl/ServerVmCtrl.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/ctrl/ServerVmCtrl.java index ea501ac..61a5bd1 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/ctrl/ServerVmCtrl.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/ctrl/ServerVmCtrl.java @@ -14,8 +14,11 @@ import com.hnkylin.cloud.manage.constant.KylinHttpResponseServerVmConstants; import com.hnkylin.cloud.manage.entity.LoginUserVo; import com.hnkylin.cloud.manage.entity.mc.resp.*; import com.hnkylin.cloud.manage.entity.req.cluster.BaseClusterParam; +import com.hnkylin.cloud.manage.entity.req.servervm.QueryTransferOrgParams; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmOperateLogPageParam; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmPageParam; +import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmTransferParam; +import com.hnkylin.cloud.manage.entity.resp.org.ParentOrgRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.PageServerVmRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.ServerVmZoneOrgTreeRespDto; import com.hnkylin.cloud.manage.service.ServerVmService; @@ -260,4 +263,22 @@ public class ServerVmCtrl { } + @PostMapping("/transferCanSelectOrg") + public BaseResult> transferCanSelectOrg(@RequestBody QueryTransferOrgParams queryTransferOrgParams, + @LoginUser LoginUserVo loginUserVo) { + return BaseResult.success(serverVmService.transferCanSelectOrg(queryTransferOrgParams, loginUserVo)); + + } + + @PostMapping("/serverVmTransfer") + @ParamCheck + public BaseResult serverVmTransfer(@ModelCheck(notNull = true) @RequestBody + ServerVmTransferParam serverVmTransferParam, + @LoginUser LoginUserVo loginUserVo) { + serverVmService.serverVmTransfer(serverVmTransferParam, loginUserVo); + return BaseResult.success(null); + + } + + } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/mc/resp/KcpServerVmSummaryResp.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/mc/resp/KcpServerVmSummaryResp.java index e68e8cd..afc7ce2 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/mc/resp/KcpServerVmSummaryResp.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/mc/resp/KcpServerVmSummaryResp.java @@ -29,5 +29,6 @@ public class KcpServerVmSummaryResp { private BigDecimal diskPercent; + private String plateformType; } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/QueryTransferOrgParams.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/QueryTransferOrgParams.java new file mode 100644 index 0000000..44f3ff7 --- /dev/null +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/QueryTransferOrgParams.java @@ -0,0 +1,12 @@ +package com.hnkylin.cloud.manage.entity.req.servervm; + + +import lombok.Data; + +@Data +public class QueryTransferOrgParams { + + private Integer clusterId; + + +} diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/ServerVmTransferParam.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/ServerVmTransferParam.java new file mode 100644 index 0000000..52a49cf --- /dev/null +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/entity/req/servervm/ServerVmTransferParam.java @@ -0,0 +1,20 @@ +package com.hnkylin.cloud.manage.entity.req.servervm; + + +import com.hnkylin.cloud.core.annotation.FieldCheck; +import lombok.Data; + +@Data +public class ServerVmTransferParam { + + @FieldCheck(notNull = true, notNullMessage = "云服务器不能为空") + private String machineUUid; + + @FieldCheck(notNull = true, notNullMessage = "用户不能为空") + private Integer transferToUserId; + + + private Integer clusterId; + + +} diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/OrgService.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/OrgService.java index 62ac4b9..d7180dc 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/OrgService.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/OrgService.java @@ -111,5 +111,14 @@ public interface OrgService { */ OrgSummaryRespDto orgSummary(BaseOrgParam baseOrgParam, LoginUserVo loginUserVo); + /** + * 云服务器转移可获取的组织列表 + * + * @param loginUserVo + * @param zoneId 可用区ID + * @return + */ + List transferCanSelectOrg(LoginUserVo loginUserVo, Integer zoneId); + } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/ServerVmService.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/ServerVmService.java index 295944f..b655511 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/ServerVmService.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/ServerVmService.java @@ -10,8 +10,11 @@ import com.hnkylin.cloud.core.common.servervm.ServerVmMonitorInfoRespDto; import com.hnkylin.cloud.core.enums.McStartVmErrorCode; import com.hnkylin.cloud.manage.entity.LoginUserVo; import com.hnkylin.cloud.manage.entity.mc.resp.*; +import com.hnkylin.cloud.manage.entity.req.servervm.QueryTransferOrgParams; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmOperateLogPageParam; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmPageParam; +import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmTransferParam; +import com.hnkylin.cloud.manage.entity.resp.org.ParentOrgRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.PageServerVmRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.ServerVmZoneOrgTreeRespDto; import org.springframework.http.ResponseEntity; @@ -170,4 +173,24 @@ public interface ServerVmService { LoginUserVo loginUserVo); + /** + * 云服务器转移 + * + * @param serverVmTransferParam + * @param loginUserVo + */ + void serverVmTransfer(ServerVmTransferParam serverVmTransferParam, LoginUserVo loginUserVo); + + + + + /** + * 云服务器转移跨组织可转移组 + * + * @param queryTransferOrgParams + * @param loginUserVo + * @return + */ + List transferCanSelectOrg(QueryTransferOrgParams queryTransferOrgParams, LoginUserVo loginUserVo); + } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/OrgServiceImpl.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/OrgServiceImpl.java index 8327805..297d128 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/OrgServiceImpl.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/OrgServiceImpl.java @@ -721,4 +721,53 @@ public class OrgServiceImpl implements OrgService { return orgSummary; } + + + @Override + public List transferCanSelectOrg(LoginUserVo loginUserVo, Integer zoneId) { + + //获取可用区绑定的VDC列表 + List vdcList = cloudVdcService.vdcListByZone(zoneId); + + if (!vdcList.isEmpty()) { + //获取绑定可用区的组织列表 + List bindZoneOrgList = + cloudOrganizationService.getOrgListByVdcList(vdcList.stream().map(CloudVdcDo::getId).collect(Collectors.toList())); + List bindZoneOrgIdList = + bindZoneOrgList.stream().map(CloudOrganizationDo::getId).collect(Collectors.toList()); + //获取登录用户组织 + CloudOrganizationDo loginUserOrg = getByUserId(loginUserVo.getUserId()); + List childOrgList = cloudOrganizationService.listChildOrgByOrgId(loginUserOrg.getId()); + + + //数据过滤,获取绑定了可用区的登录用户可见的组织列表 + List bindZoneVisibleOrgList = + childOrgList.stream().filter(item -> bindZoneOrgIdList.contains(item.getId())).collect(Collectors.toList()); + if (bindZoneVisibleOrgList.isEmpty()) { + return new ArrayList<>(); + } + + List parentOrgList = new ArrayList<>(); + //用户是否是平台管理用户 + boolean platformUser = userService.judgeIfPlatformUser(loginUserVo.getUserId()); + if (platformUser) { + CloudOrganizationDo topOrg = cloudOrganizationService.getDefaultTopOrg(); + for (CloudOrganizationDo orgDo : bindZoneVisibleOrgList) { + if (Objects.equals(orgDo.getParentId(), topOrg.getId())) { + parentOrgList.add(formatParentOrgDto(orgDo, bindZoneVisibleOrgList, null)); + } + } + } else { + for (CloudOrganizationDo orgDo : bindZoneVisibleOrgList) { + if (Objects.equals(orgDo.getId(), loginUserOrg.getId())) { + parentOrgList.add(formatParentOrgDto(orgDo, bindZoneVisibleOrgList, null)); + } + } + } + + return parentOrgList; + + } + return new ArrayList<>(); + } } diff --git a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/ServerVmServiceImpl.java b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/ServerVmServiceImpl.java index e666cbc..e492ba9 100644 --- a/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/ServerVmServiceImpl.java +++ b/mcp-cloud-manage/src/main/java/com/hnkylin/cloud/manage/service/impl/ServerVmServiceImpl.java @@ -9,9 +9,7 @@ import com.hnkylin.cloud.core.common.*; import com.hnkylin.cloud.core.common.servervm.*; import com.hnkylin.cloud.core.config.exception.KylinException; import com.hnkylin.cloud.core.domain.*; -import com.hnkylin.cloud.core.enums.McServerVmStatus; -import com.hnkylin.cloud.core.enums.McStartVmErrorCode; -import com.hnkylin.cloud.core.enums.RoleType; +import com.hnkylin.cloud.core.enums.*; import com.hnkylin.cloud.core.service.*; import com.hnkylin.cloud.manage.config.MCConfigProperties; import com.hnkylin.cloud.manage.constant.KylinCloudManageConstants; @@ -19,10 +17,15 @@ import com.hnkylin.cloud.manage.constant.KylinHttpResponseServerVmConstants; import com.hnkylin.cloud.manage.entity.LoginUserVo; import com.hnkylin.cloud.manage.entity.mc.req.ServerVmOperateLogReq; import com.hnkylin.cloud.manage.entity.mc.resp.*; +import com.hnkylin.cloud.manage.entity.req.servervm.QueryTransferOrgParams; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmOperateLogPageParam; import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmPageParam; +import com.hnkylin.cloud.manage.entity.req.servervm.ServerVmTransferParam; +import com.hnkylin.cloud.manage.entity.resp.org.ParentOrgRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.PageServerVmRespDto; import com.hnkylin.cloud.manage.entity.resp.serverVm.ServerVmZoneOrgTreeRespDto; +import com.hnkylin.cloud.manage.entity.resp.vdc.VdcArchitectureUsedResourceDto; +import com.hnkylin.cloud.manage.entity.resp.vdc.VdcUsedResourceDto; import com.hnkylin.cloud.manage.entity.resp.zone.ZoneInfoDto; import com.hnkylin.cloud.manage.enums.ZoneOrgUserType; import com.hnkylin.cloud.manage.service.*; @@ -97,6 +100,10 @@ public class ServerVmServiceImpl implements ServerVmService { @Resource private RoleService roleService; + + @Resource + private CloudZoneClusterService cloudZoneClusterService; + @Override public List serverVmZoneTree(Integer clusterId, LoginUserVo loginUserVo) { @@ -1082,4 +1089,132 @@ public class ServerVmServiceImpl implements ServerVmService { return bytes; } + @Override + public List transferCanSelectOrg(QueryTransferOrgParams queryTransferOrgParams, + LoginUserVo loginUserVo) { + + CloudZoneClusterDo zoneClusterDo = cloudZoneClusterService.getByClusterId(queryTransferOrgParams.getClusterId()); + + return orgService.transferCanSelectOrg(loginUserVo, zoneClusterDo.getZoneId()); + } + @Override + public void serverVmTransfer(ServerVmTransferParam serverVmTransferParam, LoginUserVo loginUserVo) { + + + + CloudUserDo transferToUser = cloudUserService.getById(serverVmTransferParam.getTransferToUserId()); + //调用mc接口,将对应云服务器移动到自服务分组下 + ServerVmMoveToPortalGroupParam serverVmMoveToPortalGroupParam = new ServerVmMoveToPortalGroupParam(); + serverVmMoveToPortalGroupParam.setMachineUUid(serverVmTransferParam.getMachineUUid()); + serverVmMoveToPortalGroupParam.setMoveToUser(transferToUser.getUserName()); + + try { + mcHttpService.noDataCommonMcRequest(serverVmTransferParam.getClusterId(), + serverVmMoveToPortalGroupParam, + mcConfigProperties.getMoveMachineToPortalGroup(), loginUserVo.getUserName(), 0); + transferMachine(serverVmMoveToPortalGroupParam.getMachineUUid(), + serverVmTransferParam.getTransferToUserId(), serverVmTransferParam.getClusterId(), true, + loginUserVo); + } catch (Exception e) { + throw new KylinException(KylinHttpResponseServerVmConstants.OPERATE_ERR); + } + } + + /** + * 指派云服务器给自服务用户 + * + * @param machineUuid + * @param userId + * @param clusterId + * @param verifyFlag + * @param loginUserVo + */ + private void transferMachine(String machineUuid, Integer userId, Integer clusterId, + Boolean verifyFlag, + LoginUserVo loginUserVo) { + + CloudUserMachineDo cloudUserMachineDo = + cloudUserMachineService.getUserMachineDoByUuid(machineUuid); + if (Objects.nonNull(cloudUserMachineDo)) { + //云服务器原属于用户 + CloudUserDo oldUserDo = cloudUserService.getById(cloudUserMachineDo.getUserId()); + CloudUserDo newUser = cloudUserService.getById(userId); + if (verifyFlag) { + //判断两个是否是同一个组织,如果是 则直接转移,如果不是则需要校验新用户所在组的资源池剩余额度是否允许 + if (!Objects.equals(oldUserDo.getOrganizationId(), newUser.getOrganizationId())) { + transferVerify(userId, clusterId, machineUuid, loginUserVo); + } + } + + cloudUserMachineDo.setUserId(userId); + cloudUserMachineDo.setUpdateTime(new Date()); + cloudUserMachineDo.setUpdateBy(loginUserVo.getUserId()); + cloudUserMachineService.updateById(cloudUserMachineDo); + } else { + if (verifyFlag) { + transferVerify(userId, clusterId, machineUuid, loginUserVo); + } + //说明是非自服务用户云服务器转移给自服务用户 采用到期告警策略。默认半年使用期 + Date afterMonthDate = DateUtils.getMonthAfter(new Date(), 6); + cloudUserMachineDo = new CloudUserMachineDo(); + cloudUserMachineDo.setDeadlineFlag(Boolean.FALSE); + cloudUserMachineDo.setDeadlineTime(afterMonthDate); + cloudUserMachineDo.setUserId(userId); + cloudUserMachineDo.setMachineUuid(machineUuid); + cloudUserMachineDo.setCreateBy(loginUserVo.getUserId()); + cloudUserMachineDo.setDeadlineType(ServerVmDeadlineType.POWER_OFF); + cloudUserMachineDo.setCreateTime(new Date()); + cloudUserMachineDo.setClusterId(clusterId); + cloudUserMachineService.save(cloudUserMachineDo); + } + } + + /** + * 云服务器转移校验 + * + * @param loginUserVo + */ + private void transferVerify(Integer userId, Integer clusterId, String machineUuid, LoginUserVo loginUserVo) { + //1:获取云服务器详情(架构,cpu,内存,存储) + ServerVmBaseParam serverVmBaseParam = new ServerVmBaseParam(); + serverVmBaseParam.setServerVmUuid(machineUuid); + KcpServerVmSummaryResp kcpServerVmSummaryResp = serverVmSummary(serverVmBaseParam, loginUserVo); + if (Objects.nonNull(kcpServerVmSummaryResp)) { + + + //根据申请用户获取用户对应的组织 + CloudOrganizationDo orgDo = + cloudOrganizationService.getById(cloudUserService.getById(userId).getOrganizationId()); + //获取组织绑定的VDC + CloudVdcDo vdcDo = vdcService.getVdcByOrgId(orgDo.getId()); + //获取VDC资源使用情况 + VdcUsedResourceDto vdcResourceDto = vdcService.getVdcResourceInfo(vdcDo.getId(), loginUserVo); + + //VDC-各架构资源使用情况 + List vdcArchitectureUsedResourceList = + vdcResourceDto.getVdcArchitectureUsedResourceList(); + + + ArchitectureType architectureType = + KcpCommonUtil.changeToKcpArchitectureType(kcpServerVmSummaryResp.getPlateformType()); + VdcArchitectureUsedResourceDto architectureUsedResource = + vdcArchitectureUsedResourceList.stream().filter(item -> Objects.equals(item.getArchitectureType(), + architectureType)) + .findFirst().orElse(null); + + + Integer serverVmCpu = kcpServerVmSummaryResp.getCpuCount().intValue(); + Integer serverVmMem = kcpServerVmSummaryResp.getMemoryTotal().intValue(); + Integer serverVmDisk = kcpServerVmSummaryResp.getDiskTotal().intValue(); + //校验vdc-架构-cpu + if ((Objects.isNull(architectureUsedResource) || serverVmCpu > architectureUsedResource.getSurplusCpu()) + || (Objects.isNull(architectureUsedResource) || serverVmMem > architectureUsedResource.getSurplusMem()) + || (serverVmDisk > vdcResourceDto.getSurplusStorage())) { + throw new KylinException(KylinHttpResponseServerVmConstants.TRANSFER_ERR); + } + } else { + throw new KylinException(KylinHttpResponseServerVmConstants.OPERATE_ERR); + } + } + } -- Gitee