Class: PlanStep
- Inherits:
-
Object
- Object
- PlanStep
- Defined in:
- lib/plan-step-class.rb
Instance Method Summary collapse
-
#initialize ⇒ PlanStep
constructor
A new instance of PlanStep.
- #log(msg) ⇒ Object
- #runPhaseConfigure(role, solution, test, task, ref = "") ⇒ Object
- #runPhaseInstall(role, solution, test, task) ⇒ Object
- #runPhasePatch(commit, solution, test, task, ref = "") ⇒ Object
Constructor Details
Instance Method Details
#log(msg) ⇒ Object
205 206 207 208 |
# File 'lib/plan-step-class.rb', line 205 def log (msg) puts msg @log.info(msg) end |
#runPhaseConfigure(role, solution, test, task, ref = "") ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/plan-step-class.rb', line 59 def runPhaseConfigure (role, solution, test, task, ref="") plan = JSON.parse("{ \"plan\": [ { \"role\": \"#{role}\", \"solution\": \"#{solution}\" } ] }") ENV['ES_REF'] = ref; ENV['ES_ROLE'] = role; ENV['ES_SOLUTION'] = solution; n = Worker.new n.test ( test ) start = Integer(task) lines = 1 cmd = "undefined" begin plan['plan'].each do |item| root = "#{@basePath}/roles/#{item['role']}/#{item['solution']}" if File.exist?(root) == false root = "#{@basePath}/blocks/#{item['solution']}" if File.exist?(root) == false log "-- ERROR #{root} does not exist!" raise "#{root} does not exist!" end end if (test == false) # Register the service with Consul, if consul is ready # If metadata.json exists, then use the information to register cmd = "#{root}/metadata.json" if File.exist?(cmd) md = File.read(cmd) md = JSON.parse(md) if (md['services'].size() > 0) svc = md['services'][0] adef = { "listener"=>svc['listener'], "name" => "#{svc['name']}", "id" => "#{ENV['HOSTNAME']}-#{svc['name']}", "tags"=>[ item['role'] ], "port"=>svc['port'] } log "-- Registering #{svc['name']}" h = HelperRun.new false h.run "consul", "register_service", JSON.generate(adef) end end envScript = "#{root}/environment.json" if File.exist?(envScript) envPush = PrepareEnvironment.new false envPush.addToEnv "#{envScript}" end end cmd = "#{root}/configure.sh" if File.exist?(cmd) lines = n.run cmd, start, lines - 1, false, ref end cmd = "#{root}/enable.sh" if File.exist?(cmd) lines = n.run cmd, start, lines - 1, false, ref end cmd = "#{root}/status.sh" if File.exist?(cmd) lines = n.run cmd, start, lines - 1, true, ref end if ENV.has_key? "ECOSYSTEM_CONFIG_GIT" log "-- Writing data to ecosystem git" adef = { "ES_ROLE" => role, "ES_SOLUTION" => solution } h = HelperRun.new false h.run "ecosystem", "analyze-solution", JSON.generate(adef) end end rescue => exception @log.error(cmd) @log.error(exception.to_s) @log.error(exception.backtrace) abort() end end |
#runPhaseInstall(role, solution, test, task) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/plan-step-class.rb', line 15 def runPhaseInstall (role, solution, test, task) plan = JSON.parse("{ \"plan\": [ { \"role\": \"#{role}\", \"solution\": \"#{solution}\" } ] }") ENV['ES_ROLE'] = role; ENV['ES_SOLUTION'] = solution; n = Worker.new n.test ( test ) start = Integer(task) lines = 1 cmd = "undefined" begin plan['plan'].each do |item| @log.info(item['solution']) root = "#{@basePath}/roles/#{item['role']}/#{item['solution']}" if File.exist?(root) == false root = "#{@basePath}/blocks/#{item['solution']}" if File.exist?(root) == false puts "-- ERROR #{root} does not exist!" raise "#{root} does not exist!" end end cmd = "#{root}/install.sh" if File.exist?(cmd) lines = n.run cmd, start, lines - 1 @log.info "#{ lines } lines read" end end rescue => exception @log.error(cmd) @log.error(exception.to_s) @log.error(exception.backtrace) abort() end end |
#runPhasePatch(commit, solution, test, task, ref = "") ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/plan-step-class.rb', line 153 def runPhasePatch (commit, solution, test, task, ref="") plan = JSON.parse("{ \"plan\": [ { \"commit\": \"#{commit}\", \"solution\": \"#{solution}\" } ] }") ENV['ES_REF'] = ref; ENV['ES_ROLE'] = 'patch'; ENV['ES_SOLUTION'] = solution; n = Worker.new n.test ( test ) start = Integer(task) lines = 1 cmd = "undefined" # patches/<commit>/<solution> begin plan['plan'].each do |item| root = "#{@basePath}/patches/#{item['commit']}/#{item['solution']}" if File.exist?(root) == false log "-- WARNING #{root} does not exist" else if (test == false) envScript = "#{root}/environment.json" if File.exist?(envScript) envPush = PrepareEnvironment.new false envPush.addToEnv "#{envScript}" end end ENV.store('SCRIPT_PATH', root) cmd = "#{root}/patch.sh" if File.exist?(cmd) lines = n.run cmd, start, lines - 1, false, ref end end end rescue => exception @log.error(cmd) @log.error(exception.to_s) @log.error(exception.backtrace) abort() end end |