适配容器接口域名

develop
tanshaolong 2024-09-05 15:45:50 +08:00
parent 3b69fab02f
commit 05825ffd92
6 changed files with 158 additions and 2 deletions

View File

@ -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);
// }
}

View File

@ -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";
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对象

View File

@ -48,7 +48,7 @@ public class TianYiContainerClusterProvider extends TianyiProvider {
while (true) {
body.put("pageNow", pageNow);
Result result = doGet(url, header, body);
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));

View File

@ -1,6 +1,9 @@
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;
@ -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,24 @@ public class ContainerClusterRepository extends BasicGenericDao<ContainerCluster
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 ";
@ -38,12 +60,23 @@ public class ContainerClusterRepository extends BasicGenericDao<ContainerCluster
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;
}
}

View File

@ -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);
}

View File

@ -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, "查询容器集群失败");
}
}
}