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

Prerequisites

Before you call the API operation to release an application in phases, make sure the following prerequisites are met:
  • The ID of the region in which you want to release the application in phases is obtained. For example, the region ID is cn-hangzhou.
  • A microservice namespace is created. For example, a microservice namespace with the ID of cn-hangzhou:doc is created. For more information, see Create a namespace.

    If a microservice namespace already exists, you can call the ListUserDefineRegion operation to query custom microservice namespace and obtain the value of the RegionId parameter for the microservice namespace that you want to use. For example, the value is cn-hangzhou:doc.

  • The application is created in the ECS cluster. For more information, see Create an application in an ECS cluster by calling an API operation.

    If you have created the application, call the ListApplication operation to query the created applications and obtain the ID of the specified application. The ID of the application is specified by the APPId parameter. For example, the ID of the application is 6bbc57a2-a017-4bec-b521-49a15bd3****.

  • The JAR package or WAR package that is used to deploy the application is uploaded to the destination storage system. For example, the path of the JAR package in Object Storage Service (OSS) is https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar.
  • The ID of the container version to be used is obtained if you want to release a High-Speed Service Framework (HSF) application. You can call the ListBuildPack operation to query container versions and obtain the ID of the specified container version. The ID of the container version is specified by the ConfigId parameter. For example, the ID of the container version is 57.

Release an application in phases

The following code provides an example on how to release an application in phases in an ECS cluster. The code does not contain settings of advanced parameters such as environment variables. For more information about how to set these parameters, see DeployApplication.

Note You can use the code to release a Spring Cloud or Dubbo application in phases. To release an HSF application in phases, you must add the following EDAS Container information to the code:
// The build package number of EDAS Container. This parameter is required to release an HSF application in phases. You can call the ListBuildPack operation to query the build package number. The build package number is specified by the ConfigId parameter. 
request.setBuildPackId(57);
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.DeployApplicationRequest;
import com.aliyuncs.edas.model.v20170801.DeployApplicationResponse;

public class DeployApplication {

    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 account. 
        String aliyun_user_sk = "<yourAccessKeySecret>";
        // The ID of the region in which you want to release the application in phases. 
        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. 
        DeployApplicationRequest request = new DeployApplicationRequest();
        // The ID of the application to be released. 
        request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
        // The description of the application. 
        request.setDesc("phased release");
        // The type of method to deploy the application. You can set this parameter only to url. 
        request.setDeployType("url");
        // The URL of the JAR package or WAR package that is used to deploy the application. We recommend that you store the deployment package of the application in OSS and set this parameter to the path of the deployment package in OSS. 
        request.setWarUrl("https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar");
        // The version of the deployment package. The value can be up to 64 characters in length. We recommend that you use a timestamp. 
        request.setPackageVersion("1619094147");
        // The ID of the group to which the application was deployed. If you want to deploy the application to all instance groups, set the parameter to all. 
        // You can call the ListDeployGroup operation to obtain the ID of the specified instance group. 
        request.setGroupId("all");
        // The number of phases for each group. If you set the parameter to an integer greater than 1, the application is released in phases. 
        request.setBatch(2);
        // The mode of the phased release. A value of 0 indicates that the next phase is automatically triggered. A value of 1 indicates that the next phase must be manually triggered. We recommend that you set the parameter to 0 to perform an automatic phased release. 
        request.setReleaseType((long) 0);
        // The amount of time that the system waits between two phases. Unit: minutes. By default, the value is 0. This means no wait time between phases. You can set the parameter to a value from 0 to 5. 
        request.setBatchWaitTime(1);
        // The ID of the component that is used by the application. When you release a Spring Cloud or Dubbo application in a single phase, you must specify a JDK version for the JAR package or an Apache Tomcat version for the WAR package. When you release an HSF application in a single phase, you do not need to specify the ID of the component. 
        // A value of 4 indicates Apache Tomcat 7.0.91. A value of 7 indicates Apache Tomcat 8.5.42. A value of 5 indicates OpenJDK 1.8.x. A value of 6 indicates OpenJDK 1.7.x. 
        request.setComponentIds("5");

        try {
            DeployApplicationResponse response = client.getAcsResponse(request);
            System.out.println("Message=" + response.getMessage() + "\nChangeOrderId=" + response.getChangeOrderId());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
Sample response:
Message=success
ChangeOrderId=04c5638f-405e-41de-99b2-e0dccb2****

Verify the result

After you release an application in phases, you can call the GetChangeOrderInfo operation to view the change details and the change status of the application. For more information about the parameters of the operation, see GetChangeOrderInfo.

Sample response that is returned after you call the GetChangeOrderInfo operation:
{
  "Message": "success",
  "RequestId": "01FAA54A-43C0-4681-B985-33BA44D64340",
  "Code": 200,
  "changeOrderInfo": {
    "Status": 2,
    "Desc": "Phased release",
    "PipelineInfoList": {
      "PipelineInfo": [
        {
          ......
         "PipelineId": "4ff02b63-e14d-4124-86ff-22239f80****"
          ......
          "PipelineId": "6dbbfff8-bcf7-4300-aa59-ccb06909****"
           ......
          // 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 released in phases. 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

Manually trigger the next phase

If you release the application in the manual confirmation mode, call the ContinuePipeline operation to manually trigger the next phase.

  1. Call the GetChangeOrderInfo operation to obtain the values of the PipelineId parameter. This parameter indicates the pipeline ID of each phase.
    Sample response that is returned after you call the GetChangeOrderInfo operation:
    {
      "Message": "success",
      "RequestId": "01FAA54A-43C0-4681-B985-33BA44D64340",
      "Code": 200,
      "changeOrderInfo": {
        "Status": 8,
        "Desc": "Phased release",
        "PipelineInfoList": {
          "PipelineInfo": [
            {
               ......
               "PipelineId": "4ff02b63-e14d-4124-86ff-22239f80****"
               ......
               "PipelineId": "6dbbfff8-bcf7-4300-aa59-ccb06909****"
                ......
               // The sample response is incomplete and is only for reference. 
    }  
    Note If you release the application in two phases in the manual confirmation mode, two pipeline IDs are returned in the response of the GetChangeOrderInfo operation. The second pipeline ID indicates the phase that you need to manually trigger.

    Similarly, if you release the application in three phases in the manual confirmation mode, three pipeline IDs are returned in the response of the operation. The second and third pipeline IDs indicate the phases that you need to manually trigger.

  2. Call the ContinuePipeline operation to manually trigger the next phase.
    Sample response:
    {
      "Message": "success",
      "RequestId": "B8ECF6F7-672D-40E9-91DD-1C33F06D4FD8",
      "Code": 200
    }
    Note If the application is to be released in more than two phases, repeat this step by selecting the correct pipeline ID to trigger phases one by one.