Skip to content

Commit

Permalink
Change domain classes to fix issue 56 [#56 state:resolved]
Browse files Browse the repository at this point in the history
Update domain classes to remove Workflow.scheduledExecution
bidirectionality; Add missing strategy property in Workflow
constructor for duplicating another Workflow; remove belongsTo
ScheduledExecution for Execution domain class.  Update controllers to
fix operational logic,  Update tests and legacy job support.
  • Loading branch information
gschueler committed Nov 1, 2010
1 parent d4729e6 commit 7a4c7f7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
Expand Up @@ -348,12 +348,21 @@ class ScheduledExecutionController {
def jobname = scheduledExecution.generateJobScheduledName()
def groupname = scheduledExecution.generateJobGroupName()
def jobtitle=scheduledExecution.jobName
scheduledExecution.delete()
scheduledExecutionService.deleteJob(jobname,groupname)
//unlink any Execution records
def torem=[]
def execs = scheduledExecution.executions
execs.each{Execution exec->
torem<<exec
}
torem.each{Execution exec->
scheduledExecution.removeFromExecutions(exec)
exec.scheduledExecution=null
}
scheduledExecution.delete(flush:true)
scheduledExecutionService.deleteJob(jobname,groupname)
flash.message = "Job '${jobtitle}' was successfully deleted."
redirect(controller:'menu',action:'list', params:[:])
}
else {
} else {
flash.message = "ScheduledExecution not found with id ${params.id}"
redirect(controller:'menu',action:'list', params:params)
}
Expand Down Expand Up @@ -581,13 +590,9 @@ class ScheduledExecutionController {
if(!wfitemfailed){
def oldwf=scheduledExecution.workflow
final Workflow newworkflow = new Workflow(wf)
newworkflow.scheduledExecution=scheduledExecution
scheduledExecution.workflow=newworkflow
if(oldwf){
def execs = Execution.findByWorkflow(oldwf)
if(!execs){
oldwf.delete()
}
}
wf.discard()
}else{
Expand Down Expand Up @@ -1251,7 +1256,6 @@ class ScheduledExecutionController {
}
if(!wfitemfailed){
final Workflow workflow = new Workflow(wf)
workflow.scheduledExecution=scheduledExecution
scheduledExecution.workflow=workflow
wf.discard()
}else{
Expand Down
2 changes: 0 additions & 2 deletions rundeckapp/grails-app/domain/Execution.groovy
Expand Up @@ -12,8 +12,6 @@ class Execution extends ExecutionContext {
String failedNodeList
boolean cancelled

static belongsTo = ScheduledExecution

static constraints = {
workflow(nullable:true)
argString(nullable:true)
Expand Down
3 changes: 1 addition & 2 deletions rundeckapp/grails-app/domain/Workflow.groovy
Expand Up @@ -33,9 +33,7 @@ public class Workflow {
List commands
String strategy="node-first"
static hasMany=[commands:CommandExec]
static belongsTo = [scheduledExecution:ScheduledExecution]
static constraints = {
scheduledExecution(nullable:true)
strategy(nullable:false, inList:['node-first','step-first'])
}
public String toString() {
Expand All @@ -49,6 +47,7 @@ public class Workflow {
public Workflow(Workflow source){
this.threadcount=source.threadcount
this.keepgoing=source.keepgoing
this.strategy=source.strategy
commands = new ArrayList()
source.commands.each {
commands.add(createItem(it))
Expand Down
10 changes: 10 additions & 0 deletions rundeckapp/grails-app/services/ExecutionService.groovy
Expand Up @@ -886,6 +886,11 @@ class ExecutionService implements ApplicationContextAware, Executor{
throw new ExecutionServiceException('Job "'+se.jobName+'" ['+se.id+'] is currently being executed (execution ['+found.id+'])')
}

//create duplicate workflow
if(se.workflow){
props.workflow=new Workflow(se.workflow)
}

def Execution execution = createExecution(props, framework)
se.addToExecutions(execution)
execution.scheduledExecution=se
Expand All @@ -908,6 +913,11 @@ class ExecutionService implements ApplicationContextAware, Executor{
}


if(execution.workflow && !execution.workflow.save(flush:true)){
execution.workflow.errors.allErrors.each { log.warn(it.defaultMessage) }
log.error("unable to save execution workflow")
throw new ExecutionServiceException("unable to create execution workflow")
}
if(!execution.save(flush:true)){
execution.errors.allErrors.each { log.warn(it.defaultMessage) }
log.error("unable to save execution")
Expand Down
Expand Up @@ -234,7 +234,7 @@ class ScheduledExecutionService {
def kprops=['argString','adhocLocalString','adhocRemoteString','adhocFilepath']
def props = se.properties.findAll{it.key=~/^(type|name|command|argString|adhocExecution|adhoc.*String|adhocFilepath)$/}
if(props){
def Workflow workflow = new Workflow(threadcount:1,keepgoing:true,scheduledExecution:se)
def Workflow workflow = new Workflow(threadcount:1,keepgoing:true)
def cexec
if(props.jobName){
cexec = new JobExec(props)
Expand Down
Expand Up @@ -2213,7 +2213,6 @@ public class ScheduledExecValidationTests extends GrailsUnitTestCase{
def workflow = new Workflow(threadcount:1,keepgoing:true)
def wfitem = new CommandExec(adhocExecution:true,adhocRemoteString:'test command',)
workflow.addToCommands(wfitem)
workflow.scheduledExecution=se
se.workflow=workflow
se.save()

Expand Down Expand Up @@ -2279,7 +2278,6 @@ public class ScheduledExecValidationTests extends GrailsUnitTestCase{
def workflow = new Workflow(threadcount:1,keepgoing:true)
def wfitem = new CommandExec(name: 'aResource', type: 'aType', command: 'aCommand')
workflow.addToCommands(wfitem)
workflow.scheduledExecution=se
se.workflow=workflow
se.save()

Expand Down Expand Up @@ -2338,7 +2336,6 @@ public class ScheduledExecValidationTests extends GrailsUnitTestCase{
def workflow = new Workflow(threadcount:1,keepgoing:true)
def wfitem = new CommandExec(name: 'aResource', type: 'aType', command: 'aCommand')
workflow.addToCommands(wfitem)
workflow.scheduledExecution=se
se.workflow=workflow
def opt1 = new Option(name: 'test1', defaultValue: 'val1', enforced: false, valuesUrl: "http://test.com/test")
def opt2 = new Option(name: 'test2', defaultValue: 'val2', enforced: true, values: ['a', 'b', 'c'])
Expand Down

0 comments on commit 7a4c7f7

Please sign in to comment.