1818
1919// [START automl_list_models]
2020import com .google .cloud .automl .v1 .AutoMlClient ;
21+ import com .google .cloud .automl .v1 .AutoMlSettings ;
2122import com .google .cloud .automl .v1 .ListModelsRequest ;
2223import com .google .cloud .automl .v1 .LocationName ;
2324import com .google .cloud .automl .v1 .Model ;
2425import java .io .IOException ;
26+ import org .threeten .bp .Duration ;
2527
2628class ListModels {
2729
@@ -36,20 +38,33 @@ static void listModels(String projectId) throws IOException {
3638 // Initialize client that will be used to send requests. This client only needs to be created
3739 // once, and can be reused for multiple requests. After completing all of your requests, call
3840 // 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 )) {
4055 // A resource that represents Google Cloud Platform location.
4156 LocationName projectLocation = LocationName .of (projectId , "us-central1" );
4257
4358 // Create list models request.
44- ListModelsRequest listModlesRequest =
59+ ListModelsRequest listModelsRequest =
4560 ListModelsRequest .newBuilder ()
4661 .setParent (projectLocation .toString ())
4762 .setFilter ("" )
4863 .build ();
4964
5065 // List all the models available in the region by applying filter.
5166 System .out .println ("List of models:" );
52- for (Model model : client .listModels (listModlesRequest ).iterateAll ()) {
67+ for (Model model : client .listModels (listModelsRequest ).iterateAll ()) {
5368 // Display the model information.
5469 System .out .format ("Model name: %s\n " , model .getName ());
5570 // To get the model id, you have to parse it out of the `name` field. As models Ids are
0 commit comments