-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IA-4295] [IA-4327] Add Sam client to Leonardo, populate workspace ID #4757
Conversation
@@ -42,7 +42,8 @@ final case class ListPersistentDiskResponse(id: DiskId, | |||
size: DiskSize, | |||
diskType: DiskType, | |||
blockSize: BlockSize, | |||
labels: LabelMap | |||
labels: LabelMap, | |||
workspaceId: Option[WorkspaceId] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added optional workspaceId
to the v1 getDisk
and listDisks
API responses.
(It was already there for runtimes and apps)
* @param ev trace id | ||
* @return optional workspace ID | ||
*/ | ||
override def lookupWorkspaceParentForGoogleProject(userInfo: UserInfo, googleProject: GoogleProject)(implicit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is where it looks up the workspaceId from Sam. This code is shared for runtimes, disks, and apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, so for GCP, Rawls creates the workspace and then calls Sam to create the corresponding resource? So we are more or less guaranteed that the Sam resource has been created by the time Leo makes this call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that's correct, there should always be a workspace Sam resource for any Terra workspace in use today. Even so I tried to make this code handle errors and emit logs/metrics, just in case something goes wrong -- we don't want this code to cause runtime creation failures.
) | ||
) | ||
_ <- authProvider | ||
.notifyResourceCreated(samResource, userInfo.userEmail, googleProject) | ||
.handleErrorWith { t => | ||
log.error(t)( | ||
s"[${ctx.traceId}] Failed to notify the AuthProvider for creation of persistent disk ${disk.projectNameString}" | ||
) >> F.raiseError(t) | ||
) >> F.raiseError[Unit](t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's just me, but my Intellij flags this as a compile error -- adding the Unit
type param fixed
it. (Made similar changes in a couple other places.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, my IntelliJ never yelled at me for that, but it can't hurt, thanks for fixing :)
lastUsedApp, | ||
petSA, | ||
nodepool.id, | ||
req.workspaceId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note v1 apps actually have workspaceId
as an optional field in the request json. However not all clients are sending it (seems like AoU "allowed" apps are populating it, but not Galaxy). Also Leo does not validate this field, so theoretically a caller could provide any workspace ID at app creation time. For those reasons I'm switching it to the workspace ID retrieved from Sam from the google project (which is validated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, my main comment is around switching to the Sam client instead of the DAO if possible.
* @param ev trace id | ||
* @return optional workspace ID | ||
*/ | ||
override def lookupWorkspaceParentForGoogleProject(userInfo: UserInfo, googleProject: GoogleProject)(implicit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, so for GCP, Rawls creates the workspace and then calls Sam to create the corresponding resource? So we are more or less guaranteed that the Sam resource has been created by the time Leo makes this call?
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/auth/SamAuthProvider.scala
Outdated
Show resolved
Hide resolved
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/auth/SamAuthProvider.scala
Outdated
Show resolved
Hide resolved
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/HttpSamDAO.scala
Outdated
Show resolved
Hide resolved
) | ||
) | ||
_ <- authProvider | ||
.notifyResourceCreated(samResource, userInfo.userEmail, googleProject) | ||
.handleErrorWith { t => | ||
log.error(t)( | ||
s"[${ctx.traceId}] Failed to notify the AuthProvider for creation of persistent disk ${disk.projectNameString}" | ||
) >> F.raiseError(t) | ||
) >> F.raiseError[Unit](t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, my IntelliJ never yelled at me for that, but it can't hurt, thanks for fixing :)
Updated the description -- added the generated Sam client to Leo and started using it for certain things (though not access control decisions yet). Unit tests are all passing, will do more manual testing as a next step. |
...src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamApiClientProvider.scala
Show resolved
Hide resolved
...src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamApiClientProvider.scala
Outdated
Show resolved
Hide resolved
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamException.scala
Outdated
Show resolved
Hide resolved
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamServiceInterp.scala
Show resolved
Hide resolved
http/src/main/scala/org/broadinstitute/dsde/workbench/leonardo/dao/sam/SamServiceInterp.scala
Outdated
Show resolved
Hide resolved
...main/scala/org/broadinstitute/dsde/workbench/leonardo/http/service/LeoAppServiceInterp.scala
Outdated
Show resolved
Hide resolved
@LizBaldo no rush but I applied PR feedback, think it's ready for another look. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, so much cleaner. Thanks for addressing all of my comments!
*/ | ||
private def extractMessage(messagePrefix: String, apiException: ApiException): String = { | ||
// The generated ApiException class unfortunately formats getMessage(), and includes | ||
// the entire response body. We want to extract the actual message from that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 😨
Did some more smoke testing on a BEE (different runtime/app operations, cloud environments screen, jupyter/rstudio/galaxy). It looks good. Will merge this and keep an eye on things |
https://broadworkbench.atlassian.net/browse/IA-4327
https://broadworkbench.atlassian.net/browse/IA-4295
Summary of changes
This PR does a few things:
workspaceId
going forward for v1 runtimes, disks, and appssam-client
dependency to LeonardoSamApiClientProvider
andSamService
classes for interacting with Sam using the generated client. Deprecated[Http]SamDAO
and[Leo|Sam]AuthProvider
.PetClusterServiceAccountProvider
over toSamService
as a POC (read: logic for retrieving pets, proxy groups).Note: access control logic is not touched as part of this PR -- that will be a separate pull request.
Testing these changes
What to test
Who tested and where
jenkins retest
orjenkins multi-test
.