develop
tanshaolong 2024-09-05 16:21:09 +08:00
commit 7bce87c19f
5 changed files with 94 additions and 749 deletions

View File

@ -1,7 +1,6 @@
package com.bocloud.ctstack.plugin.controller;
import com.bocloud.ctstack.plugin.domain.model.database.CreateRdsModel;
import com.bocloud.ctstack.plugin.domain.model.database.FlavorModel;
import com.bocloud.ctstack.plugin.domain.model.database.ProjectModel;
import com.bocloud.ctstack.plugin.entity.CloudRds;
import com.bocloud.ctstack.plugin.service.impl.CloudRdsService;
@ -11,16 +10,20 @@ import com.megatron.common.model.Pager;
import com.megatron.common.model.RequestContext;
import com.megatron.common.utils.Common;
import com.megatron.common.utils.ResultTools;
import com.megatron.framework.utils.IpTool;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/v1/cloudrds")
@ -45,13 +48,22 @@ public class CloudRdsController {
return cloudRdsService.listProjects(vendorId, regionId, type, context);
}
@Operation(tags = {"CMC", "CSC"}, summary = "查询云数据库可用区列表")
@GetMapping("/zones")
public GeneralResult<List<ProjectModel>> listZones(@RequestParam(value = "regionId") String regionId,
@RequestParam(value = "vendorId") Long vendorId,
@RequestParam(value = "projectId") String projectId,
@Value(Common.REQ_CONTEXT) RequestContext context) {
return cloudRdsService.listZones(vendorId, regionId, projectId, context);
}
@Operation(tags = {"CMC", "CSC"}, summary = "查询云数据库RDS规格列表")
@GetMapping("/flavors")
public GeneralResult<Map<String, Map<String, Map<String, List<FlavorModel>>>>> listFlavors(@RequestParam(value = "type") String type,
@RequestParam(value = "regionId") String regionId,
@RequestParam(value = "projectId") String projectId,
@RequestParam(value = "vendorId") Long vendorId,
@Value(Common.REQ_CONTEXT) RequestContext context) {
public GeneralResult listFlavors(@RequestParam(value = "type") String type,
@RequestParam(value = "regionId") String regionId,
@RequestParam(value = "projectId") String projectId,
@RequestParam(value = "vendorId") Long vendorId,
@Value(Common.REQ_CONTEXT) RequestContext context) {
return cloudRdsService.listFlavors(vendorId, regionId, type, projectId, context);
}

View File

@ -388,7 +388,7 @@ public class TianyiLocationProvider extends TianyiProvider {
}
log.info("同步资源池信息:{}",poolModelGeneralResult.isSuccess());
//syncRds(syncModel);
syncRds(syncModel);
log.info("end sync ... current region is " + this.getRegionId());
return new GeneralResult(true, syncModel, "数据同步成功!");

View File

@ -7,9 +7,12 @@ import com.bocloud.ctstack.plugin.domain.model.database.FlavorModel;
import com.bocloud.ctstack.plugin.provider.TianyiProvider;
import com.megatron.common.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class TianyiRdsFlavorProvider extends TianyiProvider {
@ -25,737 +28,42 @@ public class TianyiRdsFlavorProvider extends TianyiProvider {
/*
1=2=3=4=
*/
private static final String[] instanceTypes = new String[]{"1", "2", "3"};
private static final String[] instanceTypes = new String[]{"通用型", "计算增强型", "内存优化型"};
public Map<String, Map<String, Map<String, List<FlavorModel>>>> listAllType(String prodCode, String projectId) throws Exception {
List<FlavorModel> flavorModels = new ArrayList<>();
public List<FlavorModel> listAllType(String prodCode, String projectId) throws Exception {
List<FlavorModel> models = new ArrayList<>();
for (String type : instanceTypes) {
List<FlavorModel> list = list(prodCode, type, projectId);
flavorModels.addAll(list);
if (!CollectionUtils.isEmpty(list)) {
models.addAll(list);
}
}
return flavorModels
.stream()
.collect(Collectors.groupingBy(FlavorModel::getProdVersion,
Collectors.groupingBy(FlavorModel::getProdSpecName,
Collectors.groupingBy(FlavorModel::getInstanceType))));
return models;
}
public List<FlavorModel> list(String prodCode, String instanceType, String projectId) throws Exception {
String da = "\n" +
"{\n" +
" \"returnObj\":{\n" +
" \"data\":[\n" +
" {\n" +
" \"prodId\":10003011,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"单机版\",\n" +
" \"prodSpecDesc\":\"单机版\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"12.16\",\n" +
" \"instSpecInfoList\":[\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.2xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" },\n" +
" {\n" +
" \"prodId\":10003012,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"一主一备\",\n" +
" \"prodSpecDesc\":\"一主一备\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"12.16\",\n" +
" \"instSpecInfoList\":[\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"2C8G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.large.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"2C8G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.large.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.2xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"2C4G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.large.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"4C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" },\n" +
" {\n" +
" \"prodId\":10003013,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"单机版\",\n" +
" \"prodSpecDesc\":\"单机版\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"14.9\",\n" +
" \"instSpecInfoList\":[\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" },\n" +
" {\n" +
" \"prodId\":10003014,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"一主一备\",\n" +
" \"prodSpecDesc\":\"一主一备\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"14.9\",\n" +
" \"instSpecInfoList\":[\n" +
" \n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.2xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.2xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" },\n" +
" {\n" +
" \"prodId\":10003015,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"单机版\",\n" +
" \"prodSpecDesc\":\"单机版\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"13.12\",\n" +
" \"instSpecInfoList\":[\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"2C4G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.large.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"4C8G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"4C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj3A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj3A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.2xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj3A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"2C4G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.large.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.2xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.2xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" },\n" +
" {\n" +
" \"prodId\":10003016,\n" +
" \"prodCode\":\"POSTGRESQL\",\n" +
" \"prodSpecName\":\"一主一备\",\n" +
" \"prodSpecDesc\":\"一主一备\",\n" +
" \"instanceDesc\":null,\n" +
" \"prodVersion\":\"13.12\",\n" +
" \"instSpecInfoList\":[\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.2xlarge.4\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"8C16G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.2xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"16C32G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj2A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s6.4xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S6\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" },\n" +
" {\n" +
" \"specId\":null,\n" +
" \"prodPerformanceSpec\":\"32C64G\",\n" +
" \"azList\":[\n" +
" \"cn-hd11-jsnj1A-public-ctcloud\"\n" +
" ],\n" +
" \"specName\":\"s7.8xlarge.2\",\n" +
" \"cpuType\":null,\n" +
" \"generation\":\"S7\",\n" +
" \"minRate\":null,\n" +
" \"maxRate\":null\n" +
" }\n" +
" ],\n" +
" \"prodHostConfig\":{\n" +
" \"hostInsts\":[\n" +
" {\n" +
" \"hostTypeName\":\"主节点\",\n" +
" \"hostType\":\"master\",\n" +
" \"prodPerformanceSpeces\":[\n" +
" \"32C64G\",\n" +
" \"2C4G\",\n" +
" \"8C16G\",\n" +
" \"4C8G\",\n" +
" \"2C8G\",\n" +
" \"4C16G\",\n" +
" \"8C32G\",\n" +
" \"16C64G\",\n" +
" \"16C32G\"\n" +
" ],\n" +
" \"prodPerformanceSpecCompute\":[\n" +
"\n" +
" ],\n" +
" \"prodPerformanceSpecMemory\":[\n" +
"\n" +
" ],\n" +
" \"hostDefaultNum\":1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"hostSpec\":null,\n" +
" \"lvsSpec\":null\n" +
" }\n" +
"\n" +
" ]\n" +
" },\n" +
" \"statusCode\":200,\n" +
" \"message\":\"SUCCESS\"\n" +
"}\n" +
"\n";
String url = "/PG/teledb-acceptor/v2/openapi/accept-order-info/template";
Map<String, Object> headers = new HashMap<>();
headers.put("Project-Id", projectId);
headers.put("project-id", projectId);
headers.put("regionId", this.getRegionId());
JSONObject body = new JSONObject();
body.put("prodType", 1);
body.put("prodCode", prodCode);
body.put("regionId", this.getRegionId());
body.put("instanceType", instanceType);
String key = "1";
if ("通用型".equals(instanceType)) {
key = "1";
} else if ("计算增强型".equals(instanceType)) {
key = "2";
} else {
key = "3";
}
body.put("instanceType", key);
Result result = doGet(url, headers, body);
JSONObject returnObj = checkResult(result, "查询规格列表");
List<FlavorModel> data = JSONArray.parseArray(returnObj.getString("data"), FlavorModel.class);
data.forEach(flavorModel -> flavorModel.setInstanceType(instanceType));
/* JSONObject returnObj = JSONObject.parseObject(da).getJSONObject("returnObj");
List<FlavorModel> data = JSONArray.parseArray(returnObj.getString("data"), FlavorModel.class);
data.forEach(flavorModel -> flavorModel.setInstanceType(instanceType));*/
return data;
}
}

View File

@ -7,9 +7,7 @@ import com.bocloud.ctstack.plugin.domain.model.database.CreateRdsModel;
import com.bocloud.ctstack.plugin.domain.model.database.ProjectModel;
import com.bocloud.ctstack.plugin.domain.model.database.RdsModel;
import com.bocloud.ctstack.plugin.provider.TianyiProvider;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.Result;
import com.megatron.common.utils.ListTool;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
@ -44,6 +42,20 @@ public class TianyiRdsProvider extends TianyiProvider {
}
public List<ProjectModel> listZones(String regionId, String projectId) throws Exception {
String url = "/teledb-acceptor/v2/openapi/accept-order-info/availabilityZone";
Map<String, Object> headers = new HashMap<>();
headers.put("project-id", projectId);
headers.put("regionId", this.getRegionId());
JSONObject body = new JSONObject();
body.put("regionId", regionId);
Result result = doGet(url, headers, body);
JSONObject returnObj = checkResult(result, "查询规格列表");
return JSONArray.parseArray(returnObj.getString("data"), ProjectModel.class);
}
public List<RdsModel> listPg(String name, String projectId) throws Exception {
int pageNum = 1;
@ -55,7 +67,7 @@ public class TianyiRdsProvider extends TianyiProvider {
}
String apiUrl = "/PG/v1/product/page-paas-product";
Map<String, Object> headers = new HashMap<>();
headers.put("Project-Id", projectId);
headers.put("project-id", projectId);
headers.put("regionId", this.getRegionId());
Result result = doGet(apiUrl, headers, body);
JSONObject returnObj = checkResult(result, "查询列表");
@ -101,7 +113,7 @@ public class TianyiRdsProvider extends TianyiProvider {
}
String apiUrl = "/RDS2/v1/open-api/instance/instance-list";
Map<String, Object> headers = new HashMap<>();
headers.put("Project-Id", projectId);
headers.put("project-id", projectId);
headers.put("regionId", this.getRegionId());
Result result = doPost(apiUrl, headers, body);
JSONObject returnObj = checkResult(result, "查询列表");

View File

@ -1,11 +1,6 @@
package com.bocloud.ctstack.plugin.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.domain.*;
import com.bocloud.cmp.entity.CloudVendor;
import com.bocloud.cmp.enums.OrderItemStatus;
import com.bocloud.cmp.repository.CloudVendorRepository;
import com.bocloud.cmp.util.ResourceEventPublisher;
import com.bocloud.ctstack.plugin.config.ButlerConfig;
@ -14,31 +9,36 @@ import com.bocloud.ctstack.plugin.domain.model.database.FlavorModel;
import com.bocloud.ctstack.plugin.domain.model.database.ProjectModel;
import com.bocloud.ctstack.plugin.domain.model.database.RdsModel;
import com.bocloud.ctstack.plugin.entity.CloudRds;
import com.bocloud.ctstack.plugin.provider.database.TianyiRdsFlavorProvider;
import com.bocloud.ctstack.plugin.provider.database.TianyiRdsProvider;
import com.bocloud.ctstack.plugin.repository.CloudRdsRepository;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.megatron.common.encrypt.AESEncryptor;
import com.megatron.common.encrypt.Encryptor;
import com.megatron.common.model.*;
import com.megatron.common.utils.*;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.GridBean;
import com.megatron.common.model.OperateResult;
import com.megatron.common.model.Pager;
import com.megatron.common.model.Param;
import com.megatron.common.model.RequestContext;
import com.megatron.common.model.Sign;
import com.megatron.common.utils.Common;
import com.megatron.common.utils.GridHelper;
import com.megatron.common.utils.ListTool;
import com.megatron.common.utils.MapTools;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestParam;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Slf4j
@Service("cloudRdsService")
@ -100,15 +100,28 @@ public class CloudRdsService {
}
}
public GeneralResult listZones(Long vendorId, String regionId, String projectId, RequestContext context) {
try {
CloudVendor vendor = cloudVendorRepository.query(vendorId);
Assert.notNull(vendor, "数据不存在");
TianyiRdsProvider rdsProvider = new TianyiRdsProvider(butlerConfig.regionButler(vendor.getUuid(), regionId));
List<ProjectModel> project = rdsProvider.listZones(regionId, projectId);
return new GeneralResult<>(true, project, "查询成功");
} catch (Exception e) {
log.error("list cloud rds Flavor failure:", e);
return new GeneralResult<>(false, "查询失败", null, null);
}
}
public GeneralResult<Map<String, Map<String, Map<String, List<FlavorModel>>>>> listFlavors(Long vendorId, String regionId, String type, String projectId, RequestContext context) {
public GeneralResult listFlavors(Long vendorId, String regionId, String type, String projectId, RequestContext context) {
try {
CloudVendor vendor = cloudVendorRepository.query(vendorId);
Assert.notNull(vendor, "数据不存在");
TianyiRdsFlavorProvider flavorProvider = new TianyiRdsFlavorProvider(butlerConfig.regionButler(vendor.getUuid(), regionId));
Map<String, Map<String, Map<String, List<FlavorModel>>>> map = flavorProvider.listAllType(type, projectId);
return new GeneralResult<>(true, map, "查询成功");
List<FlavorModel> instanceTypes = flavorProvider.listAllType(type, projectId);
return new GeneralResult<>(true, instanceTypes, "查询成功");
} catch (Exception e) {
log.error("list cloud rds Flavor failure:", e);
return new GeneralResult<>(false, "查询失败", null, null);