Skip to content

Commit 371273a

Browse files
Added performance-provisioning-type, fixed test
1 parent 613df56 commit 371273a

File tree

3 files changed

+67
-29
lines changed

3 files changed

+67
-29
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ 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+
String performanceProvisioningType = "advanced";
5152

5253
createHyperdiskStoragePool(projectId, zone, storagePoolName, storagePoolType,
53-
capacityProvisioningType, provisionedCapacity, provisionedIops, provisionedThroughput);
54+
capacityProvisioningType, provisionedCapacity, provisionedIops,
55+
provisionedThroughput, performanceProvisioningType);
5456
}
5557

5658
// Creates a hyperdisk storagePool in a project
5759
public static StoragePool createHyperdiskStoragePool(String projectId, String zone,
58-
String storagePoolName, String storagePoolType,
59-
String capacityProvisioningType, long capacity,
60-
long iops, long throughput)
60+
String storagePoolName, String storagePoolType, String capacityProvisioningType,
61+
long capacity, long iops, long throughput, String performanceProvisioningType)
6162
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6263
// Initialize client that will be used to send requests. This client only needs to be created
6364
// once, and can be reused for multiple requests.
@@ -71,6 +72,7 @@ public static StoragePool createHyperdiskStoragePool(String projectId, String zo
7172
.setPoolProvisionedCapacityGb(capacity)
7273
.setPoolProvisionedIops(iops)
7374
.setPoolProvisionedThroughput(throughput)
75+
.setPerformanceProvisioningType(performanceProvisioningType)
7476
.build();
7577

7678
InsertStoragePoolRequest request = InsertStoragePoolRequest.newBuilder()

compute/cloud-client/src/test/java/compute/Util.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.api.gax.rpc.NotFoundException;
2020
import com.google.cloud.compute.v1.AggregatedListInstancesRequest;
21+
import com.google.cloud.compute.v1.DeleteStoragePoolRequest;
2122
import com.google.cloud.compute.v1.Disk;
2223
import com.google.cloud.compute.v1.DisksClient;
2324
import com.google.cloud.compute.v1.Instance;
@@ -29,9 +30,12 @@
2930
import com.google.cloud.compute.v1.InstancesClient.AggregatedListPagedResponse;
3031
import com.google.cloud.compute.v1.InstancesScopedList;
3132
import com.google.cloud.compute.v1.ListInstanceTemplatesRequest;
33+
import com.google.cloud.compute.v1.Operation;
3234
import com.google.cloud.compute.v1.RegionDisksClient;
3335
import com.google.cloud.compute.v1.Reservation;
3436
import com.google.cloud.compute.v1.ReservationsClient;
37+
import com.google.cloud.compute.v1.StoragePool;
38+
import com.google.cloud.compute.v1.StoragePoolsClient;
3539
import compute.reservation.DeleteReservation;
3640
import java.io.IOException;
3741
import java.nio.charset.StandardCharsets;
@@ -43,6 +47,7 @@
4347
import java.util.Map;
4448
import java.util.Random;
4549
import java.util.concurrent.ExecutionException;
50+
import java.util.concurrent.TimeUnit;
4651
import java.util.concurrent.TimeoutException;
4752
import java.util.stream.IntStream;
4853

@@ -206,4 +211,37 @@ && isCreatedBeforeThresholdTime(reservation.getCreationTimestamp())) {
206211
}
207212
}
208213
}
214+
215+
public static void cleanUpExistingStoragePool(
216+
String prefixToDelete, String projectId, String zone)
217+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
218+
try (StoragePoolsClient storagePoolsClient = StoragePoolsClient.create()) {
219+
for (StoragePool storagePool : storagePoolsClient.list(projectId, zone).iterateAll()) {
220+
if (storagePool.getName().contains(prefixToDelete)
221+
&& isCreatedBeforeThresholdTime(storagePool.getCreationTimestamp())) {
222+
deleteStoragePool(projectId, zone, storagePool.getName());
223+
}
224+
}
225+
}
226+
}
227+
228+
public static void deleteStoragePool(String project, String zone, String storagePoolName)
229+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
230+
try (StoragePoolsClient storagePoolsClient = StoragePoolsClient.create()) {
231+
DeleteStoragePoolRequest request =
232+
DeleteStoragePoolRequest.newBuilder()
233+
.setProject(project)
234+
.setZone(zone)
235+
.setStoragePool(storagePoolName)
236+
.build();
237+
Operation operation = storagePoolsClient.deleteAsync(request).get(1, TimeUnit.MINUTES);
238+
if (operation.hasError()) {
239+
System.out.println("StoragePool deletion failed!");
240+
throw new Error(operation.getError().toString());
241+
}
242+
// Wait for server update
243+
TimeUnit.SECONDS.sleep(50);
244+
System.out.println("Deleted storage pool: " + storagePoolName);
245+
}
246+
}
209247
}

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.google.cloud.compute.v1.Disk;
2222
import com.google.cloud.compute.v1.StoragePool;
23+
import compute.Util;
2324
import compute.disks.storagepool.CreateDiskInStoragePool;
2425
import compute.disks.storagepool.CreateHyperdiskStoragePool;
2526
import java.io.IOException;
@@ -31,7 +32,6 @@
3132
import org.junit.FixMethodOrder;
3233
import org.junit.jupiter.api.AfterAll;
3334
import org.junit.jupiter.api.BeforeAll;
34-
import org.junit.jupiter.api.Disabled;
3535
import org.junit.jupiter.api.Test;
3636
import org.junit.jupiter.api.Timeout;
3737
import org.junit.runner.RunWith;
@@ -43,10 +43,7 @@
4343
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
4444
public class HyperdisksIT {
4545
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
46-
// Zone in which the hyperdisk will be created.
47-
private static final String ZONE_1 = "europe-west1-b";
48-
// Zone in which the storage pool will be created.
49-
private static final String ZONE_2 = "us-central1-a";
46+
private static final String ZONE = "europe-west1-b";
5047
private static String HYPERDISK_NAME;
5148
private static String HYPERDISK_IN_POOL_NAME;
5249
private static String STORAGE_POOL_NAME;
@@ -58,34 +55,35 @@ public static void requireEnvVar(String envVarName) {
5855
}
5956

6057
@BeforeAll
61-
public static void setUp() {
58+
public static void setUp()
59+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6260
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
6361
requireEnvVar("GOOGLE_CLOUD_PROJECT");
6462

6563
HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
6664
HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
6765
STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID();
66+
67+
Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE);
6868
}
6969

7070
@AfterAll
7171
public static void cleanup()
7272
throws IOException, InterruptedException, ExecutionException, TimeoutException {
7373
// Delete all disks created for testing.
74-
DeleteDisk.deleteDisk(PROJECT_ID, ZONE_1, HYPERDISK_NAME);
75-
// DeleteDisk.deleteDisk(PROJECT_ID, ZONE_2, HYPERDISK_IN_POOL_NAME);
76-
//
77-
// try (StoragePoolsClient client = StoragePoolsClient.create()) {
78-
// client.deleteAsync(PROJECT_ID, ZONE_2, STORAGE_POOL_NAME);
79-
// }
74+
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_NAME);
75+
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
76+
77+
Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
8078
}
8179

8280
@Test
8381
public void stage1_CreateHyperdiskTest()
8482
throws IOException, ExecutionException, InterruptedException, TimeoutException {
85-
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE_1);
83+
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
8684

8785
Disk hyperdisk = CreateHyperdisk
88-
.createHyperdisk(PROJECT_ID, ZONE_1, HYPERDISK_NAME, diskType,
86+
.createHyperdisk(PROJECT_ID, ZONE, HYPERDISK_NAME, diskType,
8987
10, 3000, 140);
9088

9189
Assert.assertNotNull(hyperdisk);
@@ -94,18 +92,17 @@ public void stage1_CreateHyperdiskTest()
9492
Assert.assertEquals(140, hyperdisk.getProvisionedThroughput());
9593
Assert.assertEquals(10, hyperdisk.getSizeGb());
9694
Assert.assertTrue(hyperdisk.getType().contains("hyperdisk-balanced"));
97-
Assert.assertTrue(hyperdisk.getZone().contains(ZONE_1));
95+
Assert.assertTrue(hyperdisk.getZone().contains(ZONE));
9896
}
9997

100-
@Disabled
10198
@Test
10299
public void stage1_CreateHyperdiskStoragePoolTest()
103100
throws IOException, ExecutionException, InterruptedException, TimeoutException {
104101
String poolType = String.format("projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced",
105-
PROJECT_ID, ZONE_2);
102+
PROJECT_ID, ZONE);
106103
StoragePool storagePool = CreateHyperdiskStoragePool
107-
.createHyperdiskStoragePool(PROJECT_ID, ZONE_2, STORAGE_POOL_NAME, poolType,
108-
"advanced", 10240, 10000, 10240);
104+
.createHyperdiskStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME, poolType,
105+
"advanced", 10240, 10000, 10240, "advanced");
109106

110107
Assert.assertNotNull(storagePool);
111108
Assert.assertEquals(STORAGE_POOL_NAME, storagePool.getName());
@@ -114,19 +111,20 @@ public void stage1_CreateHyperdiskStoragePoolTest()
114111
Assert.assertEquals(10240, storagePool.getPoolProvisionedCapacityGb());
115112
Assert.assertTrue(storagePool.getStoragePoolType().contains("hyperdisk-balanced"));
116113
Assert.assertTrue(storagePool.getCapacityProvisioningType().equalsIgnoreCase("advanced"));
117-
Assert.assertTrue(storagePool.getZone().contains(ZONE_2));
114+
Assert.assertTrue(storagePool.getZone().contains(ZONE));
115+
Assert.assertTrue(storagePool.getPerformanceProvisioningType().equalsIgnoreCase("advanced"));
116+
118117
}
119118

120-
@Disabled
121119
@Test
122120
public void stage2_CreateHyperdiskStoragePoolTest()
123121
throws IOException, ExecutionException, InterruptedException, TimeoutException {
124-
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE_2);
122+
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
125123
String storagePoolLink = String
126124
.format("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/storagePools/%s",
127-
PROJECT_ID, ZONE_2, STORAGE_POOL_NAME);
125+
PROJECT_ID, ZONE, STORAGE_POOL_NAME);
128126
Disk disk = CreateDiskInStoragePool
129-
.createDiskInStoragePool(PROJECT_ID, ZONE_2, HYPERDISK_IN_POOL_NAME, storagePoolLink,
127+
.createDiskInStoragePool(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME, storagePoolLink,
130128
diskType, 10, 3000, 140);
131129

132130
Assert.assertNotNull(disk);
@@ -136,6 +134,6 @@ public void stage2_CreateHyperdiskStoragePoolTest()
136134
Assert.assertEquals(140, disk.getProvisionedThroughput());
137135
Assert.assertEquals(10, disk.getSizeGb());
138136
Assert.assertTrue(disk.getType().contains("hyperdisk-balanced"));
139-
Assert.assertTrue(disk.getZone().contains(ZONE_2));
137+
Assert.assertTrue(disk.getZone().contains(ZONE));
140138
}
141139
}

0 commit comments

Comments
 (0)