canzea 0.1.68 → 0.1.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66118112f0f957613b280ca67f65bcebcb89d31b
4
- data.tar.gz: 31104a3cf3b7f25148772a5559eea102419b7e57
3
+ metadata.gz: 07dc4c1aadbd19f8106535b8325927e968cedc3c
4
+ data.tar.gz: e71d34bd52ad13fefd94cc246847ba5ff6627214
5
5
  SHA512:
6
- metadata.gz: 239141a64ec67686b4a18e11dd3284205534101fdeb70b3bd64e52fa06df1859bae7b848b9b451fcd412c2d13c3f550fe34a4f60064c345e445d8b6817561fcf
7
- data.tar.gz: bfeddf0f43d68def281f8b6d4a08c767d92a686edbf4b3f3fbbc9def120994530fe695b6e2f5580a05b0b1c5283b7122134bd909c7d720bce368ce872d9cbbc5
6
+ metadata.gz: 52331702b5d5882e6b4bf03c2d79c72aac8c4c233b35826da71a2d8f40b49b6511173ec3437a8592b16e3f72edf9deb4666d5771b65ac8da6ca449a777ca2eac
7
+ data.tar.gz: d8184297a9dfcece6d6114fdda76c790f76721fac4d0bfa9a7c2fcc29ca72d1f0612e30237a19ba94111799a34cf0d8aa028a597e96b955ec69adba8e496e9a8
@@ -1,3 +1,3 @@
1
1
  module Canzea
2
- VERSION = "0.1.68"
2
+ VERSION = "0.1.70"
3
3
  end
@@ -34,7 +34,7 @@ class AddEnv
34
34
 
35
35
  def injectEnvironmentVariables()
36
36
  extraConfig = Canzea::config[:catalog_location] + "/env.json"
37
- @log.info "Looking to read env.json"
37
+ @log.info "Looking at for env vars: #{extraConfig}"
38
38
  if File.exists?(extraConfig)
39
39
  puts "-- Reading #{extraConfig}"
40
40
  file = File.read(extraConfig)
@@ -13,27 +13,35 @@ class ApplyConfig
13
13
 
14
14
  # Read the configuration file and make calls out to run
15
15
 
16
- @log.info("Processing #{gitRoot}/configure.json")
17
- puts "Processing #{gitRoot}/configure.json"
16
+ log "Processing #{gitRoot}/configure.json"
17
+
18
18
  steps = JSON.parse(File.read("#{gitRoot}/configure.json"))
19
19
 
20
+ AddEnv.new.injectEnvironmentVariables()
21
+
20
22
  index = 1
21
23
  steps["steps"].each { | step |
22
24
 
23
- AddEnv.new.injectEnvironmentVariables()
25
+
26
+ ref = "Step #{index.to_s.rjust(2, "0")} / #{steps['steps'].length}"
24
27
 
25
28
  role = step['role']
26
29
  solution = step['solution']
27
- puts "#{stepNum} and #{index}"
30
+
28
31
  if (stepNum == nil or index >= Integer(stepNum))
29
- @log.info "[#{index}] Configure for #{role} and #{solution}"
30
- ps.runPhaseConfigure role, solution, test, (task == nil ? 1:task)
32
+ log " [#{ref}] Configure for #{role} and #{solution}"
33
+ ps.runPhaseConfigure role, solution, test, (task == nil ? 1:task), ref
31
34
  task = 1
32
35
  else
33
- @log.info "[#{index}] Configure for #{role} and #{solution} SKIP"
36
+ log " [#{ref}] Configure for #{role} and #{solution} SKIP"
34
37
  end
35
38
  index = index + 1
36
39
  }
37
40
  end
38
41
 
42
+ def log (msg)
43
+ puts msg
44
+ @log.info(msg)
45
+ end
46
+
39
47
  end
@@ -6,6 +6,7 @@ require 'canzea/config'
6
6
 
7
7
  class PreparePlan
8
8
  def initialize ()
9
+ @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
9
10
  @basePath = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}/catalog"
10
11
  end
11
12
 
@@ -13,12 +14,12 @@ class PreparePlan
13
14
  def do (blueprint, segment, step, test, privateKey, serverBase, serverNumber)
14
15
  planStep = PlanStep.new
15
16
 
16
- puts "Processing configure.json for #{segment} in #{blueprint} from #{@basePath}"
17
+ log "Processing configure.json for #{segment} in #{blueprint} from #{@basePath}"
17
18
 
18
19
  instructions = YAML.load_file("#{@basePath}/blueprints/#{blueprint}/instruction.yml")
19
20
  segment = instructions['instructions']['segments'][segment]
20
21
 
21
- puts segment['abbreviation']
22
+ log segment['abbreviation']
22
23
 
23
24
  index = 1
24
25
  segment['image'].each { |item|
@@ -26,12 +27,12 @@ class PreparePlan
26
27
  parts = item.split(':')
27
28
 
28
29
  if (index < Integer(step))
29
- puts "[#{index}] #{item} SKIPPING"
30
+ log "[#{index.to_s.rjust(2, "0")}] #{item} SKIPPING"
30
31
  else
31
- puts "[#{index}] #{item}"
32
+ log "[#{index.to_s.rjust(2, "0")}] #{item}"
32
33
  if (test == false)
33
34
  publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{serverBase}-#{serverNumber}.json")
34
- RemoteRun.new.do publicIp, privateKey, parts[1], parts[2]
35
+ RemoteRun.new.do publicIp, privateKey, parts[1], parts[2], index.to_s.rjust(2, "0")
35
36
  # Keep track of what we have done; parsing the response and looking at the JSON
36
37
  end
37
38
  end
@@ -40,4 +41,8 @@ class PreparePlan
40
41
  }
41
42
  end
42
43
 
44
+ def log (msg)
45
+ puts "-- #{msg}"
46
+ @log.info(msg)
47
+ end
43
48
  end
@@ -4,6 +4,10 @@ require "pathname"
4
4
  require "ssh-base-cmd-class"
5
5
 
6
6
  class RemoteInit
7
+ def initialize ()
8
+ @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
9
+ end
10
+
7
11
  def do (publicIp, privateKey)
8
12
  cmd1 = "yum -y install git"
9
13
 
@@ -20,15 +24,15 @@ class RemoteInit
20
24
 
21
25
  remote = RemoteCall.new
22
26
 
23
- remote.exec publicIp, privateKey, cmd1
24
- remote.exec publicIp, privateKey, cmd2
25
- remote.exec publicIp, privateKey, cmd3
26
- remote.exec publicIp, privateKey, cmd4
27
- remote.exec publicIp, privateKey, cmd5
28
- remote.exec publicIp, privateKey, cmd6
29
- remote.exec publicIp, privateKey, cmd7
30
- remote.exec publicIp, privateKey, cmd8
31
- remote.exec publicIp, privateKey, cmd9
27
+ remote.exec publicIp, privateKey, cmd1, "1-9"
28
+ remote.exec publicIp, privateKey, cmd2, "2-9"
29
+ remote.exec publicIp, privateKey, cmd3, "3-9"
30
+ remote.exec publicIp, privateKey, cmd4, "4-9"
31
+ remote.exec publicIp, privateKey, cmd5, "5-9"
32
+ remote.exec publicIp, privateKey, cmd6, "6-9"
33
+ remote.exec publicIp, privateKey, cmd7, "7-9"
34
+ remote.exec publicIp, privateKey, cmd8, "8-9"
35
+ remote.exec publicIp, privateKey, cmd9, "9-9"
32
36
  end
33
37
 
34
38
  end
@@ -4,8 +4,8 @@ require "pathname"
4
4
  require "ssh-base-cmd-class"
5
5
 
6
6
  class RemoteRun
7
- def do(publicIp, privateKey, role, solution)
7
+ def do(publicIp, privateKey, role, solution, ref="")
8
8
  remote = RemoteCall.new
9
- remote.exec publicIp, privateKey, "canzea --lifecycle=install --role=#{role} --solution=#{solution}"
9
+ remote.exec publicIp, privateKey, "canzea --lifecycle=install --role=#{role} --solution=#{solution}", ref
10
10
  end
11
11
  end
@@ -49,7 +49,7 @@ class PlanStep
49
49
  end
50
50
  end
51
51
 
52
- def runPhaseConfigure (role, solution, test, task)
52
+ def runPhaseConfigure (role, solution, test, task, ref="")
53
53
 
54
54
  plan = JSON.parse("{ \"plan\": [ { \"role\": \"#{role}\", \"solution\": \"#{solution}\" } ] }")
55
55
 
@@ -64,11 +64,10 @@ class PlanStep
64
64
  begin
65
65
 
66
66
  plan['plan'].each do |item|
67
- @log.info(item['solution'])
68
67
 
69
68
  root = "#{@basePath}/roles/#{item['role']}/#{item['solution']}"
70
69
  if File.exist?(root) == false
71
- puts "-- ERROR #{root} does not exist!"
70
+ log "-- ERROR #{root} does not exist!"
72
71
  raise "#{root} does not exist!"
73
72
  end
74
73
 
@@ -83,7 +82,7 @@ class PlanStep
83
82
  svc = md['services'][0]
84
83
 
85
84
  adef = {"listener"=>svc['listener'], "service"=>svc['name'], "tags"=>[ item['role'] ], "port"=>svc['port']}
86
- puts "-- Registering #{svc['name']}"
85
+ log "-- Registering #{svc['name']}"
87
86
  h = HelperRun.new
88
87
  h.run "consul", "register_service", JSON.generate(adef)
89
88
  end
@@ -99,23 +98,17 @@ class PlanStep
99
98
 
100
99
  cmd = "#{@basePath}/roles/#{item['role']}/#{item['solution']}/configure.sh"
101
100
  if File.exist?(cmd)
102
- lines = n.run cmd, start, lines - 1
103
-
104
- @log.info("#{ lines } lines read")
101
+ lines = n.run cmd, start, lines - 1, false, ref
105
102
  end
106
103
 
107
104
  cmd = "#{@basePath}/roles/#{item['role']}/#{item['solution']}/enable.sh"
108
105
  if File.exist?(cmd)
109
- lines = n.run cmd, start, lines - 1
110
-
111
- @log.info("#{ lines } lines read")
106
+ lines = n.run cmd, start, lines - 1, false, ref
112
107
  end
113
108
 
114
109
  cmd = "#{@basePath}/roles/#{item['role']}/#{item['solution']}/status.sh"
115
110
  if File.exist?(cmd)
116
- lines = n.run cmd, start, lines - 1, true
117
-
118
- @log.info("#{ lines } lines read")
111
+ lines = n.run cmd, start, lines - 1, true, ref
119
112
  end
120
113
 
121
114
  end
@@ -126,4 +119,10 @@ class PlanStep
126
119
  abort()
127
120
  end
128
121
  end
122
+
123
+ def log (msg)
124
+ puts msg
125
+ @log.info(msg)
126
+ end
127
+
129
128
  end
@@ -7,38 +7,54 @@ require 'openssl'
7
7
  require 'base64'
8
8
 
9
9
  class RemoteCall
10
- def exec (hostname, privateKey, cmd)
10
+ def initialize ()
11
+ @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
12
+ end
13
+
14
+ def exec (hostname, privateKey, cmd, ref = "")
11
15
 
12
16
  @username = "root"
13
17
 
14
- Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh|
18
+ @log.info(" R [#{ref}] COMMAND: #{cmd}")
15
19
 
16
- chan = ssh.open_channel do |channel|
17
- channel.request_pty
18
- channel.env("DIGITAL_OCEAN_API_KEY", ENV['DIGITAL_OCEAN_API_KEY'])
19
- channel.env("VAULT_TOKEN", ENV['VAULT_TOKEN'])
20
- channel.env("CONSUL_URL", ENV['CONSUL_URL'])
21
- channel.env("WORK_DIR", ENV['WORK_DIR'])
22
- channel.exec(cmd) do |ch, success|
23
- abort "could not execute command" unless success
24
-
25
- channel.on_data do |ch, data|
26
- puts data
27
- end
20
+ begin
21
+ Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh|
22
+
23
+ chan = ssh.open_channel do |channel|
24
+ channel.request_pty
25
+ channel.env("DIGITAL_OCEAN_API_KEY", ENV['DIGITAL_OCEAN_API_KEY'])
26
+ channel.env("VAULT_TOKEN", ENV['VAULT_TOKEN'])
27
+ channel.env("CONSUL_URL", ENV['CONSUL_URL'])
28
+ channel.env("WORK_DIR", ENV['WORK_DIR'])
29
+ channel.exec(cmd) do |ch, success|
30
+ abort "could not execute command" unless success
31
+
32
+ channel.on_data do |ch, data|
33
+ puts data
28
34
 
29
- channel.on_request("exit-status") do |ch, data|
30
- exit_code = data.read_long
31
- if (exit_code == 0)
32
- else
33
- abort()
35
+ data.sub(/\n/, '').scan(/.{1,80}/).each do | line |
36
+ @log.info(" R [#{ref}] STDOUT: #{line}")
37
+ end
38
+ end
39
+
40
+ channel.on_request("exit-status") do |ch, data|
41
+ exit_code = data.read_long
42
+ @log.info(" R [#{ref}] Exit status: #{exit_code}")
43
+ if (exit_code == 0)
44
+ else
45
+ abort()
46
+ end
34
47
  end
35
- end
36
48
 
37
- channel.on_close do |ch|
49
+ channel.on_close do |ch|
50
+ end
38
51
  end
39
52
  end
53
+ chan.wait
40
54
  end
41
- chan.wait
55
+ rescue
56
+ @log.info(" R ABORTED!")
57
+ raise
42
58
  end
43
59
  end
44
60
 
@@ -63,6 +79,8 @@ class RemoteCall
63
79
  @username = "root"
64
80
 
65
81
  puts "Uploading #{localFile} to #{remoteFile}"
82
+ @log.info(" R : Uploading to #{hostname}")
83
+ @log.info(" R : Uploading #{localFile} to #{remoteFile}")
66
84
  Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh|
67
85
  ssh.sftp.upload!(localFile, remoteFile)
68
86
  end
@@ -72,9 +90,13 @@ class RemoteCall
72
90
 
73
91
  @username = "root"
74
92
 
93
+ @log.info(" R : Getting from #{hostname}")
94
+ @log.info(" R : Getting file #{remoteFile}")
95
+
75
96
  Net::SSH.start(hostname, @username, :paranoid => false, :keys => [privateKey]) do |ssh|
76
97
  ssh.sftp.download!(remoteFile, localFile)
77
98
  end
99
+ @log.info(" R : Saved to #{localFile}")
78
100
  end
79
101
 
80
102
  end
@@ -25,25 +25,26 @@ end
25
25
  class Worker
26
26
  @test = false
27
27
 
28
+ def initialize ()
29
+ @log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
30
+ end
28
31
 
29
32
  def test (t)
30
33
  @test = t
31
34
  end
32
35
 
33
- def run(command, start, lines, statusIndicator = false )
36
+ def run(command, start, lines, statusIndicator = false, ref = "" )
34
37
  audit = Audit.new
35
38
 
36
- log = Logger.new(Canzea::config[:logging_root] + '/plans.log')
37
-
38
- log.info("HANDLING: " + command)
39
+ @log.info(" [#{ref}] HANDLING: " + command)
39
40
 
40
41
  File.foreach(command) { |l|
41
42
  if ( l.start_with?('## ') )
42
- log.info "#{lines + 1} Label: " + l
43
+ @log.info "#{lines + 1} Label: " + l
43
44
  elsif ( l.start_with?('#') )
44
45
  elsif ( /\S/ !~ l )
45
46
  elsif ( l.chomp.end_with?(".sh") && !l.chomp.end_with?(".atomic.sh") && !l.include?("cp ") && !l.include?("chmod") )
46
- log.info("#{lines + 1} RECURSE: " + l)
47
+ @log.info(" [#{ref}] RECURSE: " + l)
47
48
 
48
49
  workingDir = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}/catalog"
49
50
 
@@ -56,7 +57,7 @@ class Worker
56
57
  else
57
58
 
58
59
  if ( (lines + 1) < start )
59
- log.info("Skipping : #{lines + 1} #{l}")
60
+ @log.info(" [#{ref}] Skipping : #{lines + 1} #{l}")
60
61
  lines += 1
61
62
  next
62
63
  end
@@ -64,7 +65,7 @@ class Worker
64
65
 
65
66
  audit.start( "#{lines + 1 }", l.chomp)
66
67
 
67
- log.info("#{lines + 1} FOUND: " + l)
68
+ @log.info(" [#{ref}] #{(lines + 1).to_s.rjust(2, "0")} : " + l)
68
69
 
69
70
  if @test == false
70
71
  t1 = Time.now
@@ -102,9 +103,9 @@ class Worker
102
103
 
103
104
  puts "-- Exit Status = #{exit_status}"
104
105
 
105
- log.info("STDOUT #{output}")
106
+ @log.info("STDOUT #{output}")
106
107
 
107
- log.info("Exit Status = #{exit_status}")
108
+ @log.info("Exit Status = #{exit_status}")
108
109
 
109
110
  # if exit status is failure then exit right away
110
111
 
@@ -129,7 +130,7 @@ class Worker
129
130
  raise
130
131
  end
131
132
  else
132
- puts "-- TEST -- [#{lines + 1}] FOUND: " + l
133
+ puts "-- TEST [#{lines + 1}] FOUND: " + l
133
134
  end
134
135
 
135
136
  end
data/lib/trace-runner.rb CHANGED
@@ -32,8 +32,6 @@ class RunnerWorker
32
32
 
33
33
  audit.start( "#{lines + 1 }", l.chomp)
34
34
 
35
- log.info("#{lines + 1} FOUND: " + l)
36
-
37
35
  t1 = Time.now
38
36
 
39
37
  workingDir = Canzea::config[:pwd]
@@ -57,22 +55,25 @@ class RunnerWorker
57
55
 
58
56
  log_w.close_write
59
57
 
58
+ t2 = Time.now
59
+ msecs = time_diff_milli t1, t2
60
+
60
61
  output = log_w.string
61
62
 
62
- output.split(/\n/).each do | line |
63
- puts "-- #{line}"
63
+ output.scan(/.{1,80}/).each do | line |
64
+ log.info("STDOUT: #{line}")
64
65
  end
65
- puts "-- Exit Status = #{exit_status}"
66
-
67
- log.info("STDOUT #{output}")
68
66
 
69
67
  log.info("Exit Status = #{exit_status}")
68
+ log.info("Completed in (ms) : #{msecs}")
70
69
 
71
- # if exit status is failure then exit right away
70
+ puts "-- Exit Status = #{exit_status}"
71
+ output.split(/\n/).each do | line |
72
+ puts "-- #{line}"
73
+ end
72
74
 
73
- t2 = Time.now
74
75
 
75
- msecs = time_diff_milli t1, t2
76
+ # if exit status is failure then exit right away
76
77
 
77
78
  audit.complete("#{lines + 1}", l.chomp, exit_status.exitstatus, msecs, output)
78
79
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canzea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.68
4
+ version: 0.1.70
5
5
  platform: ruby
6
6
  authors:
7
7
  - Canzea Technologies
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler