Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package compute.disks.storagepool;

// [START compute_hyperdisk_pool_create]

import com.google.cloud.compute.v1.InsertStoragePoolRequest;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.StoragePool;
Expand All @@ -32,12 +31,13 @@ public static void main(String[] args)
// Project ID or project number of the Google Cloud project you want to use.
String projectId = "YOUR_PROJECT_ID";
// Name of the zone in which you want to create the storagePool.
String zone = "europe-central2-b";
String zone = "us-central1-a";
// Name of the storagePool you want to create.
String storagePoolName = "YOUR_STORAGE_POOL_NAME";
// The type of disk you want to create. This value uses the following format:
// "projects/%s/zones/%s/storagePoolTypes/hyperdisk-throughput|hyperdisk-balanced"
String storagePoolType = "hyperdisk-balanced";
// The type of disk you want to create.
// Storage types can be "hyperdisk-throughput" or "hyperdisk-balanced"
String storagePoolType = String.format(
"projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced", projectId, zone);
// Optional: the capacity provisioning type of the storage pool.
// The allowed values are advanced and standard. If not specified, the value advanced is used.
String capacityProvisioningType = "advanced";
Expand All @@ -48,16 +48,19 @@ public static void main(String[] args)
long provisionedIops = 3000;
// the throughput in MBps to provision for the storage pool.
long provisionedThroughput = 140;
// The allowed values are low-casing strings "advanced" and "standard".
// If not specified, "advanced" is used.
String performanceProvisioningType = "advanced";

createHyperdiskStoragePool(projectId, zone, storagePoolName, storagePoolType,
capacityProvisioningType, provisionedCapacity, provisionedIops, provisionedThroughput);
capacityProvisioningType, provisionedCapacity, provisionedIops,
provisionedThroughput, performanceProvisioningType);
}

// Creates a hyperdisk storagePool in a project
public static StoragePool createHyperdiskStoragePool(String projectId, String zone,
String storagePoolName, String storagePoolType,
String capacityProvisioningType, long capacity,
long iops, long throughput)
String storagePoolName, String storagePoolType, String capacityProvisioningType,
long capacity, long iops, long throughput, String performanceProvisioningType)
throws IOException, ExecutionException, InterruptedException, TimeoutException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
Expand All @@ -71,6 +74,7 @@ public static StoragePool createHyperdiskStoragePool(String projectId, String zo
.setPoolProvisionedCapacityGb(capacity)
.setPoolProvisionedIops(iops)
.setPoolProvisionedThroughput(throughput)
.setPerformanceProvisioningType(performanceProvisioningType)
.build();

InsertStoragePoolRequest request = InsertStoragePoolRequest.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.MethodSorters;

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

// Check if the required environment variables are set.
public static void requireEnvVar(String envVarName) {
Expand All @@ -60,26 +62,21 @@ public static void setUp()
throws IOException, ExecutionException, InterruptedException, TimeoutException {
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
requireEnvVar("GOOGLE_CLOUD_PROJECT");
HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();
STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID();

Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE);
Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE);
}

@AfterAll
public static void cleanup()
throws IOException, InterruptedException, ExecutionException, TimeoutException {
// Delete all disks created for testing.
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_NAME);
//DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);
DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME);

//Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME);
}

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

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

@Disabled
@Test
public void stage1_CreateHyperdiskStoragePoolTest()
@Order(1)
public void testCreateHyperdiskStoragePool()
throws IOException, ExecutionException, InterruptedException, TimeoutException {
String poolType = String.format("projects/%s/zones/%s/storagePoolTypes/hyperdisk-balanced",
PROJECT_ID, ZONE);
StoragePool storagePool = CreateHyperdiskStoragePool
.createHyperdiskStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME, poolType,
"advanced", 10240, 10000, 10240);
CAPACITY_PROVISIONING_TYPE, 10240, 10000, 1024,
PERFORMANCE_PROVISIONING_TYPE);

Assert.assertNotNull(storagePool);
Assert.assertEquals(STORAGE_POOL_NAME, storagePool.getName());
Assert.assertEquals(10000, storagePool.getPoolProvisionedIops());
Assert.assertEquals(10240, storagePool.getPoolProvisionedThroughput());
Assert.assertEquals(1024, storagePool.getPoolProvisionedThroughput());
Assert.assertEquals(10240, storagePool.getPoolProvisionedCapacityGb());
Assert.assertTrue(storagePool.getStoragePoolType().contains("hyperdisk-balanced"));
Assert.assertTrue(storagePool.getCapacityProvisioningType().equalsIgnoreCase("advanced"));
Assert.assertTrue(storagePool.getCapacityProvisioningType()
.equalsIgnoreCase(CAPACITY_PROVISIONING_TYPE));
Assert.assertTrue(storagePool.getPerformanceProvisioningType()
.equalsIgnoreCase(PERFORMANCE_PROVISIONING_TYPE));
Assert.assertTrue(storagePool.getZone().contains(ZONE));
}

@Disabled
@Test
public void stage2_CreateHyperdiskStoragePoolTest()
@Order(2)
public void testCreateDiskInStoragePool()
throws IOException, ExecutionException, InterruptedException, TimeoutException {
String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", ZONE);
String storagePoolLink = String
Expand Down