class RHC::Commands::App

Public Instance Methods

create(name, cartridges) click to toggle source
# File lib/rhc/commands/app.rb, line 63
def create(name, cartridges)
  check_config!

  check_name!(name)

  cartridges = check_cartridges(cartridges, &require_one_web_cart)

  options.default          :dns => true,
    :git => true

  raise ArgumentError, "You have named both your main application and your Jenkins application '#{name}'. In order to continue you'll need to specify a different name with --enable-jenkins or choose a different application name." if jenkins_app_name == name && enable_jenkins?

  rest_domain = check_domain!
  rest_app = nil
  repo_dir = nil

  cart_names = cartridges.collect do |c|
    c.usage_rate? ? "#{c.short_name} (addtl. costs may apply)" : c.short_name
  end.join(', ')

  paragraph do
    header "Application Options"
    table([["Namespace:", options.namespace],
           ["Cartridges:", cart_names],
          (["Source Code:", options.from_code] if options.from_code),
           ["Gear Size:", options.gear_size || "default"],
           ["Scaling:", options.scaling ? "yes" : "no"],
          ].compact
         ).each { |s| say "  #{s}" }
  end

  paragraph do
    say "Creating application '#{name}' ... "

    # create the main app
    rest_app = create_app(name, cartridges, rest_domain, options.gear_size, options.scaling, options.from_code)
    success "done"

    paragraph{ indent{ success rest_app.messages.map(&:strip) } }
  end

  build_app_exists = rest_app.building_app

  if enable_jenkins?
    unless build_app_exists
      paragraph do
        say "Setting up a Jenkins application ... "

        begin
          build_app_exists = add_jenkins_app(rest_domain)

          success "done"
          paragraph{ indent{ success build_app_exists.messages.map(&:strip) } }

        rescue Exception => e
          warn "not complete"
          add_issue("Jenkins failed to install - #{e}",
                    "Installing jenkins and jenkins-client",
                    "rhc create-app jenkins",
                    "rhc add-cartridge jenkins-client -a #{rest_app.name}")
        end
      end
    end

    paragraph do
      messages = []
      add_jenkins_client_to(rest_app, messages)
      paragraph{ indent{ success messages.map(&:strip) } }
    end if build_app_exists
  end

  debug "Checking SSH keys through the wizard"
  check_sshkeys! unless options.no_keys

  if options.dns
    paragraph do
      say "Waiting for your DNS name to be available ... "
      if dns_propagated? rest_app.host
        success "done"
      else
        warn "failure"
        add_issue("We were unable to lookup your hostname (#{rest_app.host}) in a reasonable amount of time and can not clone your application.",
                  "Clone your git repo",
                  "rhc git-clone #{rest_app.name}")

        output_issues(rest_app)
        return 0
      end
    end

    if options.git
      section(:now => true, :top => 1, :bottom => 1) do
        begin
          repo_dir = git_clone_application(rest_app)
        rescue RHC::GitException => e
          warn "#{e}"
          unless RHC::Helpers.windows? and windows_nslookup_bug?(rest_app)
            add_issue("We were unable to clone your application's git repo - #{e}",
                      "Clone your git repo",
                      "rhc git-clone #{rest_app.name}")
          end
        end
      end
    end
  end

  output_issues(rest_app) if issues?
        
  paragraph do
    say "Your application '#{rest_app.name}' is now available."
    paragraph do
      indent do
        say table [
            ['URL:', rest_app.app_url],
            ['SSH to:', rest_app.ssh_string],
            ['Git remote:', rest_app.git_url],
            (['Cloned to:', repo_dir] if repo_dir)
          ].compact
      end
    end
  end
  paragraph{ say "Run 'rhc show-app #{name}' for more details about your app." }

  0
end
delete(app) click to toggle source
# File lib/rhc/commands/app.rb, line 200
def delete(app)
  rest_app = rest_client.find_application(options.namespace, app)

  confirm_action "#{color("This is a non-reversible action! Your application code and data will be permanently deleted if you continue!", :yellow)}\n\nAre you sure you want to delete the application '#{app}'?"

  say "Deleting application '#{rest_app.name}' ... "
  rest_app.destroy
  success "deleted"

  paragraph{ rest_app.messages.each{ |s| success s } }

  0
end
force_stop(app) click to toggle source
# File lib/rhc/commands/app.rb, line 240
def force_stop(app)
  app_action app, :stop, true

  results { say "#{app} force stopped" }
  0
end
reload(app) click to toggle source
# File lib/rhc/commands/app.rb, line 262
def reload(app)
  app_action app, :reload

  results { say "#{app} config reloaded" }
  0
end
restart(app) click to toggle source
# File lib/rhc/commands/app.rb, line 251
def restart(app)
  app_action app, :restart

  results { say "#{app} restarted" }
  0
end
show(app_name) click to toggle source
# File lib/rhc/commands/app.rb, line 305
def show(app_name)

  if options.state
    gear_groups_for_app(app_name).each do |gg|
      say "Cartridge #{gg.cartridges.collect { |c| c['name'] }.join(', ')} is #{gear_group_state(gg.gears.map{ |g| g['state'] })}"
    end

  elsif options.gears && options.gears != true
    groups = rest_client.find_application_gear_groups(options.namespace, app_name)

    case options.gears
    when 'quota'
      opts = {:as => :gear, :split_cells_on => %r\s*\t/, :header => ['Gear', 'Cartridges', 'Used', 'Limit'], :align => [nil, nil, :right, :right]}
      table_from_gears('echo "$(du -s 2>/dev/null | cut -f 1)"', groups, opts) do |gear, data, group|
        [gear['id'], group.cartridges.collect{ |c| c['name'] }.join(' '), (human_size(data.chomp) rescue 'error'), human_size(group.quota)]
      end
    when 'ssh'
      groups.each{ |group| group.gears.each{ |g| say (ssh_string(g['ssh_url']) or raise NoPerGearOperations) } }
    else 
      run_on_gears(ssh_command_for_op(options.gears), groups)
    end

  elsif options.gears
    gear_info = gear_groups_for_app(app_name).map do |group|
      group.gears.map do |gear|
        [
          gear['id'],
          gear['state'] == 'started' ? gear['state'] : color(gear['state'], :yellow),
          group.cartridges.collect{ |c| c['name'] }.join(' '),
          group.gear_profile,
          ssh_string(gear['ssh_url'])
        ]
      end
    end.flatten(1)

    say table(gear_info, :header => ['ID', 'State', 'Cartridges', 'Size', 'SSH URL'])
  else
    app = rest_client.find_application(options.namespace, app_name, :include => :cartridges)
    display_app(app, app.cartridges)
  end

  0
end
start(app) click to toggle source
# File lib/rhc/commands/app.rb, line 218
def start(app)
  app_action app, :start

  results { say "#{app} started" }
  0
end
status(app) click to toggle source
# File lib/rhc/commands/app.rb, line 354
def status(app)
  # TODO: add a way to deprecate this and alias to show --apache
  options.state = true
  show(app)
end
stop(app) click to toggle source
# File lib/rhc/commands/app.rb, line 229
def stop(app)
  app_action app, :stop

  results { say "#{app} stopped" }
  0
end
tidy(app) click to toggle source
# File lib/rhc/commands/app.rb, line 273
def tidy(app)
  app_action app, :tidy

  results { say "#{app} cleaned up" }
  0
end