Skip to content

Commit

Permalink
Merge a5cc69f into e4cdd00
Browse files Browse the repository at this point in the history
  • Loading branch information
kcibul authored Aug 2, 2019
2 parents e4cdd00 + a5cc69f commit 924575c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Latest SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-metric

Contains utility functions for talking to Google APIs and DAOs for Google PubSub, Google Directory, Google IAM, and Google BigQuery.

Latest SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.20-a9f29eb"`
Latest SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.21-TRAVIS-REPLACE-ME"`

To depend on the `MockGoogle*` classes, additionally depend on:

`"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.20-a9f29eb" % "test" classifier "tests"`
`"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.21-TRAVIS-REPLACE-ME" % "test" classifier "tests"`

[Changelog](google/CHANGELOG.md)

Expand Down
12 changes: 12 additions & 0 deletions google/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

This file documents changes to the `workbench-google` library, including notes on how to upgrade to new versions.

## 0.21

SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.21-TRAVIS-REPLACE-ME"`

### Added

- A new whenGlobalUsageLimited predicate in `GoogleUtilities.RetryPredicates`

### Changed

- applied whenGlobalUsageLimited to createServiceAccountKey

## 0.20

SBT dependency: `"org.broadinstitute.dsde.workbench" %% "workbench-google" % "0.20-a9f29eb"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ object GoogleUtilities {
case _ => false
}

def whenGlobalUsageLimited(throwable: Throwable): Boolean = throwable match {
case t: GoogleJsonResponseException =>
(t.getStatusCode == 403 || t.getStatusCode == 429) && t.getDetails.getErrors.asScala.head.getDomain.equalsIgnoreCase("global")
case _ => false
}

def when404(throwable: Throwable): Boolean = throwable match {
case t: GoogleHttpResponseException => t.getStatusCode == 404
case _ => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class HttpGoogleIamDAO(appName: String,
val request = new CreateServiceAccountRequest().setAccountId(serviceAccountName.value)
.setServiceAccount(new ServiceAccount().setDisplayName(displayName.value))
val inserter = iam.projects().serviceAccounts().create(s"projects/${serviceAccountProject.value}", request)
retryWithRecover(when5xx, whenUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
retryWithRecover(when5xx, whenUsageLimited, whenGlobalUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
executeGoogleRequest(inserter)
} {
case t: GoogleJsonResponseException if t.getStatusCode == StatusCodes.NotFound.intValue => throw new WorkbenchException(s"The project [${serviceAccountProject.value}] was not found")
Expand All @@ -114,7 +114,7 @@ class HttpGoogleIamDAO(appName: String,
val serviceAccountEmail = toServiceAccountEmail(serviceAccountProject, serviceAccountName)
val name = s"projects/${serviceAccountProject.value}/serviceAccounts/${serviceAccountEmail.value}"
val deleter = iam.projects().serviceAccounts().delete(name)
retryWithRecover(when5xx, whenUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
retryWithRecover(when5xx, whenUsageLimited, whenGlobalUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
executeGoogleRequest(deleter)
()
} {
Expand Down Expand Up @@ -178,7 +178,7 @@ class HttpGoogleIamDAO(appName: String,
.setPrivateKeyType("TYPE_GOOGLE_CREDENTIALS_FILE")
.setKeyAlgorithm("KEY_ALG_RSA_2048")
val creater = iam.projects().serviceAccounts().keys().create(s"projects/${serviceAccountProject.value}/serviceAccounts/${serviceAccountEmail.value}", request)
retry(when5xx, whenUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
retry(when5xx, whenUsageLimited, whenGlobalUsageLimited, when404, whenInvalidValueOnBucketCreation, whenNonHttpIOException) { () =>
executeGoogleRequest(creater)
} map googleKeyToWorkbenchKey
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class GoogleUtilitiesSpec extends TestKit(ActorSystem("MySpec")) with GoogleUtil
whenUsageLimited(buildGoogleJsonResponseException(403, None, None, Some("usageLimits"))) shouldBe true
whenUsageLimited(buildGoogleJsonResponseException(429, None, None, Some("usageLimits"))) shouldBe true

whenGlobalUsageLimited(buildGoogleJsonResponseException(429, None, None, Some("global"))) shouldBe true

when404(buildGoogleJsonResponseException(404)) shouldBe true
when404(buildHttpResponseException(404)) shouldBe true

Expand All @@ -96,6 +98,11 @@ class GoogleUtilitiesSpec extends TestKit(ActorSystem("MySpec")) with GoogleUtil
whenUsageLimited(buildGoogleJsonResponseException(400)) shouldBe false
whenUsageLimited(new IOException("boom")) shouldBe false

whenGlobalUsageLimited(buildGoogleJsonResponseException(403, None, None, Some("boom"))) shouldBe false
whenGlobalUsageLimited(buildGoogleJsonResponseException(429, None, None, Some("boom"))) shouldBe false
whenGlobalUsageLimited(buildGoogleJsonResponseException(400)) shouldBe false
whenGlobalUsageLimited(new IOException("boom")) shouldBe false

when404(buildGoogleJsonResponseException(403)) shouldBe false
when404(buildHttpResponseException(403)) shouldBe false

Expand Down
2 changes: 1 addition & 1 deletion project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object Settings {
val googleSettings = only212 ++ commonSettings ++ List(
name := "workbench-google",
libraryDependencies ++= googleDependencies,
version := createVersion("0.20"),
version := createVersion("0.21"),
coverageExcludedPackages := ".*HttpGoogle.*DAO.*"
) ++ publishSettings

Expand Down

0 comments on commit 924575c

Please sign in to comment.