All Products
Search
Document Center

Enterprise Distributed Application Service:Release an application in phases in an ECS cluster by calling an API operation

Last Updated:Jun 15, 2023

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 in an ECS cluster, make sure the following prerequisites are met:

  • EDAS SDK for Java is installed. For more information, see "Use EDAS SDK for Java to call EDAS API".

  • The ID of the region where the application is created is obtained. In this example, the region ID is cn-hangzhou.

  • A microservice namespace 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 namespaces and obtain the ID of the microservice namespace from the RegionId parameter.

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

    If the application is already created in an ECS cluster, you can call the ListApplication operation to query applications and obtain the application ID from the AppId parameter. In this example, the application ID is 6bbc57a2-a017-4bec-b521-49a15bd3****.

  • The JAR package or WAR package that is used to deploy the application is uploaded to the destination URL. In this example, the destination URL in Object Storage Service (OSS) is https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar.

  • If you want to release a High-Speed Service Framework (HSF) application, make sure that the version of EDAS Container is obtained. You can call the ListBuildPack operation to query EDAS Container versions and obtain the EDAS Container version from the ConfigId parameter. In this example, the EDAS Container version is 57.

Release an application in phases

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

Note

You can use the sample code to release a Spring Cloud or Dubbo application in phases. To release an HSF application in phases, you must add the following information about EDAS Container to the sample code:

// The build package number of EDAS Container. This parameter must be specified when you release an HSF application in phases. You can call the ListBuildPack operation and obtain the build package number from 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 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 stored 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 ID of the region where 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 configure the related parameters. 
        DeployApplicationRequest request = new DeployApplicationRequest();
        // The ID of the application. 
        request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
        // The description of the application. 
        request.setDesc("Phased release of an application");
        // The method to deploy the application. Set the value to url. 
        request.setDeployType("url");
        // The URL of the JAR package or WAR package that you want to use to deploy the application. We recommend that you store the deployment package of the application in OSS and use the OSS storage path. 
        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 instance group in which you want to deploy the application. If you want to deploy the application to all instance groups, set this parameter to all. 
        // If you want to deploy the applicaiton in a specific instance group, call the ListDeployGroup operation and obtain the group ID from the GroupId parameter. 
        request.setGroupId("all");
        // The number of phases for each group. If you set this 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 specifies that the next phase is automatically triggered. A value of 1 specifies that the next phase must be manually triggered. We recommend that you set this parameter to 0 to perform an automatic phased release. 
        request.setReleaseType((long) 0);
        // The amount of time for which the system waits between two phases. Unit: minutes. The default value is 0. A value of 0 specifies no waiting time between two phases. The maximum value is 5. 
        request.setBatchWaitTime(1);
        // The ID of the application component. When you release a Spring Cloud or Dubbo application in a single phase, you must specify a JDK version for a JAR package or an Apache Tomcat version for a WAR package. When you release an HSF application in a single phase, you do not need to specify the ID of the application component. 
        // A value of 4 specifies Apache Tomcat 7.0.91. A value of 7 specifies Apache Tomcat 8.5.42. A value of 5 specifies OpenJDK 1.8.x. A value of 6 specifies 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();
        }
    }
}

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

Message=success
ChangeOrderId=04c5638f-405e-41de-99b2-e0dccb2****

Check 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 operation-specific parameters, see GetChangeOrderInfo.

The following result 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 check whether the application is released in phases based on the value of the changeOrderInfo.Status parameter. Valid values of the changeOrderInfo.Status parameter:

  • 0: The application is ready to be released.

  • 1: The application is being released.

  • 2: The application is released.

  • 3: The application failed to be released.

  • 6: The release of the application is terminated.

  • 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 application failed to be released due to a system exception.

Manually trigger the next phase

If you manually release the application in phases, 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 specifies the ID of each phase during a phased release of an application.

    The following result is returned after you call the GetChangeOrderInfo operation:

    {
      "Message": "success",
      "RequestId": "01FAA54A-43C0-4681-B985-33BA44D64340",
      "Code": 200,
      "changeOrderInfo": {
        "Status": 8,
        "Desc": "Phased release of an application",
        "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 manually release the application in two phases, two phase IDs are returned after you call the GetChangeOrderInfo operation. You must manually trigger the second phase that corresponds to the second phase ID.

    Similarly, if you manually release the application in three phases, three phase IDs are returned after you call the operation. You must manually trigger the second and third phases that correspond to the second and third phase IDs.

  2. Call the ContinuePipeline operation to manually trigger the next phase.

    The following result is returned:

    {
      "Message": "success",
      "RequestId": "B8ECF6F7-672D-40E9-91DD-1C33F06D4FD8",
      "Code": 200
    }
    Note

    If you manually trigger multiple phases, select the correct phase ID and repeat this step to trigger phases one by one.