@yuntools/ali-alb
Version:
阿里云 ALB 负载均衡模块封装,支持 ESM,CJS 导入,提供 TypeScript 类型定义
172 lines (168 loc) • 6.26 kB
text/typescript
import * as Alb from '@alicloud/alb20200616';
import Alb__default, { ListServerGroupServersResponseBodyServers, ListAsynJobsResponseBodyJobs, ListServerGroupsResponseBodyServerGroups, UpdateServerGroupServersAttributeResponseBody } from '@alicloud/alb20200616';
export { ListAsynJobsRequest, ListAsynJobsResponseBodyJobs, ListServerGroupServersRequest, ListServerGroupsRequest, ListServerGroupsResponseBodyServerGroups, UpdateServerGroupServersAttributeRequest, UpdateServerGroupServersAttributeResponseBody } from '@alicloud/alb20200616';
import { EcsClient } from '@yuntools/ali-ecs';
type ServerGroupId = string;
type GroupServer = ListServerGroupServersResponseBodyServers;
interface ActionRet {
/** 异步任务信息 */
jobInfo: ListAsynJobsResponseBodyJobs | undefined;
/** 服务器属性 */
groupServer: GroupServer | undefined;
}
type JobId = string;
/**
* 异步任务的执行状态
*/
declare enum JobStatus {
/** 异步消息已入队,等待处理 */
Enqueued = "Enqueued",
/** 调用执行成功 */
Succeeded = "Succeeded",
/** 调用执行失败 */
Failed = "Failed",
/** 调用执行中 */
Running = "Running",
Processing = "Processing",
/** 调用执行终止 */
Stopped = "Stopped",
/** 执行停止中 */
Stopping = "Stopping",
/** 执行因函数被删除等原因处于无效状态(任务未被执行) */
Invalid = "Invalid",
/** 您为任务配置了最长排队等待的期限。该任务因为超期被丢弃(任务未被执行) */
Expired = "Expired",
/** 异步调用因执行错误重试中 */
Retrying = "Retrying"
}
declare enum Action {
/** 查询指定异步任务信息 */
GetAsyncJobResult = "GetAsyncJobResult",
/** ALB 服务组列表 */
ListServerGroups = "ListServerGroups",
/** ALB 服务组所有服务器列表 */
ListServerGroupServers = "ListServerGroupServers",
/** 更新 ALB 服务器组指定服务器的(权重)属性 */
UpdateServerGroupServersAttribute = "UpdateServerGroupServersAttribute"
}
declare enum ActionType {
up = "up",
down = "down"
}
/** 更新服务组指定服务器权重属性 */
interface UpdateServerWeightOptions {
/** 服务组id */
serverGroupId: string;
/** Ecs 实例id, 不能和 publicIp 同时为空 */
ecsId?: string | undefined;
/** Ecs 实例公网ip,不能和 ecsId 同时为空 */
ip?: string | undefined;
/** 目标权重 */
weight: number;
/** 当前权重 */
currentWeight?: number | undefined;
/**
* 首次更新步长
* @default 10
*/
startStep?: number | undefined;
/**
* 每次更新步长
* @default 30
*/
step?: number;
}
interface UpdateServerWeightOptionsInner extends UpdateServerWeightOptions {
ecsId: string;
currentWeight: number;
}
interface CalcuWeightOptions {
dstWeight: number;
currentWeight: number;
/**
* 首次更新步长
* @default 10
*/
startStep: number;
/**
* 每次更新步长
* @default 30
*/
step: number;
}
/** 阿里云 ALB 负载均衡服务接口 */
declare class AlbClient {
protected id: string;
protected secret: string;
endpoint: string;
ecsClientInstance?: EcsClient | undefined;
/**
* 是否输出日志
* @default false
*/
debug: boolean;
/**
* 是否输出渐进日志
* @default true
*/
showProgressLog: boolean;
client: Alb__default;
nextToken: string;
ecsClient: EcsClient;
groupServersCache: Map<string, Alb.ListServerGroupServersResponseBodyServers[]>;
cacheTime: number;
cacheTTLSec: number;
constructor(id: string, secret: string, endpoint?: string, ecsClientInstance?: EcsClient | undefined);
/**
* 获取指定服务组信息
*/
getGroup(serverGroupId: string): Promise<ListServerGroupsResponseBodyServerGroups | undefined>;
/**
* 获取指定服务组指定服务器信息
*/
getGroupServer(serverGroupId: string, serverId: string, withoutCache?: boolean): Promise<GroupServer | undefined>;
/**
* 根据公网 IPs 获取指定服务组指定服务器信息
*/
getGroupServerByPublicIps(serverGroupId: string, ips: string[]): Promise<Map<string, GroupServer>>;
/**
* 根据公网 IP 获取指定服务组指定服务器信息
*/
getGroupServerByPublicIp(serverGroupId: string, ip: string): Promise<GroupServer | undefined>;
/**
* 列出指定服务器组的服务器列表信息
*/
listGroupServers(serverGroupId: string): Promise<GroupServer[] | undefined>;
/**
* 获取异步任务信息
*/
getJobInfo(jobId: string): Promise<ListAsynJobsResponseBodyJobs | undefined>;
/**
* 渐进更新指定服务器的权重到指定值,
* 直到异步任务状态为 Succeeded 或 Failed,
* 并返回异步任务信息和服务器信息
*/
updateServerWeightByPublicIp(options: UpdateServerWeightOptions): Promise<ActionRet | undefined>;
/**
* 渐进更新指定服务器的权重到指定值,
* 直到异步任务状态为 Succeeded 或 Failed,
* 并返回异步任务信息和服务器信息
*/
updateServerWeight(options: UpdateServerWeightOptions): Promise<ActionRet | undefined>;
/**
* 设置服务器组的权重属性
*/
setServersWeight(serverGroupId: string, serverIds: string[], weight: number): Promise<UpdateServerGroupServersAttributeResponseBody>;
/**
* 查询指定任务的状态是否匹配输入的状态值
*/
isJobMatchStatusList<T extends JobStatus>(jobId: string, statusArray: T[]): Promise<T | false>;
cleanCache(force?: boolean): void;
updateCache(groupId: ServerGroupId, servers: GroupServer[] | undefined): void;
private _cleanCache;
private loopServerUntilWeight;
private loopJobUntilStatuses;
private createClient;
}
declare function caculateWeights(options: CalcuWeightOptions): number[];
export { Action, ActionRet, ActionType, AlbClient, CalcuWeightOptions, GroupServer, JobId, JobStatus, ServerGroupId, UpdateServerWeightOptions, UpdateServerWeightOptionsInner, caculateWeights };