Merge remote-tracking branch 'origin/develop' into develop
commit
946d4cf92e
|
@ -0,0 +1,50 @@
|
|||
package com.bocloud.ctstack.plugin.controller;
|
||||
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.bocloud.ctstack.plugin.service.ContainerService;
|
||||
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.*;
|
||||
|
||||
@Tag(name = "容器集群管理")
|
||||
@RestController
|
||||
@RequestMapping("/v1/containers")
|
||||
public class ContainerController {
|
||||
|
||||
@Autowired
|
||||
private ContainerService containerService;
|
||||
|
||||
/**
|
||||
* 查看集群列表
|
||||
*
|
||||
* @param pager
|
||||
* @return
|
||||
*/
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询集群列表")
|
||||
@GetMapping
|
||||
public GeneralResult<GridBean<ContainerCluster>> list(Pager pager) {
|
||||
return containerService.list(pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加集群
|
||||
*
|
||||
* @param model
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
// @Operation(tags = {"CMC", "CSC"}, summary = "创建集群")
|
||||
// @PostMapping
|
||||
// public GeneralResult<ContainerCluster> create(@RequestBody ContainerClusterModel model,
|
||||
// @Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
// return containerService.create(model, context);
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.bocloud.ctstack.plugin.domain.model;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ContainerClusterModel {
|
||||
|
||||
private String name;
|
||||
private String remark;
|
||||
private String clusterSpec;
|
||||
private String status;
|
||||
private String regionId;
|
||||
private String clusterUuid;
|
||||
private String clusterType;
|
||||
private String version;
|
||||
private Date expiredTime;
|
||||
private String nodeCidr;
|
||||
private String vpcUuid;
|
||||
private Date created;
|
||||
private String eipUuid;
|
||||
private String loadBalancerUuid;
|
||||
private String resourceGroupUuid;
|
||||
private String serviceCidr;
|
||||
private Long businessId;
|
||||
private List<ContainerNodeModel> nodeModels;
|
||||
private List<ContainerNodePoolModel> nodePoolModels;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 ContainerNodeModel {
|
||||
private String nodeName;
|
||||
private String nodeStatus;
|
||||
private String regionId;
|
||||
private String clusterName;
|
||||
private String clusterUuid;
|
||||
private Date created;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
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 ContainerNodePoolModel {
|
||||
private String name;
|
||||
private String nodepoolUuid;
|
||||
private String remark;
|
||||
private String status;
|
||||
private String regionId;
|
||||
private String clusterUuid;
|
||||
private String clusterName;
|
||||
private boolean isDefault;
|
||||
private String type;
|
||||
private Long totalNodes;
|
||||
private Long healthyNodes;
|
||||
private Long failedNodes;
|
||||
private Date created;
|
||||
private String kubernetesConfig;
|
||||
private String scalingGroup;
|
||||
// 天翼云的数据
|
||||
private Long cpu;
|
||||
private Long memory;
|
||||
private String vmSpecName; // 节点规格
|
||||
private String vmSpecType; // 节点规格类型
|
||||
private String vmSpecId; // 节点规格id
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.bocloud.ctstack.plugin.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ContarinerClusterModel {
|
||||
|
||||
private String name;
|
||||
}
|
|
@ -35,7 +35,7 @@ public class TianyiSyncModel {
|
|||
private List<PhysicalServerModel> physicalModels;
|
||||
private ResourcePoolModel resourcePoolModel;
|
||||
private List<RdsModel> rdsModels;
|
||||
private List<ContarinerClusterModel> contarinerClusterModels;
|
||||
private List<ContainerClusterModel> containerClusterModels;
|
||||
/**
|
||||
* @param serverModels
|
||||
* @param imageModels
|
||||
|
|
|
@ -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;
|
||||
// 天翼云使用字段 结束
|
||||
}
|
|
@ -100,6 +100,16 @@ public class TianyiProvider {
|
|||
return httpClient.get(header, params, uri);
|
||||
}
|
||||
|
||||
public Result doGet2(String url, Map<String, Object> headers, Map<String, Object> params) {
|
||||
HttpClient httpClient = new HttpClient(60 * 1000, PostDataFormat.RAW);
|
||||
httpClient.setDataFormat(null);
|
||||
|
||||
String uri = "http://ccse-global.ctapi.ctyun.local:31167" + url;
|
||||
Map<String, Object> header = buildHeader(HttpRequestMethod.GET, url, headers, params);
|
||||
printCurl(HttpRequestMethod.GET, uri, header, params);
|
||||
return httpClient.get(header, params, uri);
|
||||
}
|
||||
|
||||
public Result doGetWithBody(String url, Map<String, Object> headers, Map<String, Object> params) {
|
||||
try {
|
||||
//创建httpclient对象
|
||||
|
@ -150,6 +160,20 @@ public class TianyiProvider {
|
|||
return httpClient.post(header, params, uri);
|
||||
}
|
||||
|
||||
public Result doPut(String url, Map<String, Object> headers, Map<String, Object> params) {
|
||||
HttpClient httpClient = new HttpClient(60 * 1000, PostDataFormat.RAW);
|
||||
String uri = buildUrl(url);
|
||||
Map<String, Object> header = buildHeader(HttpRequestMethod.PUT, url, headers, params);
|
||||
printCurl(HttpRequestMethod.PUT, uri, header, params);
|
||||
return httpClient.post(header, params, uri);
|
||||
}
|
||||
|
||||
public Result doDelete(String url, Map<String, Object> headers) {
|
||||
HttpClient httpClient = new HttpClient(20 * 1000, PostDataFormat.RAW);
|
||||
httpClient.setDataFormat(null);
|
||||
return httpClient.get(buildHeader(HttpRequestMethod.DELETE, url, headers, null), null, buildUrl(url));
|
||||
}
|
||||
|
||||
public String getCtUserId() {
|
||||
return ctUserId;
|
||||
}
|
||||
|
|
|
@ -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.setContarinerClusterModels((List<ContarinerClusterModel>) 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);
|
||||
}
|
||||
|
||||
// 同步云硬盘
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package com.bocloud.ctstack.plugin.provider.container;
|
||||
|
||||
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.ContarinerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.provider.TianyiProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.tianyiconvertor.BeanConvertor;
|
||||
import com.bocloud.ctstack.plugin.provider.tianyiconvertor.ContainerClusterConvertor;
|
||||
|
@ -12,6 +11,7 @@ import com.megatron.common.model.GeneralResult;
|
|||
import com.megatron.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
public class TianYiContainerClusterProvider extends TianyiProvider {
|
||||
|
||||
|
||||
BeanConvertor<ContarinerClusterModel, JSONObject> containerClusterConvertor = new ContainerClusterConvertor();
|
||||
BeanConvertor<ContainerClusterModel, JSONObject> containerClusterConvertor = new ContainerClusterConvertor();
|
||||
|
||||
Butler butler = null;
|
||||
|
||||
|
@ -37,18 +37,112 @@ public class TianYiContainerClusterProvider extends TianyiProvider {
|
|||
|
||||
public GeneralResult list() {
|
||||
try {
|
||||
String url = "/v1.1/ccse/clusters/page";
|
||||
Integer pageNow = 1;
|
||||
Integer pageSize = 100;
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("pageSize", pageSize);
|
||||
Map<String, Object> header = new HashMap<>();
|
||||
header.put("regionId", this.getRegionId());
|
||||
Result result = doGet(url, header);
|
||||
log.info("result:{}", JSON.toJSONString(result));
|
||||
JSONObject checkedResult = checkResult(result, "查询容器集群列表");
|
||||
log.info("checkedResult:{}", JSON.toJSONString(checkedResult));
|
||||
List<JSONObject> records = JSONObject.parseObject(checkedResult.getString("records"), List.class);
|
||||
String url = "/v1.1/ccse/clusters/page";
|
||||
List<JSONObject> records = new ArrayList<>();
|
||||
|
||||
while (true) {
|
||||
body.put("pageNow", pageNow);
|
||||
Result result = doGet2(url, header, body);
|
||||
JSONObject returnObj = checkResult(result, "查询容器集群列表");
|
||||
log.info("checkedResult:{}", JSON.toJSONString(returnObj));
|
||||
records.addAll(JSONObject.parseObject(returnObj.getString("records"), List.class));
|
||||
pageNow++;
|
||||
Integer current = returnObj.getInteger("current");
|
||||
Integer pages = returnObj.getInteger("pages");
|
||||
if (current == pages) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new GeneralResult(true, containerClusterConvertor.convertList(records), "查询成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询容器集群列表失败 : " + e);
|
||||
return new GeneralResult(false, "查询容器集群列表失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult create(ContainerClusterModel model) {
|
||||
try {
|
||||
String url = "/v1.1/ccse/clusters/createByPaas";
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
|
||||
// 容器body参数
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("reqType", "2"); // 2为天翼云, 1桌面云
|
||||
body.put("resPoolId", model.getResourceGroupUuid());
|
||||
// clusterBaseV2VO参数
|
||||
JSONObject clusterBaseV2VO = new JSONObject();
|
||||
body.put("clusterBaseV2VO", clusterBaseV2VO);
|
||||
// masterHost参数
|
||||
JSONObject masterHost = new JSONObject();
|
||||
body.put("masterHost", masterHost);
|
||||
// slaveHost参数
|
||||
JSONObject slaveHost = new JSONObject();
|
||||
body.put("slaveHost", slaveHost);
|
||||
|
||||
Result result = doPost(url, headers, body);
|
||||
JSONObject returnObj = checkResult(result, "创建容器集群");
|
||||
// TODO: 等待订单完成
|
||||
return detail(model.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("创建容器集群失败 : " + e);
|
||||
return new GeneralResult(false, "创建容器集群失失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult remove(String poolId, String InstanceId) {
|
||||
try {
|
||||
String url = "/v1.1/ccse/clusters/deleteByPaas";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("resPoolId", poolId);
|
||||
body.put("prodInstId", InstanceId);
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doPost(url, headers, body);
|
||||
checkResult(result, "删除容器集群");
|
||||
return new GeneralResult(true, "删除容器集群成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除容器集群失败 : " + e);
|
||||
return new GeneralResult(false, "删除容器集群失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult detail(String clusterName) {
|
||||
try {
|
||||
String apiUrl = "/v1.1/ccse/clusters/" + clusterName;
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doGet(apiUrl, headers);
|
||||
JSONObject returnObj = checkResult(result, "查询容器集群详情");
|
||||
// TODO:
|
||||
ContainerClusterModel model = JSONObject.parseObject(JSONObject.toJSONString(returnObj), ContainerClusterModel.class);
|
||||
return new GeneralResult(true, model, "查询容器集群详情成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询容器集群详情失败 : " + e);
|
||||
return new GeneralResult(false, null, "查询容器集群详情失败");
|
||||
}
|
||||
}
|
||||
|
||||
private GeneralResult modifyDesc(String clusterName, String clusterDesc) {
|
||||
try {
|
||||
String apiUrl = "/ccse/clusters/" + clusterName;
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("clusterDesc", clusterDesc);
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doPut(apiUrl, headers, body);
|
||||
checkResult(result, "修改集群描述");
|
||||
return detail(clusterName);
|
||||
} catch (Exception e) {
|
||||
log.error("修改容器集群失败 : " + e);
|
||||
return new GeneralResult(false, "修改容器集群失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
package com.bocloud.ctstack.plugin.provider.container;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.cmp.domain.Butler;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerNodeModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerNodePoolModel;
|
||||
import com.bocloud.ctstack.plugin.provider.TianyiProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.tianyiconvertor.BeanConvertor;
|
||||
import com.bocloud.ctstack.plugin.provider.tianyiconvertor.ContainerNodeConvertor;
|
||||
import com.bocloud.ctstack.plugin.provider.tianyiconvertor.ContainerNodePoolConvertor;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class TianYiContainerNodeProvider extends TianyiProvider {
|
||||
BeanConvertor<ContainerNodeModel, JSONObject> nodeConvertor = new ContainerNodeConvertor();
|
||||
BeanConvertor<ContainerNodePoolModel, JSONObject> nodePoolConvertor = new ContainerNodePoolConvertor();
|
||||
|
||||
Butler butler = null;
|
||||
|
||||
/**
|
||||
* 构造方法,所有的云平台驱动都必须要实现或重写该构造方法
|
||||
*
|
||||
* @param butler 云平台认证信息
|
||||
*/
|
||||
public TianYiContainerNodeProvider(Butler butler) {
|
||||
super(butler);
|
||||
this.butler = butler;
|
||||
}
|
||||
|
||||
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 {
|
||||
String url = "/ccse/clusters/" + poolModel.getClusterName() + "/nodePool";
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
|
||||
// 容器body参数
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("nodePoolName", poolModel.getName());
|
||||
body.put("vmSpecName", poolModel.getVmSpecName());
|
||||
body.put("vmSpecId", poolModel.getVmSpecId());
|
||||
body.put("cpu", poolModel.getCpu());
|
||||
body.put("memory", poolModel.getMemory());
|
||||
|
||||
Result result = doPost(url, headers, body);
|
||||
JSONObject returnObj = checkResult(result, "创建容器集群");
|
||||
|
||||
return detailNodePool(poolModel.getClusterName(), poolModel.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("创建容器集群节点池失败 : " + e);
|
||||
return new GeneralResult(false, "创建容器集群节点池失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult detailNodePool(String clusterName, String poolName) {
|
||||
try {
|
||||
String apiUrl = "/v1.1/ccse/clusters/" + clusterName + "/nodePool/" + poolName;
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doGet(apiUrl, headers);
|
||||
JSONObject returnObj = checkResult(result, "查询容器节点池详情");
|
||||
ContainerNodePoolModel poolModel = nodePoolConvertor.convertModel(returnObj);
|
||||
return new GeneralResult(true, poolModel, "查询容器节点池详情成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询容器节点池详情失败 : " + e);
|
||||
return new GeneralResult(false, null, "查询容器节点池详情失败");
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult listNodePools(String clusterName) {
|
||||
try {
|
||||
Integer pageNow = 1;
|
||||
Integer pageSize = 100;
|
||||
String url = "/v1.1/ccse/clusters/" + clusterName + "/nodePool/page";
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("pageSize", pageSize);
|
||||
Map<String, Object> header = new HashMap<>();
|
||||
header.put("regionId", this.getRegionId());
|
||||
List<JSONObject> records = new ArrayList<>();
|
||||
|
||||
while (true) {
|
||||
body.put("pageNow", pageNow);
|
||||
Result result = doGet(url, header, body);
|
||||
JSONObject returnObj = checkResult(result, "容器集群节点池列表");
|
||||
records.addAll(JSONObject.parseObject(returnObj.getString("records"), List.class));
|
||||
pageNow++;
|
||||
Integer current = returnObj.getInteger("current");
|
||||
Integer pages = returnObj.getInteger("pages");
|
||||
if (current == pages) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new GeneralResult(true, nodePoolConvertor.convertList(records), "查询容器集群节点池列表成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询容器集群节点池列表失败 : " + e);
|
||||
return new GeneralResult(false, "查询容器集群节点池列表失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult deleteNodePool(String clusterName, String poolName) {
|
||||
try {
|
||||
String url = "/ccse/clusters/" + clusterName + "/nodePool/" + poolName + "/delete";
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doDelete(url, headers);
|
||||
checkResult(result, "删除容器节点资源池");
|
||||
return new GeneralResult(true, "删除容器节点资源池成功");
|
||||
} catch (Exception e) {
|
||||
log.error("删除容器节点资源池失败 : " + e);
|
||||
return new GeneralResult(false, "删除容器节点资源池失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,47 @@
|
|||
package com.bocloud.ctstack.plugin.provider.tianyiconvertor;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContarinerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerClusterModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerClusterConvertor implements BeanConvertor<ContarinerClusterModel, JSONObject> {
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class ContainerClusterConvertor implements BeanConvertor<ContainerClusterModel, JSONObject> {
|
||||
|
||||
@Override
|
||||
public List<ContarinerClusterModel> convertList(List<? extends JSONObject> list) {
|
||||
List<ContarinerClusterModel> contarinerClusterModels = new ArrayList<>();
|
||||
public List<ContainerClusterModel> convertList(List<? extends JSONObject> list) {
|
||||
List<ContainerClusterModel> containerClusterModels = new ArrayList<>();
|
||||
for (JSONObject object : list) {
|
||||
contarinerClusterModels.add(convertModel(object));
|
||||
containerClusterModels.add(convertModel(object));
|
||||
}
|
||||
return contarinerClusterModels;
|
||||
return containerClusterModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContarinerClusterModel convertModel(JSONObject jsonObject) {
|
||||
public ContainerClusterModel convertModel(JSONObject jsonObject) {
|
||||
if (null == jsonObject) return null;
|
||||
if (jsonObject.isEmpty()) return null;
|
||||
ContarinerClusterModel contarinerClusterModel = new ContarinerClusterModel();
|
||||
ContainerClusterModel containerClusterModel = new ContainerClusterModel();
|
||||
|
||||
contarinerClusterModel.setName(jsonObject.getString("clusterName"));
|
||||
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"));
|
||||
containerClusterModel.setStatus(jsonObject.getString("clusterStatus"));
|
||||
containerClusterModel.setServiceCidr(jsonObject.getString("serviceCidr"));
|
||||
containerClusterModel.setNodeCidr(jsonObject.getString("podCidr"));
|
||||
containerClusterModel.setCreated(jsonObject.getDate("createdTime"));
|
||||
containerClusterModel.setBusinessId(jsonObject.getLong("bizState"));
|
||||
containerClusterModel.setResourceGroupUuid(jsonObject.getString("resPoolId"));
|
||||
containerClusterModel.setEipUuid(jsonObject.getString("eip"));
|
||||
containerClusterModel.setExpiredTime(jsonObject.getDate("expireTime"));
|
||||
containerClusterModel.setLoadBalancerUuid(jsonObject.getString("masterSlbIp"));
|
||||
containerClusterModel.setVpcUuid(jsonObject.getString("vpcId"));
|
||||
|
||||
return contarinerClusterModel;
|
||||
return containerClusterModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.bocloud.ctstack.plugin.provider.tianyiconvertor;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerNodeModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerNodeConvertor implements BeanConvertor<ContainerNodeModel, JSONObject> {
|
||||
|
||||
|
||||
@Override
|
||||
public List<ContainerNodeModel> convertList(List<? extends JSONObject> list) {
|
||||
List<ContainerNodeModel> containerNodeModels = new ArrayList<>();
|
||||
for (JSONObject object : list) {
|
||||
containerNodeModels.add(convertModel(object));
|
||||
}
|
||||
return containerNodeModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerNodeModel convertModel(JSONObject jsonObject) {
|
||||
if (null == jsonObject) return null;
|
||||
if (jsonObject.isEmpty()) return null;
|
||||
ContainerNodeModel containerNodeModel = new ContainerNodeModel();
|
||||
|
||||
containerNodeModel.setNodeName(jsonObject.getString("nodeName"));
|
||||
containerNodeModel.setNodeStatus(jsonObject.getString("nodeStatus"));
|
||||
containerNodeModel.setCreated(jsonObject.getDate("createdTime"));
|
||||
|
||||
return containerNodeModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.bocloud.ctstack.plugin.provider.tianyiconvertor;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.ctstack.plugin.domain.model.ContainerNodePoolModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ContainerNodePoolConvertor implements BeanConvertor<ContainerNodePoolModel, JSONObject> {
|
||||
|
||||
|
||||
@Override
|
||||
public List<ContainerNodePoolModel> convertList(List<? extends JSONObject> list) {
|
||||
List<ContainerNodePoolModel> containerNodePoolModels = new ArrayList<>();
|
||||
for (JSONObject object : list) {
|
||||
containerNodePoolModels.add(convertModel(object));
|
||||
}
|
||||
return containerNodePoolModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerNodePoolModel convertModel(JSONObject jsonObject) {
|
||||
if (null == jsonObject) return null;
|
||||
if (jsonObject.isEmpty()) return null;
|
||||
ContainerNodePoolModel containerNodePoolModel = new ContainerNodePoolModel();
|
||||
|
||||
containerNodePoolModel.setName(jsonObject.getString("nodePoolName"));
|
||||
containerNodePoolModel.setNodepoolUuid(jsonObject.getString("nodePoolName"));
|
||||
containerNodePoolModel.setRemark(jsonObject.getString("description"));
|
||||
containerNodePoolModel.setStatus(jsonObject.getString("status"));
|
||||
//containerNodePoolModel.setIsDefault(jsonObject.getBoolean("isDefault"));
|
||||
containerNodePoolModel.setVmSpecType(jsonObject.getString("vmType"));
|
||||
containerNodePoolModel.setVmSpecName(jsonObject.getString("vmSpecName"));
|
||||
containerNodePoolModel.setVmSpecId(jsonObject.getString("vmSpecId"));
|
||||
containerNodePoolModel.setCpu(jsonObject.getLong("cpu"));
|
||||
containerNodePoolModel.setMemory(jsonObject.getLong("memory"));
|
||||
containerNodePoolModel.setVmSpecId(jsonObject.getString("vmSpecId"));
|
||||
containerNodePoolModel.setFailedNodes(jsonObject.getLong("unNormalNodeNum"));
|
||||
containerNodePoolModel.setHealthyNodes(jsonObject.getLong("normalNodeNum"));
|
||||
containerNodePoolModel.setTotalNodes(jsonObject.getLong("nodeTotalNum"));
|
||||
containerNodePoolModel.setCreated(jsonObject.getDate("createdTime"));
|
||||
containerNodePoolModel.setKubernetesConfig(jsonObject.getString("kubeletArgs"));
|
||||
containerNodePoolModel.setScalingGroup(jsonObject.getString("nodeGroup"));
|
||||
|
||||
return containerNodePoolModel;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,9 @@ public class TyHttpUtils {
|
|||
headersOfAuth.put("hybrid-date", hybridDate);
|
||||
String requestId = UUID.randomUUID().toString().replace("-", "");
|
||||
headersOfAuth.put("ctyun-hybrid-request-id", requestId);
|
||||
logger.info("----------------------------------------------------------");
|
||||
logger.info(requestId);
|
||||
logger.info("----------------------------------------------------------");
|
||||
String forSignature = forSignature(method, headersOfAuth, params);
|
||||
byte[] kdate = kdate(hybridDate, accessKey, secretKey);
|
||||
byte[] signatureBytes = HmacSHA256Util.hmacSHA256(forSignature.getBytes(StandardCharsets.UTF_8), kdate);
|
||||
|
@ -49,6 +52,9 @@ public class TyHttpUtils {
|
|||
newHeaders.put("Content-Type", "application/json");
|
||||
newHeaders.put("hybrid-date", hybridDate);
|
||||
newHeaders.put("ctyun-hybrid-request-id", requestId);
|
||||
logger.info("----------------------------------------------------------");
|
||||
logger.info(requestId);
|
||||
logger.info("----------------------------------------------------------");
|
||||
newHeaders.put("Hybrid-Authorization", authorization);
|
||||
newHeaders.put("ctUserId", ctUserId);
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.megatron.common.model.Pager;
|
||||
import com.megatron.common.model.Param;
|
||||
import com.megatron.common.model.SimpleBean;
|
||||
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.ArrayList;
|
||||
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 int count(List<Param> params) {
|
||||
String sql = "select count(1) from container_cluster a where a.is_deleted = 0";
|
||||
sql = this.getQueryBuilder().buildRaw(sql, params, null, "a");
|
||||
Map<String, Object> paramMap = this.getQueryBuilder().getParam(params);
|
||||
return this.countQuery(sql, paramMap).intValue();
|
||||
}
|
||||
|
||||
public List<ContainerCluster> list(int page, int rows, List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.*,b.name vdc_name,c.name vendor_name , r.name region_name from container_cluster a "
|
||||
+ " left join vdc b on a.vdc_id = b.id "
|
||||
+ " left join cloud_vendor c on a.vendor_id = c.id "
|
||||
+ " left join region r on a.region_id = r.id and a.vendor_id = r.vendor_id "
|
||||
+ " where a.is_deleted = 0 ";
|
||||
sql = this.getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "a");
|
||||
Map<String, Object> paramMap = this.getQueryBuilder().getParam(params);
|
||||
return this.list(ContainerCluster.class, sql, paramMap);
|
||||
}
|
||||
|
||||
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 List<SimpleBean> list(List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.id,a.name from container_cluster a where a.is_deleted = 0";
|
||||
sql = this.getQueryBuilder().build(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a");
|
||||
Map<String, Object> paramMap = this.getQueryBuilder().getParam(params);
|
||||
List<ContainerCluster> clusters = this.list(ContainerCluster.class, sql, paramMap);
|
||||
List<SimpleBean> beans = new ArrayList<SimpleBean>();
|
||||
for (ContainerCluster cluster : clusters) {
|
||||
beans.add(new SimpleBean(cluster.getId(), cluster.getName()));
|
||||
}
|
||||
return beans;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.bocloud.ctstack.plugin.service;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.GridBean;
|
||||
import com.megatron.common.model.Pager;
|
||||
|
||||
public interface ContainerService {
|
||||
|
||||
GeneralResult<GridBean<ContainerCluster>> list(Pager pager);
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.bocloud.ctstack.plugin.service.impl;
|
||||
|
||||
import com.bocloud.cmp.entity.Server;
|
||||
import com.bocloud.cmp.entity.ServerConfig;
|
||||
import com.bocloud.ctstack.plugin.entity.Cluster;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.bocloud.ctstack.plugin.repository.ContainerClusterRepository;
|
||||
import com.bocloud.ctstack.plugin.service.ContainerService;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.GridBean;
|
||||
import com.megatron.common.model.Pager;
|
||||
import com.megatron.common.model.SimpleBean;
|
||||
import com.megatron.common.utils.Common;
|
||||
import com.megatron.common.utils.GridHelper;
|
||||
import com.megatron.common.utils.ListTool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service("containerService")
|
||||
public class ContainerServiceImpl implements ContainerService {
|
||||
|
||||
@Autowired
|
||||
private ContainerClusterRepository containerClusterRepository;
|
||||
|
||||
@Override
|
||||
public GeneralResult<GridBean<ContainerCluster>> list(Pager pager) {
|
||||
GridBean gridBean = null;
|
||||
try {
|
||||
pager.getSorter().put("gmtCreate", Common.ONE);
|
||||
int total = this.containerClusterRepository.count(pager.getParams());
|
||||
if (pager.getSimple()) {
|
||||
List<SimpleBean> beans = this.containerClusterRepository.list(pager.getParams(), pager.getSorter());
|
||||
gridBean = new GridBean(1, 1, total, beans);
|
||||
} else {
|
||||
List<ContainerCluster> list = this.containerClusterRepository.list(pager.getPage(), pager.getRows(), pager.getParams(), pager.getSorter());
|
||||
gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list);
|
||||
}
|
||||
return new GeneralResult<>(true, gridBean, "查询成功");
|
||||
} catch (Exception e) {
|
||||
log.error("Query container cluster list fail:", e);
|
||||
return new GeneralResult<>(false, "查询容器集群失败");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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