Merge branch 'develop' of http://23.33.3.13:30000/iidi/bocloud.cloud.plugin into develop
commit
62ea931108
|
@ -0,0 +1,2 @@
|
|||
@Library('jgpl_6.5') _
|
||||
servicePipeline()
|
|
@ -116,6 +116,15 @@ public class FlavorController {
|
|||
return flavorService.remove(id, context);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询物理机规格")
|
||||
@GetMapping("/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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除云主机规格
|
||||
*
|
||||
|
|
|
@ -298,4 +298,14 @@ public class ImageController {
|
|||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return imageService.copy(bean, context);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像")
|
||||
@GetMapping("/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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author yuemian
|
||||
* @since 2024/09/02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/v1/physical/servers")
|
||||
@Tag(name = "物理机")
|
||||
public class PhysicalServerController {
|
||||
|
||||
@Autowired
|
||||
private PhysicalServerService physicalServerService;
|
||||
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表")
|
||||
@GetMapping
|
||||
public GeneralResult<GridBean<PhysicalServer>> list(Pager pager,
|
||||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return physicalServerService.list(pager, context);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "获取物理机列表")
|
||||
@GetMapping(value = "/listAll")
|
||||
public GeneralResult listAll(@RequestParam(value = "regionId") String regionId,
|
||||
@RequestParam(value = "regionId") String zoneId) {
|
||||
return physicalServerService.listAll(regionId, zoneId);
|
||||
}
|
||||
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "添加物理机")
|
||||
@PostMapping
|
||||
public GeneralResult<PhysicalServer> create(@RequestBody PhysicalServer physicalServer,
|
||||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return physicalServerService.create(physicalServer, context);
|
||||
}
|
||||
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "修改物理机")
|
||||
@PutMapping("/{id}")
|
||||
public GeneralResult<PhysicalServer> 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<PhysicalServer> detail(@PathVariable(value = Common.ID) Long id) {
|
||||
return physicalServerService.detail(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -425,4 +425,15 @@ public class VolumeController {
|
|||
// 分页查询volume
|
||||
return volumeService.listByInstanceId(instanceId, resourceSize);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询物理机镜像")
|
||||
@GetMapping("/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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,8 @@ public class HostModel {
|
|||
private Long hddTotalSizeByte;
|
||||
private Long ssdTotalSizeByte;
|
||||
|
||||
private Boolean isHost;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param uuid
|
||||
|
|
|
@ -75,4 +75,5 @@ public class ImageModel {
|
|||
// hcso
|
||||
private String wholeImageType;
|
||||
private String backupUuid;
|
||||
private Boolean isPhysical;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
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 displayName;
|
||||
|
||||
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;
|
||||
|
||||
private String hostname;
|
||||
|
||||
private String extIp;
|
||||
|
||||
private String password;
|
||||
|
||||
private String vpcName;
|
||||
|
||||
private Long cycleCount;
|
||||
|
||||
private String cycleType;
|
||||
|
||||
private Long orderCount;
|
||||
|
||||
}
|
|
@ -32,6 +32,7 @@ public class TianyiSyncModel {
|
|||
private List<NetworkCardModel> networkCardModels;
|
||||
private List<ClusterModel> clusterModels;
|
||||
private List<HostModel> hostModels;
|
||||
private List<PhysicalServerModel> physicalModels;
|
||||
private ResourcePoolModel resourcePoolModel;
|
||||
private List<RdsModel> rdsModels;
|
||||
private List<ContainerClusterModel> containerClusterModels;
|
||||
|
|
|
@ -75,4 +75,26 @@ public class TianyiFlavorProvider extends TianyiServerProvider {
|
|||
return new GeneralResult(false, "查询规格列表失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult listFlavorPhysical(String regionId, String azName) {
|
||||
try {
|
||||
String apiUrl = "/v4/ebm/device-type-list";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("regionID", regionId);
|
||||
body.put("azName", azName);
|
||||
|
||||
Result result = doGet(apiUrl, null, body);
|
||||
JSONObject returnObj = checkResult(result, "查询物理机规格列表");
|
||||
|
||||
List<JSONObject> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -8,6 +9,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 +154,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)) {
|
||||
|
@ -206,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<RegionModel>) regionList.getData());
|
||||
}
|
||||
|
@ -216,6 +219,13 @@ public class TianyiLocationProvider extends TianyiProvider {
|
|||
if(clusterResult.isSuccess()){
|
||||
syncModel.setHostModels(clusterResult.getData());
|
||||
}
|
||||
log.info("获取物理机信息...");
|
||||
TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(this.getButler());
|
||||
GeneralResult<List<PhysicalServerModel>> physicalResult = physicalProvider.list();
|
||||
log.info("同步物理机结果:{}", JSON.toJSONString(physicalResult));
|
||||
if(physicalResult.isSuccess()){
|
||||
syncModel.setPhysicalModels(physicalResult.getData());
|
||||
}
|
||||
// 同步vpc
|
||||
log.info("获取vpc信息...");
|
||||
TianyiVpcProvider tianyiVpcProvider = new TianyiVpcProvider(this.getButler());
|
||||
|
@ -359,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, "数据同步成功!");
|
||||
|
|
|
@ -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<JSONObject> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,246 @@
|
|||
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;
|
||||
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.apache.commons.lang3.StringUtils;
|
||||
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<PhysicalServerModel, JSONObject> physcicalConvertor = new PhyscicalConvertor();
|
||||
|
||||
|
||||
public GeneralResult<List<PhysicalServerModel>> list() {
|
||||
try {
|
||||
List<PhysicalServerModel> physicalModels = new ArrayList<>();
|
||||
List<JSONObject> zoneList = this.listZones(this.getRegionId());
|
||||
if (!CollectionUtils.isEmpty(zoneList)) {
|
||||
List<JSONObject> 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));
|
||||
}
|
||||
}
|
||||
log.info("results:" + JSON.toJSONString(physicalModels));
|
||||
return new GeneralResult(true, physicalModels, "查询物理机列表成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询物理机列表失败 :", e);
|
||||
return new GeneralResult(false, "查询物理机列表失败" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult create(PhysicalServerModel model) {
|
||||
log.info("物理机创建参数:" + JSON.toJSONString(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.getCycleType());
|
||||
jsonObject.put("orderCount", model.getOrderCount());
|
||||
Result result = doPost(apiUrl, jsonObject);
|
||||
log.info("物理机创建结果:" + JSON.toJSONString(result));
|
||||
JSONObject returnObj = checkResult(result, "创建物理机");
|
||||
List<JSONObject> resources = returnObj.getJSONArray("resources").toJavaList(JSONObject.class);
|
||||
if (CollectionUtils.isEmpty(resources)) {
|
||||
return GeneralResult.FAILED("物理机创建失败:无创建resource信息返回");
|
||||
}
|
||||
List<PhysicalServerModel> models = new ArrayList<>();
|
||||
List<String> 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<JSONObject> 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<JSONObject> jsonObjects = JSONArray.parseArray(returnObj.getString("zoneList"), JSONObject.class);
|
||||
return jsonObjects;
|
||||
} catch (Exception e) {
|
||||
log.error("查询资源池列表失败 :", e);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GeneralResult<List<PhysicalServerModel>> listByResourceId(List<String> resourceIds, String zoneId) {
|
||||
try {
|
||||
List<PhysicalServerModel> 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<JSONObject> 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());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult<List<PhysicalServerModel>> listAll(String regionId, String zoneId) {
|
||||
try {
|
||||
List<PhysicalServerModel> 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<JSONObject> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<JSONObject> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
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<PhysicalServerModel, JSONObject> {
|
||||
|
||||
|
||||
|
||||
@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"));
|
||||
model.setDisplayName(info.getString("displayName"));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.cmp.entity.PhysicalServer;
|
||||
import com.megatron.common.model.Pager;
|
||||
import com.megatron.common.model.Param;
|
||||
import com.megatron.common.utils.Common;
|
||||
import com.megatron.common.utils.MapTools;
|
||||
import com.megatron.database.core.intf.impl.BasicGenericDao;
|
||||
import com.megatron.framework.core.CurrentService;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物理服务器数据访问
|
||||
*
|
||||
* @author wangyu
|
||||
* @version 1.0
|
||||
* @since 2020年5月15日
|
||||
*/
|
||||
@Repository("serverRepository")
|
||||
public class PhysicalServerRepository extends BasicGenericDao<PhysicalServer, Long> {
|
||||
|
||||
|
||||
public PhysicalServerRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) {
|
||||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
public List<PhysicalServer> listByVendor(Long vendorId) {
|
||||
String sql = "select a.* from physical_server a where a.is_deleted = 0";
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> params = MapTools.simpleMap("id", id);
|
||||
params.put("gmtModify", new Date());
|
||||
params.put("userId", userId);
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public int count(List<Param> params) throws Exception {
|
||||
String sql = "select count(1) from physical_server where 1 = 1 ";
|
||||
sql = this.getQueryBuilder().build(sql, params, new HashMap<>(8), "");
|
||||
Map<String, Object> param = this.getQueryBuilder().getParam(params);
|
||||
return this.countQuery(sql, param).intValue();
|
||||
}
|
||||
|
||||
public List<PhysicalServer> list(int page, int rows, List<Param> params, Map<String, String> sorter) throws Exception {
|
||||
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<String, Object> param = this.getQueryBuilder().getParam(params);
|
||||
return this.list(PhysicalServer.class, sql, param);
|
||||
}
|
||||
|
||||
}
|
|
@ -56,6 +56,8 @@ public interface FlavorService {
|
|||
*/
|
||||
GeneralResult<String> remove(Long id, RequestContext context);
|
||||
|
||||
GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, RequestContext context);
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
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<GridBean<PhysicalServer>> list(Pager pager, RequestContext context);
|
||||
GeneralResult listAll( String regionId, String zoneId);
|
||||
|
||||
|
||||
GeneralResult<PhysicalServer> detail(Long id);
|
||||
|
||||
GeneralResult<PhysicalServer> create(PhysicalServer physicalServer, RequestContext context);
|
||||
|
||||
|
||||
GeneralResult<PhysicalServer> modify(PhysicalServer physicalServer, RequestContext context);
|
||||
|
||||
GeneralResult remove(Long id, RequestContext context);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -226,4 +226,6 @@ public interface VolumeService {
|
|||
public GeneralResult<GridBean<Volume>> listByVaults(Pager pager, RequestContext context);
|
||||
|
||||
public GeneralResult<List<Volume>> listByInstanceId(String instanceId, Long resourceSize);
|
||||
|
||||
public GeneralResult listVolumeRaid(Long vendorId, String regionId, String zoneId, String deviceType, String volumeType, RequestContext context);
|
||||
}
|
||||
|
|
|
@ -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.listFlavorPhysical(regionId, zoneId);
|
||||
} catch (Exception e) {
|
||||
log.error("查询物理机规格失败"+ e.getMessage(), e);
|
||||
return GeneralResult.FAILED("查询物理机规格失败"+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<String> 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<String> modify(Flavor flavorParam, RequestContext context) {
|
||||
return new GeneralResult<>(false, "暂不支持!");
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
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.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;
|
||||
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;
|
||||
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.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
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<GridBean<PhysicalServer>> list(Pager pager, RequestContext context) {
|
||||
List<PhysicalServer> list = null;
|
||||
int total = 0;
|
||||
GridBean gridBean = null;
|
||||
try {
|
||||
List<Param> params = Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>());
|
||||
Map<String, String> 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 listAll( String regionId, String zoneId) {
|
||||
CloudVendor vendor = cloudVendorRepository.query(1L);
|
||||
TianyiPhysicalProvider physicalProvider = new TianyiPhysicalProvider(butlerConfig.regionButler(vendor.getUuid(), "2022guizhou_syj"));
|
||||
GeneralResult result = physicalProvider.listAll(regionId, zoneId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<PhysicalServer> 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<PhysicalServer> 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)) {
|
||||
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<PhysicalServerModel> 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
|
||||
public GeneralResult<PhysicalServer> 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());
|
||||
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();
|
||||
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, "删除任务下发失败");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.ctstack.plugin.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<PhysicalServerModel> physicalServerModels, Long vendorId, Long userId) {
|
||||
if (ListTool.isEmpty(physicalServerModels)) {
|
||||
physicalServerRepository.removeByVendor(vendorId, userId);
|
||||
return;
|
||||
}
|
||||
List<PhysicalServer> physicalServers = physicalServerRepository.listByVendor(vendorId);
|
||||
Map<String, PhysicalServer> 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"});
|
||||
physicalServerRepository.update(server);
|
||||
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<String, PhysicalServer> entry : serverMap.entrySet()) {
|
||||
Long serverId = entry.getValue().getId();
|
||||
physicalServerRepository.remove(serverId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Hu Wentao
|
||||
* @date 2020/10/29 10:31
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -30,7 +30,7 @@
|
|||
<!-- <module>bocloud.cas.plugin</module>-->
|
||||
<!-- <module>bocloud.jdcloud.plugin</module> -->
|
||||
<module>bocloud.ctstack.plugin</module>
|
||||
<module>bocloud.ctcloud.plugin</module>
|
||||
<!-- <module>bocloud.ctcloud.plugin</module>-->
|
||||
<!-- <module>bocloud.volcengine.plugin</module>-->
|
||||
<!-- <module>bocloud.kingcloud.plugin</module>-->
|
||||
<!-- <module>bocloud.fusioncloud.plugin</module>-->
|
||||
|
|
Loading…
Reference in New Issue