Files
certd/packages/libs/lib-jdcloud/src/repo/jmr/v1/jmr.js
T
2025-04-02 23:13:55 +08:00

1206 lines
33 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright 2018 JDCLOUD.COM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:#www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 集群管理
* JMR集群管理相关接口
*
* OpenAPI spec version: v1
* Contact:
*
* NOTE: This class is auto generated by the jdcloud code generator program.
*/
require('../../../lib/node_loader')
var JDCloud = require('../../../lib/core')
var Service = JDCloud.Service
var serviceId = 'jmr'
Service._services[serviceId] = true
/**
* jmr service.
* @version 1.1.6
*/
class JMR extends Service {
constructor (options = {}) {
options._defaultEndpoint = {}
options._defaultEndpoint.protocol =
options._defaultEndpoint.protocol || 'https'
options._defaultEndpoint.host =
options._defaultEndpoint.host || 'jmr.jdcloud-api.com'
options.basePath = '/v1' // 默认要设为空""
super(serviceId, options)
}
/**
* 查询用户的集群列表及相关服务的一些信息
* @param {Object} opts - parameters
* @param {string} [opts.dataCenter] - 地域信息 optional
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param object data 包括集群信息列表
* @param boolean status
*/
idataCluster (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling idataCluster"
)
}
opts = opts || {}
if (opts.dataCenter === undefined || opts.dataCenter === null) {
throw new Error(
"Missing the required parameter 'opts.dataCenter' when calling idataCluster"
)
}
let postBody = null
let queryParams = {}
let pathParams = {
regionId: regionId,
dataCenter: opts.dataCenter
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call idataCluster with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/idata',
'GET',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 获取对应版本的软件清单信息
* @param {Object} opts - parameters
* @param {string} opts.version - JMR软件版本号
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param string data 对应的软件清单信息
* @param boolean status
*/
getSoftwareInfo (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling getSoftwareInfo"
)
}
opts = opts || {}
if (opts.version === undefined || opts.version === null) {
throw new Error(
"Missing the required parameter 'opts.version' when calling getSoftwareInfo"
)
}
let postBody = null
let queryParams = {}
if (opts.version !== undefined && opts.version !== null) {
queryParams['version'] = opts.version
}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call getSoftwareInfo with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/softwareInfo',
'GET',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 查询JMR的版本信息
* @param {Object} opts - parameters
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param string data
* @param boolean status
*/
getJmrVersionList (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling getJmrVersionList"
)
}
opts = opts || {}
let postBody = null
let queryParams = {}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call getJmrVersionList with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/jmrVersions',
'GET',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 查询JMR的监控模板信息
* @param {Object} opts - parameters
* @param {string} opts.clusterId - 集群ID
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param monitorLabelDetail data
* @param boolean status
*/
monitorLabelList (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling monitorLabelList"
)
}
opts = opts || {}
if (opts.clusterId === undefined || opts.clusterId === null) {
throw new Error(
"Missing the required parameter 'opts.clusterId' when calling monitorLabelList"
)
}
let postBody = {}
let queryParams = {}
let pathParams = {
regionId: regionId,
clusterId: opts.clusterId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call monitorLabelList with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/monitorLabelList/{clusterId}',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 查询指定集群的详细信息
* @param {Object} opts - parameters
* @param {string} opts.clusterId - 集群ID
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param cluster cluster
* @param boolean status
*/
describeCluster (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling describeCluster"
)
}
opts = opts || {}
if (opts.clusterId === undefined || opts.clusterId === null) {
throw new Error(
"Missing the required parameter 'opts.clusterId' when calling describeCluster"
)
}
let postBody = null
let queryParams = {}
let pathParams = {
regionId: regionId,
clusterId: opts.clusterId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call describeCluster with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/clusters/{clusterId}',
'GET',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 查询用户集群的列表
* @param {Object} opts - parameters
* @param {string} [opts.dataCenter] - 地域 optional
* @param {string} [opts.status] - 集群状态,CREATINGRUNNINGRELEASEDFAILED等 optional
* @param {string} [opts.clusterName] - 集群名称 optional
* @param {string} [opts.orderBy] - 排序,比如 id desc optional
* @param {integer} [opts.pageNum] - 页数,默认为1 optional
* @param {integer} [opts.pageSize] - 每页数目,默认为10 optional
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param integer totalNum 集群总的数目
* @param clusterListNode clusters
* @param boolean status
*/
describeClusters (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling describeClusters"
)
}
opts = opts || {}
let postBody = null
let queryParams = {}
if (opts.dataCenter !== undefined && opts.dataCenter !== null) {
queryParams['dataCenter'] = opts.dataCenter
}
if (opts.status !== undefined && opts.status !== null) {
queryParams['status'] = opts.status
}
if (opts.clusterName !== undefined && opts.clusterName !== null) {
queryParams['clusterName'] = opts.clusterName
}
if (opts.orderBy !== undefined && opts.orderBy !== null) {
queryParams['orderBy'] = opts.orderBy
}
if (opts.pageNum !== undefined && opts.pageNum !== null) {
queryParams['pageNum'] = opts.pageNum
}
if (opts.pageSize !== undefined && opts.pageSize !== null) {
queryParams['pageSize'] = opts.pageSize
}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call describeClusters with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/clusters',
'GET',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 释放集群
* @param {Object} opts - parameters
* @param {string} opts.clusterId - 集群ID
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param boolean status 是否开始释放集群
*/
releaseCluster (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling releaseCluster"
)
}
opts = opts || {}
if (opts.clusterId === undefined || opts.clusterId === null) {
throw new Error(
"Missing the required parameter 'opts.clusterId' when calling releaseCluster"
)
}
let postBody = {}
let queryParams = {}
let pathParams = {
regionId: regionId,
clusterId: opts.clusterId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call releaseCluster with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/clusters/{clusterId}:release',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 扩容集群
* @param {Object} opts - parameters
* @param {clusterExpansion} opts.clusterExpansion - 描述集群扩容信息
* @param {string} [opts.clientToken] - 用于保证请求的幂等性。由客户端生成,长度不能超过64个字符。
optional
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param boolean status 是否开始扩容集群
*/
clusterExpansion (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling clusterExpansion"
)
}
opts = opts || {}
if (opts.clusterExpansion === undefined || opts.clusterExpansion === null) {
throw new Error(
"Missing the required parameter 'opts.clusterExpansion' when calling clusterExpansion"
)
}
let postBody = {}
if (opts.clusterExpansion !== undefined && opts.clusterExpansion !== null) {
postBody['clusterExpansion'] = opts.clusterExpansion
}
if (opts.clientToken !== undefined && opts.clientToken !== null) {
postBody['clientToken'] = opts.clientToken
}
let queryParams = {}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call clusterExpansion with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/cluster:expansion',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 缩容集群
* @param {Object} opts - parameters
* @param {clusterReduction} opts.clusterReduction - 描述集群缩容信息
* @param {string} [opts.clientToken] - 用于保证请求的幂等性。由客户端生成,长度不能超过64个字符。
optional
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param boolean status 是否开始缩容集群
*/
clusterReduction (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling clusterReduction"
)
}
opts = opts || {}
if (opts.clusterReduction === undefined || opts.clusterReduction === null) {
throw new Error(
"Missing the required parameter 'opts.clusterReduction' when calling clusterReduction"
)
}
let postBody = {}
if (opts.clusterReduction !== undefined && opts.clusterReduction !== null) {
postBody['clusterReduction'] = opts.clusterReduction
}
if (opts.clientToken !== undefined && opts.clientToken !== null) {
postBody['clientToken'] = opts.clientToken
}
let queryParams = {}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call clusterReduction with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/cluster:reduction',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
/**
* 创建集群
* @param {Object} opts - parameters
* @param {clusterSpec} opts.clusterSpec - 描述集群配置
* @param {string} [opts.clientToken] - 用于保证请求的幂等性。由客户端生成,长度不能超过64个字符。
optional
* @param {string} regionId - ID of the region
* @param {string} callback - callback
@return {Object} result
* @param boolean status 是否开始创建集群
* @param string clusterId 集群ID
* @param string message 创建集群的信息
*/
createCluster (opts, regionId = this.config.regionId, callback) {
if (typeof regionId === 'function') {
callback = regionId
regionId = this.config.regionId
}
if (regionId === undefined || regionId === null) {
throw new Error(
"Missing the required parameter 'regionId' when calling createCluster"
)
}
opts = opts || {}
if (opts.clusterSpec === undefined || opts.clusterSpec === null) {
throw new Error(
"Missing the required parameter 'opts.clusterSpec' when calling createCluster"
)
}
let postBody = {}
if (opts.clusterSpec !== undefined && opts.clusterSpec !== null) {
postBody['clusterSpec'] = opts.clusterSpec
}
if (opts.clientToken !== undefined && opts.clientToken !== null) {
postBody['clientToken'] = opts.clientToken
}
let queryParams = {}
let pathParams = {
regionId: regionId
}
let headerParams = {
'User-Agent': 'JdcloudSdkNode/1.0.0 jmr/1.1.6'
}
let contentTypes = ['application/json']
let accepts = ['application/json']
// 扩展自定义头
if (opts['x-extra-header']) {
for (let extraHeader in opts['x-extra-header']) {
headerParams[extraHeader] = opts['x-extra-header'][extraHeader]
}
if (Array.isArray(opts['x-extra-header']['content-type'])) {
contentTypes = opts['x-extra-header']['content-type']
} else if (typeof opts['x-extra-header']['content-type'] === 'string') {
contentTypes = opts['x-extra-header']['content-type'].split(',')
}
if (Array.isArray(opts['x-extra-header']['accept'])) {
accepts = opts['x-extra-header']['accept']
} else if (typeof opts['x-extra-header']['accept'] === 'string') {
accepts = opts['x-extra-header']['accept'].split(',')
}
}
let formParams = {}
let returnType = null
this.config.logger(
`call createCluster with params:\npathParams:${JSON.stringify(
pathParams
)},\nqueryParams:${JSON.stringify(
queryParams
)}, \nheaderParams:${JSON.stringify(
headerParams
)}, \nformParams:${JSON.stringify(
formParams
)}, \npostBody:${JSON.stringify(postBody)}`,
'DEBUG'
)
let request = super.makeRequest(
'/regions/{regionId}/cluster:create',
'POST',
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType,
callback
)
return request.then(
function (result) {
if (callback && typeof callback === 'function') {
return callback(null, result)
}
return result
},
function (error) {
if (callback && typeof callback === 'function') {
return callback(error)
}
return Promise.reject(error)
}
)
}
}
module.exports = JMR