Search in sources :

Example 1 with Disk

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());
}
Also used : Instance(com.google.cloud.compute.v1.Instance) InstancesClient(com.google.cloud.compute.v1.InstancesClient) Test(org.junit.Test)

Example 2 with Disk

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());
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.DisksClient.ListPagedResponse) AggregatedListPagedResponse(com.google.cloud.compute.v1.DisksClient.AggregatedListPagedResponse) Test(org.junit.Test)

Example 3 with Disk

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());
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.RegionDisksClient.ListPagedResponse) Test(org.junit.Test)

Example 4 with Disk

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());
    }
}
Also used : Operation(com.google.cloud.compute.v1.Operation) ImagesClient(com.google.cloud.compute.v1.ImagesClient) Image(com.google.cloud.compute.v1.Image)

Example 5 with Disk

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());
    }
}
Also used : Operation(com.google.cloud.compute.v1.Operation) Disk(com.google.cloud.compute.v1.Disk) DisksClient(com.google.cloud.compute.v1.DisksClient)

Aggregations

Operation (com.google.cloud.compute.v1.Operation)22 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)12 Instance (com.google.cloud.compute.v1.Instance)12 InstancesClient (com.google.cloud.compute.v1.InstancesClient)11 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)8 DisksClient (com.google.cloud.compute.v1.DisksClient)7 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)7 Image (com.google.cloud.compute.v1.Image)5 ImagesClient (com.google.cloud.compute.v1.ImagesClient)5 InstanceTemplatesClient (com.google.cloud.compute.v1.InstanceTemplatesClient)5 InsertInstanceTemplateRequest (com.google.cloud.compute.v1.InsertInstanceTemplateRequest)4 InstanceTemplate (com.google.cloud.compute.v1.InstanceTemplate)4 Disk (com.google.cloud.compute.v1.Disk)3 GlobalOperationsClient (com.google.cloud.compute.v1.GlobalOperationsClient)3 Test (org.junit.Test)3 InstanceProperties (com.google.cloud.compute.v1.InstanceProperties)2 Snapshot (com.google.cloud.compute.v1.Snapshot)2 SnapshotsClient (com.google.cloud.compute.v1.SnapshotsClient)2 Vector (java.util.Vector)2 CustomerEncryptionKeyProtectedDisk (com.google.cloud.compute.v1.CustomerEncryptionKeyProtectedDisk)1