Class: Stackato::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/conan/stackato.rb

Constant Summary collapse

@@token_file =
File.join(Dir.tmpdir(), "token_#{Time.now.to_i}")

Instance Method Summary collapse

Constructor Details

#initialize(executable, target, dry_run = false) ⇒ Commands

Returns a new instance of Commands.



10
11
12
13
14
15
16
17
# File 'lib/conan/stackato.rb', line 10

def initialize(executable, target, dry_run=false)
  @executable = executable
  @target = target
  @dry_run = dry_run
  v = get_version
  puts(v)
  raise "Stackato 3.1.* required. Found #{v}" unless v =~ /3\.1\.[0-9]+/
end

Instance Method Details

#delete(app_name) ⇒ Object



75
76
77
78
# File 'lib/conan/stackato.rb', line 75

def delete(app_name)
  shell_cmd("delete", "--no-prompt #{app_name}", true)  #instead of ignore error- look for Found a problem with input "application": An application "tentacles-integ-sea2" does not exist in space 'MTN::kraken'. Please use a different value.

end

#get_versionObject



43
44
45
46
47
48
49
50
51
# File 'lib/conan/stackato.rb', line 43

def get_version    
  begin
    v, err, status = Open3.capture3("#{@executable} version")
    abort "Stackato error: #{err}" unless status.success?        
    v
  rescue Exception => e
    abort "Failed to invoke Stackato client: #{e}"
  end    
end

#login(username, password, space) ⇒ Object



53
54
55
# File 'lib/conan/stackato.rb', line 53

def (username, password, space)
  shell_cmd("login", "--space #{space} --password '#{password}' #{username}")
end

#map(app_name, url) ⇒ Object



84
85
86
# File 'lib/conan/stackato.rb', line 84

def map(app_name, url)
  shell_cmd("map", "#{app_name} #{url}")
end

#push(manifest, name, urls = [], no_start = false) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/conan/stackato.rb', line 57

def push(manifest, name, urls=[], no_start=false)
  # '--force-war-unpacking false' prevents clients 3.1.2 and newer from exploding our java application jars
  args = "--force-war-unpacking false --manifest #{manifest} --no-prompt --reset --timeout 5m --as #{name}"
  
  if no_start
    args << " --no-start"
  else
    args << " --force-start"
  end

  urls.each do |url|
    args << " --url #{url}"
  end

  shell_cmd("push", args)
  puts(">> push complete")
end

#rename(old_app_name, new_app_name) ⇒ Object



80
81
82
# File 'lib/conan/stackato.rb', line 80

def rename(old_app_name, new_app_name)
  shell_cmd("rename", "#{old_app_name} #{new_app_name}")
end

#shell_cmd(stackato_cmd, args, ignoreErrs = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/conan/stackato.rb', line 19

def shell_cmd(stackato_cmd, args, ignoreErrs=false)
  base_args = "--target #{@target} --token-file #{@@token_file}"

  cmd = "#{@executable} #{stackato_cmd} #{base_args} #{args}"
  puts(">>> #{cmd}")
  if @dry_run
    puts "Dry-run, skipping execution of command: #{cmd}"
  else
    # output, err, status = Open3.capture3(cmd)
    #  raise "Stackato error: #{err}" unless (ignoreErrs||status.success?)
    #  output
    Open3.popen2e(cmd) do |stdin, stdout_stderr, wait_thr|
      Thread.new do
        stdout_stderr.each_char { |c| putc c }
      end
      stdin.close
      exit_status = wait_thr.value          
      unless ignoreErrs || exit_status.success?
        abort "Stackato #{stackato_cmd} failed"
      end
    end
  end
end

#unmap(app_name, url) ⇒ Object



88
89
90
# File 'lib/conan/stackato.rb', line 88

def unmap(app_name, url)
  shell_cmd("unmap", "#{app_name} #{url}")
end