UpdateSmartCluster (Java SDK V2)

Updated at:

This topic provides an example of how to update a SmartCluster task using the OSS Java SDK V2.

Prerequisites

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

  • Configure access credentials using environment variables. The sample code in this topic uses EnvironmentVariableCredentialsProvider to read access credentials from the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.

Permissions

An Alibaba Cloud account has all permissions by default. RAM users and RAM roles have no permissions by default. You must grant the required permission to a RAM user or RAM role to call the operation.

API

Action

Description

UpdateSmartCluster

oss:MetaQuery

Updates 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 UpdateSmartClusterSample {
    public static void main(String[] args) throws Exception {
        String endpoint = null;
        String region = "cn-hangzhou";
        String bucket = "examplebucket";
        String datasetName = "exampledataset";
        String objectId = "exampleclusterid";
        String name = "examplecluster";
        String description = "example dataset";

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

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

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

            UpdateSmartClusterRequest.Builder requestBuilder = UpdateSmartClusterRequest.newBuilder()
                    .bucket(bucket)
                    .datasetName(datasetName)
                    .objectId(objectId);

            if (name != null) {
                requestBuilder.name(name);
            }
            if (description != null) {
                requestBuilder.description(description);
            }

            UpdateSmartClusterResult result = client.updateSmartCluster(requestBuilder.build());

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

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

Related documents