Skip to content

Commit

Permalink
[AN-225] Cromwell Google Batch API workspace setting (#3136)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-schu authored Nov 26, 2024
1 parent 1f24e53 commit 91f0574
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 56 deletions.
14 changes: 12 additions & 2 deletions core/src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5989,13 +5989,15 @@ components:
- GcpBucketSoftDelete
- GcpBucketRequesterPays
- SeparateSubmissionFinalOutputs
- UseCromwellGcpBatchBackend
config:
description: The configuration of the workspace setting
oneOf:
- $ref: '#/components/schemas/WorkspaceSettingGcpBucketLifecycleConfig'
- $ref: '#/components/schemas/WorkspaceSettingGcpBucketSoftDeleteConfig'
- $ref: '#/components/schemas/WorkspaceSettingGcpBucketRequesterPaysConfig'
- $ref: '#/components/schemas/WorkspaceSettingSeparateSubmissionFinalOutputs'
- $ref: '#/components/schemas/WorkspaceSettingSeparateSubmissionFinalOutputsConfig'
- $ref: '#/components/schemas/WorkspaceSettingUseCromwellGcpBatchBackendConfig'
WorkspaceSettingGcpBucketLifecycleConfig:
required:
- rules
Expand Down Expand Up @@ -6054,14 +6056,22 @@ components:
enabled:
type: boolean
description: Enabled status to set for requester pays
WorkspaceSettingSeparateSubmissionFinalOutputs:
WorkspaceSettingSeparateSubmissionFinalOutputsConfig:
required:
- enabled
type: object
properties:
enabled:
type: boolean
description: Whether submission final outputs should be separated from intermediate outputs
WorkspaceSettingUseCromwellGcpBatchBackendConfig:
required:
- enabled
type: object
properties:
enabled:
type: boolean
description: Whether workflows submitted to Cromwell should be run using Cromwell's GCP Batch backend
WorkspaceSubmissionStats:
required:
- runningSubmissionsCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import org.broadinstitute.dsde.rawls.model.WorkspaceJsonSupport.{
GcpBucketLifecycleConfigFormat,
GcpBucketRequesterPaysConfigFormat,
GcpBucketSoftDeleteConfigFormat,
SeparateSubmissionFinalOutputsConfigFormat
SeparateSubmissionFinalOutputsConfigFormat,
UseCromwellGcpBatchBackendConfigFormat
}
import org.broadinstitute.dsde.rawls.model.WorkspaceSettingConfig.{
GcpBucketLifecycleConfig,
GcpBucketRequesterPaysConfig,
GcpBucketSoftDeleteConfig,
SeparateSubmissionFinalOutputsConfig
SeparateSubmissionFinalOutputsConfig,
UseCromwellGcpBatchBackendConfig
}
import org.broadinstitute.dsde.rawls.model.WorkspaceSettingTypes.WorkspaceSettingType
import org.broadinstitute.dsde.rawls.model._
Expand Down Expand Up @@ -71,6 +73,10 @@ object WorkspaceSettingRecord {
SeparateSubmissionFinalOutputsSetting(
workspaceSettingRecord.config.parseJson.convertTo[SeparateSubmissionFinalOutputsConfig]
)
case WorkspaceSettingTypes.UseCromwellGcpBatchBackend =>
UseCromwellGcpBatchBackendSetting(
workspaceSettingRecord.config.parseJson.convertTo[UseCromwellGcpBatchBackendConfig]
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.broadinstitute.dsde.rawls.model.{
RawlsRequestContext,
SamWorkspaceActions,
SeparateSubmissionFinalOutputsSetting,
UseCromwellGcpBatchBackendSetting,
Workspace,
WorkspaceName,
WorkspaceSetting,
Expand Down Expand Up @@ -94,6 +95,7 @@ class WorkspaceSettingService(protected val ctx: RawlsRequestContext,
}
case GcpBucketRequesterPaysSetting(GcpBucketRequesterPaysConfig(_)) => None
case SeparateSubmissionFinalOutputsSetting(SeparateSubmissionFinalOutputsConfig(_)) => None
case UseCromwellGcpBatchBackendSetting(UseCromwellGcpBatchBackendConfig(_)) => None
}
}

Expand Down Expand Up @@ -158,11 +160,14 @@ class WorkspaceSettingService(protected val ctx: RawlsRequestContext,
case GcpBucketRequesterPaysSetting(GcpBucketRequesterPaysConfig(enabled)) =>
gcsDAO.setRequesterPays(workspace.bucketName, enabled, workspace.googleProjectId)

// SeparateSubmissionFinalOutputsSetting and UseCromwellGcpBatchBackendSetting are not bucket settings,
// so we do not need to apply anything here

case SeparateSubmissionFinalOutputsSetting(SeparateSubmissionFinalOutputsConfig(_)) =>
// SeparateSubmissionFinalOutputsSetting is not a bucket setting, so we don't need to apply anything here
Future.successful(())

case _ => throw new RawlsException("unsupported workspace setting")
case UseCromwellGcpBatchBackendSetting(UseCromwellGcpBatchBackendConfig(_)) =>
Future.successful(())
}

validateSettings(workspaceSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import org.broadinstitute.dsde.rawls.model.WorkspaceSettingConfig.{
GcpBucketLifecycleConfig,
GcpBucketLifecycleRule,
GcpBucketRequesterPaysConfig,
GcpBucketSoftDeleteConfig
GcpBucketSoftDeleteConfig,
SeparateSubmissionFinalOutputsConfig,
UseCromwellGcpBatchBackendConfig
}
import org.broadinstitute.dsde.rawls.model.WorkspaceSettingTypes.GcpBucketSoftDelete
import org.broadinstitute.dsde.rawls.model.{
GcpBucketLifecycleSetting,
GcpBucketRequesterPaysSetting,
GcpBucketSoftDeleteSetting,
SeparateSubmissionFinalOutputsSetting,
UseCromwellGcpBatchBackendSetting,
Workspace,
WorkspaceSetting,
WorkspaceSettingTypes
}
import org.joda.time.DateTime
Expand Down Expand Up @@ -99,6 +102,46 @@ class WorkspaceSettingRepositorySpec
assertResult(result)(List(appliedSetting))
}

// Helps ensure that WorkspaceSettingRecord.toWorkspaceSetting in WorkspaceSettingComponent.scala
// is able to successfully create every type of workspace setting from a corresponding record
for {
workspaceSetting <- List(
GcpBucketLifecycleSetting(GcpBucketLifecycleConfig(List())),
GcpBucketSoftDeleteSetting(GcpBucketSoftDeleteConfig(0)),
GcpBucketRequesterPaysSetting(GcpBucketRequesterPaysConfig(true)),
SeparateSubmissionFinalOutputsSetting(SeparateSubmissionFinalOutputsConfig(true)),
UseCromwellGcpBatchBackendSetting(UseCromwellGcpBatchBackendConfig(true))
)
}
it should s"be able to get a ${workspaceSetting.getClass.getSimpleName}" in {
val repo = new WorkspaceSettingRepository(slickDataSource)
val workspaceRepo = new WorkspaceRepository(slickDataSource)
val ws: Workspace = makeWorkspace()
Await.result(workspaceRepo.createWorkspace(ws), Duration.Inf)

Await.result(
slickDataSource.inTransaction { dataAccess =>
for {
_ <- dataAccess.workspaceSettingQuery.saveAll(ws.workspaceIdAsUUID,
List(workspaceSetting),
userInfo.userSubjectId
)
_ <- dataAccess.workspaceSettingQuery.updateSettingStatus(
ws.workspaceIdAsUUID,
workspaceSetting.settingType,
WorkspaceSettingRecord.SettingStatus.Pending,
WorkspaceSettingRecord.SettingStatus.Applied
)
} yield ()
},
Duration.Inf
)

val result = Await.result(repo.getWorkspaceSettings(ws.workspaceIdAsUUID), Duration.Inf)

assertResult(result)(List(workspaceSetting))
}

behavior of "getWorkspacesSettingsOfType"

it should "return applied soft delete setting when soft delete type is requested" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import org.broadinstitute.dsde.rawls.model.WorkspaceSettingConfig.{
GcpBucketLifecycleRule,
GcpBucketRequesterPaysConfig,
GcpBucketSoftDeleteConfig,
SeparateSubmissionFinalOutputsConfig
SeparateSubmissionFinalOutputsConfig,
UseCromwellGcpBatchBackendConfig
}
import org.broadinstitute.dsde.rawls.model.{
ErrorReport,
Expand All @@ -27,6 +28,7 @@ import org.broadinstitute.dsde.rawls.model.{
SamUserStatusResponse,
SamWorkspaceActions,
SeparateSubmissionFinalOutputsSetting,
UseCromwellGcpBatchBackendSetting,
UserInfo,
Workspace,
WorkspaceSettingTypes
Expand Down Expand Up @@ -184,7 +186,8 @@ class WorkspaceSettingServiceUnitTests extends AnyFlatSpec with MockitoTestUtils
GcpBucketLifecycleSetting(GcpBucketLifecycleConfig(List.empty)),
GcpBucketSoftDeleteSetting(GcpBucketSoftDeleteConfig(7.days.toSeconds)),
GcpBucketRequesterPaysSetting(GcpBucketRequesterPaysConfig(true)),
SeparateSubmissionFinalOutputsSetting(SeparateSubmissionFinalOutputsConfig(true))
SeparateSubmissionFinalOutputsSetting(SeparateSubmissionFinalOutputsConfig(true)),
UseCromwellGcpBatchBackendSetting(UseCromwellGcpBatchBackendConfig(true))
)

val workspaceRepository = mock[WorkspaceRepository]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import org.broadinstitute.dsde.rawls.model.WorkspaceSettingConfig.{
GcpBucketLifecycleRule,
GcpBucketRequesterPaysConfig,
GcpBucketSoftDeleteConfig,
SeparateSubmissionFinalOutputsConfig
SeparateSubmissionFinalOutputsConfig,
UseCromwellGcpBatchBackendConfig
}
import org.broadinstitute.dsde.rawls.model.WorkspaceSettingTypes.{
GcpBucketLifecycle,
GcpBucketRequesterPays,
GcpBucketSoftDelete,
SeparateSubmissionFinalOutputs,
UseCromwellGcpBatchBackend,
WorkspaceSettingType
}
import org.broadinstitute.dsde.rawls.model.WorkspaceState.WorkspaceState
Expand Down Expand Up @@ -591,6 +593,9 @@ case class GcpBucketRequesterPaysSetting(override val config: GcpBucketRequester
case class SeparateSubmissionFinalOutputsSetting(override val config: SeparateSubmissionFinalOutputsConfig)
extends WorkspaceSetting(settingType = WorkspaceSettingTypes.SeparateSubmissionFinalOutputs, config)

case class UseCromwellGcpBatchBackendSetting(override val config: UseCromwellGcpBatchBackendConfig)
extends WorkspaceSetting(settingType = WorkspaceSettingTypes.UseCromwellGcpBatchBackend, config)

object WorkspaceSettingTypes {
sealed trait WorkspaceSettingType extends RawlsEnumeration[WorkspaceSettingType] {
override def toString: String = getClass.getSimpleName.stripSuffix("$")
Expand All @@ -602,6 +607,7 @@ object WorkspaceSettingTypes {
case "gcpbucketsoftdelete" => GcpBucketSoftDelete
case "gcpbucketrequesterpays" => GcpBucketRequesterPays
case "separatesubmissionfinaloutputs" => SeparateSubmissionFinalOutputs
case "usecromwellgcpbatchbackend" => UseCromwellGcpBatchBackend
case _ => throw new RawlsException(s"invalid WorkspaceSetting [$name]")
}

Expand All @@ -612,6 +618,8 @@ object WorkspaceSettingTypes {
case object GcpBucketRequesterPays extends WorkspaceSettingType

case object SeparateSubmissionFinalOutputs extends WorkspaceSettingType

case object UseCromwellGcpBatchBackend extends WorkspaceSettingType
}

sealed trait WorkspaceSettingConfig
Expand All @@ -629,6 +637,8 @@ object WorkspaceSettingConfig {
case class GcpBucketRequesterPaysConfig(enabled: Boolean) extends WorkspaceSettingConfig

case class SeparateSubmissionFinalOutputsConfig(enabled: Boolean) extends WorkspaceSettingConfig

case class UseCromwellGcpBatchBackendConfig(enabled: Boolean) extends WorkspaceSettingConfig
}

case class WorkspaceSettingResponse(successes: List[WorkspaceSetting], failures: Map[WorkspaceSettingType, ErrorReport])
Expand Down Expand Up @@ -1261,6 +1271,9 @@ class WorkspaceJsonSupport extends JsonSupport {
jsonFormat1(
SeparateSubmissionFinalOutputsConfig.apply
)
implicit val UseCromwellGcpBatchBackendConfigFormat: RootJsonFormat[UseCromwellGcpBatchBackendConfig] = jsonFormat1(
UseCromwellGcpBatchBackendConfig.apply
)

implicit object WorkspaceSettingTypeFormat extends RootJsonFormat[WorkspaceSettingType] {
override def write(obj: WorkspaceSettingType): JsValue = JsString(obj.toString)
Expand All @@ -1277,6 +1290,7 @@ class WorkspaceJsonSupport extends JsonSupport {
case config: GcpBucketSoftDeleteConfig => config.toJson
case config: GcpBucketRequesterPaysConfig => config.toJson
case config: SeparateSubmissionFinalOutputsConfig => config.toJson
case config: UseCromwellGcpBatchBackendConfig => config.toJson
}

// We prevent reading WorkspaceSettingConfig directly because we need
Expand All @@ -1302,7 +1316,8 @@ class WorkspaceJsonSupport extends JsonSupport {
GcpBucketRequesterPaysSetting(fields("config").convertTo[GcpBucketRequesterPaysConfig])
case SeparateSubmissionFinalOutputs =>
SeparateSubmissionFinalOutputsSetting(fields("config").convertTo[SeparateSubmissionFinalOutputsConfig])
case _ => throw DeserializationException(s"unexpected setting type $settingType")
case UseCromwellGcpBatchBackend =>
UseCromwellGcpBatchBackendSetting(fields("config").convertTo[UseCromwellGcpBatchBackendConfig])
}
}
}
Expand Down
Loading

0 comments on commit 91f0574

Please sign in to comment.