From b2eea0f2752ebb1be33c5eed869d3b271ee99c00 Mon Sep 17 00:00:00 2001 From: yuemian <--list> Date: Thu, 5 Sep 2024 16:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/controller/CloudRdsController.java | 32 +- .../database/TianyiRdsFlavorProvider.java | 738 +----------------- .../provider/database/TianyiRdsProvider.java | 20 +- .../plugin/service/impl/CloudRdsService.java | 51 +- 4 files changed, 93 insertions(+), 748 deletions(-) diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/CloudRdsController.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/CloudRdsController.java index 95e5823c..51291e27 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/CloudRdsController.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/controller/CloudRdsController.java @@ -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> 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>>>> 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); } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsFlavorProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsFlavorProvider.java index 900ba2b5..0bba46b7 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsFlavorProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsFlavorProvider.java @@ -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>>> listAllType(String prodCode, String projectId) throws Exception { - List flavorModels = new ArrayList<>(); + public List listAllType(String prodCode, String projectId) throws Exception { + List models = new ArrayList<>(); for (String type : instanceTypes) { List 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 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 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 data = JSONArray.parseArray(returnObj.getString("data"), FlavorModel.class); data.forEach(flavorModel -> flavorModel.setInstanceType(instanceType)); - - - /* JSONObject returnObj = JSONObject.parseObject(da).getJSONObject("returnObj"); - List data = JSONArray.parseArray(returnObj.getString("data"), FlavorModel.class); - data.forEach(flavorModel -> flavorModel.setInstanceType(instanceType));*/ return data; } + } diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsProvider.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsProvider.java index 21bdf8e8..b405924d 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsProvider.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/provider/database/TianyiRdsProvider.java @@ -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 listZones(String regionId, String projectId) throws Exception { + String url = "/teledb-acceptor/v2/openapi/accept-order-info/availabilityZone"; + + Map 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 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 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 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, "查询列表"); diff --git a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/CloudRdsService.java b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/CloudRdsService.java index f28e9756..01cdb063 100644 --- a/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/CloudRdsService.java +++ b/bocloud.ctstack.plugin/src/main/java/com/bocloud/ctstack/plugin/service/impl/CloudRdsService.java @@ -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 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>>>> 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>>> map = flavorProvider.listAllType(type, projectId); - return new GeneralResult<>(true, map, "查询成功"); + List 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);