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()));
}
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.
}
}
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());
}
}
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);
}
}
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());
}
}
}
}
Aggregations