Search in sources :

Example 1 with PatchFirewallRequest

use of com.google.cloud.compute.v1.PatchFirewallRequest 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, 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()) {
        /* 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(3, TimeUnit.MINUTES);
        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)

Aggregations

Firewall (com.google.cloud.compute.v1.Firewall)1 FirewallsClient (com.google.cloud.compute.v1.FirewallsClient)1 Operation (com.google.cloud.compute.v1.Operation)1 PatchFirewallRequest (com.google.cloud.compute.v1.PatchFirewallRequest)1