Skip to content

Commit 5c97f27

Browse files
feat(compute): extend compute hyperdisk pool create (#9595)
* Added performance-provisioning-type, fixed test * fixed test * Enabled tests * Fixed whitespaces * Added comments * Fixed comments and zone * Fixed timeout and zone in test class * Fixed naming, added variable CAPACITY_PROVISIONING_TYPE * Fixed storagePoolType * Fixed lint issue
1 parent 22e1c11 commit 5c97f27

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
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

0 commit comments

Comments
 (0)