|
17 | 17 | package com.google.cloud.vision.samples.automl;
|
18 | 18 |
|
19 | 19 | // Imports the Google Cloud client library
|
| 20 | +import com.google.api.gax.longrunning.OperationFuture; |
20 | 21 | import com.google.cloud.automl.v1beta1.AutoMlClient;
|
21 | 22 | import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType;
|
22 | 23 | import com.google.cloud.automl.v1beta1.Dataset;
|
|
27 | 28 | import com.google.cloud.automl.v1beta1.InputConfig;
|
28 | 29 | import com.google.cloud.automl.v1beta1.ListDatasetsRequest;
|
29 | 30 | import com.google.cloud.automl.v1beta1.LocationName;
|
| 31 | +import com.google.cloud.automl.v1beta1.OperationMetadata; |
30 | 32 | import com.google.cloud.automl.v1beta1.OutputConfig;
|
31 | 33 | import com.google.protobuf.Empty;
|
32 | 34 | import java.io.IOException;
|
33 | 35 | import java.util.concurrent.ExecutionException;
|
| 36 | +import java.util.concurrent.TimeUnit; |
| 37 | +import java.util.concurrent.TimeoutException; |
34 | 38 | import net.sourceforge.argparse4j.ArgumentParsers;
|
35 | 39 | import net.sourceforge.argparse4j.inf.ArgumentParser;
|
36 | 40 | import net.sourceforge.argparse4j.inf.ArgumentParserException;
|
@@ -211,9 +215,21 @@ static void importData(String projectId, String computeRegion, String datasetId,
|
211 | 215 | // Import data from the input URI
|
212 | 216 | InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
|
213 | 217 | System.out.println("Processing import...");
|
214 |
| - Empty response = client.importDataAsync(datasetFullId.toString(), inputConfig).get(); |
215 |
| - System.out.println(String.format("Dataset imported. %s", response)); |
216 |
| - } catch (IOException | InterruptedException | ExecutionException e) { |
| 218 | + |
| 219 | + // Start the import job |
| 220 | + OperationFuture<Empty, OperationMetadata> operation = |
| 221 | + client.importDataAsync(datasetFullId, inputConfig); |
| 222 | + |
| 223 | + // More info on gax longrunning Operation: |
| 224 | + // http://googleapis.github.io/gax-java/1.4.1/apidocs/com/google/api/gax/grpc/OperationFuture.html |
| 225 | + System.out.format("Operation name: %s%n", operation.getName()); |
| 226 | + |
| 227 | + // If you want to wait for the operation to finish, adjust the timeout appropriately. The |
| 228 | + // operation will still run if you choose not to wait for it to complete. You can check the |
| 229 | + // status of your operation using the operation's name. |
| 230 | + Empty response = operation.get(5, TimeUnit.MINUTES); |
| 231 | + System.out.format("Dataset imported. %s%n", response); |
| 232 | + } catch (IOException | InterruptedException | ExecutionException | TimeoutException e) { |
217 | 233 | e.printStackTrace();
|
218 | 234 | }
|
219 | 235 | }
|
|
0 commit comments