@cloudbase/manager-node 4.7.3 → 4.7.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ const archiver_1 = __importDefault(require("archiver"));
16
16
  const fs_extra_1 = require("fs-extra");
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const utils_1 = require("../utils");
19
+ const type_1 = require("./type");
19
20
  /**
20
21
  * 云托管服务管理类
21
22
  * 提供云托管服务的初始化、下载、列表查询和删除等功能
@@ -105,6 +106,87 @@ class CloudRunService {
105
106
  ServerType: params === null || params === void 0 ? void 0 : params.serverType
106
107
  }));
107
108
  }
109
+ async setTraffic(serverName, stablePercent, canaryPercent) {
110
+ // 校验比例之和是否为100%
111
+ if (stablePercent + canaryPercent !== 100) {
112
+ throw new Error('稳定版本流量比例和灰度版本流量比例之和必须等于 100');
113
+ }
114
+ const envConfig = this.environment.lazyEnvironmentConfig;
115
+ const { Task } = await this.tcbrService.request('DescribeServerManageTask', {
116
+ EnvId: envConfig.EnvId,
117
+ ServerName: serverName, // 服务名
118
+ TaskId: 0 // 任务Id
119
+ });
120
+ // 判断是否存在灰度版本
121
+ const isGary = (Task === null || Task === void 0 ? void 0 : Task.ReleaseType) === type_1.ReleaseTypeEnum.GRAY && (Task === null || Task === void 0 ? void 0 : Task.Status) === 'running';
122
+ if (!isGary) {
123
+ throw new Error('不存在灰度版本或版本部署未完成');
124
+ }
125
+ // 获取当前版本和灰度版本
126
+ const { ReleaseOrderInfo } = await this.tcbrService.request('DescribeReleaseOrder', {
127
+ EnvId: envConfig.EnvId, // 环境 Id
128
+ ServerName: serverName // 服务名
129
+ });
130
+ const { CurrentVersion, ReleaseVersion } = ReleaseOrderInfo;
131
+ // 设置版本比例
132
+ return await this.tcbrService.request('ReleaseGray', {
133
+ EnvId: envConfig.EnvId, // 环境 Id
134
+ ServerName: serverName, // 服务名
135
+ GrayType: "gray",
136
+ TrafficType: "FLOW",
137
+ GrayFlowRatio: canaryPercent,
138
+ VersionFlowItems: [{
139
+ VersionName: CurrentVersion.VersionName,
140
+ FlowRatio: stablePercent,
141
+ IsDefaultPriority: true,
142
+ Priority: 1,
143
+ }, {
144
+ VersionName: ReleaseVersion.VersionName,
145
+ FlowRatio: canaryPercent,
146
+ IsDefaultPriority: false,
147
+ Priority: 2,
148
+ }]
149
+ });
150
+ }
151
+ /**
152
+ * 完成灰度
153
+ */
154
+ async promote(serverName) {
155
+ const envConfig = this.environment.lazyEnvironmentConfig;
156
+ // 获取当前版本和灰度版本
157
+ const { ReleaseOrderInfo } = await this.tcbrService.request('DescribeReleaseOrder', {
158
+ EnvId: envConfig.EnvId, // 环境 Id
159
+ ServerName: serverName // 服务名
160
+ });
161
+ const { CurrentVersion, ReleaseVersion } = ReleaseOrderInfo;
162
+ const res = await this.tcbrService.request('ReleaseGray', {
163
+ EnvId: envConfig.EnvId, // 环境 Id
164
+ ServerName: serverName, // 服务名
165
+ GrayType: "gray",
166
+ TrafficType: "FLOW",
167
+ GrayFlowRatio: 100,
168
+ VersionFlowItems: [{ VersionName: ReleaseVersion.VersionName, FlowRatio: 100, Priority: 0, IsDefaultPriority: true }],
169
+ CloseGrayRelease: true,
170
+ });
171
+ }
172
+ /**
173
+ * 取消灰度
174
+ */
175
+ async rollback(serverName) {
176
+ const envConfig = this.environment.lazyEnvironmentConfig;
177
+ const { Task } = await this.tcbrService.request('DescribeServerManageTask', {
178
+ EnvId: envConfig.EnvId,
179
+ ServerName: serverName, // 服务名
180
+ TaskId: 0 // 任务Id
181
+ });
182
+ const res = await this.tcbrService.request('OperateServerManage', {
183
+ EnvId: envConfig.EnvId, // 环境 Id
184
+ ServerName: serverName,
185
+ TaskId: Task.Id,
186
+ OperateType: 'go_back',
187
+ });
188
+ return res;
189
+ }
108
190
  /**
109
191
  *查询云托管服务详情
110
192
  * @param {Object} params 查询参数
@@ -156,7 +238,7 @@ class CloudRunService {
156
238
  * @returns {Promise<IResponseInfo>} 返回部署操作的响应信息
157
239
  */
158
240
  async deploy(params) {
159
- const { serverName, targetPath = process.cwd(), serverConfig } = params;
241
+ const { serverName, targetPath = process.cwd(), serverConfig, deployInfo: { ReleaseType = "FULL" } } = params;
160
242
  /**
161
243
  * 参数校验和默认值设置
162
244
  */
@@ -204,7 +286,7 @@ class CloudRunService {
204
286
  RepoLanguage: 'Node.js'
205
287
  };
206
288
  }
207
- deployInfo.ReleaseType = 'FULL';
289
+ deployInfo.ReleaseType = ReleaseType;
208
290
  return this._upsertFunction(false, {
209
291
  name: serverName,
210
292
  deployInfo,
@@ -291,6 +373,15 @@ __decorate([
291
373
  __decorate([
292
374
  (0, utils_1.preLazy)()
293
375
  ], CloudRunService.prototype, "list", null);
376
+ __decorate([
377
+ (0, utils_1.preLazy)()
378
+ ], CloudRunService.prototype, "setTraffic", null);
379
+ __decorate([
380
+ (0, utils_1.preLazy)()
381
+ ], CloudRunService.prototype, "promote", null);
382
+ __decorate([
383
+ (0, utils_1.preLazy)()
384
+ ], CloudRunService.prototype, "rollback", null);
294
385
  __decorate([
295
386
  (0, utils_1.preLazy)()
296
387
  ], CloudRunService.prototype, "detail", null);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CloudrunServerType = void 0;
3
+ exports.ReleaseTypeEnum = exports.CloudrunServerType = void 0;
4
4
  var CloudrunServerType;
5
5
  (function (CloudrunServerType) {
6
6
  /**
@@ -12,3 +12,14 @@ var CloudrunServerType;
12
12
  */
13
13
  CloudrunServerType["Container"] = "container";
14
14
  })(CloudrunServerType || (exports.CloudrunServerType = CloudrunServerType = {}));
15
+ var ReleaseTypeEnum;
16
+ (function (ReleaseTypeEnum) {
17
+ /**
18
+ * 灰度发布
19
+ */
20
+ ReleaseTypeEnum["GRAY"] = "GRAY";
21
+ /**
22
+ * 全量发布
23
+ */
24
+ ReleaseTypeEnum["FULL"] = "FULL";
25
+ })(ReleaseTypeEnum || (exports.ReleaseTypeEnum = ReleaseTypeEnum = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.7.3",
3
+ "version": "4.7.4-beta.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  import { Environment } from '../environment';
2
2
  import { IResponseInfo } from '../interfaces';
3
- import { CloudrunServerType, ICloudrunDetailResponse, ICloudrunListResponse, ICloudrunServerBaseConfig, ICloudrunServerBaseInfo, IDiffConfigItem, ITemplate } from './type';
3
+ import { CloudrunServerType, ICloudrunDetailResponse, ICloudrunListResponse, ICloudrunServerBaseConfig, ICloudrunServerBaseInfo, IDiffConfigItem, ITemplate, ReleaseTypeEnum } from './type';
4
4
  /**
5
5
  * 云托管服务管理类
6
6
  * 提供云托管服务的初始化、下载、列表查询和删除等功能
@@ -56,6 +56,19 @@ export declare class CloudRunService {
56
56
  serverName?: string;
57
57
  serverType?: CloudrunServerType;
58
58
  }): Promise<ICloudrunListResponse>;
59
+ setTraffic(serverName: string, stablePercent: number, canaryPercent: number): Promise<{
60
+ RequestId?: string;
61
+ }>;
62
+ /**
63
+ * 完成灰度
64
+ */
65
+ promote(serverName: string): Promise<void>;
66
+ /**
67
+ * 取消灰度
68
+ */
69
+ rollback(serverName: string): Promise<{
70
+ RequestId?: string;
71
+ }>;
59
72
  /**
60
73
  *查询云托管服务详情
61
74
  * @param {Object} params 查询参数
@@ -99,6 +112,9 @@ export declare class CloudRunService {
99
112
  deploy(params: {
100
113
  serverName: string;
101
114
  targetPath: string;
115
+ deployInfo: {
116
+ ReleaseType: ReleaseTypeEnum;
117
+ };
102
118
  serverConfig?: Partial<Pick<ICloudrunServerBaseConfig, 'OpenAccessTypes' | 'Cpu' | 'Mem' | 'MinNum' | 'MaxNum' | 'PolicyDetails' | 'CustomLogs' | 'EnvParams' | 'Port' | 'Dockerfile' | 'BuildDir' | 'InternalAccess' | 'InternalDomain' | 'EntryPoint' | 'Cmd' | 'InstallDependency'>>;
103
119
  }): Promise<IResponseInfo>;
104
120
  /**
@@ -8,6 +8,16 @@ export declare enum CloudrunServerType {
8
8
  */
9
9
  Container = "container"
10
10
  }
11
+ export declare enum ReleaseTypeEnum {
12
+ /**
13
+ * 灰度发布
14
+ */
15
+ GRAY = "GRAY",
16
+ /**
17
+ * 全量发布
18
+ */
19
+ FULL = "FULL"
20
+ }
11
21
  /**
12
22
  * 服务基础信息接口
13
23
  */
@@ -327,3 +337,71 @@ export interface ITemplate {
327
337
  language: string;
328
338
  zipFileStore: string;
329
339
  }
340
+ export interface ITaskStepInfo {
341
+ Name?: string;
342
+ Status?: string;
343
+ StartTime?: string;
344
+ EndTime?: string;
345
+ CostTime?: number;
346
+ FailReason?: string;
347
+ }
348
+ export interface IServerManageTaskInfo {
349
+ Id?: number;
350
+ EnvId?: string;
351
+ ServerName?: string;
352
+ CreateTime?: string;
353
+ ChangeType?: string;
354
+ ReleaseType?: string;
355
+ DeployType?: string;
356
+ PreVersionName?: string;
357
+ VersionName?: string;
358
+ PipelineId?: number;
359
+ PipelineTaskId?: number;
360
+ ReleaseId?: number;
361
+ Status?: string;
362
+ Steps?: ITaskStepInfo[];
363
+ FailReason?: string;
364
+ OperatorRemark?: string;
365
+ }
366
+ export interface IObjectKVPriority {
367
+ Key?: string;
368
+ Value?: string;
369
+ Priority?: number;
370
+ }
371
+ export interface IVersionInfo {
372
+ VersionName?: string;
373
+ FlowRatio?: number;
374
+ Status?: string;
375
+ CreatedTime?: string;
376
+ UpdatedTime?: string;
377
+ BuildId?: number;
378
+ UploadType?: string;
379
+ Remark?: string;
380
+ UrlParam?: IObjectKV;
381
+ Priority?: number;
382
+ IsDefaultPriority?: boolean;
383
+ FlowParams?: IObjectKVPriority[];
384
+ MinReplicas?: number;
385
+ MaxReplicas?: number;
386
+ RunId?: string;
387
+ Percent?: number;
388
+ CurrentReplicas?: number;
389
+ Architecture?: string;
390
+ }
391
+ export interface IObjectKV {
392
+ Key: string;
393
+ Value: string;
394
+ }
395
+ export interface IReleaseOrderInfo {
396
+ Id?: number;
397
+ ServerName?: string;
398
+ CurrentVersion?: IVersionInfo;
399
+ ReleaseVersion?: IVersionInfo;
400
+ GrayStatus?: string;
401
+ ReleaseStatus?: string;
402
+ TrafficTypeValues?: IObjectKV[];
403
+ TrafficType?: string;
404
+ FlowRatio?: number;
405
+ CreateTime?: string;
406
+ IsReleasing?: boolean;
407
+ }