When you run multiple versions of an application on Elastic Compute Service (ECS) instances, you need a way to isolate versions, route traffic selectively, and perform canary releases without redeploying the entire fleet. Enterprise Distributed Application Service (EDAS) instance groups let you partition ECS instances so that each group runs a different application version. You can then shift traffic between groups, validate a new version on a small group, and promote it to the rest.
This topic covers five operations with the EDAS SDK for Java:
Quick start
The following example creates an instance group named Beta, associates it with an application version, and prints the resulting group ID. Replace the placeholder IDs with your own values.
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupResponse;
public class QuickStart {
public static void main(String[] args) throws Exception {
String regionId = "cn-hangzhou";
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
InsertDeployGroupRequest request = new InsertDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupName("Beta");
request.setInitPackageVersionId("3fc52328-8746-4422-a742-94e0cfc7****");
InsertDeployGroupResponse response = client.getAcsResponse(request);
System.out.println("GroupName=" + response.getDeployGroupEntity().getGroupName()
+ "\nId=" + response.getDeployGroupEntity().getId());
}
}Expected output:
GroupName=Beta
Id=941be68c-4aac-48a1-88fe-c9ad1502****For more operations such as moving instances between groups, configuring JVM and Tomcat settings, or deleting groups, see the sections below.
How instance groups work
When you create an application in the EDAS console, EDAS automatically creates a default group (_DEFAULT_GROUP). The default group cannot be deleted and is sufficient for single-version deployments.
For multi-version deployments, create additional groups to isolate versions. For example, an application named itemcenter runs on 10 ECS instances. Six instances belong to the default group and four belong to a beta group. Each group can have its own JVM, Tomcat, launch template, and Server Load Balancer (SLB) settings.
Before you begin
Before you call any of the operations in this topic, make sure that you have:
The EDAS SDK for Java installed. See Use EDAS SDK for Java to call EDAS API
The region ID where your application runs (for example,
cn-hangzhou)(Conditional) The application version ID, if you plan to create an instance group. Call ListHistoryDeployVersion and use the
PackageVersion.Idvalue(Conditional) The Elastic Compute Container (ECC) ID, if you plan to move an ECS instance between groups. Call ListApplicationEcc and use the
EccIdvalueECS instances created (for example,
i-bp13o01lzmbsvhsl****)An ECS cluster created. See Create an ECS cluster by calling an API operation. If you already have a cluster, call ListCluster and use the
ClusterIdvalue (for example,369d06d7-450b-4f3d-bf75-9536fcd9****)
Common client setup
All examples in this topic share the same client initialization. Configure it once before running any operation:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
// Replace with the region ID where your application runs
String regionId = "cn-hangzhou";
// Retrieve AccessKey credentials from environment variables
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);Set the following environment variables before running the code:
| Variable | Description |
|---|---|
ALIBABA_CLOUD_ACCESS_KEY_ID | AccessKey ID of your Alibaba Cloud account or a RAM user |
ALIBABA_CLOUD_ACCESS_KEY_SECRET | AccessKey secret of your Alibaba Cloud account or a RAM user |
Create an instance group
Call InsertDeployGroup to create an instance group and associate it with an application version.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | String | Yes | Application ID. |
| GroupName | String | Yes | Group name. Supports letters, digits, underscores (_), and periods (.). Maximum 64 characters. |
| InitPackageVersionId | String | Yes | Deployment package version ID to initialize the group. Get this by calling ListHistoryDeployVersion. |
Sample code
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.InsertDeployGroupResponse;
InsertDeployGroupRequest request = new InsertDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupName("Beta");
request.setInitPackageVersionId("3fc52328-8746-4422-a742-94e0cfc7****");
try {
InsertDeployGroupResponse response = client.getAcsResponse(request);
System.out.println("GroupName=" + response.getDeployGroupEntity().getGroupName()
+ "\nId=" + response.getDeployGroupEntity().getId());
} catch (com.aliyuncs.exceptions.ClientException e) {
// Common errors:
// - Invalid AppId: The specified application does not exist.
// - Duplicate GroupName: A group with this name already exists.
e.printStackTrace();
}Sample response
GroupName=Beta
Id=941be68c-4aac-48a1-88fe-c9ad1502****Verify the result
Call ListDeployGroup and check whether the new group name appears in the response:
{
"DeployGroupList": {
"DeployGroup": [
{
"GroupName": "Beta",
"AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
"GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****"
}
]
},
"Message": "success",
"Code": 200
}Move an ECS instance to a different group
Call ChangeDeployGroup to move an ECS instance from one instance group to another.
Only one ECS instance can be moved per API call.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | String | Yes | Application ID. |
| EccInfo | String | Yes | ECC ID of the ECS instance. Get this by calling ListApplicationEcc. |
| GroupName | String | Yes | Target group name. Use _DEFAULT_GROUP to move the instance back to the default group. |
| ForceStatus | Boolean | No | Force the move when the deployment package version of the ECC differs from the target group. Default: false. |
Sample code
import com.aliyuncs.edas.model.v20170801.ChangeDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.ChangeDeployGroupResponse;
ChangeDeployGroupRequest request = new ChangeDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setEccInfo("4009a824-ce33-4ba0-9ca2-346249a9****");
request.setGroupName("Beta");
request.setForceStatus(true);
try {
ChangeDeployGroupResponse response = client.getAcsResponse(request);
System.out.println("Message=" + response.getMessage()
+ "\nChangeOrderId=" + response.getChangeOrderId());
} catch (com.aliyuncs.exceptions.ClientException e) {
// Common errors:
// - Invalid EccInfo: The specified ECC does not exist.
// - Version mismatch: Set ForceStatus to true to force the move.
e.printStackTrace();
}Sample response
Message=success
ChangeOrderId=369d06d7-450b-4f3d-bf75-9536fcd9****Verify the result
Call ListApplicationEcc and confirm that the GroupId for the ECS instance matches the target group:
{
"EccInfoList": {
"EccInfo": [
{
"EcuId": "8287bcf6-cde3-4377-8906-086d2c32****",
"GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****",
"AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
"EccId": "02cdcdfa-f22b-45e6-8a0f-a738c766****"
}
]
},
"Message": "success",
"Code": 200
}Set JVM parameters for a group
Call UpdateJvmConfiguration to set Java Virtual Machine (JVM) parameters for a specific instance group.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | String | Yes | Application ID. |
| GroupId | String | Yes | Instance group ID. Get this by calling ListDeployGroup. |
| MinHeapSize | Integer | No | Initial heap size in MB. |
| MaxHeapSize | Integer | No | Maximum heap size in MB. |
| MaxPermSize | Integer | No | Permanent generation size in MB. |
| Options | String | No | Custom JVM options (for example, -Dproperty=value). |
Sample code
import com.aliyuncs.edas.model.v20170801.UpdateJvmConfigurationRequest;
import com.aliyuncs.edas.model.v20170801.UpdateJvmConfigurationResponse;
UpdateJvmConfigurationRequest request = new UpdateJvmConfigurationRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupId("941be68c-4aac-48a1-88fe-c9ad1502****");
request.setMinHeapSize(500);
request.setMaxHeapSize(500);
request.setMaxPermSize(500);
request.setOptions("-Dproperty=value");
try {
UpdateJvmConfigurationResponse response = client.getAcsResponse(request);
System.out.println("Message=" + response.getMessage());
} catch (com.aliyuncs.exceptions.ClientException e) {
// Common errors:
// - Invalid GroupId: The specified instance group does not exist.
e.printStackTrace();
}Sample response
Message=successVerify the result
Call GetJvmConfiguration to confirm the updated JVM settings:
{
"Message": "success",
"JvmConfiguration": {
"Options": "-Dproperty=value",
"MaxPermSize": 500,
"MaxHeapSize": 500,
"MinHeapSize": 500
},
"Code": 200
}Set Tomcat parameters for a group
Call UpdateContainerConfiguration to set Tomcat container parameters for a specific instance group.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | String | Yes | Application ID. |
| GroupId | String | Yes | Instance group ID. Get this by calling ListDeployGroup. |
| ContextPath | String | No | Tomcat context path. Valid values: empty string, null, a WAR package name, ROOT (root directory), or a custom string. |
| HttpPort | Integer | No | Application port (for example, 8080). |
| MaxThreads | Integer | No | Maximum number of threads. |
| URIEncoding | String | No | URI encoding scheme. Valid values: ISO-8859-1, GBK, GB2312, UTF-8. |
| UseBodyEncoding | Boolean | No | Whether to use the request body encoding scheme for URI query parameters. Default: false. |
Sample code
import com.aliyuncs.edas.model.v20170801.UpdateContainerConfigurationRequest;
import com.aliyuncs.edas.model.v20170801.UpdateContainerConfigurationResponse;
UpdateContainerConfigurationRequest request = new UpdateContainerConfigurationRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupId("941be68c-4aac-48a1-88fe-c9ad1502****");
request.setContextPath("");
request.setHttpPort(8080);
request.setMaxThreads(20);
request.setURIEncoding("ISO-8859-1");
request.setUseBodyEncoding(true);
try {
UpdateContainerConfigurationResponse response = client.getAcsResponse(request);
System.out.println("Message=" + response.getMessage());
} catch (com.aliyuncs.exceptions.ClientException e) {
// Common errors:
// - Invalid GroupId: The specified instance group does not exist.
e.printStackTrace();
}Sample response
Message=successVerify the result
Call GetContainerConfiguration to confirm the updated Tomcat settings:
{
"Message": "success",
"ContainerConfiguration": {
"HttpPort": 8080,
"ContextPath": "ROOT",
"UseBodyEncoding": true,
"URIEncoding": "ISO-8859-1",
"MaxThreads": 20
},
"Code": 200
}Delete an instance group
Call DeleteDeployGroup to delete an instance group.
An instance group that contains ECS instances cannot be deleted. Move all instances to another group first. See Move an ECS instance to a different group.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| AppId | String | Yes | Application ID. |
| GroupName | String | Yes | Name of the instance group to delete. |
Sample code
import com.aliyuncs.edas.model.v20170801.DeleteDeployGroupRequest;
import com.aliyuncs.edas.model.v20170801.DeleteDeployGroupResponse;
DeleteDeployGroupRequest request = new DeleteDeployGroupRequest();
request.setAppId("6bbc57a2-a017-4bec-b521-49a15bd3****");
request.setGroupName("Beta");
try {
DeleteDeployGroupResponse response = client.getAcsResponse(request);
System.out.println("Message=" + response.getMessage()
+ "\nData=" + response.getData());
} catch (com.aliyuncs.exceptions.ClientException e) {
// Common errors:
// - Group not empty: Move all instances to another group before deleting.
// - Invalid GroupName: The specified group does not exist.
e.printStackTrace();
}Sample response
Message=success
Data=1Verify the result
Call ListDeployGroup and confirm the deleted group no longer appears in the response:
{
"DeployGroupList": {
"DeployGroup": [
{
"GroupName": "_DEFAULT_GROUP",
"AppId": "6bbc57a2-a017-4bec-b521-49a15bd3****",
"GroupId": "941be68c-4aac-48a1-88fe-c9ad1502****"
}
]
},
"Message": "success",
"Code": 200
}Error handling
All EDAS SDK operations throw ClientException (client-side errors such as invalid parameters or network issues) or ServerException (server-side errors). The following table lists common error scenarios and solutions:
| Operation | Error scenario | Solution |
|---|---|---|
InsertDeployGroup | Duplicate group name | Choose a different group name or query existing groups with ListDeployGroup. |
InsertDeployGroup | Invalid InitPackageVersionId | Call ListHistoryDeployVersion to get valid version IDs. |
ChangeDeployGroup | Version mismatch between ECC and target group | Set ForceStatus to true to force the move. |
ChangeDeployGroup | Invalid EccInfo | Call ListApplicationEcc to get valid ECC IDs. |
DeleteDeployGroup | Group contains ECS instances | Move all instances to another group before deleting. |
| All operations | Invalid AppId | Verify the application exists and you have access to it. |
Related API operations
| Operation | Description |
|---|---|
| InsertDeployGroup | Create an instance group. |
| ChangeDeployGroup | Move an ECS instance to a different group. |
| UpdateJvmConfiguration | Set JVM parameters for an instance group. |
| UpdateContainerConfiguration | Set Tomcat parameters for an instance group. |
| DeleteDeployGroup | Delete an instance group. |
| ListDeployGroup | Query instance groups for an application. |
| ListHistoryDeployVersion | Query historical deployment versions. |
| ListApplicationEcc | Query ECC information for an application. |
| GetJvmConfiguration | Query JVM settings for an instance group. |
| GetContainerConfiguration | Query Tomcat settings for an instance group. |
| ListCluster | Query ECS clusters. |