Skip to content

Commit

Permalink
AJ-1749: disable import service dao for getJob (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb authored May 17, 2024
1 parent 8eb272a commit 0ce2e59
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,19 @@ class EntityService(rawlsDAO: RawlsDAO, importServiceDAO: ImportServiceDAO, cwds
Future.failed(new ApiException(StatusCodes.NotFound.intValue, s"Import $jobId not found"))
}

val importServiceFuture: () => Future[ImportServiceListResponse] = () => importServiceDAO.getJob(workspaceNamespace, workspaceName, jobId)(userInfo) map { importServiceResponse =>
logger.info(s"Found job $jobId in Import Service")
importServiceResponse
} recover { importServiceError =>
logger.info(s"Job $jobId not returned successfully by either cWDS or Import Service")
importServiceError match {
case fex: FireCloudExceptionWithErrorReport => throw fex
case t => throw new FireCloudExceptionWithErrorReport(ErrorReport(StatusCodes.InternalServerError, t))
val importServiceFuture: () => Future[ImportServiceListResponse] = () => if (importServiceDAO.isEnabled) {
importServiceDAO.getJob(workspaceNamespace, workspaceName, jobId)(userInfo) map { importServiceResponse =>
logger.info(s"Found job $jobId in Import Service")
importServiceResponse
} recover { importServiceError =>
logger.info(s"Job $jobId not returned successfully by either cWDS or Import Service")
importServiceError match {
case fex: FireCloudExceptionWithErrorReport => throw fex
case t => throw new FireCloudExceptionWithErrorReport(ErrorReport(StatusCodes.InternalServerError, t))
}
}
} else {
Future.failed(new FireCloudExceptionWithErrorReport(ErrorReport(StatusCodes.NotFound, s"Import $jobId not found")))
}

// if cWDS found the job, return it; else, try Import Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
when(cwdsDAO.getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(cwdsResponse)
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.failed(importServiceNotFound))

Expand All @@ -428,6 +429,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
doThrow(new ApiException(404, "unit test intentional error"))
.when(cwdsDAO).getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo])
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.successful(importServiceResponse))

Expand All @@ -451,6 +453,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
doThrow(new ApiException(500, "unit test intentional error"))
.when(cwdsDAO).getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo])
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.successful(importServiceResponse))

Expand All @@ -472,6 +475,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
doThrow(new ApiException(404, "cWDS unit test intentional error"))
.when(cwdsDAO).getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo])
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.failed(importServiceNotFound))

Expand All @@ -497,6 +501,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
doThrow(new ApiException(404, "cWDS unit test intentional error"))
.when(cwdsDAO).getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo])
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.failed(
new FireCloudExceptionWithErrorReport(
Expand Down Expand Up @@ -528,6 +533,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
when(cwdsDAO.isEnabled).thenReturn(true)
doThrow(new ApiException(500, "cWDS unit test intentional error"))
.when(cwdsDAO).getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo])
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.failed(
new FireCloudExceptionWithErrorReport(
Expand Down Expand Up @@ -560,6 +566,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
val mockRawlsDAO = mockito[MockRawlsDAO]

when(cwdsDAO.isEnabled).thenReturn(false)
when(importServiceDAO.isEnabled).thenReturn(true)
when(importServiceDAO.getJob(any[String], any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenReturn(Future.successful(importServiceResponse))

Expand All @@ -573,6 +580,32 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
verify(cwdsDAO, never).getJobV1(any[String], any[String])(any[UserInfo])
verify(mockRawlsDAO, never).getWorkspace(any[String], any[String])(any[UserInfo])
}

"should not call Import Service if it is not enabled" in {
val jobId = UUID.randomUUID().toString

val importServiceResponse = ImportServiceListResponse(jobId, "status1", "filename1", None)

// set up mocks
val cwdsDAO = mockito[MockCwdsDAO]
val importServiceDAO = mockito[MockImportServiceDAO]

when(cwdsDAO.isEnabled).thenReturn(true)
when(cwdsDAO.getJobV1(any[String], ArgumentMatchers.eq(jobId))(any[UserInfo]))
.thenThrow(new ApiException(404, "unit test intentional error"))
when(importServiceDAO.isEnabled).thenReturn(false)

// inject mocks to entity service
val entityService = getEntityService(mockImportServiceDAO = importServiceDAO, cwdsDAO = cwdsDAO)

// get job via entity service
val getJobFuture = entityService.getJob("workspaceNamespace", "workspaceName", jobId, dummyUserInfo("mytoken"))
val actual = getJobFuture.failed.futureValue
actual shouldBe a[FireCloudExceptionWithErrorReport]
actual.asInstanceOf[FireCloudExceptionWithErrorReport].errorReport.statusCode should contain(StatusCodes.NotFound)

verify(importServiceDAO, never).getJob(any[String], any[String], any[String])(any[UserInfo])
}
}

private def getEntityService(mockGoogleServicesDAO: MockGoogleServicesDAO = new MockGoogleServicesDAO,
Expand Down

0 comments on commit 0ce2e59

Please sign in to comment.