This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to release an application in phases by using a JAR package, a WAR package, or an image in a Kubernetes cluster by calling an API operation.

Prerequisites

Before you call the API operation to release an application in phases, make sure that the following prerequisites are met:

Background information

If you need to call an API operation to release an application in phases, we recommend that you perform an automatic phased release. When you perform a manual phased release, you must call the ContinuePipeline operation to manually trigger the next phase. For more information, see Manually trigger the next phase.

The following are two sample policies for phased release. You can select and modify a policy based on your business requirements.
  • Manually release an application in two phases
    {"type":"BatchUpdate","batchUpdate":{"batch":2,"releaseType":"manual"}}
  • Automatically release an application in two phases at an interval of 2 minutes
    {"type":"BatchUpdate","batchUpdate":{"batch":2,"releaseType":"auto","batchWaitTime":2}}

Release an application in phases by using a JAR package or WAR package

The following code provides an example on how to release an application in phases by using a JAR package in a Kubernetes cluster in EDAS. For more information about advanced parameters, such as parameters that are related to scheduling rules, startup commands, and environment variables, see DeployK8sApplication.

Note If you want to use a WAR package to deploy an application, add the following two parameters to the sample code as needed:
// The version of Tomcat on which the deployment package of the application depends. This parameter is applicable to Spring Cloud and Dubbo applications that are deployed by using WAR packages. 
request.setWebContainer("apache-tomcat-7.0.91");  
// The version of EDAS Container on which the deployment package of the application depends. This parameter is applicable to HSF applications that are deployed by using WAR packages.      
request.setEdasContainerVersion("3.5.9");
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.DeployK8sApplicationRequest;
import com.aliyuncs.edas.model.v20170801.DeployK8sApplicationResponse;

public class DeployK8sApplication {

    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. 
        DeployK8sApplicationRequest request = new DeployK8sApplicationRequest();
        // The ID of the application. 
        request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
        // The URL and version of the JAR package or WAR package. 
        request.setPackageUrl("https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.2-SNAPSHOT.jar");
        request.setPackageVersion("2021-04-15 14:01:12");
        // The version of the Java development kit (JDK) on which the deployment package of the application depends. Valid values: Open JDK 7 and Open JDK 8. 
        request.setJDK("Open JDK 8");
        // The custom policy for phased release. In this example, the application is automatically released in two phases at an interval of 2 minutes. 
        request.setUpdateStrategy("{\"type\":\"BatchUpdate\",\"batchUpdate\":{\"batch\":2,\"releaseType\":\"auto\",\"batchWaitTime\":2}}");
        // The number of instances for the application. 
        request.setReplicas(3);
        // The CPU quota and memory quota for application instances. A value of 0 indicates that no quotas are set. 
        request.setCpuLimit(0);
        request.setMemoryLimit(0);
        request.setCpuRequest(0);
        request.setMemoryRequest(0);
        // The minimum number of CPU cores required. Unit: cores. A value of 0 indicates that no quota is set. 
        request.setMcpuRequest(0);
        // The maximum number of CPU cores allowed. Unit: cores. A value of 0 indicates that no quota is set. 
        request.setMcpuLimit(0);
        // The description of the change record. 
        request.setChangeOrderDesc("Phased release (JAR package)");

        try {
            DeployK8sApplicationResponse response = client.getAcsResponse(request);
            System.out.println("ChangeOrderId=" + response.getChangeOrderId() + "\nMessage=" + response.getMessage());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
Sample response:
ChangeOrderId=e16bdf30-00c9-4b12-87b5-0ad35f3f****
Message=success

Release an application in phases by using an image

The following code provides an example on how to release an application in phases by using an image in a Kubernetes cluster in EDAS. For more information about advanced parameters, such as parameters that are related to scheduling rules, startup commands, and environment variables, see DeployK8sApplication.

Note In this example, a manual phased release is performed. You can modify the policy to perform an automatic phased release as needed.
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.DeployK8sApplicationRequest;
import com.aliyuncs.edas.model.v20170801.DeployK8sApplicationResponse;

public class DeployK8sApplication {

    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. 
        DeployK8sApplicationRequest request = new DeployK8sApplicationRequest();
        // The ID of the application. 
        request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
        // The address of the image. 
        request.setImage("registry-vpc.cn-hangzhou.aliyuncs.com/edas-demo-project/provider:2.0");
        // The custom policy for phased release. In this example, the application is manually released in two phases. You can modify the policy to perform an automatic phased release as needed. 
        request.setUpdateStrategy("{"type":"BatchUpdate","batchUpdate":{"batch":2,"releaseType":"manual"}}");
        // The number of instances for the application. 
        request.setReplicas(3);
        // The CPU quota and memory quota for application instances. A value of 0 indicates that no quotas are set. 
        request.setCpuLimit(0);
        request.setMemoryLimit(0);
        request.setCpuRequest(0);
        request.setMemoryRequest(0);
        // The minimum number of CPU cores required. Unit: cores. A value of 0 indicates that no quota is set. 
        request.setMcpuRequest(0);
        // The maximum number of CPU cores allowed. Unit: cores. A value of 0 indicates that no quota is set. 
        request.setMcpuLimit(0);
        // The description of the change record. 
        request.setChangeOrderDesc("Phased release (image)");

        try {
            DeployK8sApplicationResponse response = client.getAcsResponse(request);
            System.out.println("ChangeOrderId=" + response.getChangeOrderId() + "\nMessage=" + response.getMessage());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
Sample response:
ChangeOrderId=7ed96c93-cbd5-4614-a304-861ede6c****
Message=success

Verify the result

After you release the application in phases, 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:
  • Change details for the application that is released in phases by using a JAR package or WAR package
    {
      "Message": "success",
      "RequestId": "DA4E96FA-4C75-486A-A4F4-30F62C9EA53C",
      "Code": 200,
      "changeOrderInfo": {
        "Status": 2,
        "Desc": "Phased release (JAR package)",
        "PipelineInfoList": {
          "PipelineInfo": [
            {
              ......
              "TaskMessage": "Apply success. <br>application is ready at desired state, version: 22"
              ......
              // The sample response is incomplete and is only for reference. 
  • Change details for the application that is released in phases by using an image
    {
      "Message": "success",
      "RequestId": "FE1722D2-4B81-467C-9828-EFFBA3B3F565",
      "Code": 200,
      "changeOrderInfo": {
        "Status": 8,
        "Desc": "Phased release (image)",
        "PipelineInfoList": {
          "PipelineInfo": [
            {
              ......
             "PipelineId": "4ff02b63-e14d-4124-86ff-22239f80****"
              ......
              "PipelineId": "6dbbfff8-bcf7-4300-aa59-ccb06909****"
               .......
               "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 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
Note If a value of 3 is returned for the changeOrderInfo.Status parameter, the application fails to be released in phases. To find the cause of the failure, check the value of the TaskMessage parameter. After the issue is fixed, release the application in phases again.

Manually trigger the next phase

When you perform a manual phased release, you must call the ContinuePipeline operation to manually trigger the next phase.

  1. Call the GetChangeOrderInfo operation to obtain the pipeline IDs that indicate the phases of the application release. The pipeline IDs are specified by the PipelineId parameter.
    Sample response that is returned after you call the GetChangeOrderInfo operation:
    {
      "Message": "success",
      "RequestId": "FE1722D2-4B81-467C-9828-EFFBA3B3F565",
      "Code": 200,
      "changeOrderInfo": {
        "Status": 8,
        "Desc": "Phased release (image)",
        "PipelineInfoList": {
          "PipelineInfo": [
            {
              ......
             "PipelineId": "4ff02b63-e14d-4124-86ff-22239f80****"
              ......
              "PipelineId": "6dbbfff8-bcf7-4300-aa59-ccb06909****"
               .......
               "TaskMessage": "Apply success. <br>application is ready at desired state, version: 22"
               ......
              // The sample response is incomplete and is only for reference. 
    Note In this example, the application is manually released in two phases. Two pipeline IDs are returned after you call the GetChangeOrderInfo operation. The second pipeline ID indicates the phase that you need to manually trigger.

    Similarly, if you manually release the application in three phases, three pipeline IDs are returned. 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 release.
    Sample response:
    {
      "Message": "success",
      "RequestId": "B8ECF6F7-672D-40E9-91DD-1C33F06D4FD8",
      "Code": 200
    }
    Note In this example, the application is manually released in two phases. You need to manually trigger only one phase. 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.

    When you trigger phases, make sure that the shortest interval between two phases is met. By default, this interval is 10 seconds.