From 76fa9721c675c5ec6ef520e0c0ac90fefb7f0bcf Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Mon, 2 Sep 2024 15:59:14 +0800 Subject: [PATCH 01/23] =?UTF-8?q?=E5=A4=A9=E7=BF=BC=E4=BA=91-=E7=89=A9?= =?UTF-8?q?=E7=90=86=E6=9C=BA=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/controller/FlavorController.java | 9 ++ .../plugin/domain/model/HostModel.java | 2 + .../plugin/domain/model/ImageModel.java | 1 + .../domain/model/PhysicalServerModel.java | 92 +++++++++++++++++++ .../plugin/domain/model/TianyiSyncModel.java | 1 + .../provider/common/TianyiFlavorProvider.java | 21 +++++ .../common/TianyiLocationProvider.java | 9 ++ .../compute/TianyiPhysicalProvider.java | 80 ++++++++++++++++ .../tianyiconvertor/PhyscicalConvertor.java | 72 +++++++++++++++ .../ctstack/plugin/service/FlavorService.java | 2 + .../service/impl/FlavorServiceImpl.java | 37 +++++++- .../service/impl/TianyiTransporter.java | 46 ++++++++++ 12 files changed, 369 insertions(+), 3 deletions(-) create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java index 25e9ce77..f2024f21 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java @@ -116,6 +116,15 @@ public class FlavorController { return flavorService.remove(id, context); } + @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机规格") + @DeleteMapping("/listPhysical") + public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, + @RequestParam(value = "regionId") String regionId, + @RequestParam(value = "zoneId") String zoneId, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return flavorService.listPhysical(vendorId, regionId, zoneId, context); + } + /** * 批量删除云主机规格 * diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/HostModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/HostModel.java index edf5c11a..8879d7d8 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/HostModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/HostModel.java @@ -90,6 +90,8 @@ public class HostModel { private Long hddTotalSizeByte; private Long ssdTotalSizeByte; + private Boolean isHost; + /** * @param name * @param uuid diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ImageModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ImageModel.java index 15c703ae..767e8aa4 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ImageModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ImageModel.java @@ -75,4 +75,5 @@ public class ImageModel { // hcso private String wholeImageType; private String backupUuid; + private Boolean isPhysical; } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java new file mode 100644 index 00000000..ace7f1df --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java @@ -0,0 +1,92 @@ +package com.bocloud.ctstack.plugin.domain.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PhysicalServerModel { + + private Long id; + + private String regionId; + + private String zoneId; + + private Long vendorId; + + private String resourceId; + + private String instanceUuid; + + private String deviceUuid; + + private String deviceType; + + private String name; + + private String remark; + + private String systemVolumeRaidId; + + private String dataVolumeRaidId; + + private String imageUuid; + + private Long osType; + + private String osTypeName; + + private String vpcUuid; + + private String subnetUuid; + + private String privateIp; + + private String publicIp; + + private String ebmState; + + private String flavor; + + private String interfaces; + + private String raidDetail; + + private String attachedVolumes; + + private String deviceDetail; + + private Boolean freezing; + + private String localId;// cloudtower监控需要用到 + + private Boolean expired; + + private String createTime; + + private String updatedTime; + + private String deleteTime; + + private String expiredTime; + + private Boolean onDemand; + + private Date gmtCreate; + + private Date gmtModify; + + private Long creatorId; + + private Long tenantId; + + private Long projectId; + + private Boolean isDeleted; + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java index c216c52a..4f5988e0 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java @@ -32,6 +32,7 @@ public class TianyiSyncModel { private List networkCardModels; private List clusterModels; private List hostModels; + private List physicalModels; private ResourcePoolModel resourcePoolModel; private List rdsModels; private List contarinerClusterModels; diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java index 280016c6..9d743587 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java @@ -75,4 +75,25 @@ public class TianyiFlavorProvider extends TianyiServerProvider { return new GeneralResult(false, "查询规格列表失败", e.getMessage()); } } + + public GeneralResult listPhysical(String regionId, String azName) { + try { + String apiUrl = "/v4/ebm/device-type-list"; + JSONObject body = new JSONObject(); + body.put("regionID", this.getRegionId()); + body.put("azName", azName); + + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询物理机规格列表"); + + List results = JSONArray.parseArray(returnObj.getString("results"), JSONObject.class); + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "物理机规格列表为空"); + } + return new GeneralResult(true, results, "查询物理机规格列表成功"); + } catch (Exception e) { + log.error("查询物理机规格列表失败 : " + e); + return new GeneralResult(false, "查询物理机规格列表失败", e.getMessage()); + } + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index 25b239b8..7cf14d3e 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -8,6 +8,7 @@ import com.bocloud.ctstack.plugin.domain.model.database.ProjectModel; import com.bocloud.ctstack.plugin.domain.model.database.RdsModel; import com.bocloud.ctstack.plugin.provider.TianyiProvider; import com.bocloud.ctstack.plugin.provider.compute.TianyiImageProvider; +import com.bocloud.ctstack.plugin.provider.compute.TianyiPhysicalProvider; import com.bocloud.ctstack.plugin.provider.compute.TianyiServerProvider; import com.bocloud.ctstack.plugin.provider.container.TianYiContainerClusterProvider; import com.bocloud.ctstack.plugin.provider.database.TianyiRdsProvider; @@ -152,6 +153,7 @@ public class TianyiLocationProvider extends TianyiProvider { hostModel.setName(object.getString("hostName")); hostModel.setHostName(object.getString("hostName")); hostModel.setHostIp(object.getString("ip")); + hostModel.setIsHost(true); String cpuInfo = object.getString("cpuInfo"); if (!StringUtils.isEmpty(cpuInfo)) { @@ -216,6 +218,13 @@ public class TianyiLocationProvider extends TianyiProvider { if(clusterResult.isSuccess()){ syncModel.setHostModels(clusterResult.getData()); } + log.info("获取物理机信息..."); + TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(this.getButler()); + GeneralResult> physicalResult = physicalProvider.list(); + log.info("同步物理机结果:{}", physicalResult.isSuccess()); + if(physicalResult.isSuccess()){ + syncModel.setPhysicalModels(physicalResult.getData()); + } // 同步vpc log.info("获取vpc信息..."); TianyiVpcProvider tianyiVpcProvider = new TianyiVpcProvider(this.getButler()); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java new file mode 100644 index 00000000..1b5e95e9 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -0,0 +1,80 @@ +package com.bocloud.ctstack.plugin.provider.compute; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.bocloud.cmp.domain.Butler; +import com.bocloud.ctstack.plugin.domain.model.PhysicalServerModel; +import com.bocloud.ctstack.plugin.provider.TianyiProvider; +import com.bocloud.ctstack.plugin.provider.tianyiconvertor.BeanConvertor; +import com.bocloud.ctstack.plugin.provider.tianyiconvertor.PhyscicalConvertor; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.Result; +import com.megatron.common.utils.ListTool; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author yuemian + * @create 2024-09-02 + * @Description: 物理机相关接口 + */ + +@Slf4j +public class TianyiPhysicalProvider extends TianyiProvider { + + public TianyiPhysicalProvider(Butler butler) { + super(butler); + } + + private BeanConvertor physcicalConvertor = new PhyscicalConvertor(); + + + public GeneralResult> list() { + try { + List physicalModels = new ArrayList<>(); + List zoneList = this.listZones(this.getRegionId()); + if (!CollectionUtils.isEmpty(zoneList)) { + List results = new ArrayList<>(); + for (JSONObject zone : zoneList) { + String apiUrl = "/v4/ebm/list"; + JSONObject body = new JSONObject(); + body.put("regionID", this.getRegionId()); + body.put("azName", zone.getString("name")); + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询物理机列表"); + results.addAll(JSONArray.parseArray(returnObj.getString("results"), JSONObject.class)); + } + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "物理机列表为空"); + } + for (JSONObject model : results) { + physicalModels.add(physcicalConvertor.convertModel(model)); + } + } + return new GeneralResult(true, physicalModels, "查询宿主机列表成功"); + } catch (Exception e) { + log.error("查询宿主机列表失败 :", e); + return new GeneralResult(false, "查询宿主机列表失败" + e.getMessage()); + } + } + + public List listZones(String regionId) { + try { + Thread.sleep(1500); + String apiUrl = "/v4/region/get-zones"; + JSONObject body = new JSONObject(); + body.put("regionID", regionId); + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询可用区列表"); + + List jsonObjects = JSONArray.parseArray(returnObj.getString("zoneList"), JSONObject.class); + return jsonObjects; + } catch (Exception e) { + log.error("查询资源池列表失败 :", e); + return null; + } + } +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java new file mode 100644 index 00000000..366ecf89 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java @@ -0,0 +1,72 @@ +package com.bocloud.ctstack.plugin.provider.tianyiconvertor; + + +import com.alibaba.fastjson.JSONObject; +import com.bocloud.ctstack.plugin.domain.model.PhysicalServerModel; + +/** + * @Package: com.bocloud.cmp.provider.tianyiconvertor + * @ClassName: VpcConvertor1 + * @Author: 胡文涛 + * @CreateTime: 2020/9/30 10:25 + * @Description: + */ +public class PhyscicalConvertor implements BeanConvertor { + + + + @Override + public PhysicalServerModel convertModel(JSONObject info) { + PhysicalServerModel model = new PhysicalServerModel(); + if (null != info) { + model.setRegionId(info.getString("region")); + model.setZoneId(info.getString("azName")); + model.setName(info.getString("name")); + model.setResourceId(info.getString("resourceId")); + model.setInstanceUuid(info.getString("instanceUUID")); + model.setDeviceUuid(info.getString("deviceUuid")); + model.setDeviceType(info.getString("deviceType")); + model.setName(info.getString("name")); + model.setRemark(info.getString("description")); + model.setSystemVolumeRaidId(info.getString("systemVolumeRaidID")); + model.setDataVolumeRaidId(info.getString("dataVolumeRaidID")); + model.setImageUuid(info.getString("imageID")); + model.setOsType(info.getLong("osType")); + model.setOsTypeName(info.getString("osTypeName")); + model.setVpcUuid(info.getString("vpcID")); + model.setSubnetUuid(info.getString("subnetID")); + model.setPrivateIp(info.getString("privateIp")); + model.setPublicIp(info.getString("publicIp")); + model.setEbmState(info.getString("ebmState")); + if (info.getJSONObject("flavor") != null) { + model.setFlavor(info.getJSONObject("flavor").toJSONString()); + } + if (info.getJSONArray("interfaces") != null) { + model.setInterfaces(info.getJSONArray("interfaces").toJSONString()); + } + if (info.getJSONObject("raidDetail") != null) { + model.setRaidDetail(info.getJSONObject("raidDetail").toJSONString()); + } + if (info.getJSONArray("attachedVolumes") != null) { + model.setAttachedVolumes(info.getJSONArray("attachedVolumes").toJSONString()); + } + if (info.getJSONObject("deviceDetail") != null) { + model.setDeviceDetail(info.getJSONObject("deviceDetail").toJSONString()); + } + model.setFreezing(info.getBoolean("freezing")); + model.setExpired(info.getBoolean("expired")); + model.setCreateTime(info.getString("createdTime")); + model.setUpdatedTime(info.getString("updatedTime")); + model.setDeleteTime(info.getString("deleteTime")); + model.setExpiredTime(info.getString("expiredTime")); + model.setOnDemand(info.getBoolean("onDemand")); + model.setIsDeleted(false); + model.setCreatorId(1L); + model.setTenantId(0L); + model.setProjectId(0L); + } + return model; + } + + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/FlavorService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/FlavorService.java index 3798ac5f..8c9006b2 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/FlavorService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/FlavorService.java @@ -56,6 +56,8 @@ public interface FlavorService { */ GeneralResult remove(Long id, RequestContext context); + GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, RequestContext context); + /** * 修改配置 * diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java index 4297e871..82f439e2 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java @@ -7,6 +7,7 @@ import com.bocloud.cmp.util.ResourceEventPublisher; import com.bocloud.ctstack.plugin.config.ButlerConfig; import com.bocloud.ctstack.plugin.entity.Flavor; import com.bocloud.ctstack.plugin.entity.Region; +import com.bocloud.ctstack.plugin.provider.common.TianyiFlavorProvider; import com.bocloud.ctstack.plugin.repository.CloudServerRepository; import com.bocloud.ctstack.plugin.repository.FlavorExtraSpecsRepository; import com.bocloud.ctstack.plugin.repository.FlavorRepository; @@ -15,8 +16,17 @@ import com.bocloud.ctstack.plugin.service.FlavorService; import com.bocloud.ctstack.plugin.util.ExcelExporter; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.megatron.common.model.*; -import com.megatron.common.utils.*; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.GridBean; +import com.megatron.common.model.OperateResult; +import com.megatron.common.model.Pager; +import com.megatron.common.model.Param; +import com.megatron.common.model.RequestContext; +import com.megatron.common.utils.Common; +import com.megatron.common.utils.DateTools; +import com.megatron.common.utils.GridHelper; +import com.megatron.common.utils.ListTool; +import com.megatron.common.utils.MapTools; import com.megatron.framework.lock.LockFactory; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -28,7 +38,12 @@ import org.springframework.util.ObjectUtils; import java.io.IOException; import java.io.OutputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -142,6 +157,21 @@ public class FlavorServiceImpl implements FlavorService { } + @Override + public GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, RequestContext context) { + try { + CloudVendor vendor = cloudVendorRepository.query(vendorId); + if (vendor == null) { + return GeneralResult.FAILED("云平台不存在"); + } + TianyiFlavorProvider flavorProvider = new TianyiFlavorProvider(butlerConfig.regionButler(vendor.getUuid(), regionId)); + return flavorProvider.listPhysical(regionId, zoneId); + } catch (Exception e) { + log.error("查询物理机规格失败"+ e.getMessage(), e); + return GeneralResult.FAILED("查询物理机规格失败"+ e.getMessage()); + } + } + @Override public GeneralResult create(Flavor flavor, RequestContext context) { return new GeneralResult<>(false, "暂不支持!"); @@ -152,6 +182,7 @@ public class FlavorServiceImpl implements FlavorService { return new GeneralResult<>(false, "暂不支持!"); } + @Override public GeneralResult modify(Flavor flavorParam, RequestContext context) { return new GeneralResult<>(false, "暂不支持!"); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java index 3230e772..714bfa9f 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java @@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.cmp.entity.CloudVendor; +import com.bocloud.cmp.entity.PhysicalServer; import com.bocloud.cmp.entity.Server; import com.bocloud.cmp.entity.ServerConfig; import com.bocloud.cmp.enums.ResourceCategory; +import com.bocloud.cmp.repository.PhysicalServerRepository; import com.bocloud.cmp.repository.ServerRepository; import com.bocloud.ctstack.plugin.config.ButlerConfig; import com.bocloud.ctstack.plugin.domain.model.*; @@ -102,6 +104,8 @@ public class TianyiTransporter { private CtResourcePoolInfoRepository ctResourcePoolInfoRepository; @Autowired private CloudRdsRepository cloudRdsRepository; + @Autowired + private PhysicalServerRepository physicalServerRepository; public Result transport(CloudVendor vendor, Long operator) { @@ -173,6 +177,10 @@ public class TianyiTransporter { log.info("Starting sync host......"); this.syncHost(hostModels, vendor.getId(), userId); log.info("End sync host......"); + //同步物理机 + log.info("Starting sync physical server......"); + this.syncPhysicalServer(model.getPhysicalModels(), vendor.getId(), userId); + log.info("End sync physical server......"); // 同步vpc log.info("Starting sync vpc......"); this.syncVpc(model.getVpcModels(), vendor.getId(), userId, region); @@ -414,6 +422,44 @@ public class TianyiTransporter { } } + private void syncPhysicalServer(List physicalServerModels, Long vendorId, Long userId) { + if (ListTool.isEmpty(physicalServerModels)) { + List servers = physicalServerRepository.listByVendor(vendorId); + physicalServerRepository.removeByVendor(vendorId, userId); + return; + } + List physicalServers = physicalServerRepository.listByVendor(vendorId); + Map serverMap = Maps.newHashMap(); + for (PhysicalServer server : physicalServers) { + serverMap.put(server.getInstanceUuid(), server); + } + for (PhysicalServerModel physicalServerModel : physicalServerModels) { + PhysicalServer server = null; + if (serverMap.containsKey(physicalServerModel.getInstanceUuid())) { + server = serverMap.get(physicalServerModel.getInstanceUuid()); + if (server != null) { + BeanUtils.copyProperties(physicalServerModel, server, new String[]{"id", "tenantId", "creatorId", "projectId", "isDeleted", "gmtCreate"}); + serverMap.remove(server.getInstanceUuid()); + continue; + } + } + server = new PhysicalServer(); + BeanUtils.copyProperties(physicalServerModel, server); + server.setVendorId(vendorId); + server.setIsDeleted(false); + server.setGmtCreate(new Date()); + server.setGmtModify(new Date()); + server.setCreatorId(userId); + server.setTenantId(0L); + server.setProjectId(0L); + physicalServerRepository.save(server); + } + for (Map.Entry entry : serverMap.entrySet()) { + Long serverId = entry.getValue().getId(); + physicalServerRepository.remove(serverId, userId); + } + } + /** * @author Hu Wentao * @date 2020/10/29 10:31 From ed48babcea8b79cba9ec5c38167a6f586aca273e Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Mon, 2 Sep 2024 16:56:00 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E5=A4=A9=E7=BF=BC=E4=BA=91-=E7=89=A9?= =?UTF-8?q?=E7=90=86=E6=9C=BA=E6=9F=A5=E8=AF=A2=E3=80=81=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PhysicalServerController.java | 75 +++++++++ .../domain/model/PhysicalServerModel.java | 2 + .../compute/TianyiPhysicalProvider.java | 39 +++++ .../tianyiconvertor/PhyscicalConvertor.java | 1 + .../repository/PhysicalServerRepository.java | 73 ++++++++ .../plugin/service/PhysicalServerService.java | 26 +++ .../impl/PhysicalServerServiceImpl.java | 156 ++++++++++++++++++ .../service/impl/TianyiTransporter.java | 3 +- 8 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/repository/PhysicalServerRepository.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java new file mode 100644 index 00000000..6189c85e --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java @@ -0,0 +1,75 @@ +package com.bocloud.ctstack.plugin.controller; + +import com.bocloud.cmp.entity.PhysicalServer; +import com.bocloud.ctstack.plugin.service.PhysicalServerService; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.GridBean; +import com.megatron.common.model.Pager; +import com.megatron.common.model.RequestContext; +import com.megatron.common.utils.Common; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author zhangdi + * @since 2018/7/2 + */ +@RestController +@RequestMapping("/v1/physical/servers") +@Tag(name = "命名规则") +public class PhysicalServerController { + + @Autowired + private PhysicalServerService physicalServerService; + + + @Operation(tags = {"CMC", "CSC"}, summary = "获取命名规则列表") + @GetMapping + public GeneralResult> list(Pager pager, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return physicalServerService.list(pager, context); + } + + + @Operation(tags = {"CMC", "CSC"}, summary = "添加标签") + @PostMapping + public GeneralResult create(@RequestBody PhysicalServer physicalServer, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return physicalServerService.create(physicalServer, context); + } + + + @Operation(tags = {"CMC", "CSC"}, summary = "修改标签") + @PutMapping("/{id}") + public GeneralResult modify(@PathVariable(value = Common.ID) Long id, + @RequestBody PhysicalServer physicalServer, + @Value(Common.REQ_CONTEXT) RequestContext context) { + physicalServer.setId(id); + return physicalServerService.modify(physicalServer, context); + } + + @Operation(tags = {"CMC", "CSC"}, summary = "删除标签") + @DeleteMapping("/{id}") + public GeneralResult remove(@PathVariable(value = Common.ID) Long id, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return physicalServerService.remove(id, context); + } + + + @Operation(tags = {"CMC", "CSC"}, summary = "查看标签详情") + @GetMapping("/{id}") + public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { + return physicalServerService.detail(id); + } + +} \ No newline at end of file diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java index ace7f1df..aaeba42f 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java @@ -29,6 +29,8 @@ public class PhysicalServerModel { private String name; + private String displayName; + private String remark; private String systemVolumeRaidId; diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 1b5e95e9..8bad275b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -11,6 +11,7 @@ import com.megatron.common.model.GeneralResult; import com.megatron.common.model.Result; import com.megatron.common.utils.ListTool; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -77,4 +78,42 @@ public class TianyiPhysicalProvider extends TianyiProvider { return null; } } + + public GeneralResult modify(PhysicalServerModel model) { + try { + String apiUrl = "/v4/ebm/update"; + JSONObject headers = new JSONObject(); + headers.put("regionId", this.getRegionId()); + headers.put("instanceUUID", model.getInstanceUuid()); + if (StringUtils.isNotBlank(model.getRemark())) { + headers.put("description", model.getRemark()); + } + if (StringUtils.isNotBlank(model.getDisplayName())) { + headers.put("displayName", model.getDisplayName()); + } + + Result result = doPost(apiUrl, headers); + checkResult(result, "修改物理主机"); + return new GeneralResult(true, "修改物理机成功"); + } catch (Exception e) { + log.error("修改物理机失败 : " + e); + return new GeneralResult(false, "修改物理机失败", e.getMessage()); + } + } + + public GeneralResult remove(PhysicalServerModel model) { + try { + String apiUrl = "/v4/ebm/delete"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("regionID", this.getRegionId()); + jsonObject.put("azName", model.getZoneId()); + jsonObject.put("instanceUUID", model.getInstanceUuid()); + Result result = doPost(apiUrl, jsonObject); + checkResultArray(result, "删除物理机"); + return new GeneralResult(true, "删除物理机成功"); + } catch (Exception e) { + log.error("删除物理机失败 : " + e.getMessage(), e); + return new GeneralResult(false, "删除物理机失败", e.getMessage()); + } + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java index 366ecf89..0bcdbd0c 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/PhyscicalConvertor.java @@ -38,6 +38,7 @@ public class PhyscicalConvertor implements BeanConvertor { + + + public PhysicalServerRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) { + super(jdbcTemplate, npJdbcTemplate, service); + } + + public List listByVendor(Long vendorId) { + String sql = "select a.* from physical_server a where a.is_deleted = 0"; + Map params = new HashMap<>(8); + if (null != vendorId) { + sql += " and a.vendor_id = :vendorId"; + params.put(Common.VENDORID, vendorId); + } + return this.list(PhysicalServer.class, sql, params); + } + + public boolean removeByVendor(Long vendorId, Long userId) { + String sql = "update physical_server set is_deleted = true , gmt_modify = :gmtModify where is_deleted = 0 and vendor_id = :vendorId"; + Map params = MapTools.simpleMap(Common.VENDORID, vendorId); + params.put("gmtModify", new Date()); + return this.execute(sql, params) > 0; + } + + public boolean remove(Long id, Long userId) { + String sql = "update physical_server set is_deleted = true,gmt_modify = :gmtModify, mender_id = :userId where is_deleted = 0 and id = :id"; + Map params = MapTools.simpleMap("id", id); + params.put("gmtModify", new Date()); + params.put("userId", userId); + return this.execute(sql, params) > 0; + } + + public int count(List params) throws Exception { + String sql = "select count(1) from physical_server where 1 = 1 "; + sql = this.getQueryBuilder().build(sql, params, new HashMap<>(8), ""); + Map param = this.getQueryBuilder().getParam(params); + return this.countQuery(sql, param).intValue(); + } + + public List list(int page, int rows, List params, Map sorter) throws Exception { + String sql = "select a.* from physical_server a where 1 = 1 "; + sql = this.getQueryBuilder().build(sql, new Pager(page, rows, params, sorter), "a"); + Map param = this.getQueryBuilder().getParam(params); + return this.list(PhysicalServer.class, sql, param); + } + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java new file mode 100644 index 00000000..b9fbea75 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java @@ -0,0 +1,26 @@ +package com.bocloud.ctstack.plugin.service; + +import com.bocloud.cmp.entity.PhysicalServer; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.GridBean; +import com.megatron.common.model.Pager; +import com.megatron.common.model.RequestContext; + +public interface PhysicalServerService { + + + GeneralResult> list(Pager pager, RequestContext context); + + + GeneralResult detail(Long id); + + GeneralResult create(PhysicalServer physicalServer, RequestContext context); + + + GeneralResult modify(PhysicalServer physicalServer, RequestContext context); + + GeneralResult remove(Long id, RequestContext context); + + + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java new file mode 100644 index 00000000..faa8e3d1 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -0,0 +1,156 @@ +package com.bocloud.ctstack.plugin.service.impl; + +import com.bocloud.cmp.entity.CloudVendor; +import com.bocloud.cmp.entity.PhysicalServer; +import com.bocloud.cmp.repository.CloudVendorRepository; +import com.bocloud.ctstack.plugin.repository.PhysicalServerRepository; +import com.bocloud.ctstack.plugin.config.ButlerConfig; +import com.bocloud.ctstack.plugin.domain.model.PhysicalServerModel; +import com.bocloud.ctstack.plugin.entity.Label; +import com.bocloud.ctstack.plugin.provider.compute.TianyiPhysicalProvider; +import com.bocloud.ctstack.plugin.repository.ResourceEventRepository; +import com.bocloud.ctstack.plugin.repository.VolumeRepository; +import com.bocloud.ctstack.plugin.repository.VpcRepository; +import com.bocloud.ctstack.plugin.service.PhysicalServerService; +import com.google.common.collect.Maps; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.GridBean; +import com.megatron.common.model.Pager; +import com.megatron.common.model.Param; +import com.megatron.common.model.RequestContext; +import com.megatron.common.utils.GridHelper; +import com.megatron.framework.lock.AutoCloseLock; +import com.megatron.framework.lock.LockFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +@Slf4j +@Service("physicalServerService") +public class PhysicalServerServiceImpl implements PhysicalServerService { + + @Autowired + private LockFactory lockFactory; + @Autowired + private ResourceEventRepository resourceEventRepository; + @Autowired + private CloudVendorRepository cloudVendorRepository; + @Autowired + private VpcRepository vpcRepository; + @Autowired + private VolumeRepository volumeRepository; + @Autowired + private PhysicalServerRepository physicalServerRepository; + @Autowired + private ButlerConfig butlerConfig; + + @Override + public GeneralResult> list(Pager pager, RequestContext context) { + List list = null; + int total = 0; + GridBean gridBean = null; + try { + List params = Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>()); + Map sorter = Optional.ofNullable(pager.getSorter()).orElse(Maps.newHashMap()); + Boolean simple = Optional.ofNullable(pager.getSimple()).orElse(false); + Integer page = Optional.ofNullable(pager.getPage()).orElse(1); + Integer rows = Optional.ofNullable(pager.getRows()).orElse(10); + total = physicalServerRepository.count(params); + list = physicalServerRepository.list(page, rows, params, sorter); + gridBean = GridHelper.getBean(page, rows, total, list); + return new GeneralResult<>(true, gridBean, "查询成功"); + } catch (Exception e) { + log.error("list physical server failure:", e); + return new GeneralResult<>(false, "查询失败"); + } + } + + @Override + public GeneralResult detail(Long id) { + try { + PhysicalServer physicalServer = physicalServerRepository.get(PhysicalServer.class, id); + return new GeneralResult<>(true, physicalServer, "查询成功"); + } catch (Exception e) { + log.error("Get error message:", e); + return new GeneralResult<>(false, "查询失败"); + } + } + + @Override + public GeneralResult create(PhysicalServer physicalServer, RequestContext context) { + return null; + } + + @Override + public GeneralResult modify(PhysicalServer physicalServer, RequestContext context) { + String path = PhysicalServer.class.getSimpleName() + "_" + physicalServer.getId(); + try (AutoCloseLock lock = lockFactory.getACLock(path)) { + Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时"); + PhysicalServer oldServer = this.physicalServerRepository.get(PhysicalServer.class, physicalServer.getId()); + if (null == oldServer) { + log.warn("physical server does not exist!"); + return new GeneralResult<>(false, "数据不存在"); + } + CloudVendor vendor = cloudVendorRepository.query(oldServer.getVendorId()); + if (vendor == null) { + return GeneralResult.FAILED("云平台不存在"); + } + new Thread(() -> { + PhysicalServerModel model = new PhysicalServerModel(); + model.setInstanceUuid(oldServer.getInstanceUuid()); + model.setRegionId(oldServer.getRegionId()); + model.setZoneId(oldServer.getZoneId()); + model.setRemark(physicalServer.getRemark()); + TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), oldServer.getRegionId())); + GeneralResult result = physicalProvider.modify(model); + if (result.isSuccess()) { + oldServer.setRemark(physicalServer.getRemark()); + physicalServerRepository.update(oldServer); + } + }).start(); + return new GeneralResult<>(true, "修改任务已下发"); + } catch (Exception e) { + log.error("Modify label error:", e); + return new GeneralResult<>(false, "修改失败"); + } + } + + @Override + public GeneralResult remove(Long id, RequestContext context) { + String path = Label.class.getSimpleName() + "_" + id; + try (AutoCloseLock lock = lockFactory.getACLock(path)) { + Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时"); + PhysicalServer oldServer = this.physicalServerRepository.get(PhysicalServer.class, id); + if (null == oldServer) { + log.warn("physical server does not exist!"); + return new GeneralResult<>(false, "数据不存在"); + } + CloudVendor vendor = cloudVendorRepository.query(oldServer.getVendorId()); + if (vendor == null) { + return GeneralResult.FAILED("云平台不存在"); + } + new Thread(() -> { + PhysicalServerModel model = new PhysicalServerModel(); + model.setInstanceUuid(oldServer.getInstanceUuid()); + model.setRegionId(oldServer.getRegionId()); + model.setZoneId(oldServer.getZoneId()); + TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), oldServer.getRegionId())); + GeneralResult result = physicalProvider.remove(model); + if (result.isSuccess()) { + physicalServerRepository.remove(id, context.getTarget()); + } + }).start(); + return new GeneralResult<>(true, "删除任务下发"); + } catch (Exception e) { + log.error("Remove physical server error:", e); + return new GeneralResult<>(false, "删除任务下发失败"); + } + } +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java index 714bfa9f..02dc5680 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java @@ -8,7 +8,7 @@ import com.bocloud.cmp.entity.PhysicalServer; import com.bocloud.cmp.entity.Server; import com.bocloud.cmp.entity.ServerConfig; import com.bocloud.cmp.enums.ResourceCategory; -import com.bocloud.cmp.repository.PhysicalServerRepository; +import com.bocloud.ctstack.plugin.repository.PhysicalServerRepository; import com.bocloud.cmp.repository.ServerRepository; import com.bocloud.ctstack.plugin.config.ButlerConfig; import com.bocloud.ctstack.plugin.domain.model.*; @@ -439,6 +439,7 @@ public class TianyiTransporter { server = serverMap.get(physicalServerModel.getInstanceUuid()); if (server != null) { BeanUtils.copyProperties(physicalServerModel, server, new String[]{"id", "tenantId", "creatorId", "projectId", "isDeleted", "gmtCreate"}); + physicalServerRepository.update(server); serverMap.remove(server.getInstanceUuid()); continue; } From d41a504370554e19fe913955ac8fc4bc5f6de6a0 Mon Sep 17 00:00:00 2001 From: Hoshi <1196756653@qq.com> Date: Tue, 3 Sep 2024 09:33:46 +0800 Subject: [PATCH 03/23] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..93a5110b --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,2 @@ +@Library('jgpl_6.5') _ +servicePipeline() From fcc5f0404c71354f9a42bc737f7c6e63021ed0cc Mon Sep 17 00:00:00 2001 From: Hoshi <1196756653@qq.com> Date: Tue, 3 Sep 2024 10:21:06 +0800 Subject: [PATCH 04/23] =?UTF-8?q?=E5=8F=AA=E6=9E=84=E5=BB=BA=E5=A4=A9?= =?UTF-8?q?=E7=BF=BC=E4=BA=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a58d2b56..5b276589 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ bocloud.ctstack.plugin - bocloud.ctcloud.plugin + From 41f6ffaea8df386178e29d27e691b4602bc54bc8 Mon Sep 17 00:00:00 2001 From: Hoshi <1196756653@qq.com> Date: Tue, 3 Sep 2024 10:25:43 +0800 Subject: [PATCH 05/23] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A4=9A=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b276589..a58d2b56 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ bocloud.ctstack.plugin - + bocloud.ctcloud.plugin From c676cdea821bfc9f8fbe20f9eb5a9a90d76b6dd8 Mon Sep 17 00:00:00 2001 From: Hoshi <1196756653@qq.com> Date: Tue, 3 Sep 2024 10:30:35 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E5=8F=AA=E6=9E=84=E5=BB=BA=E5=A4=A9?= =?UTF-8?q?=E7=BF=BC=E4=BA=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a58d2b56..5b276589 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ bocloud.ctstack.plugin - bocloud.ctcloud.plugin + From aeb319b03905a143c9b9e60a98459bbed9310b89 Mon Sep 17 00:00:00 2001 From: Hoshi <1196756653@qq.com> Date: Tue, 3 Sep 2024 10:56:09 +0800 Subject: [PATCH 07/23] =?UTF-8?q?Jenkins=E8=B0=83=E8=AF=95=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 93a5110b..fd068593 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,2 +1,2 @@ @Library('jgpl_6.5') _ -servicePipeline() +servicePipeline() \ No newline at end of file From 2110cc845de2d5636c8f3b59ef3244c7cad0282b Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 11:12:37 +0800 Subject: [PATCH 08/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E8=A7=84=E6=A0=BC=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctstack/plugin/provider/common/TianyiFlavorProvider.java | 3 ++- .../bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java index 9d743587..df2f216e 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java @@ -76,7 +76,7 @@ public class TianyiFlavorProvider extends TianyiServerProvider { } } - public GeneralResult listPhysical(String regionId, String azName) { + public GeneralResult listFlavorPhysical(String regionId, String azName) { try { String apiUrl = "/v4/ebm/device-type-list"; JSONObject body = new JSONObject(); @@ -96,4 +96,5 @@ public class TianyiFlavorProvider extends TianyiServerProvider { return new GeneralResult(false, "查询物理机规格列表失败", e.getMessage()); } } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java index 82f439e2..b395d510 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/FlavorServiceImpl.java @@ -165,7 +165,7 @@ public class FlavorServiceImpl implements FlavorService { return GeneralResult.FAILED("云平台不存在"); } TianyiFlavorProvider flavorProvider = new TianyiFlavorProvider(butlerConfig.regionButler(vendor.getUuid(), regionId)); - return flavorProvider.listPhysical(regionId, zoneId); + return flavorProvider.listFlavorPhysical(regionId, zoneId); } catch (Exception e) { log.error("查询物理机规格失败"+ e.getMessage(), e); return GeneralResult.FAILED("查询物理机规格失败"+ e.getMessage()); From 0636f385bc9699c818457a5b6cf5a8137e95710b Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 11:12:57 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E9=95=9C=E5=83=8F=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/controller/ImageController.java | 10 +++++++++ .../provider/compute/TianyiImageProvider.java | 22 +++++++++++++++++++ .../ctstack/plugin/service/ImageService.java | 3 +++ .../plugin/service/impl/ImageServiceImpl.java | 16 ++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java index 0c18193a..a6cf6e5b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java @@ -298,4 +298,14 @@ public class ImageController { @Value(Common.REQ_CONTEXT) RequestContext context) { return imageService.copy(bean, context); } + + @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像") + @DeleteMapping("/listPhysical") + public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, + @RequestParam(value = "regionId") String regionId, + @RequestParam(value = "zoneId") String zoneId, + @RequestParam(value = "deviceType") String deviceType, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return imageService.listPhysical(vendorId, regionId, zoneId, deviceType, context); + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiImageProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiImageProvider.java index ed6ca84b..33bf9c2b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiImageProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiImageProvider.java @@ -222,4 +222,26 @@ public class TianyiImageProvider extends TianyiProvider { return new GeneralResult(false, "根据jobId查询磁盘JOB状态信息失败", e.getMessage()); } } + + public GeneralResult listImgaePhysical(String regionId, String azName, String deviceType) { + try { + String apiUrl = "/v4/ebm/image-list"; + JSONObject body = new JSONObject(); + body.put("regionID", this.getRegionId()); + body.put("azName", azName); + body.put("deviceType", deviceType); + + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询物理机镜像列表"); + + List results = JSONArray.parseArray(returnObj.getString("results"), JSONObject.class); + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "物理机镜像列表为空"); + } + return new GeneralResult(true, results, "查询物理机镜像列表成功"); + } catch (Exception e) { + log.error("查询物理机镜像列表失败 : " + e); + return new GeneralResult(false, "查询物理机镜像列表失败", e.getMessage()); + } + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/ImageService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/ImageService.java index 074eb379..9ba79c61 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/ImageService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/ImageService.java @@ -217,4 +217,7 @@ public interface ImageService { * @return */ GeneralResult copy(Image bean, RequestContext context); + + GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, String deviceType, RequestContext context); + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/ImageServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/ImageServiceImpl.java index 2d027e9a..b7948211 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/ImageServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/ImageServiceImpl.java @@ -18,6 +18,7 @@ import com.bocloud.cmp.util.ResourceEventPublisher; import com.bocloud.ctstack.plugin.config.ButlerConfig; import com.bocloud.ctstack.plugin.domain.model.ImageModel; import com.bocloud.ctstack.plugin.entity.*; +import com.bocloud.ctstack.plugin.provider.common.TianyiFlavorProvider; import com.bocloud.ctstack.plugin.provider.compute.TianyiImageProvider; import com.bocloud.ctstack.plugin.repository.*; import com.bocloud.ctstack.plugin.service.ImageService; @@ -1148,4 +1149,19 @@ public class ImageServiceImpl implements ImageService { public GeneralResult copy(Image bean, RequestContext context) { return new GeneralResult(false, "暂不支持"); } + + @Override + public GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, String deviceType, RequestContext context) { + try { + CloudVendor vendor = cloudVendorRepository.query(vendorId); + if (vendor == null) { + return GeneralResult.FAILED("云平台不存在"); + } + TianyiImageProvider imageProvider = new TianyiImageProvider(butlerConfig.regionButler(vendor.getUuid(), regionId)); + return imageProvider.listImgaePhysical(regionId, zoneId, deviceType); + } catch (Exception e) { + log.error("查询物理机镜像失败"+ e.getMessage(), e); + return GeneralResult.FAILED("查询物理机镜像失败"+ e.getMessage()); + } + } } \ No newline at end of file From c81027e127acc9ffe2cf9673f250b1370f120eb3 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 11:13:29 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E7=A3=81?= =?UTF-8?q?=E7=9B=98raid=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PhysicalServerController.java | 18 +++--- .../plugin/controller/VolumeController.java | 11 ++++ .../domain/model/PhysicalServerModel.java | 14 +++++ .../compute/TianyiPhysicalProvider.java | 60 +++++++++++++++++++ .../storage/TianyiVolumeProvider.java | 23 +++++++ .../ctstack/plugin/service/VolumeService.java | 2 + .../service/impl/VolumeServiceImpl.java | 16 +++++ 7 files changed, 135 insertions(+), 9 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java index 6189c85e..8a55b155 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java @@ -21,19 +21,19 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** - * @author zhangdi - * @since 2018/7/2 + * @author yuemian + * @since 2024/09/02 */ @RestController @RequestMapping("/v1/physical/servers") -@Tag(name = "命名规则") +@Tag(name = "物理机") public class PhysicalServerController { @Autowired private PhysicalServerService physicalServerService; - @Operation(tags = {"CMC", "CSC"}, summary = "获取命名规则列表") + @Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表") @GetMapping public GeneralResult> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) { @@ -41,15 +41,15 @@ public class PhysicalServerController { } - @Operation(tags = {"CMC", "CSC"}, summary = "添加标签") + @Operation(tags = {"CMC", "CSC"}, summary = "添加物理机") @PostMapping public GeneralResult create(@RequestBody PhysicalServer physicalServer, - @Value(Common.REQ_CONTEXT) RequestContext context) { + @Value(Common.REQ_CONTEXT) RequestContext context) { return physicalServerService.create(physicalServer, context); } - @Operation(tags = {"CMC", "CSC"}, summary = "修改标签") + @Operation(tags = {"CMC", "CSC"}, summary = "修改物理机") @PutMapping("/{id}") public GeneralResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody PhysicalServer physicalServer, @@ -58,7 +58,7 @@ public class PhysicalServerController { return physicalServerService.modify(physicalServer, context); } - @Operation(tags = {"CMC", "CSC"}, summary = "删除标签") + @Operation(tags = {"CMC", "CSC"}, summary = "删除物理机") @DeleteMapping("/{id}") public GeneralResult remove(@PathVariable(value = Common.ID) Long id, @Value(Common.REQ_CONTEXT) RequestContext context) { @@ -66,7 +66,7 @@ public class PhysicalServerController { } - @Operation(tags = {"CMC", "CSC"}, summary = "查看标签详情") + @Operation(tags = {"CMC", "CSC"}, summary = "查看物理机详情") @GetMapping("/{id}") public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { return physicalServerService.detail(id); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java index 4ee211fe..5ddcc405 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java @@ -425,4 +425,15 @@ public class VolumeController { // 分页查询volume return volumeService.listByInstanceId(instanceId, resourceSize); } + + @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像") + @DeleteMapping("/v1/volumes/raids") + public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, + @RequestParam(value = "regionId") String regionId, + @RequestParam(value = "zoneId") String zoneId, + @RequestParam(value = "deviceType") String deviceType, + @RequestParam(value = "volumeType") String volumeType, + @Value(Common.REQ_CONTEXT) RequestContext context) { + return volumeService.listVolumeRaid(vendorId, regionId, zoneId, deviceType, volumeType, context); + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java index aaeba42f..baef98e9 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/PhysicalServerModel.java @@ -91,4 +91,18 @@ public class PhysicalServerModel { private Boolean isDeleted; + private String hostname; + + private String extIp; + + private String password; + + private String vpcName; + + private Long cycleCount; + + private String cycleType; + + private Long orderCount; + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 8bad275b..c23a3c64 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -62,6 +62,64 @@ public class TianyiPhysicalProvider extends TianyiProvider { } } + /*public GeneralResult create(PhysicalServerModel model) { + try { + String apiUrl = "/v4/ebm/create"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("regionID", this.getRegionId()); + jsonObject.put("azName", model.getZoneId()); + jsonObject.put("name", model.getName()); + jsonObject.put("hostname", model.getHostname()); + jsonObject.put("description", model.getRemark()); + jsonObject.put("deviceType", model.getDeviceType()); + jsonObject.put("imageUUID", model.getImageUuid()); + jsonObject.put("password", model.getPassword()); + jsonObject.put("vpcID", model.getVpcUuid()); + jsonObject.put("extIP", model.getExtIp()); + jsonObject.put("systemVolumeRaidUUID", model.getSystemVolumeRaidId()); + jsonObject.put("dataVolumeRaidUUID", model.getDataVolumeRaidId()); + //网络数据 + JSONObject object = new JSONObject(); + object.put("title", model.getVpcName()); + object.put("master", true); + object.put("subnetID", model.getSubnetUuid()); + JSONArray networkCardList = new JSONArray(); + networkCardList.add(object); + jsonObject.put("networkCardList", networkCardList); + //订购时长 + if (model.getCycleCount() != null) { + jsonObject.put("cycleCount", model.getCycleCount()); + } + jsonObject.put("cycleType", model.getName()); + jsonObject.put("orderCount", model.getOrderCount()); + Result result = doPost(apiUrl, jsonObject); + JSONObject returnObj = checkResult(result, "创建物理机"); + List resources = returnObj.getJSONArray("resources").toJavaList(JSONObject.class); + String resourceID = resources.get(0).getString("resourceID"); + if (resourceID == null) { + return new GeneralResult(false, "创建物理机失败!"); + } + Long startTime = System.currentTimeMillis(); + while (true) { + sleepSomeTime(5000); + PhysicalServerModel physicalServerModel = (PhysicalServerModel) detail(resourceID, model.getRegionId(), false).getData(); + if (null != physicalServerModel) { + return new GeneralResult<>(true, physicalServerModel, "success"); + } else { + log.warn("根据ResourceId[{}]查询云主机信息返回空数据", resourceID); + } + Long endTime = System.currentTimeMillis(); + // 等待三分钟 + if (endTime - startTime > 15 * 60 * 1000) { + return GeneralResult.FAILED("查询资源详情超时!"); + } + } + } catch (Exception e) { + log.error("创建物理机失败 : " + e.getMessage(), e); + return GeneralResult.FAILED("创建物理机失败:" + e.getMessage()); + } + }*/ + public List listZones(String regionId) { try { Thread.sleep(1500); @@ -116,4 +174,6 @@ public class TianyiPhysicalProvider extends TianyiProvider { return new GeneralResult(false, "删除物理机失败", e.getMessage()); } } + + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/storage/TianyiVolumeProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/storage/TianyiVolumeProvider.java index d2f4a113..9c391d51 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/storage/TianyiVolumeProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/storage/TianyiVolumeProvider.java @@ -363,5 +363,28 @@ public class TianyiVolumeProvider extends TianyiProvider { } } + public GeneralResult listVolumeRaid(String regionId, String azName, String deviceType, String volumeType) { + try { + String apiUrl = "/v4/ebm/raid-type-list"; + JSONObject body = new JSONObject(); + body.put("regionID", this.getRegionId()); + body.put("azName", azName); + body.put("deviceType", deviceType); + body.put("volumeType", volumeType); + + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询磁盘raid列表"); + + List results = JSONArray.parseArray(returnObj.getString("results"), JSONObject.class); + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "磁盘raid列表为空"); + } + return new GeneralResult(true, results, "查询磁盘raid列表成功"); + } catch (Exception e) { + log.error("查询磁盘raid列表失败 : " + e); + return new GeneralResult(false, "查询磁盘raid列表失败", e.getMessage()); + } + } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/VolumeService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/VolumeService.java index 275a1a67..7b8ba0ce 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/VolumeService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/VolumeService.java @@ -226,4 +226,6 @@ public interface VolumeService { public GeneralResult> listByVaults(Pager pager, RequestContext context); public GeneralResult> listByInstanceId(String instanceId, Long resourceSize); + + public GeneralResult listVolumeRaid(Long vendorId, String regionId, String zoneId, String deviceType, String volumeType, RequestContext context); } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/VolumeServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/VolumeServiceImpl.java index 6c053ee4..69d82483 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/VolumeServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/VolumeServiceImpl.java @@ -24,6 +24,7 @@ import com.bocloud.ctstack.plugin.entity.ServerVolume; import com.bocloud.ctstack.plugin.entity.Snapshot; import com.bocloud.ctstack.plugin.entity.Storage; import com.bocloud.ctstack.plugin.entity.Volume; +import com.bocloud.ctstack.plugin.provider.common.TianyiFlavorProvider; import com.bocloud.ctstack.plugin.provider.storage.TianyiVolumeProvider; import com.bocloud.ctstack.plugin.provider.storage.TianyiVolumeSnapshotProvider; import com.bocloud.ctstack.plugin.repository.*; @@ -1859,4 +1860,19 @@ public class VolumeServiceImpl implements VolumeService { return new GeneralResult<>(false, e.getMessage()); } } + + @Override + public GeneralResult listVolumeRaid(Long vendorId, String regionId, String zoneId, String deviceType, String volumeType, RequestContext context) { + try { + CloudVendor vendor = cloudVendorRepository.query(vendorId); + if (vendor == null) { + return GeneralResult.FAILED("云平台不存在"); + } + TianyiVolumeProvider volumeProvider = new TianyiVolumeProvider(butlerConfig.regionButler(vendor.getUuid(), regionId)); + return volumeProvider.listVolumeRaid(regionId, zoneId, deviceType, volumeType); + } catch (Exception e) { + log.error("查询磁盘raid失败"+ e.getMessage(), e); + return GeneralResult.FAILED("查询磁盘raid失败"+ e.getMessage()); + } + } } From ce82e9271eada4b4362e8a98dcf9aad28f10059d Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 15:09:48 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E3=80=81=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/TianyiLocationProvider.java | 2 +- .../compute/TianyiPhysicalProvider.java | 80 ++++++++++++++----- .../repository/PhysicalServerRepository.java | 6 +- .../impl/PhysicalServerServiceImpl.java | 42 +++++++++- 4 files changed, 104 insertions(+), 26 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index 7cf14d3e..496aa0f9 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -220,7 +220,7 @@ public class TianyiLocationProvider extends TianyiProvider { } log.info("获取物理机信息..."); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(this.getButler()); - GeneralResult> physicalResult = physicalProvider.list(); + GeneralResult> physicalResult = physicalProvider.list(null); log.info("同步物理机结果:{}", physicalResult.isSuccess()); if(physicalResult.isSuccess()){ syncModel.setPhysicalModels(physicalResult.getData()); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index c23a3c64..0a4727f8 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -1,5 +1,6 @@ package com.bocloud.ctstack.plugin.provider.compute; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.cmp.domain.Butler; @@ -55,14 +56,14 @@ public class TianyiPhysicalProvider extends TianyiProvider { physicalModels.add(physcicalConvertor.convertModel(model)); } } - return new GeneralResult(true, physicalModels, "查询宿主机列表成功"); + return new GeneralResult(true, physicalModels, "查询物理机列表成功"); } catch (Exception e) { - log.error("查询宿主机列表失败 :", e); - return new GeneralResult(false, "查询宿主机列表失败" + e.getMessage()); + log.error("查询物理机列表失败 :", e); + return new GeneralResult(false, "查询物理机列表失败" + e.getMessage()); } } - /*public GeneralResult create(PhysicalServerModel model) { + public GeneralResult create(PhysicalServerModel model) { try { String apiUrl = "/v4/ebm/create"; JSONObject jsonObject = new JSONObject(); @@ -95,30 +96,28 @@ public class TianyiPhysicalProvider extends TianyiProvider { Result result = doPost(apiUrl, jsonObject); JSONObject returnObj = checkResult(result, "创建物理机"); List resources = returnObj.getJSONArray("resources").toJavaList(JSONObject.class); - String resourceID = resources.get(0).getString("resourceID"); - if (resourceID == null) { - return new GeneralResult(false, "创建物理机失败!"); + if (CollectionUtils.isEmpty(resources)) { + return GeneralResult.FAILED("物理机创建失败:无创建resource信息返回"); } - Long startTime = System.currentTimeMillis(); - while (true) { - sleepSomeTime(5000); - PhysicalServerModel physicalServerModel = (PhysicalServerModel) detail(resourceID, model.getRegionId(), false).getData(); - if (null != physicalServerModel) { - return new GeneralResult<>(true, physicalServerModel, "success"); - } else { - log.warn("根据ResourceId[{}]查询云主机信息返回空数据", resourceID); - } - Long endTime = System.currentTimeMillis(); - // 等待三分钟 - if (endTime - startTime > 15 * 60 * 1000) { - return GeneralResult.FAILED("查询资源详情超时!"); - } + List models = new ArrayList<>(); + List resourceIds = new ArrayList<>(); + for (JSONObject resource : resources) { + String resourceId = resource.getString("resourceID"); + resourceIds.add(resourceId); } + GeneralResult modelResult = listByResourceId(resourceIds, model.getZoneId()); + Object modelObject = modelResult.getData(); + if (modelObject != null) { + models = JSONArray.parseArray(JSON.toJSONString(modelObject), PhysicalServerModel.class); + } else { + return GeneralResult.FAILED("物理主机批量创建完全失败"); + } + return new GeneralResult<>(true, models, "success"); } catch (Exception e) { log.error("创建物理机失败 : " + e.getMessage(), e); return GeneralResult.FAILED("创建物理机失败:" + e.getMessage()); } - }*/ + } public List listZones(String regionId) { try { @@ -176,4 +175,41 @@ public class TianyiPhysicalProvider extends TianyiProvider { } + public GeneralResult> listByResourceId(List resourceIds, String zoneId) { + try { + List physicalModels = new ArrayList<>(); + for (String resourceId : resourceIds) { + long startTime = System.currentTimeMillis(); + Boolean flag = true; + while (flag) { + if (System.currentTimeMillis() - startTime > 3 * 60 * 1000) { + flag = false; + } + String apiUrl = "/v4/ebm/list"; + JSONObject body = new JSONObject(); + body.put("regionID", this.getRegionId()); + body.put("azName", zoneId); + body.put("resourceID", resourceId); + Result result = doGet(apiUrl, null, body); + JSONObject returnObj = checkResult(result, "查询物理机列表"); + List results = new ArrayList<>(); + results.addAll(JSONArray.parseArray(returnObj.getString("results"), JSONObject.class)); + if (!CollectionUtils.isEmpty(results)) { + for (JSONObject model : results) { + physicalModels.add(physcicalConvertor.convertModel(model)); + } + flag = false; + } + } + } + if (physicalModels.size() != resourceIds.size()) { + return new GeneralResult<>(false, physicalModels, "部分成功"); + } + return new GeneralResult(true, physicalModels, "查询物理机列表成功"); + } catch (Exception e) { + log.error("查询物理机列表失败 :", e); + return new GeneralResult(false, "查询物理机列表失败" + e.getMessage()); + } + } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/repository/PhysicalServerRepository.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/repository/PhysicalServerRepository.java index 160ba511..f2bfd882 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/repository/PhysicalServerRepository.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/repository/PhysicalServerRepository.java @@ -64,7 +64,11 @@ public class PhysicalServerRepository extends BasicGenericDao list(int page, int rows, List params, Map sorter) throws Exception { - String sql = "select a.* from physical_server a where 1 = 1 "; + String sql = "select a.*, b.name vpc_name, c.name subnet_name from physical_server a " + + "left join vpc b on b.vpc_id = a.vpc_uuid " + + "left join subnet c on c.subnet_uuid = a.subnet_uuid " + + "left join zone d on d.zone_id = a.zone_id " + + "where 1 = 1 "; sql = this.getQueryBuilder().build(sql, new Pager(page, rows, params, sorter), "a"); Map param = this.getQueryBuilder().getParam(params); return this.list(PhysicalServer.class, sql, param); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java index faa8e3d1..1c852c5c 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -1,13 +1,15 @@ package com.bocloud.ctstack.plugin.service.impl; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.bocloud.cmp.entity.CloudVendor; import com.bocloud.cmp.entity.PhysicalServer; import com.bocloud.cmp.repository.CloudVendorRepository; -import com.bocloud.ctstack.plugin.repository.PhysicalServerRepository; import com.bocloud.ctstack.plugin.config.ButlerConfig; import com.bocloud.ctstack.plugin.domain.model.PhysicalServerModel; import com.bocloud.ctstack.plugin.entity.Label; import com.bocloud.ctstack.plugin.provider.compute.TianyiPhysicalProvider; +import com.bocloud.ctstack.plugin.repository.PhysicalServerRepository; import com.bocloud.ctstack.plugin.repository.ResourceEventRepository; import com.bocloud.ctstack.plugin.repository.VolumeRepository; import com.bocloud.ctstack.plugin.repository.VpcRepository; @@ -22,9 +24,11 @@ import com.megatron.common.utils.GridHelper; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; @@ -85,7 +89,39 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { @Override public GeneralResult create(PhysicalServer physicalServer, RequestContext context) { - return null; + // 云平台ID + Long vendorId = physicalServer.getVendorId(); + String path = CloudVendor.class.getSimpleName() + "_" + vendorId + "_SYNC"; + try (AutoCloseLock lock = lockFactory.getACLock(path)) { + if (!lock.acquire(10, TimeUnit.SECONDS)) { + log.warn("当前云平台存在同步任务,稍后创建"); + return GeneralResult.FAILED("当前云平台存在同步任务,稍后创建!"); + } + CloudVendor vendor = cloudVendorRepository.query(vendorId); + Assert.notNull(vendor, "云平台不存在"); + new Thread(() -> { + TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), physicalServer.getRegionId())); + PhysicalServerModel model = new PhysicalServerModel(); + BeanUtils.copyProperties(physicalServer, model); + GeneralResult result = physicalProvider.create(model); + if (result.isSuccess()) { + if (result.getData() != null) { + List models = JSONArray.parseArray(JSON.toJSONString(result.getData()), PhysicalServerModel.class); + if (!CollectionUtils.isEmpty(models)) { + for (PhysicalServerModel serverModel: models) { + PhysicalServer server = new PhysicalServer(); + BeanUtils.copyProperties(serverModel, server); + physicalServerRepository.save(server); + } + } + } + } + }).start(); + return new GeneralResult<>(true, "裸金属创建任务下发成功!"); + } catch (Exception e) { + log.error("Get error message:" + e.getMessage(), e); + return GeneralResult.FAILED("裸金属创建失败:" + e.getMessage()); + } } @Override @@ -108,10 +144,12 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { model.setRegionId(oldServer.getRegionId()); model.setZoneId(oldServer.getZoneId()); model.setRemark(physicalServer.getRemark()); + model.setDisplayName(physicalServer.getDisplayName()); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), oldServer.getRegionId())); GeneralResult result = physicalProvider.modify(model); if (result.isSuccess()) { oldServer.setRemark(physicalServer.getRemark()); + oldServer.setDisplayName(physicalServer.getDisplayName()); physicalServerRepository.update(oldServer); } }).start(); From bb3c7c8af4a33c75f022491a57ee40760eaa888c Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 15:18:45 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctstack/plugin/provider/common/TianyiLocationProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index 496aa0f9..7cf14d3e 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -220,7 +220,7 @@ public class TianyiLocationProvider extends TianyiProvider { } log.info("获取物理机信息..."); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(this.getButler()); - GeneralResult> physicalResult = physicalProvider.list(null); + GeneralResult> physicalResult = physicalProvider.list(); log.info("同步物理机结果:{}", physicalResult.isSuccess()); if(physicalResult.isSuccess()){ syncModel.setPhysicalModels(physicalResult.getData()); From ed94a2bca6edc82d5076667b1fc8316c4fc46e9f Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 16:57:15 +0800 Subject: [PATCH 13/23] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bocloud/ctstack/plugin/controller/FlavorController.java | 2 +- .../com/bocloud/ctstack/plugin/controller/ImageController.java | 2 +- .../com/bocloud/ctstack/plugin/controller/VolumeController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java index f2024f21..f3956f90 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/FlavorController.java @@ -117,7 +117,7 @@ public class FlavorController { } @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机规格") - @DeleteMapping("/listPhysical") + @GetMapping("/listPhysical") public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, @RequestParam(value = "regionId") String regionId, @RequestParam(value = "zoneId") String zoneId, diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java index a6cf6e5b..d2d4ce63 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/ImageController.java @@ -300,7 +300,7 @@ public class ImageController { } @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像") - @DeleteMapping("/listPhysical") + @GetMapping("/listPhysical") public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, @RequestParam(value = "regionId") String regionId, @RequestParam(value = "zoneId") String zoneId, diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java index 5ddcc405..702ff317 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/VolumeController.java @@ -427,7 +427,7 @@ public class VolumeController { } @Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像") - @DeleteMapping("/v1/volumes/raids") + @GetMapping("/v1/volumes/raids") public GeneralResult listPhysical(@RequestParam(value = "vendorId") Long vendorId, @RequestParam(value = "regionId") String regionId, @RequestParam(value = "zoneId") String zoneId, From 37b7a682fef5de4d4304d787af58b5d79271497b Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Tue, 3 Sep 2024 17:30:45 +0800 Subject: [PATCH 14/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=A0=E5=AF=86=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PhysicalServerServiceImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java index 1c852c5c..84caf05b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -15,6 +15,8 @@ import com.bocloud.ctstack.plugin.repository.VolumeRepository; import com.bocloud.ctstack.plugin.repository.VpcRepository; import com.bocloud.ctstack.plugin.service.PhysicalServerService; import com.google.common.collect.Maps; +import com.megatron.common.encrypt.AESEncryptor; +import com.megatron.common.encrypt.Encryptor; import com.megatron.common.model.GeneralResult; import com.megatron.common.model.GridBean; import com.megatron.common.model.Pager; @@ -24,6 +26,7 @@ import com.megatron.common.utils.GridHelper; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -91,6 +94,16 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { public GeneralResult create(PhysicalServer physicalServer, RequestContext context) { // 云平台ID Long vendorId = physicalServer.getVendorId(); + if (!StringUtils.isEmpty(physicalServer.getPassword())) { + Encryptor encryptor = new AESEncryptor(); + try { + String password = encryptor.decrypt(physicalServer.getPassword().trim(), null); + physicalServer.setPassword(password); + } catch (Exception e) { + log.error("Get error message:{}", e); + return new GeneralResult(false, e.getMessage()); + } + } String path = CloudVendor.class.getSimpleName() + "_" + vendorId + "_SYNC"; try (AutoCloseLock lock = lockFactory.getACLock(path)) { if (!lock.acquire(10, TimeUnit.SECONDS)) { From bd2026a49f2e098c470ebe17059486010f3bdb55 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 11:04:24 +0800 Subject: [PATCH 15/23] log --- .../ctstack/plugin/provider/compute/TianyiPhysicalProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 0a4727f8..baa9b1df 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -94,6 +94,7 @@ public class TianyiPhysicalProvider extends TianyiProvider { jsonObject.put("cycleType", model.getName()); jsonObject.put("orderCount", model.getOrderCount()); Result result = doPost(apiUrl, jsonObject); + log.info("物理机创建结果:" + JSON.toJSONString(result)); JSONObject returnObj = checkResult(result, "创建物理机"); List resources = returnObj.getJSONArray("resources").toJavaList(JSONObject.class); if (CollectionUtils.isEmpty(resources)) { From 70bb1a28233a4b510eb6633004dcd263a62be246 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 11:07:18 +0800 Subject: [PATCH 16/23] log --- .../ctstack/plugin/provider/compute/TianyiPhysicalProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index baa9b1df..4388d12f 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -64,6 +64,7 @@ public class TianyiPhysicalProvider extends TianyiProvider { } public GeneralResult create(PhysicalServerModel model) { + log.info("物理机创建参数:" + JSON.toJSONString(model)); try { String apiUrl = "/v4/ebm/create"; JSONObject jsonObject = new JSONObject(); From c0c01303f43664de7c5e071564a0326040a8e0ee Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 11:17:15 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctstack/plugin/provider/compute/TianyiPhysicalProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 4388d12f..52004a04 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -92,7 +92,7 @@ public class TianyiPhysicalProvider extends TianyiProvider { if (model.getCycleCount() != null) { jsonObject.put("cycleCount", model.getCycleCount()); } - jsonObject.put("cycleType", model.getName()); + jsonObject.put("cycleType", model.getCycleType()); jsonObject.put("orderCount", model.getOrderCount()); Result result = doPost(apiUrl, jsonObject); log.info("物理机创建结果:" + JSON.toJSONString(result)); From f8e69117fab04d9e414d17127c1c3170605a7b69 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 11:34:33 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctstack/plugin/provider/common/TianyiLocationProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index 7cf14d3e..d5ffa97b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -1,5 +1,6 @@ package com.bocloud.ctstack.plugin.provider.common; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.cmp.domain.Butler; @@ -208,7 +209,7 @@ public class TianyiLocationProvider extends TianyiProvider { // 同步地域 log.info("获取地域信息..."); GeneralResult regionList = this.listRegions(); - log.info("同步地域结果:{}",regionList.isSuccess()); + log.info("同步地域结果:{}", JSON.toJSONString(regionList)); if(regionList.isSuccess()){ syncModel.setRegionModels((List) regionList.getData()); } From e373e7f55ffbb4005e0c16f6971d65e68514d46d Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 13:34:43 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctstack/plugin/provider/common/TianyiFlavorProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java index df2f216e..a07871a5 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiFlavorProvider.java @@ -80,7 +80,7 @@ public class TianyiFlavorProvider extends TianyiServerProvider { try { String apiUrl = "/v4/ebm/device-type-list"; JSONObject body = new JSONObject(); - body.put("regionID", this.getRegionId()); + body.put("regionID", regionId); body.put("azName", azName); Result result = doGet(apiUrl, null, body); From 6b8fbe35273c0ed62340231e89cfdfab30ad488f Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 13:53:27 +0800 Subject: [PATCH 20/23] =?UTF-8?q?mysql=E5=90=8C=E6=AD=A5=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=8C=E5=85=88=E6=B3=A8=E9=87=8A=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/provider/common/TianyiLocationProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index d5ffa97b..2040c0e8 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -222,7 +222,7 @@ public class TianyiLocationProvider extends TianyiProvider { log.info("获取物理机信息..."); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(this.getButler()); GeneralResult> physicalResult = physicalProvider.list(); - log.info("同步物理机结果:{}", physicalResult.isSuccess()); + log.info("同步物理机结果:{}", JSON.toJSONString(physicalResult)); if(physicalResult.isSuccess()){ syncModel.setPhysicalModels(physicalResult.getData()); } @@ -369,7 +369,7 @@ public class TianyiLocationProvider extends TianyiProvider { } log.info("同步资源池信息:{}",poolModelGeneralResult.isSuccess()); - syncRds(syncModel); + //syncRds(syncModel); log.info("end sync ... current region is " + this.getRegionId()); return new GeneralResult(true, syncModel, "数据同步成功!"); From 19bd1bc2bcaf461d154823224434118c80ef9761 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 15:09:50 +0800 Subject: [PATCH 21/23] log --- .../ctstack/plugin/provider/compute/TianyiPhysicalProvider.java | 1 + .../bocloud/ctstack/plugin/service/impl/TianyiTransporter.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 52004a04..333787f4 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -56,6 +56,7 @@ public class TianyiPhysicalProvider extends TianyiProvider { physicalModels.add(physcicalConvertor.convertModel(model)); } } + log.info("results:" + JSON.toJSONString(physicalModels)); return new GeneralResult(true, physicalModels, "查询物理机列表成功"); } catch (Exception e) { log.error("查询物理机列表失败 :", e); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java index 02dc5680..10c882e8 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/TianyiTransporter.java @@ -424,7 +424,6 @@ public class TianyiTransporter { private void syncPhysicalServer(List physicalServerModels, Long vendorId, Long userId) { if (ListTool.isEmpty(physicalServerModels)) { - List servers = physicalServerRepository.listByVendor(vendorId); physicalServerRepository.removeByVendor(vendorId, userId); return; } From 3be319a59a5d51acbcc7b33cb9afe45d721177ec Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Wed, 4 Sep 2024 15:17:53 +0800 Subject: [PATCH 22/23] debug --- .../plugin/controller/PhysicalServerController.java | 6 ++++++ .../plugin/provider/compute/TianyiPhysicalProvider.java | 1 + .../ctstack/plugin/service/PhysicalServerService.java | 1 + .../plugin/service/impl/PhysicalServerServiceImpl.java | 8 ++++++++ 4 files changed, 16 insertions(+) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java index 8a55b155..4533ad8b 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java @@ -40,6 +40,12 @@ public class PhysicalServerController { return physicalServerService.list(pager, context); } + @Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表") + @GetMapping(value = "/listAll") + public GeneralResult listAll() { + return physicalServerService.listAll(); + } + @Operation(tags = {"CMC", "CSC"}, summary = "添加物理机") @PostMapping diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 333787f4..2f486192 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -41,6 +41,7 @@ public class TianyiPhysicalProvider extends TianyiProvider { if (!CollectionUtils.isEmpty(zoneList)) { List results = new ArrayList<>(); for (JSONObject zone : zoneList) { + log.info("zoneName:" + zone.getString("name")); String apiUrl = "/v4/ebm/list"; JSONObject body = new JSONObject(); body.put("regionID", this.getRegionId()); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java index b9fbea75..75949a62 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java @@ -10,6 +10,7 @@ public interface PhysicalServerService { GeneralResult> list(Pager pager, RequestContext context); + GeneralResult listAll(); GeneralResult detail(Long id); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java index 84caf05b..d910f93e 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -79,6 +79,14 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { } } + @Override + public GeneralResult listAll() { + CloudVendor vendor = cloudVendorRepository.query(1L); + TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), "2022guizhou_syj")); + GeneralResult result = physicalProvider.list(); + return null; + } + @Override public GeneralResult detail(Long id) { try { From b3ff2ed7e146a89a55440420a9f7f55cdb4587f9 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Thu, 5 Sep 2024 09:29:23 +0800 Subject: [PATCH 23/23] =?UTF-8?q?=E7=89=A9=E7=90=86=E6=9C=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PhysicalServerController.java | 6 ++-- .../compute/TianyiPhysicalProvider.java | 29 ++++++++++++++++++- .../plugin/service/PhysicalServerService.java | 2 +- .../impl/PhysicalServerServiceImpl.java | 4 +-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java index 4533ad8b..2f3cdc4a 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/PhysicalServerController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -42,8 +43,9 @@ public class PhysicalServerController { @Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表") @GetMapping(value = "/listAll") - public GeneralResult listAll() { - return physicalServerService.listAll(); + public GeneralResult listAll(@RequestParam(value = "regionId") String regionId, + @RequestParam(value = "regionId") String zoneId) { + return physicalServerService.listAll(regionId, zoneId); } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java index 2f486192..5b0e1391 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/compute/TianyiPhysicalProvider.java @@ -41,7 +41,6 @@ public class TianyiPhysicalProvider extends TianyiProvider { if (!CollectionUtils.isEmpty(zoneList)) { List results = new ArrayList<>(); for (JSONObject zone : zoneList) { - log.info("zoneName:" + zone.getString("name")); String apiUrl = "/v4/ebm/list"; JSONObject body = new JSONObject(); body.put("regionID", this.getRegionId()); @@ -216,4 +215,32 @@ public class TianyiPhysicalProvider extends TianyiProvider { } } + public GeneralResult> listAll(String regionId, String zoneId) { + try { + List physicalModels = new ArrayList<>(); + String apiUrl = "/v4/ebm/list"; + JSONObject body = new JSONObject(); + body.put("regionID", regionId); + body.put("azName", zoneId); + body.put("pageNo", 1); + body.put("pageSize", this.PAGE_SIZE); + Result result = doGet(apiUrl, null, body); + log.info("物理机数据:" + JSON.toJSONString(result)); + JSONObject returnObj = checkResult(result, "查询物理机列表"); + List results = new ArrayList<>(); + results.addAll(JSONArray.parseArray(returnObj.getString("results"), JSONObject.class)); + if (ListTool.isEmpty(results)) { + return new GeneralResult(true, results, "物理机列表为空"); + } + for (JSONObject model : results) { + physicalModels.add(physcicalConvertor.convertModel(model)); + } + log.info("results:" + JSON.toJSONString(physicalModels)); + return new GeneralResult(true, physicalModels, "查询物理机列表成功"); + } catch (Exception e) { + log.error("查询物理机列表失败 :", e); + return new GeneralResult(false, "查询物理机列表失败" + e.getMessage()); + } + } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java index 75949a62..4a509312 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/PhysicalServerService.java @@ -10,7 +10,7 @@ public interface PhysicalServerService { GeneralResult> list(Pager pager, RequestContext context); - GeneralResult listAll(); + GeneralResult listAll( String regionId, String zoneId); GeneralResult detail(Long id); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java index d910f93e..60063f95 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/PhysicalServerServiceImpl.java @@ -80,10 +80,10 @@ public class PhysicalServerServiceImpl implements PhysicalServerService { } @Override - public GeneralResult listAll() { + public GeneralResult listAll( String regionId, String zoneId) { CloudVendor vendor = cloudVendorRepository.query(1L); TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), "2022guizhou_syj")); - GeneralResult result = physicalProvider.list(); + GeneralResult result = physicalProvider.listAll(regionId, zoneId); return null; }