Search in sources :

Example 76 with LocationName

use of com.google.cloud.automl.v1.LocationName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method listWorkerPoolsTest.

@Test
public void listWorkerPoolsTest() throws Exception {
    WorkerPool responsesElement = WorkerPool.newBuilder().build();
    ListWorkerPoolsResponse expectedResponse = ListWorkerPoolsResponse.newBuilder().setNextPageToken("").addAllWorkerPools(Arrays.asList(responsesElement)).build();
    mockCloudBuild.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListWorkerPoolsPagedResponse pagedListResponse = client.listWorkerPools(parent);
    List<WorkerPool> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getWorkerPoolsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListWorkerPoolsRequest actualRequest = ((ListWorkerPoolsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListWorkerPoolsPagedResponse(com.google.cloud.devtools.cloudbuild.v1.CloudBuildClient.ListWorkerPoolsPagedResponse) WorkerPool(com.google.cloudbuild.v1.WorkerPool) AbstractMessage(com.google.protobuf.AbstractMessage) ListWorkerPoolsResponse(com.google.cloudbuild.v1.ListWorkerPoolsResponse) ListWorkerPoolsRequest(com.google.cloudbuild.v1.ListWorkerPoolsRequest) LocationName(com.google.cloudbuild.v1.LocationName) Test(org.junit.Test)

Example 77 with LocationName

use of com.google.cloud.automl.v1.LocationName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method listWorkerPoolsExceptionTest.

@Test
public void listWorkerPoolsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
        client.listWorkerPools(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) LocationName(com.google.cloudbuild.v1.LocationName) Test(org.junit.Test)

Example 78 with LocationName

use of com.google.cloud.automl.v1.LocationName in project java-cloudbuild by googleapis.

the class CloudBuildClientTest method createWorkerPoolExceptionTest.

@Test
public void createWorkerPoolExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockCloudBuild.addException(exception);
    try {
        LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
        WorkerPool workerPool = WorkerPool.newBuilder().build();
        String workerPoolId = "workerPoolId-46320779";
        client.createWorkerPoolAsync(parent, workerPool, workerPoolId).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : WorkerPool(com.google.cloudbuild.v1.WorkerPool) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) LocationName(com.google.cloudbuild.v1.LocationName) Test(org.junit.Test)

Example 79 with LocationName

use of com.google.cloud.automl.v1.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 80 with LocationName

use of com.google.cloud.automl.v1.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)

Aggregations

Test (org.junit.Test)36 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 AbstractMessage (com.google.protobuf.AbstractMessage)19 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)17 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 StatusRuntimeException (io.grpc.StatusRuntimeException)17 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)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 LocationName (com.google.cloud.bigquery.connection.v1.LocationName)8 Dataset (com.google.cloud.automl.v1.Dataset)7 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)5