use of com.google.cloud.compute.v1.Disk in project java-compute by googleapis.
the class ITSmokeInstancesTest method testDefaultClient.
@Test
public void testDefaultClient() throws IOException, ExecutionException, InterruptedException {
InstancesClient defaultClient = InstancesClient.create();
Instance instanceResource = Instance.newBuilder().setName(INSTANCE).setMachineType(MACHINE_TYPE).addDisks(DISK).addNetworkInterfaces(NETWORK_INTERFACE).build();
defaultClient.insertAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceResource).get();
instances.add(instanceResource);
assertInstanceDetails(getInstance());
}
use of com.google.cloud.compute.v1.Disk in project java-compute by googleapis.
the class DisksClientTest method listTest.
@Test
public void listTest() throws Exception {
Disk responsesElement = Disk.newBuilder().build();
DiskList expectedResponse = DiskList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
mockService.addResponse(expectedResponse);
String project = "project-6911";
String zone = "zone-5246";
ListPagedResponse pagedListResponse = client.list(project, zone);
List<Disk> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getItemsList().get(0), resources.get(0));
List<String> actualRequests = mockService.getRequestPaths();
Assert.assertEquals(1, actualRequests.size());
String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
use of com.google.cloud.compute.v1.Disk in project java-compute by googleapis.
the class RegionDisksClientTest method listTest.
@Test
public void listTest() throws Exception {
Disk responsesElement = Disk.newBuilder().build();
DiskList expectedResponse = DiskList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
mockService.addResponse(expectedResponse);
String project = "project-6911";
String region = "region-9622";
ListPagedResponse pagedListResponse = client.list(project, region);
List<Disk> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getItemsList().get(0), resources.get(0));
List<String> actualRequests = mockService.getRequestPaths();
Assert.assertEquals(1, actualRequests.size());
String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
use of com.google.cloud.compute.v1.Disk in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method createImage.
private static Image createImage(Disk srcDisk) throws IOException, InterruptedException, ExecutionException {
try (ImagesClient imagesClient = ImagesClient.create()) {
Image image = Image.newBuilder().setName("test-img-" + UUID.randomUUID()).setSourceDisk(srcDisk.getSelfLink()).build();
OperationFuture<Operation, Operation> operation = imagesClient.insertAsync(PROJECT_ID, image);
operation.get();
return imagesClient.get(PROJECT_ID, image.getName());
}
}
use of com.google.cloud.compute.v1.Disk in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method createSourceDisk.
private static Disk createSourceDisk() throws IOException, ExecutionException, InterruptedException {
try (DisksClient disksClient = DisksClient.create()) {
Disk disk = Disk.newBuilder().setSourceImage(getActiveDebian().getSelfLink()).setName("test-disk-" + UUID.randomUUID()).build();
OperationFuture<Operation, Operation> operation = disksClient.insertAsync(PROJECT_ID, ZONE, disk);
// Wait for the operation to complete.
operation.get();
return disksClient.get(PROJECT_ID, ZONE, disk.getName());
}
}
Aggregations