All Products
Search
Document Center

Enterprise Distributed Application Service:Terminate an update of an application deployed in an ECS cluster by calling an API operation

Last Updated:Jun 19, 2023

This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to terminate an update of an application that is 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 sample code provides an example on how to terminate an update of an application that is deployed in an ECS cluster in EDAS:

Note

You can run the sample code to only terminate an update of the application. If an issue occurs in the new version, you must manually roll back the application to the version before the update, resolve the issue in the new version, and then redeploy the application. For more information, see Call an API operation to roll back an application that is 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 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 example, the AccessKey ID and AccessKey secret are saved in the environment variables. You can save your AccessKey ID and AccessKey secret in your configuration file based on your business requirements. 
        // To prevent key leaks, we recommend that you do not save 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 region ID of the application. 
        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 configure the related parameters. 
        AbortChangeOrderRequest request = new AbortChangeOrderRequest();
        // The change process 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();
        }
    }
}

The following result is returned after you run the sample code:

Message=success
RequestId=19C54DC3-C66C-40D0-AEED-8D5A1F00F3BA

Check the result

After you terminate the 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 operation-specific parameters, see GetChangeOrderInfo.

The following result 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: The operation to terminate an update of the application is ready.

  • 1: The operation to terminate an update of the application is being performed.

  • 2: The operation to terminate an update of the application is performed.

  • 3: The operation to terminate an update of the application failed.

  • 6: The operation to terminate an update of the application is stopped.

  • 8: The application is waiting for you to manually trigger the next phase during a manual phased release.

  • 9: The application is waiting for the system to trigger the next phase during an automatic phased release.

  • 10: The operation to terminate an update of the application failed due to a system exception.