Skip to content

Commit 17d0b59

Browse files
Always set scheduler instance id to None when importing (#394)
1 parent 6c0e27f commit 17d0b59

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/scala/za/co/absa/hyperdrive/trigger/api/rest/services/WorkflowService.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ class WorkflowServiceImpl(override val workflowRepository: WorkflowRepository,
218218
}
219219

220220
private def convertToWorkflowJoineds(workflowImports: Seq[WorkflowImportExportWrapper])(implicit ec: ExecutionContext): Future[Seq[WorkflowJoined]] = {
221+
resolveJobTemplates(workflowImports)
222+
.map(resetSchedulerInstanceId)
223+
}
224+
225+
private def resolveJobTemplates(workflowImports: Seq[WorkflowImportExportWrapper])(implicit ec: ExecutionContext): Future[Seq[WorkflowJoined]] = {
221226
val jobTemplatesNames = workflowImports.flatMap(_.jobTemplates.map(_.name)).distinct
222227
jobTemplateService.getJobTemplateIdsByNames(jobTemplatesNames).flatMap {
223228
newNameIdMap =>
@@ -263,6 +268,10 @@ class WorkflowServiceImpl(override val workflowRepository: WorkflowRepository,
263268
}
264269
}
265270

271+
private def resetSchedulerInstanceId(workflowJoineds: Seq[WorkflowJoined]): Seq[WorkflowJoined] = {
272+
workflowJoineds.map(_.copy(schedulerInstanceId = None))
273+
}
274+
266275
private[services] def getUserName: () => String = {
267276
SecurityContextHolder.getContext.getAuthentication.getPrincipal.asInstanceOf[UserDetails].getUsername
268277
}

src/test/scala/za/co/absa/hyperdrive/trigger/api/rest/services/WorkflowServiceTest.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class WorkflowServiceTest extends AsyncFlatSpec with Matchers with MockitoSugar
284284

285285
"WorkflowService.importWorkflows" should "import workflows and return projects" in {
286286
// given
287-
val workflowJoined1 = WorkflowFixture.createWorkflowJoined().copy()
287+
val workflowJoined1 = WorkflowFixture.createWorkflowJoined().copy(schedulerInstanceId = Some(42))
288288
val workflowJoined2 = WorkflowFixture.createTimeBasedShellScriptWorkflow("project").copy()
289289
val jobTemplates1 = Seq(JobTemplateFixture.GenericSparkJobTemplate, JobTemplateFixture.GenericShellJobTemplate)
290290
val jobTemplates2 = Seq(JobTemplateFixture.GenericShellJobTemplate)
@@ -329,6 +329,7 @@ class WorkflowServiceTest extends AsyncFlatSpec with Matchers with MockitoSugar
329329
workflowsToInsert should have size workflowImports.size
330330
workflowsToInsert.map(_.name) should contain theSameElementsAs workflowImports.map(_.workflowJoined.name)
331331
workflowsToInsert.map(_.isActive) should contain only false
332+
workflowsToInsert.map(_.schedulerInstanceId) should contain only None
332333
}
333334

334335
it should "fail with all job template conversion errors" in {
@@ -417,7 +418,7 @@ class WorkflowServiceTest extends AsyncFlatSpec with Matchers with MockitoSugar
417418
}
418419

419420
"WorkflowService.convertToWorkflowJoined" should "match existing job templates by name and update job template ids" in {
420-
val workflowJoined = WorkflowFixture.createWorkflowJoined().copy()
421+
val workflowJoined = WorkflowFixture.createWorkflowJoined().copy(schedulerInstanceId = Some(98))
421422
val oldJobTemplates = Seq(JobTemplateFixture.GenericSparkJobTemplate, JobTemplateFixture.GenericShellJobTemplate)
422423
val workflowImport = WorkflowImportExportWrapper(workflowJoined, oldJobTemplates)
423424
val newJobTemplates = Seq(
@@ -431,6 +432,7 @@ class WorkflowServiceTest extends AsyncFlatSpec with Matchers with MockitoSugar
431432

432433
result.dagDefinitionJoined.jobDefinitions.head.jobTemplateId shouldBe 11
433434
result.dagDefinitionJoined.jobDefinitions(1).jobTemplateId shouldBe 12
435+
result.schedulerInstanceId shouldBe None
434436
}
435437

436438
it should "return an import error if the given job template doesn't exist" in {

0 commit comments

Comments
 (0)