From ac964c1520690d976e06f1a4e708961fae8da4bf Mon Sep 17 00:00:00 2001 From: John Engelman Date: Tue, 31 Oct 2017 09:04:09 -0500 Subject: [PATCH] Add backoff and rety to GCP directory listings. (#202) --- .../google/GoogleDirectoryUserRolesProvider.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fiat-google-groups/src/main/java/com/netflix/spinnaker/fiat/roles/google/GoogleDirectoryUserRolesProvider.java b/fiat-google-groups/src/main/java/com/netflix/spinnaker/fiat/roles/google/GoogleDirectoryUserRolesProvider.java index 0ac03d23e..d2bbbbf7b 100644 --- a/fiat-google-groups/src/main/java/com/netflix/spinnaker/fiat/roles/google/GoogleDirectoryUserRolesProvider.java +++ b/fiat-google-groups/src/main/java/com/netflix/spinnaker/fiat/roles/google/GoogleDirectoryUserRolesProvider.java @@ -20,10 +20,14 @@ import com.google.api.client.googleapis.batch.BatchRequest; import com.google.api.client.googleapis.batch.json.JsonBatchCallback; import com.google.api.client.googleapis.json.GoogleJsonError; +import com.google.api.client.googleapis.json.GoogleJsonErrorContainer; +import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; import com.google.api.client.http.HttpHeaders; +import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.ExponentialBackOff; import com.google.api.services.admin.directory.Directory; import com.google.api.services.admin.directory.DirectoryScopes; import com.google.api.services.admin.directory.model.Group; @@ -114,11 +118,14 @@ public Map> multiLoadRoles(Collection userEmail try { GroupBatchCallback callback = new GroupBatchCallback().setEmailGroupsMap(emailGroupsMap) .setEmail(email); - service.groups() + HttpRequest request = service.groups() .list() .setDomain(config.getDomain()) .setUserKey(email) - .queue(batch, callback); + .buildHttpRequest(); + request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff())); + batch.queue(request, Groups.class, GoogleJsonErrorContainer.class, callback); + } catch (IOException ioe) { throw new RuntimeException(ioe); }