All Products
Search
Document Center

Batch Compute:createCluster

Last Updated:May 09, 2024

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

package com.aliyuncs.batchcompute.sample.v20151111;

import com.aliyuncs.batchcompute.main.v20151111.*;
import com.aliyuncs.batchcompute.model.v20151111.*;
import com.aliyuncs.batchcompute.pojo.v20151111.*;
import com.aliyuncs.exceptions.ClientException;


public class CreateCluster {

    public static void main(String[] args) {

        BatchCompute client = new BatchComputeClient("cn-shenzhen", "your_access_id", "your_access_secret");

        try {
            ClusterDescription clusterDescription = getClusterDesc();

            CreateClusterResponse response = client.createCluster(clusterDescription);
            String clusterId = response.getClusterId();
            //Creation succeeded

            System.out.println("Got cluster id:" + clusterId);

        } catch (ClientException e) {
            e.printStackTrace();
            //Creation failed
        }
    }


    private static ClusterDescription getClusterDesc(){
        ClusterDescription desc = new ClusterDescription();

        desc.setName("cluster_test");
        desc.setImageId("img-ubuntu");
        desc.setDescription("demo");

        GroupDescription groupDesc = new GroupDescription();
        groupDesc.setDesiredVMCount(1);
        groupDesc.setInstanceType("ecs.s3.large");
        groupDesc.setResourceType("OnDemand");
        desc.addGroup("group1", groupDesc);

        return desc;
    }
}