All Products
Search
Document Center

Enterprise Distributed Application Service:Roll back an ECS-deployed application to a historical version by using the EDAS Java SDK

Last Updated:Mar 11, 2026

When an application update introduces issues in an Elastic Compute Service (ECS) cluster, you need a fast way to restore a known-good state. The Enterprise Distributed Application Service (EDAS) RollbackApplication API redeploys a previously deployed application package to the target instance group, returning the application to a stable version without manual repackaging.

Prerequisites

Before you begin, make sure that you have:

Roll back the application

The rollback workflow has three steps: retrieve the target historical version, submit the rollback request, and verify the result.

Step 1: Retrieve the target version

Call the ListHistoryDeployVersion operation to list previously deployed versions. Identify the PackageVersion value for the version you want to roll back to (example: 20210417.154931).

To roll back a specific deploy group rather than all groups, call the ListDeployGroup operation to get the target GroupId (example: 941be68c-4aac-48a1-88fe-c9ad1502****).

Step 2: Submit the rollback request

The following code calls RollbackApplication to roll back an application to a historical version. AccessKey credentials are retrieved from environment variables.

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.RollbackApplicationRequest;
import com.aliyuncs.edas.model.v20170801.RollbackApplicationResponse;

public class RollbackApplication {

    public static void main(String[] args)  {
        // Retrieve AccessKey credentials from environment variables.
        // Do not hardcode credentials in source files.
        // Use a RAM user instead of the Alibaba Cloud account for security.
        String aliyun_user_ak = System.getenv("ACCESS_KEY_ID");
        String aliyun_user_sk = System.getenv("ACCESS_KEY_SECRET");

        // Set the region where the application is deployed.
        String region_id = "cn-hangzhou";

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

        RollbackApplicationRequest request = new RollbackApplicationRequest();

        // Required: application ID
        request.setAppId("<your-app-id>");

        // Required: target historical version (from ListHistoryDeployVersion)
        request.setHistoryVersion("<target-package-version>");

        // Deploy group ID. Set to "all" to roll back all instance groups.
        request.setGroupId("all");

        // Number of rollback phases (1-5).
        // 1 = single-batch rollback; 2-4 = phased rollback.
        request.setBatch(1);

        // Wait time between phases in minutes (0-5). Default: 0.
        // Only relevant when Batch > 1.
        request.setBatchWaitTime(0);

        try {
            RollbackApplicationResponse response = client.getAcsResponse(request);
            System.out.println("Message=" + response.getMessage()
                + "\nChangeOrderId=" + response.getChangeOrderId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}

Replace the following placeholders with actual values:

PlaceholderDescriptionExample
<your-app-id>Application ID in EDAS6bbc57a2-a017-4bec-b521-49a15bd3****
<target-package-version>Historical version from ListHistoryDeployVersion20210417.154931

Sample response:

Message=success
ChangeOrderId=b3496bf0-0b6b-42c3-921c-f5250af****

Step 3: Verify the result

Call the GetChangeOrderInfo operation with the ChangeOrderId from the rollback response to check the rollback status.

Sample response:

{
  "Message": "success",
  "RequestId": "EF09BCD3-3D37-4D76-9CF3-12B71A9EDE7C",
  "Code": 200,
  "changeOrderInfo": {
    "Status": 2,
    "Desc": "Version: 20210417.154931 | Package Name: sc-consumer-D-0.0.1-SNAPSHOT.jar...",
    "PipelineInfoList": {
      "PipelineInfo": [
        {
          "PipelineStatus": 2,
          "PipelineName": "Batch 1 Change"
        }
      ]
    }
  }
}

The changeOrderInfo.Status field indicates the rollback result:

Status valueMeaning
0Ready
1In progress
2Successful
3Failed
6Terminated
8Waiting for manual confirmation to trigger the next phase (manual phased rollback)
9Waiting to trigger the next phase (automatic phased rollback)
10Failed due to a system exception

Related operations