Class: Orch::Application

Inherits:
Thor
  • Object
show all
Defined in:
lib/orch.rb

Instance Method Summary collapse

Instance Method Details

#configObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/orch.rb', line 16

def config
  $ORCH_CONFIG = Orch::Config.new(options)

  if File.file?("#{Dir.home}/.orch/config.yml")
    say "This will over-write your existing ~/.orch/config.yaml file", :yellow
    answer = yes? "Proceed?", :yellow
    if answer == false
      exit 0
    end
  end
  say("Enter values to construct a ~/.orch/config.yaml file")
  settings = {}
  settings["marathon_url"] = ask("Marathon URL: ")
  settings["chronos_url"] = ask("Chronos URL: ")
  settings["bamboo_url"] = ask("Bamboo URL: ")

  $ORCH_CONFIG.setup_config(settings)
end

#delete(file_name) ⇒ Object



151
152
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
# File 'lib/orch.rb', line 151

def delete(file_name)
  $ORCH_CONFIG = Orch::Config.new(options)
  parser = Orch::Parse.new(file_name, options)
  result = parser.parse(false)

  if result.length == 0
    puts "nothing found to delete"
  end

  marathon = Orch::Marathon.new(options)
  chronos = Orch::Chronos.new(options)
  bamboo = Orch::Bamboo.new(options)

  result.each do |app|
    if !app[:deploy]
      puts "skipping app: #{app[:name]}"
      next
    end
    puts "deleting #{app[:name]} from #{app[:type]}"
    if app[:type] == "Chronos"
      chronos.delete(app[:url], app[:name])
    end
    if app[:type] == "Marathon"
      marathon.delete(app[:url], app[:name])
      if app[:bamboo_spec]
        bamboo.delete(app[:url], app[:name])
      end
    end
  end
end

#deploy(file_name) ⇒ Object



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
# File 'lib/orch.rb', line 107

def deploy(file_name)
  $ORCH_CONFIG = Orch::Config.new(options)
  parser = Orch::Parse.new(file_name, options)
  result = parser.parse(false)

  if result.length == 0
    puts "nothing found to deploy"
  end

  marathon = Orch::Marathon.new(options)
  chronos = Orch::Chronos.new(options)
  bamboo = Orch::Bamboo.new(options)
  result.each do |app|
    if !app[:deploy]
      puts "skipping app: #{app[:name]}"
      next
    end
    puts "deploying #{app[:name]} to #{app[:type]}"
    #puts "#{app[:json]}"  - should I support show_json here as well?
    if app[:type] == "Chronos"
      chronos.deploy(app[:url], app[:json].to_json)
    end
    if app[:type] == "Marathon"
      marathon.deploy(app[:url], app[:name], app[:json].to_json)
      if app[:bamboo_spec]
        bamboo.deploy(app[:bamboo_url], app[:name], app[:bamboo_spec])
      end
    end
  end
end

#restart(file_name) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/orch.rb', line 191

def restart(file_name)
  $ORCH_CONFIG = Orch::Config.new(options)
  parser = Orch::Parse.new(file_name, options)
  result = parser.parse(false)

  if result.length == 0
    puts "nothing found to restart"
  end

  marathon = Orch::Marathon.new(options)
  result.each do |app|
    if !app[:deploy] || (app[:type] == "Chronos")
      puts "skipping app: #{app[:name]}"
      next
    end
    puts "restarting #{app[:name]} on #{app[:type]}"
    if app[:type] == "Marathon"
      marathon.restart(app[:url], app[:name])
    end
  end
end

#verify(file_name) ⇒ Object



52
53
54
55
56
57
58
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
# File 'lib/orch.rb', line 52

def verify(file_name)
  $ORCH_CONFIG = Orch::Config.new(options)
  parser = Orch::Parse.new(file_name, options)
  result = parser.parse(true)

  numToDeploy = 0
  result.each do |app|
    numToDeploy += 1 if app[:deploy] == true
  end
  puts "Number of configs found: #{result.length} - #{numToDeploy} would deploy"

  marathon = Orch::Marathon.new(options)
  chronos = Orch::Chronos.new(options)
  bamboo = Orch::Bamboo.new(options)
  result.each do |app|
    next if app[:deploy] == false
    printf "Name: %s, Type: %s", app[:name], app[:type]
    app[:env_vars].each do |key, value|
      printf ", %s: %s", key, value
    end
    printf "\n"
    if options[:show_json]
      pretty = JSON.pretty_generate(app[:json])
      puts "JSON: #{pretty}"
    end
    foundDiffs = false
    if (app[:type] == "Chronos") && (options[:server_verify] == true)
      foundDiffs = chronos.verify(app[:url], app[:json].to_json)
    end
    if (app[:type] == "Marathon") && (options[:server_verify] == true)
      foundDiffs = marathon.verify(app[:url], app[:json].to_json)
      if app[:bamboo_spec]
        bambooDiffs = bamboo.verify(app[:bamboo_url], app[:name], app[:bamboo_spec])
        foundDiffs = foundDiffs || bambooDiffs
      end
    end
    if (!foundDiffs) && (options[:server_verify] == true)
      puts "No differences with server found"
    end
  end
end