This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to release an application to the specified instances in an Elastic Compute Service (ECS) cluster at a time by calling an operation.

Prerequisites

Before you release an application to the specified instances in an ECS cluster at a time, make sure that the following prerequisites are met:
  • The region in which the application is created in 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, you can call the ListApplication operation to query applications and obtain the ID of the application that you want to release. For 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 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.
  • For a High-Speed Service Framework (HSF) application, the information about the EDAS Container version is obtained. You can call the ListBuildPack operation to query EDAS Container versions and obtain the sequence number of the build package to be used. For example, the sequence number is 57.

Release an application to the specified instances in an ECS cluster at a time

The following code provides an example on how to release an application to the specified instances in an ECS cluster at a time. For more information about advanced parameters such as environment variables, see DeployApplication.

Note The following code is applicable only to releasing a Spring Cloud or Dubbo application to the specified instances at a time. For an HSF application, you must add the following information about the EDAS Container version to the code:
// The sequence number of the build package of EDAS Container. This parameter is required if you release an HSF application. To obtain the sequence number of a build package, you can call the ListBuildPack operation and check the value of 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 Alibaba Cloud account. 
        String aliyun_user_sk = "<yourAccessKeySecret>";
        // The ID of the region where the application is to be deployed. 
        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("create by edas pop api");
        // The deployment mode of the application. Set the value 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 upload the package to OSS and specify the OSS URL of the package. 
        request.setWarUrl("https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar");
        // The version of the package that is used to deploy the application. 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 to which the application is to be deployed. To deploy the application to all instance groups, set the parameter to all. 
        // To deploy the application to a specific instance group, call the ListDeployGroup operation to obtain the group ID. 
        request.setGroupId("all");
        // The number of phases for releasing the application to the specified instances. Set the value to 1, which indicates that the application is to be released at a time. 
        request.setBatch(1);
        // The mode in which the next phase is triggered. The value of 0 indicates that EDAS automatically triggers the next phase. The value of 1 indicates that manual confirmation is required to trigger the next phase. 
        request.setReleaseType((long) 0);
        // The ID of the component used by the application to be released to the specified instances at a time. For a Spring Cloud or Dubbo application, specify an ID that indicates a JDK version if you use a JAR package and an ID that indicates an Apache Tomcat version if you use a WAR package. For an HSF application, you do not need to set this parameter. 
        // The value of 4 indicates Apache Tomcat 7.0.91. The value of 7 indicates Apache Tomcat 8.5.42. The value of 5 indicates OpenJDK 1.8.x. The 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=f32db5e3-a105-412c-9168-6f7c5295****

Verify the result

After you release the application to the specified ECS instances, 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:
{
  "Message": "success",
  "RequestId": "9C487FE4-F188-45EC-87A5-8BD3D655568F",
  "Code": 200,
  "changeOrderInfo": {
    "Status": 2,
    "Desc": "create by edas pop api",
    "PipelineInfoList": {
         ......
        // 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 to the specified ECS instances at a time. 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