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

Prerequisites

Before you roll back an application during an update, make sure that the following prerequisites are met:

Sample code

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

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 ID of your Alibaba Cloud account or a RAM user within the Alibaba Cloud account. 
        String aliyun_user_ak = "<yourAccessKeyId>";
        // The AccessKey secret of your Alibaba Cloud account or a RAM user within the Alibaba Cloud account. 
        String aliyun_user_sk = "<yourAccessKeySecret>";
        // The ID of the region in which the application to be released resides. 
        String region_id = "cn-hangzhou";

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

        // Create an API request and set the parameters. 
        AbortAndRollbackChangeOrderRequest request = new AbortAndRollbackChangeOrderRequest();
        // The update ID of the application. 
        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****

Verify the result

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

Sample response that is returned 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 only for reference. 
You can view the value of the changeOrderInfo.Status parameter to check whether the application is rolled back. Valid values of the changeOrderInfo.Status parameter:
  • 0: ready
  • 1: in progress
  • 2: successful
  • 3: failed
  • 6: terminated
  • 8: wait for manual confirmation to trigger the next phase during a manual phased rollback
  • 9: wait to trigger the next phase during an automatic phased rollback
  • 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 find the cause of the failure, check the value of the TaskMessage parameter. After the issue is fixed, update the application again.