use of com.google.cloud.automl.v1beta1.AutoMlSettings 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;
}
}
use of com.google.cloud.automl.v1beta1.AutoMlSettings in project java-automl by googleapis.
the class SetEndpoint method setEndpoint.
// Change your endpoint
static void setEndpoint(String projectId) throws IOException {
// [START automl_set_endpoint]
AutoMlSettings settings = AutoMlSettings.newBuilder().setEndpoint("eu-automl.googleapis.com:443").build();
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
AutoMlClient client = AutoMlClient.create(settings);
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, "eu");
// [END automl_set_endpoint]
ListDatasetsRequest request = ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).setFilter("translation_dataset_metadata:*").build();
// List all the datasets available
System.out.println("List of datasets:");
for (Dataset dataset : client.listDatasets(request).iterateAll()) {
System.out.println(dataset);
}
client.close();
}
Aggregations