18
18
19
19
// [START automl_list_models]
20
20
import com .google .cloud .automl .v1 .AutoMlClient ;
21
+ import com .google .cloud .automl .v1 .AutoMlSettings ;
21
22
import com .google .cloud .automl .v1 .ListModelsRequest ;
22
23
import com .google .cloud .automl .v1 .LocationName ;
23
24
import com .google .cloud .automl .v1 .Model ;
24
25
import java .io .IOException ;
26
+ import org .threeten .bp .Duration ;
25
27
26
28
class ListModels {
27
29
@@ -36,20 +38,33 @@ static void listModels(String projectId) throws IOException {
36
38
// Initialize client that will be used to send requests. This client only needs to be created
37
39
// once, and can be reused for multiple requests. After completing all of your requests, call
38
40
// the "close" method on the client to safely clean up any remaining background resources.
39
- try (AutoMlClient client = AutoMlClient .create ()) {
41
+ AutoMlSettings .Builder autoMlSettingsBuilder = AutoMlSettings .newBuilder ();
42
+
43
+ autoMlSettingsBuilder
44
+ .listModelsSettings ()
45
+ .setRetrySettings (
46
+ autoMlSettingsBuilder
47
+ .listModelsSettings ()
48
+ .getRetrySettings ()
49
+ .toBuilder ()
50
+ .setTotalTimeout (Duration .ofSeconds (20 ))
51
+ .build ());
52
+ AutoMlSettings autoMlSettings = autoMlSettingsBuilder .build ();
53
+
54
+ try (AutoMlClient client = AutoMlClient .create (autoMlSettings )) {
40
55
// A resource that represents Google Cloud Platform location.
41
56
LocationName projectLocation = LocationName .of (projectId , "us-central1" );
42
57
43
58
// Create list models request.
44
- ListModelsRequest listModlesRequest =
59
+ ListModelsRequest listModelsRequest =
45
60
ListModelsRequest .newBuilder ()
46
61
.setParent (projectLocation .toString ())
47
62
.setFilter ("" )
48
63
.build ();
49
64
50
65
// List all the models available in the region by applying filter.
51
66
System .out .println ("List of models:" );
52
- for (Model model : client .listModels (listModlesRequest ).iterateAll ()) {
67
+ for (Model model : client .listModels (listModelsRequest ).iterateAll ()) {
53
68
// Display the model information.
54
69
System .out .format ("Model name: %s\n " , model .getName ());
55
70
// To get the model id, you have to parse it out of the `name` field. As models Ids are
0 commit comments