GetSmartCluster (OSS Java SDK V2)

Updated at:

Call GetSmartCluster with the OSS Java SDK V2 to retrieve details of a SmartCluster task.

Prerequisites

  • The OSS Java SDK V2 is installed. To use Maven, add the com.aliyun:alibabacloud-oss-v2 dependency to the pom.xml file.

  • Configure your access credentials as environment variables. The example uses the EnvironmentVariableCredentialsProvider to read credentials from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.

Permissions

By default, an Alibaba Cloud account can access all resources. RAM users and RAM roles have no permissions by default. You must grant them permissions to call API operations.

API

Action

Description

GetSmartCluster

oss:MetaQuery

Retrieves a SmartCluster task.

Sample code

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.dataprocess.OSSDataProcessClient;
import com.aliyun.sdk.service.oss2.dataprocess.OSSDataProcessClientBuilder;
import com.aliyun.sdk.service.oss2.dataprocess.models.*;

public class GetSmartClusterSample {
    public static void main(String[] args) throws Exception {
        String endpoint = null;
        String region = "cn-hangzhou";
        String bucket = "examplebucket";
        String datasetName = "exampledataset";
        String objectId = "exampleclusterid";

        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
        OSSDataProcessClientBuilder clientBuilder = OSSDataProcessClient.newBuilder()
                .credentialsProvider(provider)
                .region(region);

        if (endpoint != null) {
            clientBuilder.endpoint(endpoint);
        }

        try (OSSDataProcessClient client = clientBuilder.build()) {

            GetSmartClusterResult result = client.getSmartCluster(
                    GetSmartClusterRequest.newBuilder()
                            .bucket(bucket)
                            .datasetName(datasetName)
                            .objectId(objectId)
                            .build());

            System.out.printf("Status code:%d, request id:%s%n",
                    result.statusCode(), result.requestId());

            if (result.smartCluster() != null) {
                SmartClusterInfo info = result.smartCluster();
                System.out.printf("Object ID:%s%n", info.objectId());
                System.out.printf("Name:%s%n", info.name());
                System.out.printf("Cluster type:%s%n", info.clusterType());
                System.out.printf("Description:%s%n", info.description());
                System.out.printf("Create time:%s%n", info.createTime());
                System.out.printf("Update time:%s%n", info.updateTime());
                if (info.reason() != null) {
                    System.out.printf("Reason:%s%n", info.reason());
                }
                if (info.rules() != null) {
                    System.out.printf("Rules count:%d%n", info.rules().size());
                }
            }

        } catch (Exception e) {
            System.out.printf("error:%n%s", e);
        }
    }
}

Related documentation