Search in sources :

Example 1 with DatasetName

use of com.google.cloud.automl.v1beta1.DatasetName in project java-automl by googleapis.

the class AutoMlClientTest method listTableSpecsTest.

@Test
public void listTableSpecsTest() throws Exception {
    TableSpec responsesElement = TableSpec.newBuilder().build();
    ListTableSpecsResponse expectedResponse = ListTableSpecsResponse.newBuilder().setNextPageToken("").addAllTableSpecs(Arrays.asList(responsesElement)).build();
    mockAutoMl.addResponse(expectedResponse);
    DatasetName parent = DatasetName.of("[PROJECT]", "[LOCATION]", "[DATASET]");
    ListTableSpecsPagedResponse pagedListResponse = client.listTableSpecs(parent);
    List<TableSpec> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTableSpecsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAutoMl.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTableSpecsRequest actualRequest = ((ListTableSpecsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListTableSpecsPagedResponse(com.google.cloud.automl.v1beta1.AutoMlClient.ListTableSpecsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 2 with DatasetName

use of com.google.cloud.automl.v1beta1.DatasetName in project java-automl by googleapis.

the class ImportDataset method importDataset.

// Import a dataset
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    Duration totalTimeout = Duration.ofMinutes(45);
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build();
    AutoMlSettings.Builder builder = AutoMlSettings.newBuilder();
    builder.importDataSettings().setRetrySettings(retrySettings).build();
    AutoMlSettings settings = builder.build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create(settings)) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        // Get multiple Google Cloud Storage URIs to import data from
        GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
        // Import data from the input URI
        InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
        System.out.println("Processing import...");
        // Start the import job
        OperationFuture<Empty, OperationMetadata> operation = client.importDataAsync(datasetFullId, inputConfig);
        System.out.format("Operation name: %s%n", operation.getName());
        // If you want to wait for the operation to finish, adjust the timeout appropriately. The
        // operation will still run if you choose not to wait for it to complete. You can check the
        // status of your operation using the operation's name.
        Empty response = operation.get(45, TimeUnit.MINUTES);
        System.out.format("Dataset imported. %s%n", response);
    } catch (TimeoutException e) {
        System.out.println("The operation's polling period was not long enough.");
        System.out.println("You can use the Operation's name to get the current status.");
        System.out.println("The import job is still running and will complete as expected.");
        throw e;
    }
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1beta1.GcsSource) DatasetName(com.google.cloud.automl.v1beta1.DatasetName) Duration(org.threeten.bp.Duration) InputConfig(com.google.cloud.automl.v1beta1.InputConfig) AutoMlSettings(com.google.cloud.automl.v1beta1.AutoMlSettings) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with DatasetName

use of com.google.cloud.automl.v1beta1.DatasetName in project java-automl by googleapis.

the class TablesImportDataset method importDataset.

// Import a dataset via BigQuery or Google Cloud Storage
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        InputConfig.Builder inputConfigBuilder = InputConfig.newBuilder();
        // Determine which source type was used for the input path (BigQuery or GCS)
        if (path.startsWith("bq")) {
            // Get training data file to be imported from a BigQuery source.
            BigQuerySource.Builder bigQuerySource = BigQuerySource.newBuilder();
            bigQuerySource.setInputUri(path);
            inputConfigBuilder.setBigquerySource(bigQuerySource);
        } else {
            // Get multiple Google Cloud Storage URIs to import data from
            GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
            inputConfigBuilder.setGcsSource(gcsSource);
        }
        // Import data from the input URI
        System.out.println("Processing import...");
        Empty response = client.importDataAsync(datasetFullId, inputConfigBuilder.build()).get();
        System.out.format("Dataset imported. %s%n", response);
    }
}
Also used : Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1beta1.GcsSource) DatasetName(com.google.cloud.automl.v1beta1.DatasetName) InputConfig(com.google.cloud.automl.v1beta1.InputConfig) BigQuerySource(com.google.cloud.automl.v1beta1.BigQuerySource) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Example 4 with DatasetName

use of com.google.cloud.automl.v1beta1.DatasetName in project java-automl by googleapis.

the class DeleteDataset method deleteDataset.

// Delete a dataset
static void deleteDataset(String projectId, String datasetId) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the full path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        Empty response = client.deleteDatasetAsync(datasetFullId).get();
        System.out.format("Dataset deleted. %s\n", response);
    }
}
Also used : Empty(com.google.protobuf.Empty) DatasetName(com.google.cloud.automl.v1.DatasetName) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient)

Example 5 with DatasetName

use of com.google.cloud.automl.v1beta1.DatasetName in project java-automl by googleapis.

the class ImportDataset method importDataset.

// Import a dataset
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // Get the complete path of the dataset.
        DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
        // Get multiple Google Cloud Storage URIs to import data from
        GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
        // Import data from the input URI
        InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
        System.out.println("Processing import...");
        // Start the import job
        OperationFuture<Empty, OperationMetadata> operation = client.importDataAsync(datasetFullId, inputConfig);
        System.out.format("Operation name: %s%n", operation.getName());
        // If you want to wait for the operation to finish, adjust the timeout appropriately. The
        // operation will still run if you choose not to wait for it to complete. You can check the
        // status of your operation using the operation's name.
        Empty response = operation.get(45, TimeUnit.MINUTES);
        System.out.format("Dataset imported. %s%n", response);
    } catch (TimeoutException e) {
        System.out.println("The operation's polling period was not long enough.");
        System.out.println("You can use the Operation's name to get the current status.");
        System.out.println("The import job is still running and will complete as expected.");
        throw e;
    }
}
Also used : Empty(com.google.protobuf.Empty) GcsSource(com.google.cloud.automl.v1.GcsSource) DatasetName(com.google.cloud.automl.v1.DatasetName) InputConfig(com.google.cloud.automl.v1.InputConfig) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Empty (com.google.protobuf.Empty)7 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)6 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)5 DatasetName (com.google.cloud.automl.v1.DatasetName)5 DatasetName (com.google.cloud.automl.v1beta1.DatasetName)5 GcsSource (com.google.cloud.automl.v1.GcsSource)2 InputConfig (com.google.cloud.automl.v1.InputConfig)2 GcsSource (com.google.cloud.automl.v1beta1.GcsSource)2 InputConfig (com.google.cloud.automl.v1beta1.InputConfig)2 TimeoutException (java.util.concurrent.TimeoutException)2 After (org.junit.After)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 Dataset (com.google.cloud.automl.v1.Dataset)1 GcsDestination (com.google.cloud.automl.v1.GcsDestination)1 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)1 OutputConfig (com.google.cloud.automl.v1.OutputConfig)1 ListTableSpecsPagedResponse (com.google.cloud.automl.v1beta1.AutoMlClient.ListTableSpecsPagedResponse)1 AutoMlSettings (com.google.cloud.automl.v1beta1.AutoMlSettings)1 BigQuerySource (com.google.cloud.automl.v1beta1.BigQuerySource)1 Dataset (com.google.cloud.automl.v1beta1.Dataset)1