Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vkumra-broad committed Dec 4, 2017
1 parent e08b13e commit c7a8380
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LeonardoSpec extends FreeSpec with Matchers with Eventually with ParallelT
}

// creates a cluster and checks to see that it reaches the Running state
def createAndMonitor(googleProject: GoogleProject, clusterName: ClusterName, clusterRequest: ClusterRequest, clusterStatus:ClusterStatus = ClusterStatus.Running): Cluster = {
def createAndMonitor(googleProject: GoogleProject, clusterName: ClusterName, clusterRequest: ClusterRequest): Cluster = {
// Google doesn't seem to like simultaneous cluster creates. Add 0-30 sec jitter
Thread sleep Random.nextInt(30000)

Expand All @@ -89,8 +89,6 @@ class LeonardoSpec extends FreeSpec with Matchers with Eventually with ParallelT
clusterCheck(Leonardo.cluster.get(googleProject, clusterName), clusterRequest.labels, clusterName, Seq(ClusterStatus.Running, ClusterStatus.Error), clusterRequest.jupyterExtensionUri)
} (clusterPatience)

// now check that it didn't timeout or error
actualCluster.status shouldBe clusterStatus
actualCluster
}

Expand Down Expand Up @@ -131,7 +129,8 @@ class LeonardoSpec extends FreeSpec with Matchers with Eventually with ParallelT
val request = ClusterRequest(bucket, Map("foo" -> makeRandomId()))

val testResult: Try[T] = Try {
val cluster = createAndMonitor(googleProject, name, request, ClusterStatus.Running)
val cluster = createAndMonitor(googleProject, name, request)
cluster.status shouldBe ClusterStatus.Running
testCode(cluster)
}

Expand All @@ -141,10 +140,12 @@ class LeonardoSpec extends FreeSpec with Matchers with Eventually with ParallelT
}

def withNewErroredCluster[T](googleProject: GoogleProject)(testCode: Cluster => T): T = {
val name = ClusterName(s"automation-test-a${Random.alphanumeric.take(10).mkString.toLowerCase}z")
val request = ClusterRequest(bucket, Map("foo" -> Random.alphanumeric.take(10).mkString), Some(incorrectJupyterExtensionUri))
val name = ClusterName(s"automation-test-a${makeRandomId()}z")
val request = ClusterRequest(bucket, Map("foo" -> makeRandomId()), Some(incorrectJupyterExtensionUri))
val testResult: Try[T] = Try {
val cluster = createAndMonitor(googleProject, name, request, ClusterStatus.Error)
val cluster = createAndMonitor(googleProject, name, request)
// now check that it didn't timeout or error
cluster.status shouldBe ClusterStatus.Error
testCode(cluster)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class GoogleDataprocDAO(protected val dataprocConfig: DataprocConfig,
override def createCluster(googleProject: GoogleProject, clusterName: ClusterName, clusterRequest: ClusterRequest, initBucketName: GcsBucketName, serviceAccount: WorkbenchEmail)(implicit executionContext: ExecutionContext): Future[LeoCluster] = {
buildCluster(googleProject, clusterName, clusterRequest, initBucketName, clusterDefaultsConfig, serviceAccount).map { operation =>
//Make a Leo cluster from the Google operation details
LeoCluster.create(clusterRequest, clusterName, googleProject, getOperationUUID(operation), OperationName(operation.getName), serviceAccount, clusterDefaultsConfig, LeoClusterStatus.Creating)
LeoCluster.create(clusterRequest, clusterName, googleProject, getOperationUUID(operation), OperationName(operation.getName), serviceAccount, clusterDefaultsConfig)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ClusterStatus extends Enumeration {


object Cluster {
def create(clusterRequest: ClusterRequest, clusterName: ClusterName, googleProject: GoogleProject, googleId: UUID, operationName: OperationName, serviceAccount: WorkbenchEmail, clusterDefaultsConfig: ClusterDefaultsConfig, clusterStatus:ClusterStatus): Cluster = {
def create(clusterRequest: ClusterRequest, clusterName: ClusterName, googleProject: GoogleProject, googleId: UUID, operationName: OperationName, serviceAccount: WorkbenchEmail, clusterDefaultsConfig: ClusterDefaultsConfig): Cluster = {
Cluster(
clusterName = clusterName,
googleId = googleId,
Expand All @@ -93,7 +93,7 @@ object Cluster {
machineConfig = MachineConfig(clusterRequest.machineConfig, clusterDefaultsConfig),
clusterUrl = getClusterUrl(googleProject, clusterName),
operationName = operationName,
status = clusterStatus,
status = ClusterStatus.Creating,
hostIp = None,
createdDate = Instant.now(),
destroyedDate = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.dsde.workbench.leonardo.dao

import java.io.File
import java.net.URL
import java.time.Instant
import java.util.UUID

Expand Down Expand Up @@ -41,11 +42,11 @@ class MockGoogleDataprocDAO(protected val dataprocConfig: DataprocConfig, protec
if (clusterName == badClusterName) {
Future.failed(CallToGoogleApiFailedException(googleProject, clusterName.string, 500, "Bad Cluster!"))
} else if(clusterName == errorClusterName){
val cluster = Cluster.create(clusterRequest, clusterName, googleProject, googleID, OperationName("op-name"), serviceAccount, clusterDefaultsConfig, ClusterStatus.Error)
val cluster = Cluster(clusterName,googleID,googleProject,serviceAccount,clusterRequest.bucketPath,MachineConfig(clusterRequest.machineConfig,clusterDefaultsConfig),new URL("https://www.broadinstitute.org"),OperationName("op-name"),ClusterStatus.Error, None, Instant.now(),None,clusterRequest.labels,clusterRequest.jupyterExtensionUri)
clusters += clusterName -> cluster
Future.successful(cluster)
} else {
val cluster = Cluster.create(clusterRequest, clusterName, googleProject, googleID, OperationName("op-name"), serviceAccount, clusterDefaultsConfig, ClusterStatus.Creating)
val cluster = Cluster.create(clusterRequest, clusterName, googleProject, googleID, OperationName("op-name"), serviceAccount, clusterDefaultsConfig)
clusters += clusterName -> cluster
Future.successful(cluster)
}
Expand Down Expand Up @@ -96,7 +97,8 @@ class MockGoogleDataprocDAO(protected val dataprocConfig: DataprocConfig, protec

override def getClusterStatus(googleProject: GoogleProject, clusterName: ClusterName)(implicit executionContext: ExecutionContext): Future[ClusterStatus] = {
Future.successful {
if (clusters.contains(clusterName)) ClusterStatus.Running
if (clusters.contains(clusterName) && clusterName == errorClusterName) ClusterStatus.Error
else if(clusters.contains(clusterName)) ClusterStatus.Running
else ClusterStatus.Unknown
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,17 @@ class LeonardoServiceSpec extends TestKit(ActorSystem("leonardotest")) with Flat

it should "delete a cluster that has status Error" in isolatedDbTest {
// check that the cluster does not exist
gdDAO.clusters should not contain key (clusterName)
gdDAO.clusters should not contain key (gdDAO.errorClusterName)

// create the cluster
val clusterCreateResponse = leo.createCluster(defaultUserInfo, googleProject, gdDAO.errorClusterName, testClusterRequest).futureValue

// check that the cluster was created
gdDAO.clusters should contain key (gdDAO.errorClusterName)
gdDAO.clusters should contain key gdDAO.errorClusterName

// delete the cluster
val clusterDeleteResponse = leo.deleteCluster(googleProject, gdDAO.errorClusterName).futureValue

// the delete response should indicate 1 cluster was deleted
clusterDeleteResponse shouldEqual 1

Expand Down

0 comments on commit c7a8380

Please sign in to comment.