This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to terminate an update of an application deployed in an Elastic Compute Service (ECS) cluster by calling an API operation.

Prerequisites

Before you terminate an update of an application, make sure that the following prerequisites are met:

Terminate an update of an application

The following code provides an example on how to terminate an update for an application deployed in an ECS cluster in EDAS:

Note The following code can only terminate an update for the application and cannot automatically roll back the application to the version before the update. You must manually roll back the application to the version before the update, resolve the issues with the new version, and then redeploy the application. For more information about how to roll back an application to a historical version, see Call an API operation to roll back an application deployed in an ECS cluster to a historical version.
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.AbortChangeOrderRequest;
import com.aliyuncs.edas.model.v20170801.AbortChangeOrderResponse;

public class AbortChangeOrder {

    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 where the application whose update is to be terminated 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. 
        AbortChangeOrderRequest request = new AbortChangeOrderRequest();
        // The update ID of the application. 
        request.setChangeOrderId("47e2b863-adc8-4a0e-ac23-8361b95a****");


        try {
            AbortChangeOrderResponse response = client.getAcsResponse(request);
            System.out.println("Message=" + response.getMessage() + "\nRequestId=" + response.getRequestId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
Sample response:
Message=success
RequestId=19C54DC3-C66C-40D0-AEED-8D5A1F00F3BA

Verify the result

After you terminate an update of the application, 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": "CCC48EB3-E628-45B4-8DF3-ED8551119742",
  "Code": 200,
  "changeOrderInfo": {
    "Status": 6,
    "Desc": "create by edas pop api",
    "PipelineInfoList": {
      "PipelineInfo": [
        {
           ...... 
           // The sample response is incomplete and is only for reference. 
You can view the value of the changeOrderInfo.Status parameter to check whether an update is terminated for the application. 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 release
  • 9: wait to trigger the next phase during an automatic phased release
  • 10: failed due to a system exception