Search in sources :

Example 36 with Operation

use of com.google.container.v1.Operation in project java-docs-samples by GoogleCloudPlatform.

the class WindowsOsImageIT method cleanUp.

@AfterAll
public static void cleanUp() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    final PrintStream out = System.out;
    ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
    System.setOut(new PrintStream(stdOut));
    // Delete image.
    ImagesClient imagesClient = ImagesClient.create();
    Operation operation = imagesClient.deleteAsync(PROJECT_ID, IMAGE_NAME).get();
    if (operation.hasError()) {
        System.out.println("Image not deleted.");
    }
    // Delete instance.
    DeleteInstance.deleteInstance(PROJECT_ID, ZONE, INSTANCE_NAME);
    stdOut.close();
    System.setOut(out);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Operation(com.google.cloud.compute.v1.Operation) ImagesClient(com.google.cloud.compute.v1.ImagesClient) AfterAll(org.junit.jupiter.api.AfterAll)

Example 37 with Operation

use of com.google.container.v1.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CreateTemplateFromInstance method createTemplateFromInstance.

// Create a new instance template based on an existing instance.
// This new template specifies a different boot disk.
public static void createTemplateFromInstance(String projectId, String templateName, String instance) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create();
        GlobalOperationsClient globalOperationsClient = GlobalOperationsClient.create()) {
        SourceInstanceParams sourceInstanceParams = SourceInstanceParams.newBuilder().addDiskConfigs(DiskInstantiationConfig.newBuilder().setDeviceName("disk-1").setInstantiateFrom(InstantiateFrom.CUSTOM_IMAGE.toString()).setCustomImage(String.format("projects/%s/global/images/family/%s", "rocky-linux-cloud", "rocky-linux-8")).setAutoDelete(true).build()).build();
        InstanceTemplate instanceTemplate = InstanceTemplate.newBuilder().setName(templateName).setSourceInstance(instance).setSourceInstanceParams(sourceInstanceParams).build();
        InsertInstanceTemplateRequest insertInstanceTemplateRequest = InsertInstanceTemplateRequest.newBuilder().setProject(projectId).setInstanceTemplateResource(instanceTemplate).build();
        Operation operation = instanceTemplatesClient.insertCallable().futureCall(insertInstanceTemplateRequest).get(3, TimeUnit.MINUTES);
        Operation response = globalOperationsClient.wait(projectId, operation.getName());
        if (response.hasError()) {
            System.out.println("Instance Template creation failed ! ! " + response);
            return;
        }
        System.out.printf("Instance Template creation operation status %s: %s", templateName, response.getStatus());
    }
}
Also used : SourceInstanceParams(com.google.cloud.compute.v1.SourceInstanceParams) GlobalOperationsClient(com.google.cloud.compute.v1.GlobalOperationsClient) Operation(com.google.cloud.compute.v1.Operation) InsertInstanceTemplateRequest(com.google.cloud.compute.v1.InsertInstanceTemplateRequest) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient) InstanceTemplate(com.google.cloud.compute.v1.InstanceTemplate)

Example 38 with Operation

use of com.google.container.v1.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DeleteFirewallRule method deleteFirewallRule.

// Deletes a firewall rule from the project.
public static void deleteFirewallRule(String project, String firewallRuleName) 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. After completing all of your requests, call
       the `firewallsClient.close()` method on the client to safely
       clean up any remaining background resources. */
    try (FirewallsClient firewallsClient = FirewallsClient.create()) {
        OperationFuture<Operation, Operation> operation = firewallsClient.deleteAsync(project, firewallRuleName);
        operation.get(3, TimeUnit.MINUTES);
        System.out.println("Deleted firewall rule -> " + firewallRuleName);
    }
}
Also used : FirewallsClient(com.google.cloud.compute.v1.FirewallsClient) Operation(com.google.cloud.compute.v1.Operation)

Example 39 with Operation

use of com.google.container.v1.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DeleteInstance method deleteInstance.

// Delete the instance specified by `instanceName`
// if it's present in the given project and zone.
public static void deleteInstance(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {
        System.out.printf("Deleting instance: %s ", instanceName);
        // Describe which instance is to be deleted.
        DeleteInstanceRequest deleteInstanceRequest = DeleteInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstance(instanceName).build();
        OperationFuture<Operation, Operation> operation = instancesClient.deleteAsync(deleteInstanceRequest);
        // Wait for the operation to complete.
        Operation response = operation.get(3, TimeUnit.MINUTES);
        if (response.hasError()) {
            System.out.println("Instance deletion failed ! ! " + response);
            return;
        }
        System.out.println("Operation Status: " + response.getStatus());
    }
}
Also used : InstancesClient(com.google.cloud.compute.v1.InstancesClient) Operation(com.google.cloud.compute.v1.Operation) DeleteInstanceRequest(com.google.cloud.compute.v1.DeleteInstanceRequest)

Example 40 with Operation

use of com.google.container.v1.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DeleteInstanceTemplate method deleteInstanceTemplate.

// Delete an instance template.
public static void deleteInstanceTemplate(String projectId, String templateName) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create()) {
        DeleteInstanceTemplateRequest deleteInstanceTemplateRequest = DeleteInstanceTemplateRequest.newBuilder().setProject(projectId).setInstanceTemplate(templateName).build();
        Operation response = instanceTemplatesClient.deleteAsync(deleteInstanceTemplateRequest).get(3, TimeUnit.MINUTES);
        if (response.hasError()) {
            System.out.println("Instance template deletion failed ! ! " + response);
            return;
        }
        System.out.printf("Instance template deletion operation status for %s: %s ", templateName, response.getStatus());
    }
}
Also used : DeleteInstanceTemplateRequest(com.google.cloud.compute.v1.DeleteInstanceTemplateRequest) Operation(com.google.cloud.compute.v1.Operation) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient)

Aggregations

ArrayList (java.util.ArrayList)81 Test (org.junit.Test)75 AbstractMessage (com.google.protobuf.AbstractMessage)65 Operation (com.google.cloud.compute.v1.Operation)49 Operation (com.google.container.v1.Operation)43 StatusCondition (com.google.container.v1.StatusCondition)40 Operation (com.google.container.v1beta1.Operation)24 StatusCondition (com.google.container.v1beta1.StatusCondition)23 InstancesClient (com.google.cloud.compute.v1.InstancesClient)20 Operation (com.reprezen.kaizen.oasparser.model3.Operation)16 Path (com.reprezen.kaizen.oasparser.model3.Path)15 Operation (net.opengis.ows.v_1_0_0.Operation)15 Instance (com.google.cloud.compute.v1.Instance)13 Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)13 DomainType (net.opengis.ows.v_1_0_0.DomainType)13 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)12 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)11 Operation (org.osate.aadl2.Operation)8 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)7 BooleanLiteral (org.osate.aadl2.BooleanLiteral)7