Skip to content

Commit 772c178

Browse files
Merged changes from main
2 parents 952c416 + 282ec81 commit 772c178

30 files changed

+184
-209
lines changed

compute/cloud-client/src/main/java/compute/disks/storagepool/CreateHyperdiskStoragePool.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package compute.disks.storagepool;
1616

1717
// [START compute_hyperdisk_pool_create]
18-
1918
import com.google.cloud.compute.v1.InsertStoragePoolRequest;
2019
import com.google.cloud.compute.v1.Operation;
2120
import com.google.cloud.compute.v1.StoragePool;
@@ -32,12 +31,13 @@ public static void main(String[] args)
3231
// Project ID or project number of the Google Cloud project you want to use.
3332
String projectId = "YOUR_PROJECT_ID";
3433
// Name of the zone in which you want to create the storagePool.
35-
String zone = "europe-central2-b";
34+
String zone = "us-central1-a";
3635
// Name of the storagePool you want to create.
3736
String storagePoolName = "YOUR_STORAGE_POOL_NAME";
38-
// The type of disk you want to create. This value uses the following format:
39-
// "projects/%s/zones/%s/storagePoolTypes/hyperdisk-throughput|hyperdisk-balanced"
40-
String storagePoolType = "hyperdisk-balanced";
37+
// The type of disk you want to create.
38+
// Storage types can be "hyperdisk-throughput" or "hyperdisk-balanced"
39+
String storagePoolType = String.format(
40+
"projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced", projectId, zone);
4141
// Optional: the capacity provisioning type of the storage pool.
4242
// The allowed values are advanced and standard. If not specified, the value advanced is used.
4343
String capacityProvisioningType = "advanced";
@@ -48,16 +48,19 @@ public static void main(String[] args)
4848
long provisionedIops = 3000;
4949
// the throughput in MBps to provision for the storage pool.
5050
long provisionedThroughput = 140;
51+
// The allowed values are low-casing strings "advanced" and "standard".
52+
// If not specified, "advanced" is used.
53+
String performanceProvisioningType = "advanced";
5154

5255
createHyperdiskStoragePool(projectId, zone, storagePoolName, storagePoolType,
53-
capacityProvisioningType, provisionedCapacity, provisionedIops, provisionedThroughput);
56+
capacityProvisioningType, provisionedCapacity, provisionedIops,
57+
provisionedThroughput, performanceProvisioningType);
5458
}
5559

5660
// Creates a hyperdisk storagePool in a project
5761
public static StoragePool createHyperdiskStoragePool(String projectId, String zone,
58-
String storagePoolName, String storagePoolType,
59-
String capacityProvisioningType, long capacity,
60-
long iops, long throughput)
62+
String storagePoolName, String storagePoolType, String capacityProvisioningType,
63+
long capacity, long iops, long throughput, String performanceProvisioningType)
6164
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6265
// Initialize client that will be used to send requests. This client only needs to be created
6366
// once, and can be reused for multiple requests.
@@ -71,6 +74,7 @@ public static StoragePool createHyperdiskStoragePool(String projectId, String zo
7174
.setPoolProvisionedCapacityGb(capacity)
7275
.setPoolProvisionedIops(iops)
7376
.setPoolProvisionedThroughput(throughput)
77+
.setPerformanceProvisioningType(performanceProvisioningType)
7478
.build();
7579

7680
InsertStoragePoolRequest request = InsertStoragePoolRequest.newBuilder()

compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,27 @@
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.concurrent.TimeoutException;
3131
import org.junit.Assert;
32-
import org.junit.FixMethodOrder;
3332
import org.junit.jupiter.api.AfterAll;
3433
import org.junit.jupiter.api.BeforeAll;
35-
import org.junit.jupiter.api.Disabled;
34+
import org.junit.jupiter.api.MethodOrderer;
35+
import org.junit.jupiter.api.Order;
3636
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.TestMethodOrder;
3738
import org.junit.jupiter.api.Timeout;
3839
import org.junit.runner.RunWith;
3940
import org.junit.runners.JUnit4;
40-
import org.junit.runners.MethodSorters;
4141

4242
@RunWith(JUnit4.class)
43-
@Timeout(value = 40, unit = TimeUnit.MINUTES)
44-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
43+
@Timeout(value = 6, unit = TimeUnit.MINUTES)
44+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
4545
public class HyperdisksIT {
4646
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
47-
private static final String ZONE = "us-east1-c";
48-
private static String HYPERDISK_NAME;
49-
private static String HYPERDISK_IN_POOL_NAME;
50-
private static String STORAGE_POOL_NAME;
47+
private static final String ZONE = "us-central1-a";
48+
private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
49+
private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
50+
private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID();
51+
private static final String PERFORMANCE_PROVISIONING_TYPE = "advanced";
52+
private static final String CAPACITY_PROVISIONING_TYPE = "advanced";
5153

5254
// Check if the required environment variables are set.
5355
public static void requireEnvVar(String envVarName) {
@@ -60,26 +62,21 @@ public static void setUp()
6062
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6163
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
6264
requireEnvVar("GOOGLE_CLOUD_PROJECT");
63-
HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
64-
HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
65-
STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID();
66-
67-
Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE);
68-
Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE);
6965
}
7066

7167
@AfterAll
7268
public static void cleanup()
7369
throws IOException, InterruptedException, ExecutionException, TimeoutException {
7470
// Delete all disks created for testing.
7571
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_NAME);
76-
//DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
72+
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
7773

78-
//Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
74+
Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
7975
}
8076

8177
@Test
82-
public void stage1_CreateHyperdiskTest()
78+
@Order(1)
79+
public void testCreateHyperdisk()
8380
throws IOException, ExecutionException, InterruptedException, TimeoutException {
8481
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
8582

@@ -96,29 +93,33 @@ public void stage1_CreateHyperdiskTest()
9693
Assert.assertTrue(hyperdisk.getZone().contains(ZONE));
9794
}
9895

99-
@Disabled
10096
@Test
101-
public void stage1_CreateHyperdiskStoragePoolTest()
97+
@Order(1)
98+
public void testCreateHyperdiskStoragePool()
10299
throws IOException, ExecutionException, InterruptedException, TimeoutException {
103100
String poolType = String.format("projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced",
104101
PROJECT_ID, ZONE);
105102
StoragePool storagePool = CreateHyperdiskStoragePool
106103
.createHyperdiskStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME, poolType,
107-
"advanced", 10240, 10000, 10240);
104+
CAPACITY_PROVISIONING_TYPE, 10240, 10000, 1024,
105+
PERFORMANCE_PROVISIONING_TYPE);
108106

109107
Assert.assertNotNull(storagePool);
110108
Assert.assertEquals(STORAGE_POOL_NAME, storagePool.getName());
111109
Assert.assertEquals(10000, storagePool.getPoolProvisionedIops());
112-
Assert.assertEquals(10240, storagePool.getPoolProvisionedThroughput());
110+
Assert.assertEquals(1024, storagePool.getPoolProvisionedThroughput());
113111
Assert.assertEquals(10240, storagePool.getPoolProvisionedCapacityGb());
114112
Assert.assertTrue(storagePool.getStoragePoolType().contains("hyperdisk-balanced"));
115-
Assert.assertTrue(storagePool.getCapacityProvisioningType().equalsIgnoreCase("advanced"));
113+
Assert.assertTrue(storagePool.getCapacityProvisioningType()
114+
.equalsIgnoreCase(CAPACITY_PROVISIONING_TYPE));
115+
Assert.assertTrue(storagePool.getPerformanceProvisioningType()
116+
.equalsIgnoreCase(PERFORMANCE_PROVISIONING_TYPE));
116117
Assert.assertTrue(storagePool.getZone().contains(ZONE));
117118
}
118119

119-
@Disabled
120120
@Test
121-
public void stage2_CreateHyperdiskStoragePoolTest()
121+
@Order(2)
122+
public void testCreateDiskInStoragePool()
122123
throws IOException, ExecutionException, InterruptedException, TimeoutException {
123124
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
124125
String storagePoolLink = String

dataplex/snippets/src/main/java/dataplex/CreateAspectType.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.cloud.dataplex.v1.LocationName;
2323
import java.util.List;
2424

25-
// Sample to create Aspect Type
2625
public class CreateAspectType {
2726

2827
public static void main(String[] args) throws Exception {
@@ -59,33 +58,32 @@ public static void main(String[] args) throws Exception {
5958
System.out.println("Successfully created aspect type: " + createdAspectType.getName());
6059
}
6160

61+
// Method to create Aspect Type located in projectId, location and with aspectTypeId and
62+
// aspectFields specifying schema of the Aspect Type
6263
public static AspectType createAspectType(
6364
String projectId,
6465
String location,
6566
String aspectTypeId,
6667
List<AspectType.MetadataTemplate> aspectFields)
6768
throws Exception {
68-
LocationName locationName = LocationName.of(projectId, location);
69-
AspectType aspectType =
70-
AspectType.newBuilder()
71-
.setDescription("description of the aspect type")
72-
.setMetadataTemplate(
73-
AspectType.MetadataTemplate.newBuilder()
74-
// The name must follow regex ^(([a-zA-Z]{1})([\\w\\-_]{0,62}))$
75-
// That means name must only contain alphanumeric character or dashes or
76-
// underscores, start with an alphabet, and must be less than 63 characters.
77-
.setName("name_of_the_template")
78-
.setType("record")
79-
// Aspect Type fields, that themselves are Metadata Templates
80-
.addAllRecordFields(aspectFields)
81-
.build())
82-
.build();
83-
8469
// Initialize client that will be used to send requests. This client only needs to be created
85-
// once, and can be reused for multiple requests. After completing all of your requests, call
86-
// the "close" method on the client to safely clean up any remaining background resources,
87-
// or use "try-with-close" statement to do this automatically.
70+
// once, and can be reused for multiple requests.
8871
try (CatalogServiceClient client = CatalogServiceClient.create()) {
72+
LocationName locationName = LocationName.of(projectId, location);
73+
AspectType aspectType =
74+
AspectType.newBuilder()
75+
.setDescription("description of the aspect type")
76+
.setMetadataTemplate(
77+
AspectType.MetadataTemplate.newBuilder()
78+
// The name must follow regex ^(([a-zA-Z]{1})([\\w\\-_]{0,62}))$
79+
// That means name must only contain alphanumeric character or dashes or
80+
// underscores, start with an alphabet, and must be less than 63 characters.
81+
.setName("name_of_the_template")
82+
.setType("record")
83+
// Aspect Type fields, that themselves are Metadata Templates
84+
.addAllRecordFields(aspectFields)
85+
.build())
86+
.build();
8987
return client.createAspectTypeAsync(locationName, aspectType, aspectTypeId).get();
9088
}
9189
}

dataplex/snippets/src/main/java/dataplex/CreateEntry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class CreateEntry {
3131
public static void main(String[] args) throws Exception {
3232
// TODO(developer): Replace these variables before running the sample.
3333
String projectId = "MY_PROJECT_ID";
34+
// Available locations: https://cloud.google.com/dataplex/docs/locations
3435
String location = "MY_LOCATION";
3536
String entryGroupId = "MY_ENTRY_GROUP_ID";
3637
String entryId = "MY_ENTRY_ID";

dataplex/snippets/src/main/java/dataplex/CreateEntryGroup.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.cloud.dataplex.v1.EntryGroup;
2222
import com.google.cloud.dataplex.v1.LocationName;
2323

24-
// Samples to create Entry Group
2524
public class CreateEntryGroup {
2625

2726
public static void main(String[] args) throws Exception {
@@ -35,17 +34,15 @@ public static void main(String[] args) throws Exception {
3534
System.out.println("Successfully created entry group: " + createdEntryGroup.getName());
3635
}
3736

37+
// Method to create Entry Group located in projectId, location and with entryGroupId
3838
public static EntryGroup createEntryGroup(String projectId, String location, String entryGroupId)
3939
throws Exception {
40-
LocationName locationName = LocationName.of(projectId, location);
41-
EntryGroup entryGroup =
42-
EntryGroup.newBuilder().setDescription("description of the entry group").build();
43-
4440
// Initialize client that will be used to send requests. This client only needs to be created
45-
// once, and can be reused for multiple requests. After completing all of your requests, call
46-
// the "close" method on the client to safely clean up any remaining background resources,
47-
// or use "try-with-close" statement to do this automatically.
41+
// once, and can be reused for multiple requests.
4842
try (CatalogServiceClient client = CatalogServiceClient.create()) {
43+
LocationName locationName = LocationName.of(projectId, location);
44+
EntryGroup entryGroup =
45+
EntryGroup.newBuilder().setDescription("description of the entry group").build();
4946
return client.createEntryGroupAsync(locationName, entryGroup, entryGroupId).get();
5047
}
5148
}

dataplex/snippets/src/main/java/dataplex/CreateEntryType.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.cloud.dataplex.v1.EntryType;
2222
import com.google.cloud.dataplex.v1.LocationName;
2323

24-
// Samples to create Entry Type
2524
public class CreateEntryType {
2625

2726
public static void main(String[] args) throws Exception {
@@ -35,27 +34,26 @@ public static void main(String[] args) throws Exception {
3534
System.out.println("Successfully created entry type: " + createdEntryType.getName());
3635
}
3736

37+
// Method to create Entry Type located in projectId, location and with entryTypeId
3838
public static EntryType createEntryType(String projectId, String location, String entryTypeId)
3939
throws Exception {
40-
LocationName locationName = LocationName.of(projectId, location);
41-
EntryType entryType =
42-
EntryType.newBuilder()
43-
.setDescription("description of the entry type")
44-
// Required aspects will need to be attached to every entry created for this entry type.
45-
// You cannot change required aspects for entry type once it is created.
46-
.addRequiredAspects(
47-
EntryType.AspectInfo.newBuilder()
48-
// Example of system aspect type.
49-
// It is also possible to specify custom aspect type.
50-
.setType("projects/dataplex-types/locations/global/aspectTypes/schema")
51-
.build())
52-
.build();
53-
5440
// Initialize client that will be used to send requests. This client only needs to be created
55-
// once, and can be reused for multiple requests. After completing all of your requests, call
56-
// the "close" method on the client to safely clean up any remaining background resources,
57-
// or use "try-with-close" statement to do this automatically.
41+
// once, and can be reused for multiple requests.
5842
try (CatalogServiceClient client = CatalogServiceClient.create()) {
43+
LocationName locationName = LocationName.of(projectId, location);
44+
EntryType entryType =
45+
EntryType.newBuilder()
46+
.setDescription("description of the entry type")
47+
// Required aspects will need to be attached to every entry created for this entry
48+
// type.
49+
// You cannot change required aspects for entry type once it is created.
50+
.addRequiredAspects(
51+
EntryType.AspectInfo.newBuilder()
52+
// Example of system aspect type.
53+
// It is also possible to specify custom aspect type.
54+
.setType("projects/dataplex-types/locations/global/aspectTypes/schema")
55+
.build())
56+
.build();
5957
return client.createEntryTypeAsync(locationName, entryType, entryTypeId).get();
6058
}
6159
}

dataplex/snippets/src/main/java/dataplex/DeleteAspectType.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.cloud.dataplex.v1.AspectTypeName;
2121
import com.google.cloud.dataplex.v1.CatalogServiceClient;
2222

23-
// Sample to delete Aspect Type
2423
public class DeleteAspectType {
2524

2625
public static void main(String[] args) throws Exception {
@@ -34,15 +33,13 @@ public static void main(String[] args) throws Exception {
3433
System.out.println("Successfully deleted aspect type");
3534
}
3635

36+
// Method to delete Aspect Type located in projectId, location and with aspectTypeId
3737
public static void deleteAspectType(String projectId, String location, String aspectTypeId)
3838
throws Exception {
39-
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
40-
4139
// Initialize client that will be used to send requests. This client only needs to be created
42-
// once, and can be reused for multiple requests. After completing all of your requests, call
43-
// the "close" method on the client to safely clean up any remaining background resources,
44-
// or use "try-with-close" statement to do this automatically.
40+
// once, and can be reused for multiple requests.
4541
try (CatalogServiceClient client = CatalogServiceClient.create()) {
42+
AspectTypeName aspectTypeName = AspectTypeName.of(projectId, location, aspectTypeId);
4643
client.deleteAspectTypeAsync(aspectTypeName).get();
4744
}
4845
}

dataplex/snippets/src/main/java/dataplex/DeleteEntry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class DeleteEntry {
2525
public static void main(String[] args) throws Exception {
2626
// TODO(developer): Replace these variables before running the sample.
2727
String projectId = "MY_PROJECT_ID";
28+
// Available locations: https://cloud.google.com/dataplex/docs/locations
2829
String location = "MY_LOCATION";
2930
String entryGroupId = "MY_ENTRY_GROUP_ID";
3031
String entryId = "MY_ENTRY_ID";

dataplex/snippets/src/main/java/dataplex/DeleteEntryGroup.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.cloud.dataplex.v1.CatalogServiceClient;
2121
import com.google.cloud.dataplex.v1.EntryGroupName;
2222

23-
// Sample to delete Entry Group
2423
public class DeleteEntryGroup {
2524

2625
public static void main(String[] args) throws Exception {
@@ -34,15 +33,13 @@ public static void main(String[] args) throws Exception {
3433
System.out.println("Successfully deleted entry group");
3534
}
3635

36+
// Method to delete Entry Group located in projectId, location and with entryGroupId
3737
public static void deleteEntryGroup(String projectId, String location, String entryGroupId)
3838
throws Exception {
39-
EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId);
40-
4139
// Initialize client that will be used to send requests. This client only needs to be created
42-
// once, and can be reused for multiple requests. After completing all of your requests, call
43-
// the "close" method on the client to safely clean up any remaining background resources,
44-
// or use "try-with-close" statement to do this automatically.
40+
// once, and can be reused for multiple requests.
4541
try (CatalogServiceClient client = CatalogServiceClient.create()) {
42+
EntryGroupName entryGroupName = EntryGroupName.of(projectId, location, entryGroupId);
4643
client.deleteEntryGroupAsync(entryGroupName).get();
4744
}
4845
}

0 commit comments

Comments
 (0)