Search in sources :

Example 51 with LocationName

use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.

the class Quickstart method quickstart.

public void quickstart(String projectId, String locationId) throws IOException {
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
        // Build the parent from the project and location.
        LocationName parent = LocationName.of(projectId, locationId);
        // Call the API.
        ListKeyRingsPagedResponse response = client.listKeyRings(parent);
        // Iterate over each key ring and print its name.
        System.out.println("key rings:");
        for (KeyRing keyRing : response.iterateAll()) {
            System.out.printf("%s%n", keyRing.getName());
        }
    }
}
Also used : ListKeyRingsPagedResponse(com.google.cloud.kms.v1.KeyManagementServiceClient.ListKeyRingsPagedResponse) KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 52 with LocationName

use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.

the class WorkflowsQuickstartTest method deployWorkflow.

private static void deployWorkflow(String projectId, String location, String workflowId) throws IOException, InterruptedException, ExecutionException {
    if (workflowsClient == null) {
        workflowsClient = WorkflowsClient.create();
    }
    LocationName parent = LocationName.of(projectId, location);
    String source = new String(Files.readAllBytes(Paths.get("src/test/java/com/example/workflows/resources/source.yaml")));
    Workflow workflow = Workflow.newBuilder().setSourceContents(source).build();
    // Deploy workflow
    workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get();
}
Also used : Workflow(com.google.cloud.workflows.v1.Workflow) LocationName(com.google.cloud.workflows.v1.LocationName)

Example 53 with LocationName

use of com.google.logging.v2.LocationName in project java-automl by googleapis.

the class LanguageTextClassificationCreateDataset method createDataset.

// Create a dataset
static void createDataset(String projectId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Specify the classification type
        // Types:
        // MultiLabel: Multiple labels are allowed for one example.
        // MultiClass: At most one label is allowed per example.
        ClassificationType classificationType = ClassificationType.MULTILABEL;
        // Specify the text classification type for the dataset.
        TextClassificationDatasetMetadata metadata = TextClassificationDatasetMetadata.newBuilder().setClassificationType(classificationType).build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTextClassificationDatasetMetadata(metadata).build();
        OperationFuture<Dataset, OperationMetadata> future = client.createDatasetAsync(projectLocation, dataset);
        Dataset createdDataset = future.get();
        // Display the dataset information.
        System.out.format("Dataset name: %s\n", createdDataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = createdDataset.getName().split("/");
        String datasetId = names[names.length - 1];
        System.out.format("Dataset id: %s\n", datasetId);
    }
}
Also used : Dataset(com.google.cloud.automl.v1.Dataset) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) ClassificationType(com.google.cloud.automl.v1.ClassificationType) TextClassificationDatasetMetadata(com.google.cloud.automl.v1.TextClassificationDatasetMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 54 with LocationName

use of com.google.logging.v2.LocationName in project java-automl by googleapis.

the class ListOperationStatus method listOperationStatus.

// Get the status of an operation
static void listOperationStatus(String projectId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Create list operations request.
        ListOperationsRequest listrequest = ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build();
        // List all the operations names available in the region by applying filter.
        for (Operation operation : client.getOperationsClient().listOperations(listrequest).iterateAll()) {
            System.out.println("Operation details:");
            System.out.format("\tName: %s\n", operation.getName());
            System.out.format("\tMetadata Type Url: %s\n", operation.getMetadata().getTypeUrl());
            System.out.format("\tDone: %s\n", operation.getDone());
            if (operation.hasResponse()) {
                System.out.format("\tResponse Type Url: %s\n", operation.getResponse().getTypeUrl());
            }
            if (operation.hasError()) {
                System.out.println("\tResponse:");
                System.out.format("\t\tError code: %s\n", operation.getError().getCode());
                System.out.format("\t\tError message: %s\n\n", operation.getError().getMessage());
            }
        }
    }
}
Also used : ListOperationsRequest(com.google.longrunning.ListOperationsRequest) Operation(com.google.longrunning.Operation) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 55 with LocationName

use of com.google.logging.v2.LocationName in project java-automl by googleapis.

the class VisionClassificationCreateModel method createModel.

// Create a model
static void createModel(String projectId, String datasetId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Set model metadata.
        ImageClassificationModelMetadata metadata = ImageClassificationModelMetadata.newBuilder().setTrainBudgetMilliNodeHours(24000).build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setImageClassificationModelMetadata(metadata).build();
        // Create a model with the model metadata in the region.
        OperationFuture<Model, OperationMetadata> future = client.createModelAsync(projectLocation, model);
        // OperationFuture.get() will block until the model is created, which may take several hours.
        // You can use OperationFuture.getInitialFuture to get a future representing the initial
        // response to the request, which contains information while the operation is in progress.
        System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName());
        System.out.println("Training started...");
    }
}
Also used : ImageClassificationModelMetadata(com.google.cloud.automl.v1.ImageClassificationModelMetadata) Model(com.google.cloud.automl.v1.Model) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Aggregations

Test (org.junit.Test)28 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 AbstractMessage (com.google.protobuf.AbstractMessage)14 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)12 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)12 LocationName (com.google.cloud.automl.v1beta1.LocationName)12 LocationName (com.google.cloud.translate.v3beta1.LocationName)10 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)10 Model (com.google.cloud.automl.v1.Model)8 Dataset (com.google.cloud.automl.v1.Dataset)7 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 GcsSource (com.google.cloud.translate.v3.GcsSource)5 ArrayList (java.util.ArrayList)5