From a56102c285446a5a773d084fa0bb557aa227a1ba Mon Sep 17 00:00:00 2001 From: tanshaolong Date: Wed, 4 Sep 2024 13:56:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E7=BF=BC=E4=BA=91=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E8=B5=84=E6=BA=90=E7=BA=B3=E7=AE=A1=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/ContainerClusterModel.java | 35 +++++ .../domain/model/ContainerNodeModel.java | 19 +++ .../domain/model/ContainerNodePoolModel.java | 35 +++++ .../domain/model/ContarinerClusterModel.java | 13 -- .../plugin/domain/model/TianyiSyncModel.java | 2 +- .../plugin/provider/TianyiProvider.java | 14 ++ .../common/TianyiLocationProvider.java | 2 +- .../TianYiContainerClusterProvider.java | 112 ++++++++++++-- .../TianYiContainerNodeProvider.java | 137 ++++++++++++++++++ .../ContainerClusterConvertor.java | 40 +++-- .../ContainerNodeConvertor.java | 33 +++++ .../ContainerNodePoolConvertor.java | 48 ++++++ 12 files changed, 453 insertions(+), 37 deletions(-) create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerClusterModel.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodeModel.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodePoolModel.java delete mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContarinerClusterModel.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerNodeProvider.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodeConvertor.java create mode 100644 bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodePoolConvertor.java diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerClusterModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerClusterModel.java new file mode 100644 index 00000000..0bd9120d --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerClusterModel.java @@ -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; + +@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; + + + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodeModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodeModel.java new file mode 100644 index 00000000..7e2d09b2 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodeModel.java @@ -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; +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodePoolModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodePoolModel.java new file mode 100644 index 00000000..6cfd1eea --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContainerNodePoolModel.java @@ -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 + +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContarinerClusterModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContarinerClusterModel.java deleted file mode 100644 index c93a2928..00000000 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/ContarinerClusterModel.java +++ /dev/null @@ -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; -} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java index c216c52a..ef09e34a 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/domain/model/TianyiSyncModel.java @@ -34,7 +34,7 @@ public class TianyiSyncModel { private List hostModels; private ResourcePoolModel resourcePoolModel; private List rdsModels; - private List contarinerClusterModels; + private List containerClusterModels; /** * @param serverModels * @param imageModels diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/TianyiProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/TianyiProvider.java index 1d21587b..b602dd0d 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/TianyiProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/TianyiProvider.java @@ -150,6 +150,20 @@ public class TianyiProvider { return httpClient.post(header, params, uri); } + public Result doPut(String url, Map headers, Map params) { + HttpClient httpClient = new HttpClient(60 * 1000, PostDataFormat.RAW); + String uri = buildUrl(url); + Map 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 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; } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java index 25b239b8..bd8adb5f 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/common/TianyiLocationProvider.java @@ -290,7 +290,7 @@ public class TianyiLocationProvider extends TianyiProvider { GeneralResult containerClusterList = tianYiContainerClusterProvider.list(); log.info("同步容器结果:{}",containerClusterList.isSuccess()); if (containerClusterList.isSuccess()) { - syncModel.setContarinerClusterModels((List) containerClusterList.getData()); + syncModel.setContainerClusterModels((List) containerClusterList.getData()); } // 同步云硬盘 diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerClusterProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerClusterProvider.java index 4eec0800..2f97801a 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerClusterProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerClusterProvider.java @@ -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 containerClusterConvertor = new ContainerClusterConvertor(); + BeanConvertor 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 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 records = JSONObject.parseObject(checkedResult.getString("records"), List.class); + String url = "/v1.1/ccse/clusters/page"; + List records = new ArrayList<>(); + + while (true) { + body.put("pageNow", pageNow); + Result result = doGet(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 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 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 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 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()); + } + } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerNodeProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerNodeProvider.java new file mode 100644 index 00000000..1067a028 --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/container/TianYiContainerNodeProvider.java @@ -0,0 +1,137 @@ +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 nodeConvertor = new ContainerNodeConvertor(); + BeanConvertor 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 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 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 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 header = new HashMap<>(); + header.put("regionId", this.getRegionId()); + List 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 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()); + } + } +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerClusterConvertor.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerClusterConvertor.java index acbc7704..a000183e 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerClusterConvertor.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerClusterConvertor.java @@ -1,31 +1,45 @@ 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 { +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +public class ContainerClusterConvertor implements BeanConvertor { @Override - public List convertList(List list) { - List contarinerClusterModels = new ArrayList<>(); + public List convertList(List list) { + List 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")); + 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; } } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodeConvertor.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodeConvertor.java new file mode 100644 index 00000000..54ac320d --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodeConvertor.java @@ -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 { + + + @Override + public List convertList(List list) { + List 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; + } +} diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodePoolConvertor.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodePoolConvertor.java new file mode 100644 index 00000000..7bb644dc --- /dev/null +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/tianyiconvertor/ContainerNodePoolConvertor.java @@ -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 { + + + @Override + public List convertList(List list) { + List 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; + } +} +