All Products
Search
Document Center

Enterprise Distributed Application Service:Call an API operation to implement single-release deployment in an ECS cluster

Last Updated:Jun 19, 2023

This topic describes how to use Enterprise Distributed Application Service (EDAS) SDK for Java to call an API operation to release an application by using a JAR, WAR, or image file in an Elastic Compute Service (ECS) cluster.

Prerequisites

  • The ID of the region where the application resides 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 the details of the microservice namespace, such as the value of the RegionId parameter for the microservice namespace.

  • 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 an application already exists, you can call the ListApplication operation to query the details of the application, such as the value of the APPId parameter of the application. Sample application ID:6bbc57a2-a017-4bec-b521-49a15bd3****.

  • The deployment and update package (JAR or WAR files) are uploaded to the destination address. In this example, the deployment and update package is stored in an Object Storage Service (OSS) bucket. Sample destination address:https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar.

  • The version of the container in which your High-speed Service Framework (HSF) application runs. You can call the ListBuildPack operation to query the details of the container, such as the value of the ConfigId parameter for the container. Sample value of the ConfigId parameter:57.

Deploy an application in single-release mode

The following sample code provides an example on how to deploy an application in single-release mode in an ECS cluster. Advanced parameters that are related to environment variables are not included in the sample code. For more information about API parameters, see DeployApplication.

Note

If you want to deploy a Spring Cloud or Dubbo application in an ECS cluster, you can immediately run the following sample code. If you want to deploy an HSF application in an ECS cluster, you must add the EDAS-Container parameter to the sample code.

// The build package number of EDAS Container. If you deploy an HSF application, you must configure this parameter. 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 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 RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
        // In this sample code, the AccessKey ID and AccessKey secret are included in the environment variables. You can save your AccessKey ID and AccessKey secret to your configuration file. 
        // To prevent key leaks, we recommend that you do not include 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 deploy the application in phased-release mode. 
        String region_id = "cn-hangzhou";

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

        // Initiate 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("create by edas pop api");
        // The deployment type. Set the value to url. 
        request.setDeployType("url");
        // The URL of the JAR or WAR file that is used to deploy the application. We recommend that you save the JAR or WAR file to an OSS bucket. 
        request.setWarUrl("https:doc***.oss-cn-hangzhou.aliyuncs.com/sc-****-D-0.0.1-SNAPSHOT.jar");
        // The version of the JAR or WAR file. 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 in which you want to deploy the application. If you want to deploy the application to all groups, set the parameter to all. 
        // You can call the ListDeployGroup operation to obtain the ID of the specified group. 
        request.setGroupId("all");
        // The number of release phases for each group. The value 1 indicates that the single-release mode is used. 
        request.setBatch(1);
        // The phased-release mode. The value o indicates the automatic phased-release mode. The value 1 indicates the manual phased-release mode. 
        request.setReleaseType((long) 0);
        //The ID of the application component. If you release a Spring Cloud or Dubbo application in single-release mode, you must specify a JDK version for the JAR file or an Apache Tomcat version for the WAR file. If you specify an HSF application, you do not configure this parameter. 
        // The value 4 indicates Apache Tomcat 7.0.91, the value 7 indicates Apache Tomcat 8.5.42, the value 5 indicates OpenJDK 1.8.x, and the value 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****

Check the result

After you deploy the application in an ECS cluster, you can call the GetChangeOrderInfo operation to view the change details and change status of the application. For more information about specific API parameters, see GetChangeOrderInfo.

Sample returned response 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.

To check whether the single-release deployment of the application in the specified ECS cluster is successful, you can view the value of the changeOrderInfo.Status parameter. Valid values of the changeOrderInfo.Status parameter:

  • 0: Ready

  • 1: In progress

  • 2: Successful

  • 3: Failed

  • 6: Terminated

  • 8: Waiting to manually confirm the next phase during a manual phased-release.

  • 9: Waiting to automatically confirm the next phase during an automatic phased-release.

  • 10: Failed due to a system exception