Search in sources :

Example 1 with DatasetName

use of com.google.cloud.aiplatform.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 2 with DatasetName

use of com.google.cloud.aiplatform.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 3 with DatasetName

use of com.google.cloud.aiplatform.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 4 with DatasetName

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

Example 5 with DatasetName

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

the class ImportDataVideoObjectTrackingSampleTest method tearDown.

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
    // delete the temp dataset
    if (datasetId != null) {
        DatasetServiceSettings datasetServiceSettings = DatasetServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
        try (DatasetServiceClient datasetServiceClient = DatasetServiceClient.create(datasetServiceSettings)) {
            DatasetName datasetName = DatasetName.of(PROJECT, LOCATION, datasetId);
            OperationFuture<Empty, DeleteOperationMetadata> operationFuture = datasetServiceClient.deleteDatasetAsync(datasetName);
            operationFuture.get();
        }
    }
    System.out.flush();
    System.setOut(originalPrintStream);
}
Also used : Empty(com.google.protobuf.Empty) DatasetServiceSettings(com.google.cloud.aiplatform.v1beta1.DatasetServiceSettings) DatasetName(com.google.cloud.aiplatform.v1beta1.DatasetName) DeleteOperationMetadata(com.google.cloud.aiplatform.v1beta1.DeleteOperationMetadata) DatasetServiceClient(com.google.cloud.aiplatform.v1beta1.DatasetServiceClient) After(org.junit.After)

Aggregations

Empty (com.google.protobuf.Empty)13 DatasetName (com.google.cloud.aiplatform.v1.DatasetName)12 DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)9 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)9 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)8 ImportDataConfig (com.google.cloud.aiplatform.v1.ImportDataConfig)8 ImportDataOperationMetadata (com.google.cloud.aiplatform.v1.ImportDataOperationMetadata)8 ImportDataResponse (com.google.cloud.aiplatform.v1.ImportDataResponse)8 After (org.junit.After)7 DatasetName (com.google.cloud.aiplatform.v1beta1.DatasetName)5 DatasetServiceClient (com.google.cloud.aiplatform.v1beta1.DatasetServiceClient)5 DatasetServiceSettings (com.google.cloud.aiplatform.v1beta1.DatasetServiceSettings)5 DeleteOperationMetadata (com.google.cloud.aiplatform.v1beta1.DeleteOperationMetadata)5 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)5 DatasetName (com.google.cloud.automl.v1.DatasetName)5 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)5 DatasetName (com.google.cloud.automl.v1beta1.DatasetName)5 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)3 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)3 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)3