CreateSmartCluster (Java SDK V2)
Call the CreateSmartCluster operation with the OSS Java SDK V2 to create a SmartCluster task.
Prerequisites
The OSS Java SDK V2 is installed. If you use Maven, add the
com.aliyun:alibabacloud-oss-v2dependency to your pom.xml file.Configure your credentials through environment variables. The example in this topic uses
EnvironmentVariableCredentialsProviderto read credentials from theOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables.
Permissions
By default, an Alibaba Cloud account can perform all operations. A RAM user or a RAM role under an Alibaba Cloud account has no permissions by default. You must grant the required permissions to the RAM user or RAM role.
API | Actions | Description |
CreateSmartCluster |
| Creates 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.*;
import java.util.Arrays;
public class CreateSmartClusterSample {
public static void main(String[] args) throws Exception {
String endpoint = null;
String region = "cn-hangzhou";
String bucket = "examplebucket";
String datasetName = "exampledataset";
String name = "examplecluster";
String clusterType = "FACE";
CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
OSSDataProcessClientBuilder clientBuilder = OSSDataProcessClient.newBuilder()
.credentialsProvider(provider)
.region(region);
if (endpoint != null) {
clientBuilder.endpoint(endpoint);
}
try (OSSDataProcessClient client = clientBuilder.build()) {
SmartClusterRule rule = SmartClusterRule.newBuilder()
.ruleType("keywords")
.keywords(Arrays.asList("people", "vehicles"))
.build();
CreateSmartClusterResult result = client.createSmartCluster(
CreateSmartClusterRequest.newBuilder()
.bucket(bucket)
.datasetName(datasetName)
.name(name)
.clusterType(clusterType != null ? clusterType : "User")
.rules(Arrays.asList(rule))
.description("test knowledge cluster")
.build());
System.out.printf("Status code:%d, request id:%s%n",
result.statusCode(), result.requestId());
if (result.objectId() != null) {
System.out.printf("Object ID:%s%n", result.objectId());
}
} catch (Exception e) {
System.out.printf("error:%n%s", e);
}
}
}Related documents
For the synchronous sample code, see CreateSmartCluster.java.
For the asynchronous sample code, see CreateSmartClusterAsync.java.