task-orchestrator 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,26 @@ orchestrator:
3
3
  interpolation:
4
4
  description: command interpolation test
5
5
  save: true
6
+ defaults:
7
+ args:
8
+ arg1: zopa
9
+ arg2: popa
10
+ arg3:
11
+ cmd: ":::EXEC.date:::"
12
+ envs:
13
+ DNS: google.com
14
+ DHCP:
15
+ CMD: ":::EXEC.date:::"
6
16
  steps:
7
17
  - type: sequential
8
18
  scripts:
9
- - command: "echo :::ARG.name:::"
10
- - command: "echo :::ARG.arg1:::"
11
- - command: "echo :::ARG.arg2:::"
12
- - command: "echo :::ENV.DNS:::"
13
- - command: "echo :::EXEC.date:::"
14
- - command: "echo :::EXEC./bin/date +%s:::"
15
- # - command: "echo :::EXEC./dasdfsd:::"
19
+ - command: "echo name is :::ARG.name:::"
20
+ - command: "echo arg1 is :::ARG.arg1:::"
21
+ - command: "echo arg2 is :::ARG.arg2:::"
22
+ - command: "echo arg3 is :::ARG.arg3:::"
23
+ - command: "echo arg3 is :::ARG.cmd:::"
24
+ - command: "echo DNS is :::ENV.DNS:::"
25
+ - command: "echo DHCP is :::ENV.DHCP:::"
26
+ - command: "echo DATE is :::ENV.CMD:::"
27
+ - command: "echo DATE is :::EXEC.date:::"
28
+ - command: "echo UNIX_TIMESTAMP is :::EXEC./bin/date +%s:::"
@@ -16,6 +16,10 @@ module Orchestrator
16
16
 
17
17
  @options = options
18
18
 
19
+ @defaults = {}
20
+ @defaults[:envs] = Object.new
21
+ @defaults[:args] = Object.new
22
+
19
23
  invalid("config file #{config} does not exists") unless File.exist?(@options.config)
20
24
 
21
25
  @settings = YAML.load_file(@options.config)
@@ -50,18 +54,20 @@ module Orchestrator
50
54
  end
51
55
  end
52
56
 
53
- def interpolate_command(command)
57
+ def interpolate_command(command,pattern=/^(ENV|ARG|EXEC)\./)
54
58
  command.gsub(/:::([^:]*):::/) do
55
59
  match = $1
60
+ invalid("interpolation type is not valid in this context - :::#{match}:::") if match !~ pattern and match =~ /^(ENV|ARG|EXEC)\./
61
+
56
62
  case match
57
63
  when /^ENV\./
58
64
  env = match["ENV.".length..-1]
59
- invalid("command interpolation failed no such env variable - #{env}") unless ENV[env]
60
- ENV[env]
65
+ invalid("command interpolation failed no such env variable - #{env}") if !ENV[env] and !@defaults[:envs].instance_variable_defined?("@#{env}")
66
+ ENV[env] ? ENV[env] : @defaults[:envs].instance_variable_get("@#{env}")
61
67
  when /^ARG\./
62
68
  arg = match["ARG.".length..-1]
63
- invalid("command interpolation failed no such arg - #{arg}") unless @options.args.instance_variable_defined?("@#{arg}".to_sym)
64
- @options.args.instance_variable_get("@#{arg}".to_sym)
69
+ invalid("command interpolation failed no such arg - #{arg}") if !@options.args.instance_variable_defined?("@#{arg}") and !@defaults[:args].instance_variable_defined?("@#{arg}")
70
+ @options.args.instance_variable_defined?("@#{arg}") ? @options.args.instance_variable_get("@#{arg}") : @defaults[:args].instance_variable_get("@#{arg}")
65
71
  when /^EXEC\./
66
72
  exec = match["EXEC.".length..-1]
67
73
  result = nil
@@ -105,6 +111,19 @@ module Orchestrator
105
111
  invalid("task sms recipients is missing") unless @state['sms'].has_key?('recipients') && @state['sms']['recipients'].is_a?(String) || @state['sms']['recipients'].is_a?(Array)
106
112
  invalid("task sms from is missing") unless @state['sms'].has_key?('from') && @state['sms']['from'].is_a?(String)
107
113
  end
114
+ if @state.has_key?('defaults')
115
+ invalid("defaults must be hash") unless @state['defaults'].is_a?(Hash)
116
+ [:envs, :args].each do |type|
117
+ if @state['defaults'].has_key?(type.to_s)
118
+ invalid("default envs must be hash") unless @state['defaults'][type.to_s].is_a?(Hash)
119
+ @state['defaults'][type.to_s].each do|key,value|
120
+ value = '' unless value
121
+ invalid("default value for #{type} #{key} is invalid") unless value.is_a?(String)
122
+ @defaults[type].instance_variable_set("@#{key}",interpolate_command(value,/^EXEC\./))
123
+ end
124
+ end
125
+ end
126
+ end
108
127
  invalid("task description is missing or invalid") unless @state.has_key?('description') && @state['description'].is_a?(String)
109
128
  invalid("task save must be boolean") if @state.has_key?('save') && !!@state['save'] != @state['save']
110
129
  @state['save'] = false unless @state.has_key?('save')
@@ -1,3 +1,3 @@
1
1
  module Orchestrator
2
- VERSION ||= '0.0.8'
2
+ VERSION ||= '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: task-orchestrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pony
@@ -85,16 +85,16 @@ extra_rdoc_files: []
85
85
  files:
86
86
  - bin/orchestrator
87
87
  - lib/orchestrator.rb
88
+ - lib/orchestrator/task.rb
88
89
  - lib/orchestrator/version.rb
89
90
  - lib/orchestrator/cli.rb
90
- - lib/orchestrator/task.rb
91
- - examples/timeouts
92
- - examples/interpolation
93
- - examples/dependencies
94
91
  - examples/sequential
95
92
  - examples/failure_handler
96
- - examples/parallel
97
93
  - examples/multistep
94
+ - examples/parallel
95
+ - examples/interpolation
96
+ - examples/timeouts
97
+ - examples/dependencies
98
98
  - task-orchestrator.gemspec
99
99
  - LICENSE
100
100
  - README.md