添加天翼云容器集群接口
parent
5e0fdf4016
commit
387a702d17
|
@ -1,7 +1,10 @@
|
|||
package com.bocloud.ctstack.plugin.controller;
|
||||
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerNodePoolModel;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNode;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNodePool;
|
||||
import com.bocloud.ctstack.plugin.service.ContainerService;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.GridBean;
|
||||
|
@ -34,6 +37,42 @@ public class ContainerController {
|
|||
return containerService.list(pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看集群详情
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询集群详情")
|
||||
@GetMapping("/{id}")
|
||||
public GeneralResult<ContainerCluster> detail(@PathVariable(value = Common.ID) Long id) {
|
||||
return containerService.detail(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看集群下节点列表
|
||||
*
|
||||
* @param pager
|
||||
* @return
|
||||
*/
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询集群节点列表")
|
||||
@GetMapping("/nodes")
|
||||
public GeneralResult<GridBean<ContainerClusterNode>> listClusterNodes(Pager pager) {
|
||||
return containerService.listClusterNodes(pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看集群下节点池列表
|
||||
*
|
||||
* @param pager
|
||||
* @return
|
||||
*/
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "查询集群节点池列表")
|
||||
@GetMapping("/nodepools")
|
||||
public GeneralResult<GridBean<ContainerClusterNodePool>> listClusterNodePools(Pager pager) {
|
||||
return containerService.listClusterNodePools(pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加集群
|
||||
*
|
||||
|
@ -47,4 +86,32 @@ public class ContainerController {
|
|||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return containerService.create(model, context);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "删除容器集群")
|
||||
@DeleteMapping("/{id}")
|
||||
public GeneralResult remove(@PathVariable(value = Common.ID) Long id,
|
||||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return containerService.remove(id, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 集群创建节点池
|
||||
*
|
||||
* @param model
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "创建集群节点池")
|
||||
@PostMapping("/nodepool")
|
||||
public GeneralResult<ContainerClusterNodePool> createNodePool(@RequestBody ContainerNodePoolModel model,
|
||||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return containerService.createNodePool(model, context);
|
||||
}
|
||||
|
||||
@Operation(tags = {"CMC", "CSC"}, summary = "删除容器集群节点池")
|
||||
@DeleteMapping("nodepool/{id}")
|
||||
public GeneralResult removeNodePool(@PathVariable(value = Common.ID) Long id,
|
||||
@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||
return containerService.removeNodePool(id, context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public class ContainerClusterModel {
|
|||
private String resourceGroupUuid;
|
||||
private String serviceCidr;
|
||||
private Long businessId;
|
||||
private String prodInstId; // 平台实例ID
|
||||
private String resPoolId; // 资源池ID
|
||||
private List<ContainerNodeModel> nodeModels;
|
||||
private List<ContainerNodePoolModel> nodePoolModels;
|
||||
|
||||
|
|
|
@ -25,11 +25,13 @@ public class ContainerNodePoolModel {
|
|||
private Date created;
|
||||
private String kubernetesConfig;
|
||||
private String scalingGroup;
|
||||
private Long vendorId;
|
||||
|
||||
// 天翼云的数据
|
||||
private Long cpu;
|
||||
private Long memory;
|
||||
private String vmSpecName; // 节点规格
|
||||
private String vmSpecType; // 节点规格类型
|
||||
private String vmSpecId; // 节点规格id
|
||||
private Long vmSpecId; // 节点规格id
|
||||
|
||||
}
|
||||
|
|
|
@ -72,4 +72,10 @@ public class ContainerCluster extends GenericEntity {
|
|||
|
||||
@Column("is_recycle")
|
||||
private Boolean isRecycle;
|
||||
|
||||
@Column("resource_pool_id")
|
||||
private String resPoolId; // 资源池ID
|
||||
|
||||
@Column("prod_instance_id")
|
||||
private String prodInstId; // 平台实例ID
|
||||
}
|
||||
|
|
|
@ -163,8 +163,8 @@ public class TianYiContainerClusterProvider extends TianyiProvider {
|
|||
headers.put("regionId", this.getRegionId());
|
||||
Result result = doGet(apiUrl, headers);
|
||||
JSONObject returnObj = checkResult(result, "查询容器集群详情");
|
||||
// TODO:
|
||||
ContainerClusterModel model = JSONObject.parseObject(JSONObject.toJSONString(returnObj), ContainerClusterModel.class);
|
||||
|
||||
ContainerClusterModel model = containerClusterConvertor.convertModel(returnObj);
|
||||
return new GeneralResult(true, model, "查询容器集群详情成功");
|
||||
} catch (Exception e) {
|
||||
log.error("查询容器集群详情失败 : " + e);
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.bocloud.ctstack.plugin.provider.tianyiconvertor.ContainerNodePoolConv
|
|||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -64,6 +65,9 @@ public class TianYiContainerNodeProvider extends TianyiProvider {
|
|||
body.put("vmSpecId", poolModel.getVmSpecId());
|
||||
body.put("cpu", poolModel.getCpu());
|
||||
body.put("memory", poolModel.getMemory());
|
||||
if (!StringUtils.isEmpty(poolModel.getRemark())) {
|
||||
body.put("description", poolModel.getRemark());
|
||||
}
|
||||
|
||||
Result result = doPost(url, headers, body);
|
||||
JSONObject returnObj = checkResult(result, "创建容器集群");
|
||||
|
|
|
@ -31,10 +31,9 @@ public class ContainerNodePoolConvertor implements BeanConvertor<ContainerNodePo
|
|||
//containerNodePoolModel.setIsDefault(jsonObject.getBoolean("isDefault"));
|
||||
containerNodePoolModel.setVmSpecType(jsonObject.getString("vmType"));
|
||||
containerNodePoolModel.setVmSpecName(jsonObject.getString("vmSpecName"));
|
||||
containerNodePoolModel.setVmSpecId(jsonObject.getString("vmSpecId"));
|
||||
containerNodePoolModel.setVmSpecId(jsonObject.getLong("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"));
|
||||
|
|
|
@ -79,4 +79,20 @@ public class ContainerClusterRepository extends BasicGenericDao<ContainerCluster
|
|||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public ContainerCluster query(Long id) {
|
||||
String sql = "select a.*, v.name vpc_name, s.name subnet_name, s.cidr subnet_cidr, s.subnet_uuid subnet_uuid, g.name security_group_name, os.name enterprise_project_name, r.name region_name from container_cluster a "
|
||||
+ "left join vpc v on v.id = a.vpc_id and v.is_deleted = 0 "
|
||||
+ "left join subnet s on s.id = a.subnet_id and s.is_deleted = 0 "
|
||||
+ "left join security_group g on g.id = a.security_group_id and g.is_deleted = 0 "
|
||||
+ "left join os_tenant os on a.vendor_id = os.vendor_id and a.enterprise_project_id = os.id "
|
||||
+ "left join region r on r.vendor_id = a.vendor_id and r.region_id = a.region_id "
|
||||
+ "where a.is_deleted = 0 and a.id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
|
||||
List<ContainerCluster> list = this.list(ContainerCluster.class, sql, params);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNodePool;
|
||||
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;
|
||||
|
@ -9,6 +12,7 @@ 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;
|
||||
|
@ -20,6 +24,36 @@ public class ContainerNodePoolRepository extends BasicGenericDao<ContainerCluste
|
|||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
public int count(List<Param> params) {
|
||||
String sql = "select count(1) from container_cluster_node_pool 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<SimpleBean> list(List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.id, a.name from container_cluster_node_pool 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<ContainerClusterNodePool> pools = this.list(ContainerClusterNodePool.class, sql, paramMap);
|
||||
List<SimpleBean> beans = new ArrayList<SimpleBean>();
|
||||
for (ContainerClusterNodePool pool : pools) {
|
||||
beans.add(new SimpleBean(pool.getId(), pool.getName()));
|
||||
}
|
||||
return beans;
|
||||
}
|
||||
|
||||
public List<ContainerClusterNodePool> list(int page, int rows, List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.*,b.name cluster_name,c.name vendor_name, r.name region_name from container_cluster_node_pool a "
|
||||
+ " left join container_cluster b on a.cluster_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(ContainerClusterNodePool.class, sql, paramMap);
|
||||
}
|
||||
|
||||
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 ";
|
||||
|
@ -57,4 +91,17 @@ public class ContainerNodePoolRepository extends BasicGenericDao<ContainerCluste
|
|||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public ContainerClusterNodePool query(Long id) {
|
||||
String sql = "select a.*, os.name enterprise_project_name, r.name region_name from container_cluster_node_pool a "
|
||||
+ "left join os_tenant os on a.vendor_id = os.vendor_id and a.enterprise_project_id = os.id "
|
||||
+ "left join region r on r.vendor_id = a.vendor_id and r.region_id = a.region_id "
|
||||
+ "where a.is_deleted = 0 and a.id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
|
||||
List<ContainerClusterNodePool> list = this.list(ContainerClusterNodePool.class, sql, params);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.bocloud.ctstack.plugin.repository;
|
||||
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNode;
|
||||
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;
|
||||
|
@ -9,6 +12,7 @@ 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;
|
||||
|
@ -20,6 +24,36 @@ public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNod
|
|||
super(jdbcTemplate, npJdbcTemplate, service);
|
||||
}
|
||||
|
||||
public int count(List<Param> params) {
|
||||
String sql = "select count(1) from container_cluster_node 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<ContainerClusterNode> list(int page, int rows, List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.*,b.name cluster_name,c.name vendor_name, r.name region_name from container_cluster_node a "
|
||||
+ " left join container_cluster b on a.cluster_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(ContainerClusterNode.class, sql, paramMap);
|
||||
}
|
||||
|
||||
public List<SimpleBean> list(List<Param> params, Map<String, String> sorter) {
|
||||
String sql = "select a.id,a.name from container_cluster_node 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<ContainerClusterNode> nodes = this.list(ContainerClusterNode.class, sql, paramMap);
|
||||
List<SimpleBean> beans = new ArrayList<SimpleBean>();
|
||||
for (ContainerClusterNode node : nodes) {
|
||||
beans.add(new SimpleBean(node.getId(), node.getName()));
|
||||
}
|
||||
return beans;
|
||||
}
|
||||
|
||||
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 ";
|
||||
|
@ -57,4 +91,15 @@ public class ContainerNodeRepository extends BasicGenericDao<ContainerClusterNod
|
|||
params.put("gmtModify", new Date());
|
||||
return this.execute(sql, params) > 0;
|
||||
}
|
||||
|
||||
public ContainerClusterNode query(Long id) {
|
||||
String sql = "select a.* from container_cluster_node a "
|
||||
+ "where a.is_deleted = 0 and a.id = :id";
|
||||
Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
|
||||
List<ContainerClusterNode> list = this.list(ContainerClusterNode.class, sql, params);
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.bocloud.ctstack.plugin.service;
|
||||
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerNodePoolModel;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNode;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNodePool;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.GridBean;
|
||||
import com.megatron.common.model.Pager;
|
||||
|
@ -11,5 +14,17 @@ public interface ContainerService {
|
|||
|
||||
GeneralResult<GridBean<ContainerCluster>> list(Pager pager);
|
||||
|
||||
GeneralResult<ContainerCluster> detail(Long id);
|
||||
|
||||
GeneralResult<ContainerCluster> create(ContainerClusterModel model, RequestContext context);
|
||||
|
||||
GeneralResult remove(Long id, RequestContext context);
|
||||
|
||||
GeneralResult<ContainerClusterNodePool> createNodePool(ContainerNodePoolModel model, RequestContext context);
|
||||
|
||||
GeneralResult removeNodePool(Long id, RequestContext context);
|
||||
|
||||
GeneralResult<GridBean<ContainerClusterNode>> listClusterNodes(Pager pager);
|
||||
|
||||
GeneralResult<GridBean<ContainerClusterNodePool>> listClusterNodePools(Pager pager);
|
||||
}
|
||||
|
|
|
@ -2,17 +2,23 @@ package com.bocloud.ctstack.plugin.service.impl;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.cmp.entity.CloudVendor;
|
||||
import com.bocloud.cmp.entity.Server;
|
||||
import com.bocloud.cmp.entity.ServerConfig;
|
||||
import com.bocloud.cmp.repository.CloudVendorRepository;
|
||||
import com.bocloud.cmp.util.ResourceEventPublisher;
|
||||
import com.bocloud.ctstack.plugin.config.ButlerConfig;
|
||||
import com.bocloud.ctstack.plugin.domain.model.VpcModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerClusterModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.database.CreateRdsModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.database.RdsModel;
|
||||
import com.bocloud.ctstack.plugin.domain.model.container.ContainerNodePoolModel;
|
||||
import com.bocloud.ctstack.plugin.entity.Cluster;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerCluster;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNode;
|
||||
import com.bocloud.ctstack.plugin.entity.ContainerClusterNodePool;
|
||||
import com.bocloud.ctstack.plugin.provider.container.TianYiContainerClusterProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.database.TianyiRdsProvider;
|
||||
import com.bocloud.ctstack.plugin.provider.container.TianYiContainerNodeProvider;
|
||||
import com.bocloud.ctstack.plugin.repository.ContainerClusterRepository;
|
||||
import com.bocloud.ctstack.plugin.repository.ContainerNodePoolRepository;
|
||||
import com.bocloud.ctstack.plugin.repository.ContainerNodeRepository;
|
||||
import com.bocloud.ctstack.plugin.service.ContainerService;
|
||||
import com.megatron.common.model.*;
|
||||
import com.megatron.common.utils.Common;
|
||||
|
@ -27,7 +33,11 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service("containerService")
|
||||
|
@ -36,6 +46,12 @@ public class ContainerServiceImpl implements ContainerService {
|
|||
@Autowired
|
||||
private ContainerClusterRepository containerClusterRepository;
|
||||
|
||||
@Autowired
|
||||
private ContainerNodePoolRepository containerNodePoolRepository;
|
||||
|
||||
@Autowired
|
||||
private ContainerNodeRepository containerNodeRepository;
|
||||
|
||||
@Autowired
|
||||
private ResourceEventPublisher resourceEventPublisher;
|
||||
|
||||
|
@ -71,6 +87,20 @@ public class ContainerServiceImpl implements ContainerService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<ContainerCluster> detail(Long id) {
|
||||
try {
|
||||
ContainerCluster cluster = this.containerClusterRepository.query(id);
|
||||
if (null == cluster) {
|
||||
return new GeneralResult<>(false, "容器集群不存在");
|
||||
}
|
||||
return new GeneralResult<>(true, cluster, "查询详情成功");
|
||||
} catch (Exception e) {
|
||||
log.error("Get container cluster detail error:", e);
|
||||
return new GeneralResult<>(false, "查询详情失败");
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult<ContainerCluster> create(ContainerClusterModel model, RequestContext context) {
|
||||
try {
|
||||
CloudVendor vendor = cloudVendorRepository.query(model.getVendorId());
|
||||
|
@ -122,4 +152,150 @@ public class ContainerServiceImpl implements ContainerService {
|
|||
return new GeneralResult<ContainerCluster>(false, "创建容器集群失败", null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult remove(Long id, RequestContext context) {
|
||||
try {
|
||||
ContainerCluster cluster = containerClusterRepository.query(id);
|
||||
Assert.notNull(cluster, "容器集群不存在");
|
||||
CloudVendor vendor = cloudVendorRepository.query(cluster.getVendorId());
|
||||
Assert.notNull(vendor, "指定的地域下云平台不存在");
|
||||
|
||||
TianYiContainerClusterProvider provider =
|
||||
new TianYiContainerClusterProvider(butlerConfig.regionButler(vendor.getUuid(), cluster.getRegionId()));
|
||||
|
||||
provider.remove(cluster.getResPoolId(), cluster.getProdInstId());
|
||||
containerClusterRepository.remove(cluster.getId(), context.getTarget());
|
||||
return new GeneralResult<>(true, "删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("delete cloud rds failure:", e);
|
||||
return new GeneralResult<>(false, "删除失败", null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult<ContainerClusterNodePool> createNodePool(ContainerNodePoolModel model, RequestContext context) {
|
||||
try {
|
||||
CloudVendor vendor = cloudVendorRepository.query(model.getVendorId());
|
||||
Assert.notNull(vendor, "指定云平台不存在");
|
||||
|
||||
taskExecutor.submit(() -> {
|
||||
String operate = vendor.getType().toLowerCase() + ".cloudrds";
|
||||
String content = "容器集群节点池创建成功!";
|
||||
boolean result = true;
|
||||
try {
|
||||
TianYiContainerNodeProvider provider =
|
||||
new TianYiContainerNodeProvider(butlerConfig.regionButler(vendor.getUuid(), model.getRegionId()));
|
||||
GeneralResult createResult = provider.createNodePool(model);
|
||||
if (createResult.isFailed()) {
|
||||
result = false;
|
||||
content = createResult.getMessage();
|
||||
} else {
|
||||
// 保存新创建的容器节点池集群信息。
|
||||
ContainerNodePoolModel nodePoolModel =
|
||||
JSONObject.parseObject(JSONObject.toJSONString(createResult.getData()), ContainerNodePoolModel.class);
|
||||
ContainerClusterNodePool containerClusterNodePool = new ContainerClusterNodePool();
|
||||
BeanUtils.copyProperties(nodePoolModel, containerClusterNodePool);
|
||||
containerClusterNodePool.setVendorId(vendor.getId());
|
||||
containerClusterNodePool.setRegionId(model.getRegionId());
|
||||
containerClusterNodePool.setMenderId(context.getTarget());
|
||||
containerClusterNodePool.setCreatorId(context.getTarget());
|
||||
containerClusterNodePool.setTenantId(context.getTenant());
|
||||
containerClusterNodePool.setProjectId(context.getProject());
|
||||
containerNodePoolRepository.save(containerClusterNodePool);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("create cloud container failure:", e);
|
||||
result = false;
|
||||
content = e.getMessage();
|
||||
}
|
||||
resourceEventPublisher.send(new OperateResult(result, content, operate,
|
||||
MapTools.simpleMap(Common.VENDORID, vendor.getId()),
|
||||
OperateResult.OperateCategory.ResourceEvent, context));
|
||||
});
|
||||
return new GeneralResult<>(true, "任务已下发,正在执行...");
|
||||
} catch (Exception e) {
|
||||
log.error("create container node pool failure:", e);
|
||||
return new GeneralResult<ContainerClusterNodePool>(false, "创建容器集群节点池失败", null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralResult removeNodePool(Long id, RequestContext context) {
|
||||
try {
|
||||
ContainerClusterNodePool nodePool = containerNodePoolRepository.query(id);
|
||||
Assert.notNull(nodePool, "容器集群节点池不存在");
|
||||
CloudVendor vendor = cloudVendorRepository.query(nodePool.getVendorId());
|
||||
Assert.notNull(vendor, "指定的地域下云平台不存在");
|
||||
|
||||
TianYiContainerNodeProvider provider =
|
||||
new TianYiContainerNodeProvider(butlerConfig.regionButler(vendor.getUuid(), nodePool.getRegionId()));
|
||||
|
||||
provider.deleteNodePool(nodePool.getClusterUuid(), nodePool.getName());
|
||||
containerNodePoolRepository.remove(nodePool.getId(), context.getTarget());
|
||||
return new GeneralResult<>(true, "删除成功");
|
||||
} catch (Exception e) {
|
||||
log.error("delete cloud rds failure:", e);
|
||||
return new GeneralResult<>(false, "删除失败", null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<GridBean<ContainerClusterNode>> listClusterNodes(Pager pager) {
|
||||
GridBean gridBean = null;
|
||||
try {
|
||||
pager.getSorter().put("gmtCreate", Common.ONE);
|
||||
List<Param> params = pager.getParams();
|
||||
// for (Param param : params) {
|
||||
// Map<String, Object> paramMap = param.getParam();
|
||||
// if (paramMap.containsKey("clusterId")) {
|
||||
// Long clusterId = Long.valueOf(paramMap.get("cluserId").toString());
|
||||
// // 检查容器集群是否存在
|
||||
// ContainerCluster cluster = containerClusterRepository.query(clusterId);
|
||||
// Assert.notNull(cluster, "指定容器集群不存在");
|
||||
// paramMap.remove("cluserId");
|
||||
// }
|
||||
// }
|
||||
int total = this.containerNodeRepository.count(params);
|
||||
if (pager.getSimple()) {
|
||||
List<SimpleBean> beans = this.containerNodeRepository.list(params, pager.getSorter());
|
||||
gridBean = new GridBean(1, 1, total, beans);
|
||||
} else {
|
||||
List<ContainerClusterNode> list = this.containerNodeRepository.list(pager.getPage(), pager.getRows(), params, pager.getSorter());
|
||||
gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list);
|
||||
}
|
||||
return new GeneralResult<>(true, gridBean, "查询成功");
|
||||
} catch (Exception e) {
|
||||
log.error("Query container cluster nodes fail:", e);
|
||||
return new GeneralResult<>(false, "查询容器集群节点失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralResult<GridBean<ContainerClusterNodePool>> listClusterNodePools(Pager pager) {
|
||||
GridBean gridBean = null;
|
||||
try {
|
||||
pager.getSorter().put("gmtCreate", Common.ONE);
|
||||
List<Param> params = pager.getParams();
|
||||
// for (Param param : params) {
|
||||
// Map<String, Object> paramMap = param.getParam();
|
||||
// if (paramMap.containsKey("clusterId")) {
|
||||
// Long clusterId = Long.valueOf(paramMap.get("cluserId").toString());
|
||||
// // 检查容器集群是否存在
|
||||
// ContainerCluster cluster = containerClusterRepository.query(clusterId);
|
||||
// Assert.notNull(cluster, "指定容器集群不存在");
|
||||
// paramMap.remove("cluserId");
|
||||
// }
|
||||
// }
|
||||
int total = this.containerNodePoolRepository.count(params);
|
||||
if (pager.getSimple()) {
|
||||
List<SimpleBean> beans = this.containerNodePoolRepository.list(params, pager.getSorter());
|
||||
gridBean = new GridBean(1, 1, total, beans);
|
||||
} else {
|
||||
List<ContainerClusterNodePool> list = this.containerNodePoolRepository.list(pager.getPage(), pager.getRows(), params, pager.getSorter());
|
||||
gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list);
|
||||
}
|
||||
return new GeneralResult<>(true, gridBean, "查询成功");
|
||||
} catch (Exception e) {
|
||||
log.error("Query container cluster node pools fail:", e);
|
||||
return new GeneralResult<>(false, "查询容器集群节点池失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue