All Products
Search
Document Center

Enterprise Distributed Application Service:Call an API operation to roll back an application in a Kubernetes cluster during an update

Last Updated:Jun 16, 2023

This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to call an API operation to roll back an application in a Kubernetes cluster during an update.

Prerequisites

Sample change order ID: 47e2b863-adc8-4a0e-ac23-8361b95a****

If you saved the value of the ChangeOrderId parameter when you started an update, you do not need to call the ListRecentChangeOrder operation.

Sample code

The following sample code provides an example on how to roll back an application in an EDAS Kubernetes cluster during an update:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.edas.model.v20170801.AbortAndRollbackChangeOrderRequest;
import com.aliyuncs.edas.model.v20170801.AbortAndRollbackChangeOrderResponse;

public class AbortAndRollbackChangeOrder {

    public static void main(String[] args)  {
        // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in EDAS is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
        // In this sample code, the AccessKey ID and AccessKey secret are included in the environment variables. You can save your AccessKey ID and AccessKey secret to your configuration file. 
        // To prevent key leaks, we recommend that you do not include your AccessKey ID and AccessKey secret in the code. 
        String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
        String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");
        // The ID of the region where the application that you want to roll back resides. 
        String region_id = "cn-hangzhou";

        DefaultProfile defaultProfile = DefaultProfile.getProfile(region_id, aliyun_user_ak, aliyun_user_sk);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);

        // Initiate an API request and configure the related parameters. 
        AbortAndRollbackChangeOrderRequest request = new AbortAndRollbackChangeOrderRequest();
        // The change order ID of the application that is being updated. 
        request.setChangeOrderId("47e2b863-adc8-4a0e-ac23-8361b95a****");

        try {
            AbortAndRollbackChangeOrderResponse response = client.getAcsResponse(request);
            System.out.println("ChangeOrderId=" + response.getData().getChangeOrderId() + "\nMessage=" + response.getMessage() + "\nTraceId=" + response.getTraceId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Sample response:

ChangeOrderId=aef94ee3-3142-4abc-9d7c-57249686****
Message=success
TraceId=210e815316184954351417778d****

Check the result

After you roll back the application during an update, you can call the GetChangeOrderInfo operation to query the change details and change status of the application. For information about specific API parameters, see GetChangeOrderInfo.

Sample returned response after you call the GetChangeOrderInfo operation:

{
  "Message": "success",
  "RequestId": "92C41E0B-949F-44A2-A386-AECA8909225E",
  "Code": 200,
  "changeOrderInfo": {
    "Status": 2,
    "Desc": "Deployment Method: Phased Release | Version: 2021-04-15 14:01:12 | Package Name: sc-consumer-D-0.0.1-SNAPSHOT.jar",
    "PipelineInfoList": {
      "PipelineInfo": [
        {
          "PipelineStatus": 2,
          "PipelineName": "Batch 1 Change",
           ...... 
           "TaskMessage": "Apply success. <br>application is ready at desired state, version: 22"
            ......
           // The sample response is incomplete and is provided only for reference.

To check whether the application is rolled back, you can view the value of the changeOrderInfo.Status parameter.

Valid values of the changeOrderInfo.Status parameter:

  • 0: Ready

  • 1: In progress

  • 2: Successful

  • 3: Failed

  • 6: Terminated

  • 8: Waiting to manually confirm the next phase during a manual phased-release

  • 9: Waiting to automatically confirm the next phase during an automatic phased-release

  • 10: Failed due to a system exception

Note

If a value of 3 is returned for the changeOrderInfo.Status parameter, the application fails to be rolled back during an update. To identify the cause of the failure, check the value of the TaskMessage parameter. After you resolve the issue, update the application again.