Search in sources :

Example 16 with Operation

use of org.geotoolkit.ows.xml.v110.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 {
    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();
        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 17 with Operation

use of org.geotoolkit.ows.xml.v110.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 {
    /* 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();
        System.out.println("Deleted firewall rule -> " + firewallRuleName);
    }
}
Also used : FirewallsClient(com.google.cloud.compute.v1.FirewallsClient) Operation(com.google.cloud.compute.v1.Operation)

Example 18 with Operation

use of org.geotoolkit.ows.xml.v110.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 {
    try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create()) {
        DeleteInstanceTemplateRequest deleteInstanceTemplateRequest = DeleteInstanceTemplateRequest.newBuilder().setProject(projectId).setInstanceTemplate(templateName).build();
        Operation response = instanceTemplatesClient.deleteAsync(deleteInstanceTemplateRequest).get();
        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)

Example 19 with Operation

use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.

the class PatchFirewallRule method patchFirewallPriority.

// Modifies the priority of a given firewall rule.
public static void patchFirewallPriority(String project, String firewallRuleName, int priority) 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 `firewallsClient.close()` method on the client to safely
       clean up any remaining background resources. */
    try (FirewallsClient firewallsClient = FirewallsClient.create()) {
        /* The patch operation doesn't require the full definition of a Firewall object. It will only 
         update the values that were set in it, in this case it will only change the priority. */
        Firewall firewall = Firewall.newBuilder().setPriority(priority).build();
        PatchFirewallRequest patchFirewallRequest = PatchFirewallRequest.newBuilder().setProject(project).setFirewall(firewallRuleName).setFirewallResource(firewall).build();
        OperationFuture<Operation, Operation> operation = firewallsClient.patchAsync(patchFirewallRequest);
        operation.get();
        System.out.println("Firewall Patch applied successfully ! ");
    }
}
Also used : FirewallsClient(com.google.cloud.compute.v1.FirewallsClient) PatchFirewallRequest(com.google.cloud.compute.v1.PatchFirewallRequest) Operation(com.google.cloud.compute.v1.Operation) Firewall(com.google.cloud.compute.v1.Firewall)

Example 20 with Operation

use of org.geotoolkit.ows.xml.v110.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CreateInstance method createInstance.

// Create a new instance with the provided "instanceName" value in the specified project and zone.
public static void createInstance(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException {
    // Below are sample values that can be replaced.
    // machineType: machine type of the VM being created. This value uses the format zones/{zone}/machineTypes/{type_name}. For a list of machine types, see https://cloud.google.com/compute/docs/machine-types
    // sourceImage: path to the operating system image to mount. For details about images you can mount, see https://cloud.google.com/compute/docs/images
    // diskSizeGb: storage size of the boot disk to attach to the instance.
    // networkName: network interface to associate with the instance.
    String machineType = String.format("zones/%s/machineTypes/n1-standard-1", zone);
    String sourceImage = String.format("projects/debian-cloud/global/images/family/%s", "debian-10");
    long diskSizeGb = 10L;
    String networkName = "default";
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {
        // Instance creation requires at least one persistent disk and one network interface.
        AttachedDisk disk = AttachedDisk.newBuilder().setBoot(true).setAutoDelete(true).setType(Type.PERSISTENT.toString()).setDeviceName("disk-1").setInitializeParams(AttachedDiskInitializeParams.newBuilder().setSourceImage(sourceImage).setDiskSizeGb(diskSizeGb).build()).build();
        // Use the network interface provided in the networkName argument.
        NetworkInterface networkInterface = NetworkInterface.newBuilder().setName(networkName).build();
        // Bind `instanceName`, `machineType`, `disk`, and `networkInterface` to an instance.
        Instance instanceResource = Instance.newBuilder().setName(instanceName).setMachineType(machineType).addDisks(disk).addNetworkInterfaces(networkInterface).build();
        System.out.printf("Creating instance: %s at %s %n", instanceName, zone);
        // Insert the instance in the specified project and zone.
        InsertInstanceRequest insertInstanceRequest = InsertInstanceRequest.newBuilder().setProject(project).setZone(zone).setInstanceResource(instanceResource).build();
        OperationFuture<Operation, Operation> operation = instancesClient.insertAsync(insertInstanceRequest);
        // Wait for the operation to complete.
        Operation response = operation.get();
        if (response.hasError()) {
            System.out.println("Instance creation failed ! ! " + response);
            return;
        }
        System.out.println("Operation Status: " + response.getStatus());
    }
}
Also used : InsertInstanceRequest(com.google.cloud.compute.v1.InsertInstanceRequest) Instance(com.google.cloud.compute.v1.Instance) InstancesClient(com.google.cloud.compute.v1.InstancesClient) AttachedDisk(com.google.cloud.compute.v1.AttachedDisk) NetworkInterface(com.google.cloud.compute.v1.NetworkInterface) Operation(com.google.cloud.compute.v1.Operation)

Aggregations

ArrayList (java.util.ArrayList)79 Test (org.junit.Test)75 AbstractMessage (com.google.protobuf.AbstractMessage)65 Operation (com.google.container.v1.Operation)43 StatusCondition (com.google.container.v1.StatusCondition)40 Operation (com.google.cloud.compute.v1.Operation)31 Operation (com.google.container.v1beta1.Operation)24 StatusCondition (com.google.container.v1beta1.StatusCondition)23 Operation (net.opengis.ows.v_1_0_0.Operation)15 InstancesClient (com.google.cloud.compute.v1.InstancesClient)13 DomainType (net.opengis.ows.v_1_0_0.DomainType)13 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)8 Instance (com.google.cloud.compute.v1.Instance)8 Operation (org.osate.aadl2.Operation)8 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)7 InstanceTemplatesClient (com.google.cloud.compute.v1.InstanceTemplatesClient)7 BooleanLiteral (org.osate.aadl2.BooleanLiteral)7 ClassifierValue (org.osate.aadl2.ClassifierValue)7 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)7 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)7