本文介绍如何通过控制台及火山引擎提供的OpenAPI,查询与响应InfrastructureUpgrade.Redeploy(基础设施升级,实例重新部署)事件,快速排除故障、确保云产品稳定运行。
随着业务发展和云服务器宿主机(物理机)的健康状态变化,火山引擎将对部分老旧、性能不佳的基础设施进行升级和改造。
此种情况下,火山引擎将生成InfrastructureUpgrade.Redeploy(基础设施升级,实例重新部署)事件并通知您。收到通知后,您需要选择运维时间窗口,并授权火山引擎运维人员将您的云服务器部署到新的宿主机,避免由于基础设施升级影响您的实例运行。
本实践以“事件监控”页面响应事件为例,您还可以前往实例详情页响应事件,操作详情可查看在云服务器控制台查询并处理事件中的实例详情页。
以实例触发InfrastructureUpgrade.Redeploy(基础设施升级,实例重新部署)事件为例,更多事件类型可查看ECS事件类型汇总。
以JAVA语言接口为例,您可以参考如下顺序调用OpenAPI接口,查询、响应云服务器事件。
说明
调用DescribeSystemEvents接口,查询云服务器实例触发的事件信息。
请求示例:
public void queryInstanceEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); DescribeSystemEventsRequest describeSystemEventsRequest = new DescribeSystemEventsRequest(); // 指定待查询的实例ID describeSystemEventsRequest.setResourceIds(Arrays.asList("<A实例ID>","<B实例ID>","<C实例ID>")); // 筛选生成事件的起始时间 describeSystemEventsRequest.setCreatedAtStart("2023-05-20T01:29:38+08:00"); // 筛选生成事件的结束时间 describeSystemEventsRequest.setCreatedAtEnd("2023-05-25T18:29:38+08:00"); try { DescribeSystemEventsResponse describeSystemEventsResponse = ecsApi.describeSystemEvents(describeSystemEventsRequest); System.out.println(describeSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-25T14:15:21+08:00 id: e-ycfroor651gh9zxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Inquiring type: InfrastructureUpgrade_Redeploy updatedAt: 2023-05-26T11:58:30+08:00 }, class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-24T10:27:02+08:00 id: e-ycfoo7134kgsnzdvxxx operatedEndAt: operatedStartAt: resourceId: <B实例ID> status: Succeeded type: CreateInstance updatedAt: 2023-05-24T10:27:12+08:00 }, class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-23T17:44:17+08:00 id: e-ycfmuzgy5im0xxxx operatedEndAt: operatedStartAt: resourceId: <C实例ID> status: Succeeded type: RunInstance updatedAt: 2023-05-23T17:44:20+08:00 }] }
调用DescribeEventTypes接口,查询实例触发的所有事件是否需要响应。
请求示例:
public void queryEventType(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); DescribeEventTypesRequest describeEventTypesRequest = new DescribeEventTypesRequest(); // 指定待查询的事件类型 describeEventTypesRequest.setTypes(Arrays.asList("InfrastructureUpgrade_Redeploy","CreateInstance","RunInstance")); // 筛选需要响应的事件 describeEventTypesRequest.setResponseRequired(true); try { DescribeEventTypesResponse describeEventTypesResponse = ecsApi.describeEventTypes(describeEventTypesRequest); System.out.println(describeEventTypesResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
本实践中,实例A触发的InfrastructureUpgrade_Redeploy(基础设施升级,实例重新部署)事件需要响应。
class DescribeEventTypesResponse { eventTypes: [class EventTypeForDescribeEventTypesOutput { kind: PlannedOperations responseRequired: true status: [Inquiring, Executing, Succeeded, Rejected, Canceled] title: 基础设施升级,实例重新部署 type: InfrastructureUpgrade_Redeploy }] nextToken: }
调用UpdateSystemEvents接口,响应InfrastructureUpgrade_Redeploy(基础设施升级,实例重新部署)事件,授权火山引擎运维人员进行重新部署实例,排除故障。
说明
请求示例:
public void updateEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); UpdateSystemEventsRequest updateSystemEventsRequest = new UpdateSystemEventsRequest(); // 传入需要响应的事件ID updateSystemEventsRequest.setEventIds(Arrays.asList("e-ycfu1fit1f8hcczyxxx")); // 响应事件 updateSystemEventsRequest.setStatus("Executing"); // 指定重新部署实例时间窗 updateSystemEventsRequest.setOperatedStartAt("2023-05-28T23:58:30+08:00"); updateSystemEventsRequest.setOperatedEndAt("2023-05-29T11:58:30+08:00"); try { UpdateSystemEventsResponse updateSystemEventsResponse = ecsApi.updateSystemEvents(updateSystemEventsRequest); System.out.println(updateSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
class UpdateSystemEventsResponse { operationDetails: [class OperationDetailForUpdateSystemEventsOutput { error: null eventId: e-ycfu1fit1f8hcczxxx }] }
调用DescribeSystemEvents接口,传入已响应的事件ID,查询事件当前状态等信息。
请求示例:
public void queryInstanceEvents(){ //设置您的ak String ak = "Your AK"; //设置您的sk String sk = "Your SK"; //设置您要访问的地域,本示例为北京地域 String region = "cn-beijing"; //初始化apiclient ApiClient apiClient = new ApiClient() .setCredentials(Credentials.getCredentials(ak, sk)) .setRegion(region); EcsApi ecsApi = new EcsApi(apiClient); DescribeSystemEventsRequest describeSystemEventsRequest = new DescribeSystemEventsRequest(); // 指定待查询事件ID describeSystemEventsRequest.setEventIds(Arrays.asList("e-ycfu1fit1f8hcczyxxx")); try { DescribeSystemEventsResponse describeSystemEventsResponse = ecsApi.describeSystemEvents(describeSystemEventsRequest); System.out.println(describeSystemEventsResponse); } catch (ApiException e) { System.out.println(e.getResponseBody()); } }
返回示例:
事件处于执行中状态示例如下:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-26T11:58:30+08:00 id: e-ycfu1fit1f8hcczyxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Executing type: InfrastructureUpgrade_Redeploy updatedAt: 2023-05-26T14:19:19+08:00 }] }
事件执行成功示例如下:
class DescribeSystemEventsResponse { nextToken: systemEvents: [class SystemEventForDescribeSystemEventsOutput { createdAt: 2023-05-26T11:58:30+08:00 id: e-ycfu1fit1f8hcczyxxx operatedEndAt: 2023-05-29T11:58:30+08:00 operatedStartAt: 2023-05-28T23:58:30+08:00 resourceId: <A实例ID> status: Succeeded type: InfrastructureUpgrade_Redeploy updatedAt: 2023-05-28T23:58:30+08:00 }] }