refactor: merge action handling blocks in play() functions
Merge the two separate if blocks for handling actions into a single block
since they both use the same logic for getting the name parameter with
get_default('name', 'default').
Changes:
- Combine destroy/install/build and start/stop/restart/lifecycle blocks
- All actions now use consistent name parameter handling
- Reduces code duplication in play() functions
Updated files:
- All 5 horus installer factory files
- Generator template objname_factory_.vtemplate
This commit is contained in:
@@ -169,7 +169,11 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
@if args.cat == .installer
|
@if args.cat == .installer
|
||||||
mut other_actions := plbook.find(filter: '${args.name}.')!
|
mut other_actions := plbook.find(filter: '${args.name}.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
|
@if args.startupmanager
|
||||||
|
if other_action.name in ["destroy","install","build","start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
|
||||||
|
@else
|
||||||
if other_action.name in ["destroy","install","build"]{
|
if other_action.name in ["destroy","install","build"]{
|
||||||
|
@end
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset:=p.get_default_false("reset")
|
reset:=p.get_default_false("reset")
|
||||||
@@ -188,13 +192,7 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug("install action ${args.name}.build")
|
console.print_debug("install action ${args.name}.build")
|
||||||
${args.name}_obj.build()!
|
${args.name}_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
@if args.startupmanager
|
||||||
@if args.startupmanager
|
|
||||||
if other_action.name in ["start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut ${args.name}_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n??{${args.name}_obj}")
|
|
||||||
if other_action.name == "start"{
|
if other_action.name == "start"{
|
||||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||||
${args.name}_obj.start()!
|
${args.name}_obj.start()!
|
||||||
@@ -223,8 +221,8 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||||
${args.name}_obj.stop_post()!
|
${args.name}_obj.stop_post()!
|
||||||
}
|
}
|
||||||
|
@end
|
||||||
}
|
}
|
||||||
@end
|
|
||||||
other_action.done = true
|
other_action.done = true
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ pub fn new(args ArgsGet) !&Coordinator {
|
|||||||
log_level: args.log_level
|
log_level: args.log_level
|
||||||
repo_path: args.repo_path
|
repo_path: args.repo_path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set in Redis, if it fails (Redis not available), use in-memory config
|
// Try to set in Redis, if it fails (Redis not available), use in-memory config
|
||||||
set(obj) or {
|
set(obj) or {
|
||||||
console.print_debug('Redis not available, using in-memory configuration')
|
console.print_debug('Redis not available, using in-memory configuration')
|
||||||
set_in_mem(obj)!
|
set_in_mem(obj)!
|
||||||
}
|
}
|
||||||
|
|
||||||
return get(name: args.name)!
|
return get(name: args.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,13 +154,13 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
mut other_actions := plbook.find(filter: 'coordinator.')!
|
mut other_actions := plbook.find(filter: 'coordinator.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
if other_action.name in ['destroy', 'install', 'build'] {
|
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset := p.get_default_false('reset')
|
reset := p.get_default_false('reset')
|
||||||
mut coordinator_obj := get(name: name)!
|
mut coordinator_obj := get(name: name)!
|
||||||
console.print_debug('action object:\n${coordinator_obj}')
|
console.print_debug('action object:\n${coordinator_obj}')
|
||||||
|
|
||||||
if other_action.name == 'destroy' || reset {
|
if other_action.name == 'destroy' || reset {
|
||||||
console.print_debug('install action coordinator.destroy')
|
console.print_debug('install action coordinator.destroy')
|
||||||
coordinator_obj.destroy()!
|
coordinator_obj.destroy()!
|
||||||
@@ -173,12 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug('install action coordinator.build')
|
console.print_debug('install action coordinator.build')
|
||||||
coordinator_obj.build()!
|
coordinator_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut coordinator_obj := get(name: name)!
|
|
||||||
console.print_debug('action object:\n${coordinator_obj}')
|
|
||||||
if other_action.name == 'start' {
|
if other_action.name == 'start' {
|
||||||
console.print_debug('install action coordinator.${other_action.name}')
|
console.print_debug('install action coordinator.${other_action.name}')
|
||||||
coordinator_obj.start()!
|
coordinator_obj.start()!
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
mut other_actions := plbook.find(filter: 'herorunner.')!
|
mut other_actions := plbook.find(filter: 'herorunner.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
if other_action.name in ['destroy', 'install', 'build'] {
|
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset := p.get_default_false('reset')
|
reset := p.get_default_false('reset')
|
||||||
@@ -161,12 +161,6 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug('install action herorunner.build')
|
console.print_debug('install action herorunner.build')
|
||||||
herorunner_obj.build()!
|
herorunner_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut herorunner_obj := get(name: name)!
|
|
||||||
console.print_debug('action object:\n${herorunner_obj}')
|
|
||||||
if other_action.name == 'start' {
|
if other_action.name == 'start' {
|
||||||
console.print_debug('install action herorunner.${other_action.name}')
|
console.print_debug('install action herorunner.${other_action.name}')
|
||||||
herorunner_obj.start()!
|
herorunner_obj.start()!
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
mut other_actions := plbook.find(filter: 'osirisrunner.')!
|
mut other_actions := plbook.find(filter: 'osirisrunner.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
if other_action.name in ['destroy', 'install', 'build'] {
|
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset := p.get_default_false('reset')
|
reset := p.get_default_false('reset')
|
||||||
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug('install action osirisrunner.build')
|
console.print_debug('install action osirisrunner.build')
|
||||||
osirisrunner_obj.build()!
|
osirisrunner_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut osirisrunner_obj := get(name: name)!
|
|
||||||
console.print_debug('action object:\n${osirisrunner_obj}')
|
|
||||||
if other_action.name == 'start' {
|
if other_action.name == 'start' {
|
||||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||||
osirisrunner_obj.start()!
|
osirisrunner_obj.start()!
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
mut other_actions := plbook.find(filter: 'salrunner.')!
|
mut other_actions := plbook.find(filter: 'salrunner.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
if other_action.name in ['destroy', 'install', 'build'] {
|
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset := p.get_default_false('reset')
|
reset := p.get_default_false('reset')
|
||||||
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug('install action salrunner.build')
|
console.print_debug('install action salrunner.build')
|
||||||
salrunner_obj.build()!
|
salrunner_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut salrunner_obj := get(name: name)!
|
|
||||||
console.print_debug('action object:\n${salrunner_obj}')
|
|
||||||
if other_action.name == 'start' {
|
if other_action.name == 'start' {
|
||||||
console.print_debug('install action salrunner.${other_action.name}')
|
console.print_debug('install action salrunner.${other_action.name}')
|
||||||
salrunner_obj.start()!
|
salrunner_obj.start()!
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
}
|
}
|
||||||
mut other_actions := plbook.find(filter: 'supervisor.')!
|
mut other_actions := plbook.find(filter: 'supervisor.')!
|
||||||
for mut other_action in other_actions {
|
for mut other_action in other_actions {
|
||||||
if other_action.name in ['destroy', 'install', 'build'] {
|
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get_default('name', 'default')!
|
name := p.get_default('name', 'default')!
|
||||||
reset := p.get_default_false('reset')
|
reset := p.get_default_false('reset')
|
||||||
@@ -167,12 +167,6 @@ pub fn play(mut plbook PlayBook) ! {
|
|||||||
console.print_debug('install action supervisor.build')
|
console.print_debug('install action supervisor.build')
|
||||||
supervisor_obj.build()!
|
supervisor_obj.build()!
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut supervisor_obj := get(name: name)!
|
|
||||||
console.print_debug('action object:\n${supervisor_obj}')
|
|
||||||
if other_action.name == 'start' {
|
if other_action.name == 'start' {
|
||||||
console.print_debug('install action supervisor.${other_action.name}')
|
console.print_debug('install action supervisor.${other_action.name}')
|
||||||
supervisor_obj.start()!
|
supervisor_obj.start()!
|
||||||
@@ -319,7 +313,6 @@ pub fn (mut self Supervisor) running() !bool {
|
|||||||
return self.running_check()!
|
return self.running_check()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// switch instance to be used for supervisor
|
// switch instance to be used for supervisor
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
supervisor_default = name
|
supervisor_default = name
|
||||||
|
|||||||
Reference in New Issue
Block a user