Search in sources :

Example 6 with GetInstanceRequest

use of com.google.cloud.notebooks.v1beta1.GetInstanceRequest in project java-docs-samples by GoogleCloudPlatform.

the class StartEncryptedInstance method startEncryptedInstance.

// Starts a stopped Google Compute Engine instance (with encrypted disks).
public static void startEncryptedInstance(String project, String zone, String instanceName, String key) throws IOException, ExecutionException, InterruptedException {
    /* Initialize client that will be used to send requests. This client only needs to be created
       once, and can be reused for multiple requests. After completing all of your requests, call
       the `instancesClient.close()` method on the client to safely
       clean up any remaining background resources. */
    try (InstancesClient instancesClient = InstancesClient.create()) {
        GetInstanceRequest getInstanceRequest = GetInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstance(instanceName).build();
        Instance instance = instancesClient.get(getInstanceRequest);
        // Prepare the information about disk encryption.
        CustomerEncryptionKeyProtectedDisk protectedDisk = CustomerEncryptionKeyProtectedDisk.newBuilder().setDiskEncryptionKey(CustomerEncryptionKey.newBuilder().setRawKey(key).build()).setSource(instance.getDisks(0).getSource()).build();
        InstancesStartWithEncryptionKeyRequest startWithEncryptionKeyRequest = InstancesStartWithEncryptionKeyRequest.newBuilder().addDisks(protectedDisk).build();
        StartWithEncryptionKeyInstanceRequest encryptionKeyInstanceRequest = StartWithEncryptionKeyInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstance(instanceName).setInstancesStartWithEncryptionKeyRequestResource(startWithEncryptionKeyRequest).build();
        OperationFuture<Operation, Operation> operation = instancesClient.startWithEncryptionKeyAsync(encryptionKeyInstanceRequest);
        Operation response = operation.get();
        if (response.getStatus() == Status.DONE) {
            System.out.println("Encrypted instance started successfully ! ");
        }
    }
}
Also used : GetInstanceRequest(com.google.cloud.compute.v1.GetInstanceRequest) Instance(com.google.cloud.compute.v1.Instance) StartWithEncryptionKeyInstanceRequest(com.google.cloud.compute.v1.StartWithEncryptionKeyInstanceRequest) InstancesClient(com.google.cloud.compute.v1.InstancesClient) InstancesStartWithEncryptionKeyRequest(com.google.cloud.compute.v1.InstancesStartWithEncryptionKeyRequest) Operation(com.google.cloud.compute.v1.Operation) CustomerEncryptionKeyProtectedDisk(com.google.cloud.compute.v1.CustomerEncryptionKeyProtectedDisk)

Example 7 with GetInstanceRequest

use of com.google.cloud.notebooks.v1beta1.GetInstanceRequest in project java-bigtable by googleapis.

the class BaseBigtableInstanceAdminClientTest method getInstanceTest2.

@Test
public void getInstanceTest2() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    mockBigtableInstanceAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    Instance actualResponse = client.getInstance(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) GetInstanceRequest(com.google.bigtable.admin.v2.GetInstanceRequest) Instance(com.google.bigtable.admin.v2.Instance) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 8 with GetInstanceRequest

use of com.google.cloud.notebooks.v1beta1.GetInstanceRequest in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method testGetInstance.

@Test
public void testGetInstance() {
    GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(INSTANCE_NAME).build();
    Instance actualNotebookInstance = client.getInstance(request);
    assertEquals(expectedNotebookInstance.getContainerImage(), actualNotebookInstance.getContainerImage());
    assertEquals(expectedNotebookInstance.getName(), actualNotebookInstance.getName());
    assertEquals(expectedNotebookInstance.getNetwork(), actualNotebookInstance.getNetwork());
    assertEquals(expectedNotebookInstance.getSubnet(), actualNotebookInstance.getSubnet());
}
Also used : GetInstanceRequest(com.google.cloud.notebooks.v1beta1.GetInstanceRequest) Instance(com.google.cloud.notebooks.v1beta1.Instance) Test(org.junit.Test)

Example 9 with GetInstanceRequest

use of com.google.cloud.notebooks.v1beta1.GetInstanceRequest in project java-spanner by googleapis.

the class InstanceAdminClientTest method getInstanceTest.

@Test
public void getInstanceTest() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setConfig(InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]").toString()).setDisplayName("displayName1714148973").setNodeCount(1539922066).setProcessingUnits(-329117885).putAllLabels(new HashMap<String, String>()).addAllEndpointUris(new ArrayList<String>()).build();
    mockInstanceAdmin.addResponse(expectedResponse);
    InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
    Instance actualResponse = client.getInstance(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) GetInstanceRequest(com.google.spanner.admin.instance.v1.GetInstanceRequest) Instance(com.google.spanner.admin.instance.v1.Instance) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 GetInstanceRequest (com.google.bigtable.admin.v2.GetInstanceRequest)3 GetInstanceRequest (com.google.spanner.admin.instance.v1.GetInstanceRequest)3 Instance (com.google.bigtable.admin.v2.Instance)2 GetInstanceRequest (com.google.cloud.compute.v1.GetInstanceRequest)2 Instance (com.google.cloud.compute.v1.Instance)2 InstancesClient (com.google.cloud.compute.v1.InstancesClient)2 Instance (com.google.spanner.admin.instance.v1.Instance)2 ArrayList (java.util.ArrayList)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 InstanceName (com.google.bigtable.admin.v2.InstanceName)1 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)1 CustomerEncryptionKeyProtectedDisk (com.google.cloud.compute.v1.CustomerEncryptionKeyProtectedDisk)1 InstancesStartWithEncryptionKeyRequest (com.google.cloud.compute.v1.InstancesStartWithEncryptionKeyRequest)1 Operation (com.google.cloud.compute.v1.Operation)1 SetLabelsInstanceRequest (com.google.cloud.compute.v1.SetLabelsInstanceRequest)1 StartWithEncryptionKeyInstanceRequest (com.google.cloud.compute.v1.StartWithEncryptionKeyInstanceRequest)1 GetInstanceRequest (com.google.cloud.notebooks.v1beta1.GetInstanceRequest)1