All Products
Search
Document Center

Batch Compute:createCluster

Last Updated:May 11, 2018

Method description

Creates a cluster.

Parameter description

Parameter Type Required Description
clusterDescription ClusterDescription Yes Description of the created cluster

The package names of the following classes are all com.aliyuncs.batchcompute.pojo.v20151111.

Attributes of ClusterDescription

The getter and setter methods are available to all attributes.

Attribute Type Required Description
name String Yes Cluster name
description String No Brief description of a job
imageId String Yes It can be an ECS image ID or a registered image ID
groups Map Yes Instance group
instanceType String No Type of the instance for creating a cluster. Supported instance types vary according to the region
userData Map No User data
configs Configs No Cluster configurations, such as the disk configuration of the instance. It is described by [Configs]
notification Notification No Notification configuration. You can configure the topic or cluster related events of the MNS

Attributes of GroupDescription

The getter and setter methods are available to all attributes.

Attribute Type Required Description
desiredVMCount int Yes Expected number of started instances
instanceType String Yes Type of the instance
resourceType String No Type of the resource. Currently, this parameter can only be set to OnDemand, which is the default value
SpotStrategy String Yes Spot strategy for an instance. It takes effect only when ResourceType is Spot.
Use optional values:
SpotWithPriceLimit: Set the maximum price for the spot instance.
SpotAsPriceGo: The system provides a price automatically, and the maximum value is the Pay-As-You-Go price
SpotPriceLimit Float No Maximum price of an instance per hour. The value can contain at most three decimals. It takes effect when SpotStrategy is SpotWithPriceLimit

Attributes of Notification

The getter and setter methods are available to all attributes.

Attribute Type Required Description
topic Topic No Message topic

Attributes of Topic

The getter and setter methods are available to all attributes.

Attribute Type Required Description
endpoint String Yes ‘Endpoint’ of the MNS region. The format is http://${your_user_id}.mns.${region}-internal.aliyuncs.com/. Use the intranet endpoint whenever possible
name String Yes Name of the topic
events List<String> Yes List of events. Make sure that you enter the cluster related events

Response description

If the cluster is successfully created, a CreateClusterResponse instance is returned. You can use response.getClusterId() to obtain the name of the created cluster.

Type Description
CreateClusterResponse Obtains the ID of the created cluster
  • The CreateClusterResponse package name is com.aliyuncs.batchcompute.model.v20151111.
  • Other responses listed in the following are under this package.
  • If creation fails, a ClientException is thrown.

Sample code

  1. package com.aliyuncs.batchcompute.sample.v20151111;
  2. import com.aliyuncs.batchcompute.main.v20151111.*;
  3. import com.aliyuncs.batchcompute.model.v20151111.*;
  4. import com.aliyuncs.batchcompute.pojo.v20151111.*;
  5. import com.aliyuncs.exceptions.ClientException;
  6. public class CreateCluster {
  7. public static void main(String[] args) {
  8. BatchCompute client = new BatchComputeClient("cn-shenzhen", "your_access_id", "your_access_secret");
  9. try {
  10. ClusterDescription clusterDescription = getClusterDesc();
  11. CreateClusterResponse response = client.createCluster(clusterDescription);
  12. String clusterId = response.getClusterId();
  13. //Creation succeeded
  14. System.out.println("Got cluster id:" + clusterId);
  15. } catch (ClientException e) {
  16. e.printStackTrace();
  17. //Creation failed
  18. }
  19. }
  20. private static ClusterDescription getClusterDesc(){
  21. ClusterDescription desc = new ClusterDescription();
  22. desc.setName("cluster_test");
  23. desc.setImageId("img-ubuntu");
  24. desc.setDescription("demo");
  25. GroupDescription groupDesc = new GroupDescription();
  26. groupDesc.setDesiredVMCount(1);
  27. groupDesc.setInstanceType("ecs.s3.large");
  28. groupDesc.setResourceType("OnDemand");
  29. desc.addGroup("group1", groupDesc);
  30. return desc;
  31. }
  32. }