Skip to content

Commit

Permalink
WX-1595 Port more tests from papi-common to the GCP Batch backend (#7413
Browse files Browse the repository at this point in the history
)

Co-authored-by: Adam Nichols <anichols@broadinstitute.org>
  • Loading branch information
AlexITC and aednichols committed May 15, 2024
1 parent 101dd32 commit 5d14beb
Show file tree
Hide file tree
Showing 6 changed files with 842 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package cromwell.backend.google.batch.models

import com.google.api.gax.retrying.RetrySettings
import com.google.auth.Credentials
import com.typesafe.config.Config
import cromwell.backend.google.batch.models.GcpBatchWorkflowPaths.callCachePathPrefixFromExecutionRoot
import cromwell.backend.google.batch.runnable.WorkflowOptionKeys
import cromwell.backend.io.WorkflowPaths
import cromwell.backend.{BackendJobDescriptorKey, BackendWorkflowDescriptor}
import cromwell.cloudsupport.gcp.gcs.GcsStorage
import cromwell.core.WorkflowOptions
import cromwell.core.path.Path
import cromwell.core.path.PathFactory.PathBuilders
import cromwell.filesystems.gcs.GcsPathBuilder

import scala.concurrent.ExecutionContext
import scala.language.postfixOps

object GcpBatchWorkflowPaths {
val GcsRootOptionKey = "gcp_batch_gcs_root"
private val AuthFilePathOptionKey = "auth_bucket"
private val GcsPrefix = "gs://"

private def callCachePathPrefixFromExecutionRoot(executionRoot: String): String =
private[models] def callCachePathPrefixFromExecutionRoot(executionRoot: String): String =
// If the root looks like gs://bucket/stuff-under-bucket this should return gs://bucket
GcsPrefix + executionRoot.substring(GcsPrefix.length).takeWhile(_ != '/')
}
Expand All @@ -46,34 +41,6 @@ case class GcpBatchWorkflowPaths(workflowDescriptor: BackendWorkflowDescriptor,

private val workflowOptions: WorkflowOptions = workflowDescriptor.workflowOptions

val gcsAuthFilePath: Path = {
// The default auth file bucket is always at the root of the root workflow
val defaultBucket = executionRoot
.resolve(workflowDescriptor.rootWorkflow.name)
.resolve(workflowDescriptor.rootWorkflowId.toString)
val bucket = workflowDescriptor.workflowOptions
.get(GcpBatchWorkflowPaths.AuthFilePathOptionKey) getOrElse defaultBucket.pathAsString

/*
* This is an "exception". The filesystem used here is built from batchAuth
* unlike everywhere else where the filesystem used is built from gcsFileSystemAuth
*/
val pathBuilderWithBatchAuth = GcsPathBuilder.fromCredentials(
batchCredentials,
gcpBatchConfiguration.googleConfig.applicationName,
RetrySettings.newBuilder().build(),
GcsStorage.DefaultCloudStorageConfiguration,
workflowOptions,
Option(gcpBatchConfiguration.batchAttributes.project)
)

val authBucket = pathBuilderWithBatchAuth.build(bucket) recover { case ex =>
throw new Exception(s"Invalid gcs auth_bucket path $bucket", ex)
} get

authBucket.resolve(s"${workflowDescriptor.rootWorkflowId}_auth.json")
}

val monitoringScriptPath: Option[Path] = workflowOptions.get(WorkflowOptionKeys.MonitoringScript).toOption map {
path =>
// Fail here if the path exists but can't be built
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"manifestFormatVersion": 2,
"dockerImageCacheMap": {
"project1/dockerImage1": {
"dockerImageDigest": "sha256:c73e11b1a7854f31ff12c607738bef7b0560a880dc9d0445dde084acc0e9da09",
"diskImageName": "projects/some-google-project/global/images/dockerCacheDiskForDockerImage1"
},
"project2/dockerImage2": {
"dockerImageDigest": "sha256:7eb386481d87e41ebddceb948f25379bb339784df5247a3dfbdea2ac101b10c0",
"diskImageName": "projects/another-google-project/global/images/dockerCacheDiskForDockerImage2"
}
}
}

0 comments on commit 5d14beb

Please sign in to comment.