Merge remote-tracking branch 'origin/develop' into develop

develop
yuemian 2024-09-12 15:14:05 +08:00
commit 5c019b2c16
12 changed files with 123 additions and 43 deletions

View File

@ -94,6 +94,15 @@ public class ContainerController {
return containerService.remove(id, context);
}
@Operation(tags = {"CMC", "CSC"}, summary = "修改容器集群")
@PutMapping("/{id}")
public GeneralResult modify(@PathVariable(value = Common.ID) Long id,
@RequestBody ContainerClusterModel containerClusterModel,
@Value(Common.REQ_CONTEXT) RequestContext context) {
containerClusterModel.setId(id);
return containerService.modify(containerClusterModel, context);
}
/**
*
*

View File

@ -12,6 +12,7 @@ import java.util.List;
@NoArgsConstructor
public class ContainerClusterModel {
private Long id;
private String name;
private String remark;
private String clusterSpec;
@ -31,7 +32,6 @@ public class ContainerClusterModel {
private Long businessId;
private String prodInstId; // 平台实例ID
private String resPoolId; // 资源池ID
private List<ContainerNodeModel> nodeModels;
private List<ContainerNodePoolModel> nodePoolModels;
// 平台相同数据

View File

@ -5,6 +5,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@AllArgsConstructor
@ -34,4 +35,5 @@ public class ContainerNodePoolModel {
private String vmSpecType; // 节点规格类型
private Long vmSpecId; // 节点规格id
private List<ContainerNodeModel> nodeModels;
}

View File

@ -34,6 +34,9 @@ public class ContainerClusterNode extends GenericEntity {
@Column("node_status")
private String nodeStatus;
@Column("node_pool_uuid")
private String nodePoolUuid;
@Column("created")
private Date created; // 创建时间
}

View File

@ -304,17 +304,9 @@ public class TianyiLocationProvider extends TianyiProvider {
if (containerClusterList.isSuccess()) {
List<ContainerClusterModel> containerClusterModels = (List<ContainerClusterModel>) containerClusterList.getData();
for (ContainerClusterModel clusterModel : containerClusterModels) {
// 同步容器节点信息
log.info("获取容器节点信息...");
TianYiContainerNodeProvider tianYiContainerNodeProvider = new TianYiContainerNodeProvider(this.getButler());
GeneralResult clusterNodeList = tianYiContainerNodeProvider.listNodes(clusterModel.getName());
log.info("同步容器节点结果:{}",clusterNodeList.isSuccess());
if (clusterNodeList.isSuccess()) {
clusterModel.setNodeModels((List<ContainerNodeModel>) clusterNodeList.getData());
}
// 同步容器节点池信息
log.info("获取容器节点池信息...");
TianYiContainerNodeProvider tianYiContainerNodeProvider = new TianYiContainerNodeProvider(this.getButler());
GeneralResult clusterNodePoolList = tianYiContainerNodeProvider.listNodePools(clusterModel.getName());
log.info("同步容器节点池结果:{}",clusterNodePoolList.isSuccess());
if (clusterNodePoolList.isSuccess()) {

View File

@ -10,6 +10,7 @@ import com.bocloud.ctstack.plugin.provider.tianyiconvertor.ContainerClusterConve
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
@ -172,6 +173,19 @@ public class TianYiContainerClusterProvider extends TianyiProvider {
}
}
public GeneralResult modify(ContainerClusterModel model) {
try {
if(!StringUtils.isEmpty(model.getRemark())) {
return modifyDesc(model.getName(), model.getRemark());
} else {
return new GeneralResult(false, null, "容器集群没有可修改的内容");
}
} catch (Exception e) {
log.error("修改容器集群失败 " + e);
return new GeneralResult(false, null, "修改容器集群失败");
}
}
private GeneralResult modifyDesc(String clusterName, String clusterDesc) {
try {
String apiUrl = "/ccse/clusters/" + clusterName;

View File

@ -37,20 +37,20 @@ public class TianYiContainerNodeProvider extends TianyiProvider {
this.apiDomain = "http://ccse-global.ctapi.ctyun.local:" + this.apiPort;
}
public GeneralResult listNodes(String clusterName) {
try {
String url = "/v1.1/ccse/clusters/" + clusterName + "/nodes/list";
Map<String, Object> header = new HashMap<>();
header.put("regionId", this.getRegionId());
Result result = doGet(url, header);
JSONObject returnObj = checkResult(result, "容器集群节点列表");
return new GeneralResult(true, nodeConvertor.convertList(JSONArray.parseArray(returnObj.toJSONString(), JSONObject.class)), "查询容器集群节点列表成功");
} catch (Exception e) {
log.error("查询容器集群节点列表失败 " + e);
return new GeneralResult(false, "查询容器集群节点列表失败", e.getMessage());
}
}
// public GeneralResult listNodes(String clusterName) {
// try {
// String url = "/v1.1/ccse/clusters/" + clusterName + "/nodes/list";
// Map<String, Object> header = new HashMap<>();
// header.put("regionId", this.getRegionId());
//
// Result result = doGet(url, header);
// JSONObject returnObj = checkResult(result, "容器集群节点列表");
// return new GeneralResult(true, nodeConvertor.convertList(JSONArray.parseArray(returnObj.toJSONString(), JSONObject.class)), "查询容器集群节点列表成功");
// } catch (Exception e) {
// log.error("查询容器集群节点列表失败 " + e);
// return new GeneralResult(false, "查询容器集群节点列表失败", e.getMessage());
// }
// }
public GeneralResult createNodePool(ContainerNodePoolModel poolModel) {
try {

View File

@ -1,6 +1,7 @@
package com.bocloud.ctstack.plugin.provider.tianyiconvertor;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.ctstack.plugin.domain.model.container.ContainerNodeModel;
import com.bocloud.ctstack.plugin.domain.model.container.ContainerNodePoolModel;
import java.util.ArrayList;
@ -41,6 +42,21 @@ public class ContainerNodePoolConvertor implements BeanConvertor<ContainerNodePo
containerNodePoolModel.setKubernetesConfig(jsonObject.getString("kubeletArgs"));
containerNodePoolModel.setScalingGroup(jsonObject.getString("nodeGroup"));
// 获取节点池下面的节点列表信息。
List<ContainerNodeModel> nodeModels = new ArrayList<>();
List<JSONObject> nodes = jsonObject.getJSONArray("nodes").toJavaList(JSONObject.class);
if (nodes != null) {
for (JSONObject nodeObject : nodes) {
ContainerNodeModel nodeModel = new ContainerNodeModel();
nodeModel.setNodeName(nodeObject.getString("nodeName"));
nodeModel.setNodeStatus(nodeObject.getString("nodeStatus"));
nodeModel.setCreated(jsonObject.getDate("createdTime"));
nodeModels.add(nodeModel);
}
containerNodePoolModel.setNodeModels(nodeModels);
}
return containerNodePoolModel;
}
}

View File

@ -55,7 +55,7 @@ public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNod
}
public boolean removeByVid(Long vendorId, String regionId, Long userId) throws Exception {
String sql = "update container_cluster_node_pool set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 and vendor_id = :vendorId "
String sql = "update container_cluster_node set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 and vendor_id = :vendorId "
+ " and region_id = :regionId ";
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
params.put(Common.REGIONID, regionId);
@ -65,8 +65,8 @@ public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNod
}
public boolean removeByClusterUuid(Long vendorId, String regionId, String clusterUuid, Long userId) throws Exception {
String sql = "update container_cluster_node_pool set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 and vendor_id = :vendorId "
+ " and region_id = :regionId and cluster_uuid = :clusterUuid ";
String sql = "update container_cluster_node set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 "
+ " and region_id = :regionId and node_pool_uuid in (select node_pool_uuid from container_cluster_node_pool where is_deleted = 0 and vendor_id = :vendorId and cluster_uuid = :clusterUuid )";
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
params.put(Common.REGIONID, regionId);
params.put(Common.MENDER_ID, userId);
@ -75,12 +75,23 @@ public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNod
return this.execute(sql, params) > 0;
}
public List<ContainerClusterNode> listByClusterUuid(Long vendorId, String regionId, String clusterUuid) throws Exception {
String sql = "select a.*,t.name tenant_name from container_cluster_node a left join tenant t on a.tenant_id = t.id where a.is_deleted = 0 and a.vendor_id = :vendorId"
+ " and a.region_id = :regionId and a.cluster_uuid = :clusterUuid";
public boolean removeByNodePoolUuid(Long vendorId, String regionId, String nodePoolUuid, Long userId) throws Exception {
String sql = "update container_cluster_node set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 and vendor_id = :vendorId "
+ " and region_id = :regionId and node_pool_uuid = :nodePoolUuid ";
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
params.put(Common.REGIONID, regionId);
params.put("clusterUuid", clusterUuid);
params.put(Common.MENDER_ID, userId);
params.put("nodePoolUuid", nodePoolUuid);
params.put("gmtModify", new Date());
return this.execute(sql, params) > 0;
}
public List<ContainerClusterNode> listByNodePoolUuid(Long vendorId, String regionId, String nodePoolUuid) throws Exception {
String sql = "select a.*,t.name tenant_name from container_cluster_node a left join tenant t on a.tenant_id = t.id where a.is_deleted = 0 and a.vendor_id = :vendorId"
+ " and a.region_id = :regionId and a.node_pool_uuid = :nodePoolUuid";
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
params.put(Common.REGIONID, regionId);
params.put("nodePoolUuid", nodePoolUuid);
return this.list(ContainerClusterNode.class, sql, params);
}

View File

@ -20,6 +20,8 @@ public interface ContainerService {
GeneralResult remove(Long id, RequestContext context);
GeneralResult<ContainerCluster> modify(ContainerClusterModel model, RequestContext context);
GeneralResult<ContainerClusterNodePool> createNodePool(ContainerNodePoolModel model, RequestContext context);
GeneralResult removeNodePool(Long id, RequestContext context);

View File

@ -172,6 +172,32 @@ public class ContainerServiceImpl implements ContainerService {
}
}
public GeneralResult modify(ContainerClusterModel model, RequestContext context) {
try {
ContainerCluster queryCluser = containerClusterRepository.query(model.getId());
Assert.notNull(queryCluser, "容器集群不存在");
CloudVendor vendor = cloudVendorRepository.query(queryCluser.getVendorId());
Assert.notNull(vendor, "指定的地域下云平台不存在");
TianYiContainerClusterProvider provider =
new TianYiContainerClusterProvider(butlerConfig.regionButler(vendor.getUuid(), queryCluser.getRegionId()));
model.setName(queryCluser.getName());
GeneralResult result = provider.modify(model);
if (result.isSuccess()) {
// 保存新创建的容器节点池集群信息。
ContainerClusterModel newModel = (ContainerClusterModel) result.getData();
BeanUtils.copyProperties(newModel, queryCluser, new String[]{"id", "tenantId", "creatorId", "projectId", "isDeleted", "gmtCreate"});
queryCluser.setVendorId(vendor.getId());
containerClusterRepository.update(queryCluser);
}
return new GeneralResult<>(true, "修改容器集群成功");
} catch (Exception e) {
log.error("delete cloud rds failure:", e);
return new GeneralResult<>(false, "修改容器集群失败", null, null);
}
}
public GeneralResult<ContainerClusterNodePool> createNodePool(ContainerNodePoolModel model, RequestContext context) {
try {
CloudVendor vendor = cloudVendorRepository.query(model.getVendorId());

View File

@ -613,8 +613,7 @@ public class TianyiTransporter {
containerClusterRepository.update(containerCluster);
clusterMap.remove(model.getClusterUuid());
// 同步这个集群下的节点和节点池信息
syncContainerNodes(containerCluster, model.getNodeModels(), vendor, userId, region);
// 同步这个集群下的节点池信息
syncContainerNodePools(containerCluster, model.getNodePoolModels(), vendor, userId, region);
continue;
}
@ -629,30 +628,29 @@ public class TianyiTransporter {
containerCluster.setVendorId(vendorId);
containerClusterRepository.save(containerCluster);
// 同步这个集群下的节点和节点池信息
syncContainerNodes(containerCluster, model.getNodeModels(), vendor, userId, region);
// 同步这个集群下的节点池信息
syncContainerNodePools(containerCluster, model.getNodePoolModels(), vendor, userId, region);
}
for (Entry<String, ContainerCluster> entry : clusterMap.entrySet()) {
containerClusterRepository.remove(entry.getValue().getId(), userId);
// 删除这个容器云下面的节点和节点池
containerNodeRepository.removeByClusterUuid(vendorId, region.getRegionId(), entry.getValue().getClusterUuid(), userId);
containerNodePoolRepository.removeByClusterUuid(vendorId, region.getRegionId(), entry.getValue().getClusterUuid(), userId);
containerNodeRepository.removeByClusterUuid(vendorId, region.getRegionId(), entry.getValue().getClusterUuid(), userId);
}
}
private void syncContainerNodes(ContainerCluster containerCluster, List<ContainerNodeModel> nodeModels, CloudVendor vendor, Long userId, Region region) throws Exception {
private void syncContainerNodes(ContainerClusterNodePool nodePool, List<ContainerNodeModel> nodeModels, CloudVendor vendor, Long userId, Region region) throws Exception {
if (null == nodeModels) {
return;
}
Long vendorId = vendor.getId();
// 当容器集群下节点为空时,清空数据库
// 当容器节点池下节点为空时,清空数据库
if (ListTool.isEmpty(nodeModels)) {
containerNodeRepository.removeByClusterUuid(vendorId, region.getRegionId(), containerCluster.getClusterUuid(), userId);
containerNodeRepository.removeByNodePoolUuid(vendorId, region.getRegionId(), nodePool.getNodePoolUuid(), userId);
return;
}
List<ContainerClusterNode> nodes = containerNodeRepository.listByClusterUuid(vendorId, region.getRegionId(),
containerCluster.getClusterUuid());
List<ContainerClusterNode> nodes = containerNodeRepository.listByNodePoolUuid(vendorId, region.getRegionId(),
nodePool.getNodePoolUuid());
Map<String, ContainerClusterNode> nodeMap = Maps.newHashMap();
for (ContainerClusterNode containerClusterNode : nodes) {
nodeMap.put(containerClusterNode.getNodeName(), containerClusterNode);
@ -664,7 +662,7 @@ public class TianyiTransporter {
// 更新操作
containerClusterNode = nodeMap.get(model.getNodeName());
BeanUtils.copyProperties(model, containerClusterNode);
containerClusterNode.setClusterUuid(containerCluster.getClusterUuid());
containerClusterNode.setNodePoolUuid(nodePool.getNodePoolUuid());
containerClusterNode.setMenderId(userId);
containerClusterNode.setRegionId(region.getRegionId());
containerClusterNode.setGmtModify(new Date());
@ -676,7 +674,7 @@ public class TianyiTransporter {
}
containerClusterNode = new ContainerClusterNode();
BeanUtils.copyProperties(model, containerClusterNode);
containerClusterNode.setClusterUuid(containerCluster.getClusterUuid());
containerClusterNode.setNodePoolUuid(nodePool.getNodePoolUuid());
containerClusterNode.setMenderId(userId);
containerClusterNode.setRegionId(region.getRegionId());
containerClusterNode.setGmtModify(new Date());
@ -697,6 +695,7 @@ public class TianyiTransporter {
// 当容器集群下节点为空时,清空数据库
if (ListTool.isEmpty(nodePoolModels)) {
containerNodePoolRepository.removeByClusterUuid(vendorId, region.getRegionId(), containerCluster.getClusterUuid(), userId);
containerNodeRepository.removeByClusterUuid(vendorId, region.getRegionId(), containerCluster.getClusterUuid(), userId);
return;
}
List<ContainerClusterNodePool> nodePools = containerNodePoolRepository.listByClusterUuid(vendorId, region.getRegionId(),
@ -720,6 +719,8 @@ public class TianyiTransporter {
containerClusterNodePool.setVendorId(vendorId);
containerNodePoolRepository.update(containerClusterNodePool);
nodePoolMap.remove(model.getClusterUuid());
syncContainerNodes(containerClusterNodePool, model.getNodeModels(), vendor, userId, region);
continue;
}
containerClusterNodePool = new ContainerClusterNodePool();
@ -733,9 +734,13 @@ public class TianyiTransporter {
containerClusterNodePool.setCreatorId(userId);
containerClusterNodePool.setVendorId(vendorId);
containerNodePoolRepository.save(containerClusterNodePool);
syncContainerNodes(containerClusterNodePool, model.getNodeModels(), vendor, userId, region);
}
for (Entry<String, ContainerClusterNodePool> entry : nodePoolMap.entrySet()) {
containerNodePoolRepository.remove(entry.getValue().getId(), userId);
// 清除这个节点池下面的节点信息
containerNodeRepository.removeByNodePoolUuid(vendorId, region.getRegionId(), entry.getValue().getNodePoolUuid(), userId);
}
}