Skip to content

Commit

Permalink
Do not try to delete Orchestrator if Executions are linked to it.
Browse files Browse the repository at this point in the history
Copy Orchestrator when job is executed so that correct historical data is maintained.
Fixes #5876.
  • Loading branch information
sjrd218 committed Mar 12, 2020
1 parent 6756add commit 6d93e96
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2274,14 +2274,16 @@ class ExecutionService implements ApplicationContextAware, StepExecutor, NodeSte
'workflow',
'argString',
'timeout',
'orchestrator',
'retry',
'retryDelay',
'excludeFilterUncheck'
]
propset.each{k->
props.put(k,se[k])
}
if(se.orchestrator) {
props["orchestrator"] = new Orchestrator(se.orchestrator.toMap())
}
props.user = authContext.username
def roles = authContext.roles
if (roles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,7 @@ class ScheduledExecutionService implements ApplicationContextAware, Initializing
orchestrator = parseParamOrchestrator(params)
}
if(scheduledExecution.id && scheduledExecution.orchestrator){
scheduledExecution.orchestrator.delete()
if(!hasExecutionsLinkedToOrchestrator(scheduledExecution.orchestrator)) scheduledExecution.orchestrator.delete() //cannot deleted this orchestrator if linked to executions
scheduledExecution.orchestrator=null
}
if (orchestrator) {
Expand All @@ -2969,6 +2969,10 @@ class ScheduledExecutionService implements ApplicationContextAware, Initializing
}
}

boolean hasExecutionsLinkedToOrchestrator(Orchestrator orchestrator) {
Execution.countByOrchestrator(orchestrator) > 0
}

public void jobDefinitionOptions(ScheduledExecution scheduledExecution, ScheduledExecution input,Map params, UserAndRoles userAndRoles) {
if(input){
deleteExistingOptions(scheduledExecution)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.dtolabs.rundeck.core.schedule.JobScheduleManager
import com.dtolabs.rundeck.plugins.jobs.ExecutionLifecyclePlugin
import org.apache.log4j.Logger
import org.springframework.context.ConfigurableApplicationContext
import rundeck.Orchestrator
import rundeck.ScheduledExecutionStats

import static org.junit.Assert.*
Expand Down Expand Up @@ -79,7 +80,7 @@ import spock.lang.Unroll
*/
@TestFor(ScheduledExecutionService)
@Mock([Workflow, ScheduledExecution, CommandExec, Notification, Option, PluginStep, JobExec,
WorkflowStep, Execution, ReferencedExecution, ScheduledExecutionStats])
WorkflowStep, Execution, ReferencedExecution, ScheduledExecutionStats, Orchestrator])
class ScheduledExecutionServiceSpec extends Specification {

public static final String TEST_UUID1 = 'BB27B7BB-4F13-44B7-B64B-D2435E2DD8C7'
Expand Down Expand Up @@ -4497,6 +4498,39 @@ class ScheduledExecutionServiceSpec extends Specification {

}

@Unroll
def "do not allow orchestrator that has an execution to be deleted hasLinkedExecutions: #hasExecutionsLinked"() {
setup:
Orchestrator orch = new Orchestrator(type: "rankTiered")
orch.save()
when:
Long orchId = orch.id
ScheduledExecution se = new ScheduledExecution(
createJobParams(
jobName: 'testJob',
groupPath: 'orch/group',
project: 'orchProject',
executionEnabled: true,
orchestrator: orch
)
)
se.save()

if (hasExecutionsLinked) {
Execution e = new Execution(scheduledExecution: se, orchestrator: orch, project:"orchProject", user:"auser")
e.save()
}
service.jobDefinitionOrchestrator(se,new ScheduledExecution(),[:],null)

then:
(Orchestrator.get(orchId) == null) == orchestratorDeleted

where:
hasExecutionsLinked | orchestratorDeleted
true | false
false | true

}
}

class TriggersExtenderImpl implements TriggersExtender {
Expand Down

0 comments on commit 6d93e96

Please sign in to comment.