Dokumen ini menjelaskan kit pengembangan perangkat lunak (SDK) Alibaba Cloud untuk Java yang memungkinkan Anda mengelola instans ApsaraDB for Cassandra melalui panggilan OpenAPI. Dengan SDK ini, Anda dapat membuat, melakukan upgrade, dan menghapus instans, mengonfigurasi daftar putih, serta mengelola tag tanpa pemrograman yang rumit. SDK ini berbeda dari SDK yang digunakan untuk mengakses data di dalam instans Cassandra. Dokumen ini juga menunjukkan cara menginstal dan mulai menggunakan Alibaba Cloud SDK for Java.
Prasyarat
AccessKey telah dibuat. Untuk informasi selengkapnya, lihat Obtain an AccessKey.
Debugging online dan pembuatan contoh kode SDK
OpenAPI Explorer menyederhanakan penggunaan API. Anda dapat menggunakannya untuk memanggil API secara online, menghasilkan contoh kode SDK, dan dengan cepat mengakses antarmuka. Buka halaman OpenAPI Explorer dan pilih produk Cassandra. OpenAPI Explorer menyediakan daftar API, masing-masing dilengkapi demo debugging untuk berbagai bahasa pemrograman.
Unduh dan instal Alibaba Cloud SDK untuk Java
Anda dapat menginstal Alibaba Cloud SDK for Java dengan menambahkan dependensi Maven atau mengimpor file JAR. Untuk informasi selengkapnya, lihat Install Alibaba Cloud SDK for Java.
Saat mengunduh paket SDK menggunakan Maven, pastikan Anda mengunduh versi terbaru.
Contoh
Panggil DescribeClusterRequest untuk mendapatkan informasi kluster Cassandra
Atur parameter lingkungan.
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI****************", "yourAccessKeySecret"); // Parameter berikut bersifat opsional. Anda dapat menggunakan nilai default. DefaultProfile.addEndpoint( "cn-hangzhou", // The region ID. "cassandra", // The product code. "cassandra.aliyuncs.com" // The endpoint, which is a domain name. );Inisialisasi klien.
IAcsClient client = new DefaultAcsClient(profile);Buat objek permintaan.
DescribeClusterRequest request = new DescribeClusterRequest(); request.setClusterId("cds-wz9bui92****697r");Lakukan permintaan.
DescribeClusterResponse response; try { response = client.getAcsResponse(request); System.out.println(new Gson().toJson(response)); } catch (ClientException e) { e.printStackTrace(); }
Contoh
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
"LTAI****************", "yourAccessKeySecret");
DefaultProfile.addEndpoint(
"cn-hangzhou", // The region ID.
"cassandra", // The product code.
"cassandra.aliyuncs.com" // The endpoint, which is a domain name.
);
IAcsClient client = new DefaultAcsClient(profile);
DescribeClusterRequest request = new DescribeClusterRequest();
request.setClusterId("cds-wz9bui92****697r");
DescribeClusterResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ClientException e) {
e.printStackTrace();
}Respons contoh
{
"RequestId": "3B235CE2-2339-42A8-A11D-5F7548519AD2",
"Cluster": {
"Status": "Running",
"MajorVersion": "3.11",
"CreatedTime": "2020-04-21T08:50:04Z",
"ClusterId": "cds-wz9bui92****6973",
"MinorVersion": "3.11.9",
"PayType": "PayAsYouGo",
"LockMode": "Expired",
"IsLatestVersion": true,
"MaintainEndTime": "22:00Z",
"DataCenterCount": 1,
"ClusterName": "auto_test20200421170214",
"MaintainStartTime": "18:00Z",
"Tags": {
"Tag": [
{
"Value": "1",
"Key": "test"
},
{
"Value": "2",
"Key": "test2"
}
]
}
}
}Panggil CreateCluster untuk membuat kluster Cassandra
Atur parameter lingkungan.
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI****************", "yourAccessKeySecret"); // Parameter berikut bersifat opsional. Anda dapat menggunakan nilai default. DefaultProfile.addEndpoint( "cn-hangzhou", // The region ID. "cassandra", // The product code. "cassandra.aliyuncs.com" // The endpoint, which is a domain name. );Inisialisasi klien.
IAcsClient client = new DefaultAcsClient(profile);Buat objek permintaan.
CreateClusterRequest request = new CreateClusterRequest(); // Parameter wajib. request.setPayType("PayAsYouGo"); request.setRegionId("cn-hangzhou"); request.setZoneId("cn-hangzhou-e"); request.setMajorVersion("3.11"); request.setInstanceType("cassandra.c.large"); request.setNodeCount("2"); request.setVpcId("vpc-wz9s6dl6nttp1****ydur"); request.setVswitchId("vsw-wz9c90poaus9q****1dxl"); // Parameter opsional. request.setPeriodUnit("Year");// Parameter ini wajib jika PayType diatur ke Subscription. request.setPeriod("12");// Parameter ini wajib jika PayType diatur ke Subscription. request.setAutoRenew("false");// Parameter ini wajib jika PayType diatur ke Subscription. request.setAutoRenewPeriod("3");// Parameter ini wajib jika PayType diatur ke Subscription. request.setClientToken("ETnLKlblzczshOTUbOCzxxxxxxxxxx"); request.setClusterName("cassandra_01"); request.setDataCenterName("cassandra_dc_01"); request.setDiskType("cloud_ssd"); request.setDiskSize("160"); request.setPassword("Cassandra1@!");Lakukan permintaan.
CreateClusterResponse response; try { response = client.getAcsResponse(request); System.out.println(new Gson().toJson(response)); } catch (ClientException e) { e.printStackTrace(); }
Contoh
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
"LTAI****************", "yourAccessKeySecret");
DefaultProfile.addEndpoint(
"cn-hangzhou", // The region ID.
"cassandra", // The product code.
"cassandra.aliyuncs.com" // The endpoint, which is a domain name.
);
IAcsClient client = new DefaultAcsClient(profile);
CreateClusterRequest request = new CreateClusterRequest();
// Parameter wajib.
request.setPayType("PayAsYouGo");
request.setRegionId("cn-hangzhou");
request.setZoneId("cn-hangzhou-e");
request.setMajorVersion("3.11");
request.setInstanceType("cassandra.c.large");
request.setNodeCount("2");
request.setVpcId("vpc-wz9s6dl6nttp1****ydur");
request.setVswitchId("vsw-wz9c90poaus9q****1dxl");
// Parameter opsional.
request.setPeriodUnit("Year");// Parameter ini wajib jika PayType diatur ke Subscription.
request.setPeriod("12");// Parameter ini wajib jika PayType diatur ke Subscription.
request.setAutoRenew("false");// Parameter ini wajib jika PayType diatur ke Subscription.
request.setAutoRenewPeriod("3");// Parameter ini wajib jika PayType diatur ke Subscription.
request.setClientToken("ETnLKlblzczshOTUbOCzxxxxxxxxxx");
request.setClusterName("cassandra_01");
request.setDataCenterName("cassandra_dc_01");
request.setDiskType("cloud_ssd");
request.setDiskSize("160");
request.setPassword("Cassandra1@!");
CreateClusterResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ClientException e) {
e.printStackTrace();
}Respons contoh
{
"ClusterId":"hb-bp16o0pd5****582s",
"RequestId":"728C7EAF-4844-4D42-9BBE-DFFFBB77CF33"
}Panggil ResizeNodeCount untuk menambah jumlah node di data center
Atur parameter lingkungan.
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI****************", "yourAccessKeySecret"); // Parameter berikut bersifat opsional. Anda dapat menggunakan nilai default. DefaultProfile.addEndpoint( "cn-hangzhou", // The region ID. "cassandra", // The product code. "cassandra.aliyuncs.com" // The endpoint, which is a domain name. );Inisialisasi klien.
IAcsClient client = new DefaultAcsClient(profile);Buat objek permintaan.
ResizeNodeCountRequest request = new ResizeNodeCountRequest(); request.setClusterId("cds-bp1b136j****5d59"); request.setDataCenterId("cn-hangzhou-g"); request.setNodeCount("3");Lakukan permintaan.
ResizeNodeCountResponse response; try { response = client.getAcsResponse(request); System.out.println(new Gson().toJson(response)); } catch (ClientException e) { e.printStackTrace(); }
Contoh
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
"LTAI****************", "yourAccessKeySecret");
DefaultProfile.addEndpoint(
"cn-hangzhou", // The region ID.
"cassandra", // The product code.
"cassandra.aliyuncs.com" // The endpoint, which is a domain name.
);
IAcsClient client = new DefaultAcsClient(profile);
ResizeNodeCountRequest request = new ResizeNodeCountRequest();
request.setClusterId("cds-bp1b136j****5d59");
request.setDataCenterId("cn-hangzhou-g");
request.setNodeCount("3");
ResizeNodeCountResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ClientException e) {
e.printStackTrace();
}Respons contoh
{
"RequestId": "D7D3088F-AA4F-49C3-BB46-B04F3E35041A"
}Panggil DeleteCluster untuk menghapus kluster Cassandra
Atur parameter lingkungan.
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI****************", "yourAccessKeySecret"); // Parameter berikut bersifat opsional. Anda dapat menggunakan nilai default. DefaultProfile.addEndpoint( "cn-hangzhou", // The region ID. "cassandra", // The product code. "cassandra.aliyuncs.com" // The endpoint, which is a domain name. );Inisialisasi klien.
IAcsClient client = new DefaultAcsClient(profile);Buat objek permintaan.
DeleteClusterRequest request = new DeleteClusterRequest(); request.setClusterId("cds-bp1hy2ipk****46k");Lakukan permintaan.
DeleteClusterResponse response; try { response = client.getAcsResponse(request); System.out.println(new Gson().toJson(response)); } catch (ClientException e) { e.printStackTrace(); }
Contoh
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
"LTAI****************", "yourAccessKeySecret");
DefaultProfile.addEndpoint(
"cn-hangzhou", // The region ID.
"cassandra", // The product code.
"cassandra.aliyuncs.com" // The endpoint, which is a domain name.
);
IAcsClient client = new DefaultAcsClient(profile);
DeleteClusterRequest request = new DeleteClusterRequest();
request.setClusterId("cds-bp1hy2ipk****46k");
DeleteClusterResponse response;
try {
response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ClientException e) {
e.printStackTrace();
}Respons contoh
{
"RequestId":"728C7EAF-4844-4D42-9BBE-DFFFBB77CF33"
}