Merge branch 'iida' into develop
commit
42b86a9f1d
|
@ -6,6 +6,7 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -29,7 +30,6 @@ public class ContainerClusterModel {
|
|||
private String resourceGroupUuid;
|
||||
private String serviceCidr;
|
||||
private Long businessId;
|
||||
|
||||
|
||||
|
||||
private List<ContainerNodeModel> nodeModels;
|
||||
private List<ContainerNodePoolModel> nodePoolModels;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package com.bocloud.ctstack.plugin.entity;
|
||||
|
||||
import com.megatron.entity.annotations.Column;
|
||||
import com.megatron.entity.annotations.PK;
|
||||
import com.megatron.entity.annotations.Table;
|
||||
import com.megatron.entity.bean.GenericEntity;
|
||||
import com.megatron.entity.meta.PKStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Table("container_cluster")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ContainerCluster extends GenericEntity {
|
||||
|
||||
@PK(value = PKStrategy.AUTO)
|
||||
private Long id;
|
||||
@Column("vendor_id")
|
||||
private Long vendorId; // 云供应商ID
|
||||
|
||||
@Column("tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
@Column("project_id")
|
||||
private Long projectId;
|
||||
|
||||
@Column("cluster_uuid")
|
||||
private String clusterUuid;
|
||||
|
||||
@Column("region_id")
|
||||
private String regionId;
|
||||
|
||||
@Column("cluster_spec")
|
||||
private String clusterSpec;
|
||||
|
||||
@Column("version")
|
||||
private String version;
|
||||
|
||||
@Column("service_cidr")
|
||||
private String serviceCidr;
|
||||
|
||||
@Column("node_cidr")
|
||||
private String nodeCidr;
|
||||
|
||||
@Column("created")
|
||||
private Date created; // 创建时间
|
||||
|
||||
@Column("business_id")
|
||||
private Long businessId;
|
||||
|
||||
@Column("resource_group_uuid")
|
||||
private String resourceGroupUuid;
|
||||
|
||||
@Column("eip_uuid")
|
||||
private String eipUuid;
|
||||
|
||||
@Column("expired_time")
|
||||
private Date expiredTime;
|
||||
|
||||
@Column("load_balancer_uuid")
|
||||
private String loadBalancerUuid;
|
||||
|
||||
@Column("vpc_uuid")
|
||||
private String vpcUuid;
|
||||
|
||||
@Column("recycle_time")
|
||||
private Date recycleTime;
|
||||
|
||||
@Column("is_recycle")
|
||||
private Boolean isRecycle;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.bocloud.ctstack.plugin.entity;
|
||||
|
||||
import com.megatron.entity.annotations.Column;
|
||||
import com.megatron.entity.annotations.PK;
|
||||
import com.megatron.entity.annotations.Table;
|
||||
import com.megatron.entity.bean.GenericEntity;
|
||||
import com.megatron.entity.meta.PKStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Table("container_cluster_node")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ContainerClusterNode extends GenericEntity {
|
||||
|
||||
@PK(value = PKStrategy.AUTO)
|
||||
private Long id;
|
||||
@Column("vendor_id")
|
||||
private Long vendorId; // 云供应商ID
|
||||
|
||||
@Column("node_name")
|
||||
private String nodeName;
|
||||
|
||||
@Column("region_id")
|
||||
private String regionId;
|
||||
|
||||
@Column("cluster_uuid")
|
||||
private String clusterUuid;
|
||||
|
||||
@Column("node_status")
|
||||
private String nodeStatus;
|
||||
|
||||
@Column("created")
|
||||
private Date created; // 创建时间
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.bocloud.ctstack.plugin.entity;
|
||||
|
||||
import com.megatron.entity.annotations.Column;
|
||||
import com.megatron.entity.annotations.PK;
|
||||
import com.megatron.entity.annotations.Table;
|
||||
import com.megatron.entity.bean.GenericEntity;
|
||||
import com.megatron.entity.meta.PKStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Table("container_cluster_node_pool")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ContainerClusterNodePool extends GenericEntity {
|
||||
|
||||
@PK(value = PKStrategy.AUTO)
|
||||
private Long id;
|
||||
@Column("vendor_id")
|
||||
private Long vendorId; // 云供应商ID
|
||||
|
||||
@Column("region_id")
|
||||
private String regionId;
|
||||
|
||||
@Column("tenant_id")
|
||||
private Long tenantId;
|
||||
|
||||
@Column("project_id")
|
||||
private Long projectId;
|
||||
|
||||
@Column("nodepool_uuid")
|
||||
private String nodePoolUuid;
|
||||
|
||||
@Column("cluster_uuid")
|
||||
private String clusterUuid;
|
||||
|
||||
@Column("failed_nodes")
|
||||
private Long failedNodes;
|
||||
|
||||
@Column("healthy_nodes")
|
||||
private Long healthyNodes;
|
||||
|
||||
@Column("total_nodes")
|
||||
private Long totalNodes;
|
||||
|
||||
@Column("created")
|
||||
private Date created; // 创建时间
|
||||
|
||||
@Column("kubernetes_config")
|
||||
private String kubernetesConfig;
|
||||
|
||||
@Column("scaling_group")
|
||||
private String scalingGroup;
|
||||
|
||||
// 天翼云使用字段 开始
|
||||
@Column("vm_spec_type")
|
||||
private String vmSpecType;
|
||||
|
||||
@Column("vm_spec_name")
|
||||
private String vmSpecName;
|
||||
|
||||
@Column("vm_spec_id")
|
||||
private String vmSpecId;
|
||||
|
||||
@Column("cpu")
|
||||
private Long cpu;
|
||||
|
||||
@Column("memory")
|
||||
private Long memory;
|
||||
// 天翼云使用字段 结束
|
||||
}
|
|
@ -12,6 +12,7 @@ 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.container.TianYiContainerNodeProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.database.TianyiRdsProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.network.TianyiFloatingIpProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.network.TianyiSecurityGroupProvider;
|
||||
|
@ -293,14 +294,32 @@ public class TianyiLocationProvider extends TianyiProvider {
|
|||
syncModel.setImageModels((List<ImageModel>) imageList.getData());
|
||||
}
|
||||
|
||||
|
||||
// 同步镜像
|
||||
// 同步容器
|
||||
log.info("获取容器信息...");
|
||||
TianYiContainerClusterProvider tianYiContainerClusterProvider = new TianYiContainerClusterProvider(this.getButler());
|
||||
GeneralResult containerClusterList = tianYiContainerClusterProvider.list();
|
||||
log.info("同步容器结果:{}",containerClusterList.isSuccess());
|
||||
if (containerClusterList.isSuccess()) {
|
||||
syncModel.setContainerClusterModels((List<ContainerClusterModel>) containerClusterList.getData());
|
||||
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("获取容器节点池信息...");
|
||||
GeneralResult clusterNodePoolList = tianYiContainerNodeProvider.listNodePools(clusterModel.getName());
|
||||
log.info("同步容器节点池结果:{}",clusterNodePoolList.isSuccess());
|
||||
if (clusterNodePoolList.isSuccess()) {
|
||||
clusterModel.setNodePoolModels((List<ContainerNodePoolModel>) clusterNodePoolList.getData());
|
||||
}
|
||||
}
|
||||
syncModel.setContainerClusterModels(containerClusterModels);
|
||||
}
|
||||
|
||||
// 同步云硬盘
|
||||
|
|
|
@ -43,7 +43,6 @@ public class TianYiContainerNodeProvider extends TianyiProvider {
|
|||
|
||||
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);
|
||||
|
|
|
@ -26,6 +26,8 @@ public class ContainerClusterConvertor implements BeanConvertor<ContainerCluster
|
|||
ContainerClusterModel containerClusterModel = new ContainerClusterModel();
|
||||
|
||||
containerClusterModel.setName(jsonObject.getString("clusterName"));
|
||||
// 容器集群是没有uuid的,只能把唯一的集群名作为它的UUID
|
||||
containerClusterModel.setClusterUuid(jsonObject.getString("clusterName"));
|
||||
containerClusterModel.setRemark(jsonObject.getString("clusterDesc"));
|
||||
containerClusterModel.setClusterSpec(jsonObject.getString("deployMode"));
|
||||
containerClusterModel.setVersion(jsonObject.getString("clusterVersion"));
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
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.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component("containerClusterRepository")
|
||||
public class ContainerClusterRepository extends BasicGenericDao<ContainerCluster, Long> {
|
||||
|
||||
public ContainerClusterRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) {
|
||||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
public boolean removeByVid(Long vendorId, String regionId, Long userId) throws Exception {
|
||||
String sql = "update container_cluster 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);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public List<ContainerCluster> listByVid(Long vendorId, String regionId) throws Exception {
|
||||
String sql = "select a.*,t.name tenant_name from container_cluster 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 ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
return this.list(ContainerCluster.class, sql, params);
|
||||
}
|
||||
|
||||
public boolean remove(Long id, Long userId) throws Exception {
|
||||
String sql = "update container_cluster set is_deleted = true,gmt_modify = :gmtModify,mender_id = :menderId where is_deleted = 0 and id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap("id", id);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNodePool;
|
||||
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.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component("containerNodePoolRepository")
|
||||
public class ContainerNodePoolRepository extends BasicGenericDao<ContainerClusterNodePool, Long> {
|
||||
|
||||
public ContainerNodePoolRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) {
|
||||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
public boolean removeByVid(Long vendorId, String regionId, 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 ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public boolean removeByClusterUuid(Long vendorId, String regionId, String clusterUuid, 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 cluster_uuid = :clusterUuid ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("clusterUuid", clusterUuid);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public List<ContainerClusterNodePool> listByClusterUuid(Long vendorId, String regionId, String clusterUuid) throws Exception {
|
||||
String sql = "select a.*,t.name tenant_name from container_cluster_node_pool 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 ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put("clusterUuid", clusterUuid);
|
||||
return this.list(ContainerClusterNodePool.class, sql, params);
|
||||
}
|
||||
|
||||
public boolean remove(Long id, 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 id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap("id", id);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNode;
|
||||
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.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component("containerNodeRepository")
|
||||
public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNode, Long> {
|
||||
|
||||
public ContainerNodeRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate, CurrentService service) {
|
||||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
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 "
|
||||
+ " and region_id = :regionId ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
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 ";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("clusterUuid", clusterUuid);
|
||||
params.put("gmtModify", new Date());
|
||||
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";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
|
||||
params.put(Common.REGIONID, regionId);
|
||||
params.put("clusterUuid", clusterUuid);
|
||||
return this.list(ContainerClusterNode.class, sql, params);
|
||||
}
|
||||
|
||||
public boolean remove(Long id, 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 id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap("id", id);
|
||||
params.put(Common.MENDER_ID, userId);
|
||||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
}
|
|
@ -106,6 +106,12 @@ public class TianyiTransporter {
|
|||
private CloudRdsRepository cloudRdsRepository;
|
||||
@Autowired
|
||||
private PhysicalServerRepository physicalServerRepository;
|
||||
@Autowired
|
||||
private ContainerClusterRepository containerClusterRepository;
|
||||
@Autowired
|
||||
private ContainerNodeRepository containerNodeRepository;
|
||||
@Autowired
|
||||
private ContainerNodePoolRepository containerNodePoolRepository;
|
||||
|
||||
public Result transport(CloudVendor vendor, Long operator) {
|
||||
|
||||
|
@ -237,6 +243,12 @@ public class TianyiTransporter {
|
|||
for (Keypair keypair : keyPairList) {
|
||||
keyPairMap.put(keypair.getFingerprint(), keypair.getId());
|
||||
}
|
||||
|
||||
// 同步容器信息
|
||||
log.info("Starting sync container ......");
|
||||
this.syncContainers(model.getContainerClusterModels(), vendor, userId, region);
|
||||
log.info("End sync container ......");
|
||||
|
||||
// 同步浮动IP
|
||||
log.info("Starting sync floatIp ......");
|
||||
this.syncFloatIps(model.getServerModels(), model.getFloatingIpModels(), vendor, userId, region);
|
||||
|
@ -564,7 +576,164 @@ public class TianyiTransporter {
|
|||
for (Entry<String, FloatingIp> entry : ipMap.entrySet()) {
|
||||
floatingIpRepository.remove(entry.getValue().getId(), userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncContainers(List<ContainerClusterModel> clusterModels, CloudVendor vendor, Long userId, Region region) throws Exception {
|
||||
if (null == clusterModels) {
|
||||
return;
|
||||
}
|
||||
Long vendorId = vendor.getId();
|
||||
// 当容器集群为空时,清空数据库
|
||||
if (ListTool.isEmpty(clusterModels)) {
|
||||
containerClusterRepository.removeByVid(vendorId, region.getRegionId(), userId);
|
||||
containerNodeRepository.removeByVid(vendorId, region.getRegionId(), userId);
|
||||
containerNodePoolRepository.removeByVid(vendorId, region.getRegionId(), userId);
|
||||
return;
|
||||
}
|
||||
List<ContainerCluster> listByVid = containerClusterRepository.listByVid(vendorId, region.getRegionId());
|
||||
Map<String, ContainerCluster> clusterMap = Maps.newHashMap();
|
||||
for (ContainerCluster containerCluster : listByVid) {
|
||||
clusterMap.put(containerCluster.getClusterUuid(), containerCluster);
|
||||
}
|
||||
|
||||
ContainerCluster containerCluster = null;
|
||||
for (ContainerClusterModel model : clusterModels) {
|
||||
if (clusterMap.containsKey(model.getClusterUuid())) {
|
||||
// 更新操作
|
||||
containerCluster = clusterMap.get(model.getClusterUuid());
|
||||
BeanUtils.copyProperties(model, containerCluster);
|
||||
containerCluster.setMenderId(userId);
|
||||
containerCluster.setRegionId(region.getRegionId());
|
||||
containerCluster.setGmtModify(new Date());
|
||||
containerCluster.setCreatorId(userId);
|
||||
containerCluster.setVendorId(vendorId);
|
||||
containerClusterRepository.update(containerCluster);
|
||||
clusterMap.remove(model.getClusterUuid());
|
||||
|
||||
// 同步这个集群下的节点和节点池信息
|
||||
syncContainerNodes(containerCluster, model.getNodeModels(), vendor, userId, region);
|
||||
syncContainerNodePools(containerCluster, model.getNodePoolModels(), vendor, userId, region);
|
||||
continue;
|
||||
}
|
||||
containerCluster = new ContainerCluster();
|
||||
BeanUtils.copyProperties(model, containerCluster);
|
||||
containerCluster.setMenderId(userId);
|
||||
containerCluster.setRegionId(region.getRegionId());
|
||||
containerCluster.setGmtModify(new Date());
|
||||
containerCluster.setTenantId(0L);
|
||||
containerCluster.setProjectId(0L);
|
||||
containerCluster.setCreatorId(userId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncContainerNodes(ContainerCluster containerCluster, 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);
|
||||
return;
|
||||
}
|
||||
List<ContainerClusterNode> nodes = containerNodeRepository.listByClusterUuid(vendorId, region.getRegionId(),
|
||||
containerCluster.getClusterUuid());
|
||||
Map<String, ContainerClusterNode> nodeMap = Maps.newHashMap();
|
||||
for (ContainerClusterNode containerClusterNode : nodes) {
|
||||
nodeMap.put(containerClusterNode.getNodeName(), containerClusterNode);
|
||||
}
|
||||
|
||||
ContainerClusterNode containerClusterNode = null;
|
||||
for (ContainerNodeModel model : nodeModels) {
|
||||
if (nodeMap.containsKey(model.getNodeName())) {
|
||||
// 更新操作
|
||||
containerClusterNode = nodeMap.get(model.getNodeName());
|
||||
BeanUtils.copyProperties(model, containerClusterNode);
|
||||
containerClusterNode.setClusterUuid(containerCluster.getClusterUuid());
|
||||
containerClusterNode.setMenderId(userId);
|
||||
containerClusterNode.setRegionId(region.getRegionId());
|
||||
containerClusterNode.setGmtModify(new Date());
|
||||
containerClusterNode.setCreatorId(userId);
|
||||
containerClusterNode.setVendorId(vendorId);
|
||||
containerNodeRepository.update(containerClusterNode);
|
||||
nodeMap.remove(model.getClusterUuid());
|
||||
continue;
|
||||
}
|
||||
containerClusterNode = new ContainerClusterNode();
|
||||
BeanUtils.copyProperties(model, containerClusterNode);
|
||||
containerClusterNode.setClusterUuid(containerCluster.getClusterUuid());
|
||||
containerClusterNode.setMenderId(userId);
|
||||
containerClusterNode.setRegionId(region.getRegionId());
|
||||
containerClusterNode.setGmtModify(new Date());
|
||||
containerClusterNode.setCreatorId(userId);
|
||||
containerClusterNode.setVendorId(vendorId);
|
||||
containerNodeRepository.save(containerClusterNode);
|
||||
}
|
||||
for (Entry<String, ContainerClusterNode> entry : nodeMap.entrySet()) {
|
||||
containerNodeRepository.remove(entry.getValue().getId(), userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncContainerNodePools(ContainerCluster containerCluster, List<ContainerNodePoolModel> nodePoolModels, CloudVendor vendor, Long userId, Region region) throws Exception {
|
||||
if (null == nodePoolModels) {
|
||||
return;
|
||||
}
|
||||
Long vendorId = vendor.getId();
|
||||
// 当容器集群下节点为空时,清空数据库
|
||||
if (ListTool.isEmpty(nodePoolModels)) {
|
||||
containerNodePoolRepository.removeByClusterUuid(vendorId, region.getRegionId(), containerCluster.getClusterUuid(), userId);
|
||||
return;
|
||||
}
|
||||
List<ContainerClusterNodePool> nodePools = containerNodePoolRepository.listByClusterUuid(vendorId, region.getRegionId(),
|
||||
containerCluster.getClusterUuid());
|
||||
Map<String, ContainerClusterNodePool> nodePoolMap = Maps.newHashMap();
|
||||
for (ContainerClusterNodePool containerClusterNodePool : nodePools) {
|
||||
nodePoolMap.put(containerClusterNodePool.getNodePoolUuid(), containerClusterNodePool);
|
||||
}
|
||||
|
||||
ContainerClusterNodePool containerClusterNodePool = null;
|
||||
for (ContainerNodePoolModel model : nodePoolModels) {
|
||||
if (nodePoolMap.containsKey(model.getNodepoolUuid())) {
|
||||
// 更新操作
|
||||
containerClusterNodePool = nodePoolMap.get(model.getNodepoolUuid());
|
||||
BeanUtils.copyProperties(model, containerClusterNodePool);
|
||||
containerClusterNodePool.setClusterUuid(containerCluster.getClusterUuid());
|
||||
containerClusterNodePool.setMenderId(userId);
|
||||
containerClusterNodePool.setRegionId(region.getRegionId());
|
||||
containerClusterNodePool.setGmtModify(new Date());
|
||||
containerClusterNodePool.setCreatorId(userId);
|
||||
containerClusterNodePool.setVendorId(vendorId);
|
||||
containerNodePoolRepository.update(containerClusterNodePool);
|
||||
nodePoolMap.remove(model.getClusterUuid());
|
||||
continue;
|
||||
}
|
||||
containerClusterNodePool = new ContainerClusterNodePool();
|
||||
BeanUtils.copyProperties(model, containerClusterNodePool);
|
||||
containerClusterNodePool.setClusterUuid(containerCluster.getClusterUuid());
|
||||
containerClusterNodePool.setMenderId(userId);
|
||||
containerClusterNodePool.setRegionId(region.getRegionId());
|
||||
containerClusterNodePool.setGmtModify(new Date());
|
||||
containerClusterNodePool.setTenantId(0L);
|
||||
containerClusterNodePool.setProjectId(0L);
|
||||
containerClusterNodePool.setCreatorId(userId);
|
||||
containerClusterNodePool.setVendorId(vendorId);
|
||||
containerNodePoolRepository.save(containerClusterNodePool);
|
||||
}
|
||||
for (Entry<String, ContainerClusterNodePool> entry : nodePoolMap.entrySet()) {
|
||||
containerNodePoolRepository.remove(entry.getValue().getId(), userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncResourceGroups(List<ResourceGroupModel> resourceGroupModels, CloudVendor vendor, Long userId, Region region) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue