天翼云-物理机同步
parent
dc0c56f1cb
commit
76fa9721c6
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除云主机规格
|
||||
*
|
||||
|
|
|
@ -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,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;
|
||||
|
||||
}
|
|
@ -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<ContarinerClusterModel> contarinerClusterModels;
|
||||
|
|
|
@ -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<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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<List<PhysicalServerModel>> physicalResult = physicalProvider.list();
|
||||
log.info("同步物理机结果:{}", physicalResult.isSuccess());
|
||||
if(physicalResult.isSuccess()){
|
||||
syncModel.setPhysicalModels(physicalResult.getData());
|
||||
}
|
||||
// 同步vpc
|
||||
log.info("获取vpc信息...");
|
||||
TianyiVpcProvider tianyiVpcProvider = new TianyiVpcProvider(this.getButler());
|
||||
|
|
|
@ -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<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));
|
||||
}
|
||||
}
|
||||
return new GeneralResult(true, physicalModels, "查询宿主机列表成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询宿主机列表失败 :", e);
|
||||
return new GeneralResult(false, "查询宿主机列表失败" + 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<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"));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -56,6 +56,8 @@ public interface FlavorService {
|
|||
*/
|
||||
GeneralResult<String> remove(Long id, RequestContext context);
|
||||
|
||||
GeneralResult listPhysical(Long vendorId, String regionId, String zoneId, 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.listPhysical(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, "暂不支持!");
|
||||
|
|
|
@ -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<PhysicalServerModel> physicalServerModels, Long vendorId, Long userId) {
|
||||
if (ListTool.isEmpty(physicalServerModels)) {
|
||||
List<PhysicalServer> servers = physicalServerRepository.listByVendor(vendorId);
|
||||
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"});
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue