Skip to content

Commit

Permalink
optimized method to get workspaceId from Rawls
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb committed Nov 26, 2024
1 parent da8c046 commit d41c5c8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ class EntityService(rawlsDAO: RawlsDAO,
runningOnly: Boolean,
userInfo: UserInfo
): Future[List[CwdsListResponse]] =
rawlsDAO.getWorkspace(workspaceNamespace, workspaceName)(userInfo) map { workspace =>
cwdsDAO.listJobsV1(workspace.workspace.workspaceId, runningOnly)(userInfo)
rawlsDAO.getWorkspaceId(workspaceNamespace, workspaceName)(userInfo) map { workspaceId =>
cwdsDAO.listJobsV1(workspaceId.toString, runningOnly)(userInfo)
} recover { case apiEx: ApiException =>
throw wrapCwdsException(apiEx)
}
Expand All @@ -362,8 +362,8 @@ class EntityService(rawlsDAO: RawlsDAO,
jobId: String,
userInfo: UserInfo
): Future[CwdsListResponse] =
rawlsDAO.getWorkspace(workspaceNamespace, workspaceName)(userInfo) map { workspace =>
val cwdsResponse = cwdsDAO.getJobV1(workspace.workspace.workspaceId, jobId)(userInfo)
rawlsDAO.getWorkspaceId(workspaceNamespace, workspaceName)(userInfo) map { workspaceId =>
val cwdsResponse = cwdsDAO.getJobV1(workspaceId.toString, jobId)(userInfo)
logger.info(s"Found job $jobId in cWDS")
cwdsResponse
} recover { case apiEx: ApiException =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.broadinstitute.dsde.firecloud.dataaccess
import akka.actor.ActorSystem
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.model.Uri.Query
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.Materializer
Expand All @@ -28,6 +29,7 @@ import org.broadinstitute.dsde.workbench.util.health.SubsystemStatus
import spray.json.DefaultJsonProtocol._
import spray.json._

import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

Expand Down Expand Up @@ -91,6 +93,13 @@ class HttpRawlsDAO(implicit val system: ActorSystem,
override def getWorkspace(ns: String, name: String)(implicit userToken: WithAccessToken): Future[WorkspaceResponse] =
authedRequestToObject[WorkspaceResponse](Get(getWorkspaceUrl(ns, name)))

override def getWorkspaceId(ns: String, name: String)(implicit userToken: WithAccessToken): Future[UUID] = {
val targetUri = Uri(getWorkspaceUrl(ns, name)).withQuery(Query(("fields", "workspace.workspaceId")))
authedRequestToObject[WorkspaceIdResponse](Get(targetUri)) map { resp: WorkspaceIdResponse =>
resp.workspace.workspaceId
}
}

override def patchWorkspaceAttributes(ns: String, name: String, attributeOperations: Seq[AttributeUpdateOperation])(
implicit userToken: WithAccessToken
): Future[WorkspaceDetails] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.broadinstitute.dsde.rawls.model._
import org.broadinstitute.dsde.workbench.util.health.Subsystems
import org.broadinstitute.dsde.workbench.util.health.Subsystems.Subsystem

import java.util.UUID
import scala.concurrent.Future

/**
Expand Down Expand Up @@ -72,6 +73,8 @@ trait RawlsDAO extends LazyLogging with ReportsSubsystemStatus {

def getWorkspace(ns: String, name: String)(implicit userToken: WithAccessToken): Future[WorkspaceResponse]

def getWorkspaceId(ns: String, name: String)(implicit userToken: WithAccessToken): Future[UUID]

def patchWorkspaceAttributes(ns: String, name: String, attributes: Seq[AttributeUpdateOperation])(implicit
userToken: WithAccessToken
): Future[WorkspaceDetails]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,8 @@ object ModelJsonProtocol extends WorkspaceJsonSupport with SprayJsonSupport {
}

implicit val impShareFormat: RootJsonFormat[Share] = jsonFormat4(Share)

implicit val impWorkspaceIdFormat: RootJsonFormat[WorkspaceId] = jsonFormat1(WorkspaceId)
implicit val impWorkspaceIdResponseFormat: RootJsonFormat[WorkspaceIdResponse] = jsonFormat1(WorkspaceIdResponse)

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.broadinstitute.dsde.firecloud.model.OrchMethodRepository.AgoraConfigu
import org.broadinstitute.dsde.rawls.model._
import org.joda.time.DateTime

import java.util.UUID

case class UIWorkspaceResponse(accessLevel: Option[String] = None,
canShare: Option[Boolean] = None,
catalog: Option[Boolean] = None,
Expand Down Expand Up @@ -96,3 +98,6 @@ case class RawlsGroupMemberList(userEmails: Option[Seq[String]] = None,
)

case class WorkspaceStorageCostEstimate(estimate: String, lastUpdated: Option[DateTime])

case class WorkspaceId(workspaceId: UUID)
case class WorkspaceIdResponse(workspace: WorkspaceId)
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ class MockRawlsDAO extends RawlsDAO {
)
}

override def getWorkspaceId(ns: String, name: String)(implicit
userToken: WithAccessToken
): Future[UUID] =
getWorkspace(ns, name) map { workspaceResponse => UUID.fromString(workspaceResponse.workspace.workspaceId) }

override def getWorkspaces(implicit userInfo: WithAccessToken): Future[Seq[WorkspaceListResponse]] =
Future.successful(
Seq(
Expand Down

0 comments on commit d41c5c8

Please sign in to comment.