Search in sources :

Example 46 with Operation

use of com.reprezen.kaizen.oasparser.model3.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CreateRouteToWindowsActivationHost method createRouteToWindowsActivationHost.

// Creates a new route to kms.windows.googlecloud.com (35.190.247.13) for Windows activation.
public static void createRouteToWindowsActivationHost(String projectId, String routeName, String networkName) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Instantiates a client.
    try (RoutesClient routesClient = RoutesClient.create()) {
        // If you have Windows instances without external IP addresses,
        // you must also enable Private Google Access so that instances
        // with only internal IP addresses can send traffic to the external
        // IP address for kms.windows.googlecloud.com.
        // More information: https://cloud.google.com/vpc/docs/configure-private-google-access#enabling
        Route route = Route.newBuilder().setName(routeName).setDestRange("35.190.247.13/32").setNetwork(networkName).setNextHopGateway(String.format("projects/%s/global/gateways/default-internet-gateway", projectId)).build();
        InsertRouteRequest request = InsertRouteRequest.newBuilder().setProject(projectId).setRouteResource(route).build();
        // Wait for the operation to complete.
        Operation operation = routesClient.insertAsync(request).get(3, TimeUnit.MINUTES);
        if (operation.hasError()) {
            System.out.printf("Error in creating route %s", operation.getError());
            return;
        }
        System.out.printf("Route created %s", routeName);
    }
}
Also used : RoutesClient(com.google.cloud.compute.v1.RoutesClient) Operation(com.google.cloud.compute.v1.Operation) InsertRouteRequest(com.google.cloud.compute.v1.InsertRouteRequest) Route(com.google.cloud.compute.v1.Route)

Example 47 with Operation

use of com.reprezen.kaizen.oasparser.model3.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CreateWindowsServerInstanceExternalIp method createWindowsServerInstanceExternalIp.

// Creates a new Windows Server instance that has an external IP address.
public static void createWindowsServerInstanceExternalIp(String projectId, String zone, String instanceName) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // machineType - Machine type you want to create in following format:
    // *    "zones/{zone}/machineTypes/{type_name}". For example:
    // *    "zones/europe-west3-c/machineTypes/f1-micro"
    // *    You can find the list of available machine types using:
    // *    https://cloud.google.com/sdk/gcloud/reference/compute/machine-types/list
    String machineType = "n1-standard-1";
    // sourceImageFamily - Name of the public image family for Windows Server or SQL Server images.
    // *    https://cloud.google.com/compute/docs/images#os-compute-support
    String sourceImageFamily = "windows-2012-r2";
    // Instantiates a client.
    try (InstancesClient instancesClient = InstancesClient.create()) {
        AttachedDisk attachedDisk = AttachedDisk.newBuilder().setInitializeParams(AttachedDiskInitializeParams.newBuilder().setDiskSizeGb(64).setSourceImage(String.format("projects/windows-cloud/global/images/family/%s", sourceImageFamily)).build()).setAutoDelete(true).setBoot(true).setType(AttachedDisk.Type.PERSISTENT.toString()).build();
        Instance instance = Instance.newBuilder().setName(instanceName).setMachineType(String.format("zones/%s/machineTypes/%s", zone, machineType)).addDisks(attachedDisk).addNetworkInterfaces(NetworkInterface.newBuilder().addAccessConfigs(AccessConfig.newBuilder().setType("ONE_TO_ONE_NAT").setName("External NAT").build()).setName("global/networks/default").build()).build();
        InsertInstanceRequest request = InsertInstanceRequest.newBuilder().setProject(projectId).setZone(zone).setInstanceResource(instance).build();
        // Wait for the operation to complete.
        Operation operation = instancesClient.insertAsync(request).get(3, TimeUnit.MINUTES);
        if (operation.hasError()) {
            System.out.printf("Error in creating instance %s", operation.getError());
            return;
        }
        System.out.printf("Instance created %s", instanceName);
    }
}
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) Operation(com.google.cloud.compute.v1.Operation)

Example 48 with Operation

use of com.reprezen.kaizen.oasparser.model3.Operation in project java-docs-samples by GoogleCloudPlatform.

the class InstancesAdvancedIT method deleteDisk.

private static void deleteDisk(Disk disk) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    try (DisksClient disksClient = DisksClient.create()) {
        OperationFuture<Operation, Operation> operation = disksClient.deleteAsync(PROJECT_ID, ZONE, disk.getName());
        operation.get(3, TimeUnit.MINUTES);
    }
}
Also used : Operation(com.google.cloud.compute.v1.Operation) DisksClient(com.google.cloud.compute.v1.DisksClient)

Example 49 with Operation

use of com.reprezen.kaizen.oasparser.model3.Operation in project java-docs-samples by GoogleCloudPlatform.

the class WaitForOperation method main.

public static void main(String[] args) throws IOException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    // operation: Specify the operation to wait.
    String project = "your-project-id";
    Operation operation = Operation.newBuilder().build();
    waitForOperation(project, operation);
}
Also used : Operation(com.google.cloud.compute.v1.Operation)

Example 50 with Operation

use of com.reprezen.kaizen.oasparser.model3.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CreateInstanceWithCustomHostname method createInstanceWithCustomHostname.

// Creates an instance with custom hostname.
public static void createInstanceWithCustomHostname(String projectId, String zone, String instanceName, String hostName) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // machineType - Machine type for the VM instance specified in the following format:
    // *    "zones/{zone}/machineTypes/{type_name}". For example:
    // *    "zones/europe-west3-c/machineTypes/f1-micro"
    // *    You can find the list of available machine types by using this gcloud command:
    // *    $ gcloud compute machine-types list
    // sourceImage - Path of the disk image you want to use for your boot
    // *    disk. This image can be one of the public images
    // *    eg: "projects/...
    // *    or a private image you have access to.
    // *    You can check the list of available public images using:
    // *    $ gcloud compute images list
    // networkName - Name of the network you want the new instance to use.
    // *    For example: global/networks/default - if you want to use the default network.
    String machineType = "n1-standard-1";
    String sourceImage = String.format("projects/%s/global/images/family/%s", "debian-cloud", "debian-11");
    String networkName = "global/networks/default";
    try (InstancesClient instancesClient = InstancesClient.create()) {
        System.out.printf("Creating the %s instance in %s with hostname %s...", instanceName, zone, hostName);
        AttachedDisk disk = AttachedDisk.newBuilder().setBoot(true).setAutoDelete(true).setType(AttachedDisk.Type.PERSISTENT.toString()).setInitializeParams(// Describe the size and source image of the boot disk to attach to the instance.
        AttachedDiskInitializeParams.newBuilder().setSourceImage(sourceImage).setDiskSizeGb(10).build()).build();
        // Use the network interface provided in the networkName argument.
        NetworkInterface networkInterface = NetworkInterface.newBuilder().setName(networkName).build();
        Instance instanceResource = Instance.newBuilder().setName(instanceName).setHostname(hostName).addDisks(disk).setMachineType(String.format("zones/%s/machineTypes/%s", zone, machineType)).addNetworkInterfaces(networkInterface).build();
        InsertInstanceRequest request = InsertInstanceRequest.newBuilder().setProject(projectId).setZone(zone).setInstanceResource(instanceResource).build();
        // Wait for the create operation to complete.
        Operation response = instancesClient.insertAsync(request).get(3, TimeUnit.MINUTES);
        ;
        if (response.hasError()) {
            System.out.printf("Instance creation failed for instance: %s ; Response: %s ! ! ", instanceName, response);
            return;
        }
        System.out.printf("Instance created : %s", instanceName);
        System.out.printf("Operation Status for instance %s is %s: ", instanceName, 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)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 Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)14 Instance (com.google.cloud.compute.v1.Instance)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