Parent

Class/Module Index [+]

Quicksearch

RHC::Commands::App

Public Instance Methods

configure(app_name) click to toggle source
# File lib/rhc/commands/app.rb, line 468
def configure(app_name)
  rest_app = find_app

  app_options = {}
  app_options[:auto_deploy] = options.auto_deploy if !options.auto_deploy.nil?
  app_options[:keep_deployments] = options.keep_deployments if options.keep_deployments
  app_options[:deployment_branch] = options.deployment_branch if options.deployment_branch
  app_options[:deployment_type] = options.deployment_type if options.deployment_type

  if app_options.present?
    paragraph do
      say "Configuring application '#{app_name}' ... "
      rest_app.configure(app_options)
      success "done"
    end
  end

  paragraph { display_app(find_app, nil, [:auto_deploy, :keep_deployments, :deployment_type, :deployment_branch]) }

  paragraph { say "Your application '#{rest_app.name}' is #{app_options.empty? ? '' : 'now '}configured as listed above." }
  paragraph { say "Use 'rhc show-app #{rest_app.name} --configuration' to check your configuration values any time." } if app_options.present?

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

  check_name!(name)

  arg_envs, cartridges = cartridges.partition{|item| item.match(env_var_regex_pattern)}

  rest_domain = check_domain!
  rest_app = nil
  repo_dir = nil

  if options.from_app
    raise RHC::AppCloneNotSupportedException, "The server does not support creating apps based on others (rhc create-app --from-app)." if (!rest_domain.has_param?('ADD_APPLICATION', 'cartridges[][name]') || !rest_domain.has_param?('ADD_APPLICATION', 'cartridges[][url]'))
    raise ArgumentError, "Option --from-code is incompatible with --from--app. When creating an app based on another resource you can either specify a Git repository URL with --from-code or an existing app name with --from-app." if options.from_code     
    raise ArgumentError, "Option --no-dns is incompatible with --from-app. We need to propagate the new app DNS to be able to configure it." if options.dns == false
    raise ArgumentError, "Do not specify cartridges when creating an app based on another one. All cartridges will be copied from the original app." if !(cartridges || []).empty?

    from_app = find_app(:app => options.from_app)

    arg_envs = from_app.environment_variables.collect {|env| "#{env.name}=#{env.value} "} + arg_envs
    cartridges = from_app.cartridges.reject{|c| c.tags.include?('web_proxy')}.collect{|c| c.custom? ? c.url : c.name}
  end

  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?

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

  env = collect_env_vars(arg_envs.concat(Array(options.env)))
  if env.present? && !rest_domain.supports_add_application_with_env_vars?
    env = []
    warn "Server does not support environment variables."
  end

  scaling = options.scaling

  if from_app
    scaling = from_app.scalable if scaling.nil?

    cartridges = from_app.cartridges.reject{|c| c.tags.include?('web_proxy')}.collect do |cartridge|
      {
        :name => (cartridge.name if !cartridge.custom?), 
        :url => (cartridge.url if cartridge.custom?),
        :gear_size => options.gear_size || cartridge.gear_profile,
        :additional_gear_storage => (cartridge.additional_gear_storage if cartridge.additional_gear_storage > 0),
        :scales_from => (cartridge.scales_from if cartridge.scalable?),
        :scales_to => (cartridge.scales_to if cartridge.scalable?)
      }.reject{|k,v| v.nil? }
    end
  end

  paragraph do
    header "Application Options"
    say table([["Domain:", options.namespace],
           ["Cartridges:", cart_names],
          (["Source Code:", options.from_code] if options.from_code),
          (["From app:", from_app.name] if from_app),
           ["Gear Size:", options.gear_size || (from_app ? "Copied from '#{from_app.name}'" : "default")],
           ["Scaling:", (scaling ? "yes" : "no") + (from_app && options.scaling.nil? ? " (copied from '#{from_app.name}')" : '')],
          (["Environment Variables:", env.map{|item| "#{item.name}=#{item.value}"}.join(', ')] if env.present?),
          ].compact
         )
  end

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

    # create the main app
    rest_app = create_app(name, cartridges, rest_domain, options.gear_size, scaling, options.from_code, env, options.auto_deploy, options.keep_deployments, options.deployment_branch, options.deployment_type)
    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
  end

  if from_app
    say "Setting deployment configuration ... "
    rest_app.configure({:auto_deploy => from_app.auto_deploy, :keep_deployments => from_app.keep_deployments , :deployment_branch => from_app.deployment_branch, :deployment_type => from_app.deployment_type})
    success 'done'

    snapshot_filename = temporary_snapshot_filename(from_app.name)
    save_snapshot(from_app, snapshot_filename)
    restore_snapshot(rest_app, snapshot_filename)
    File.delete(snapshot_filename) if File.exist?(snapshot_filename)

    paragraph { warn "The application '#{from_app.name}' has aliases set which were not copied. Please configure the aliases of your new application manually." } unless from_app.aliases.empty?
  end

  if options.git
    section(:now => true, :top => 1, :bottom => 1) do
      begin
        if has_git?
          repo_dir = git_clone_application(rest_app)
        else
          warn "You do not have git installed, so your application's git repo will not be cloned"
        end
      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

  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 259
def delete(app)
  rest_app = find_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
deploy(ref) click to toggle source
# File lib/rhc/commands/app.rb, line 451
def deploy(ref)
  rest_app = find_app

  raise RHC::DeploymentsNotSupportedException.new if !rest_app.supports? "DEPLOY"

  deploy_artifact(rest_app, ref, options.hot_deploy, options.force_clean_build)

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

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

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

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

  results { say "#{app} scaled down" }
  0
end
scale_up(app) click to toggle source
# File lib/rhc/commands/app.rb, line 296
def scale_up(app)
  app_action :scale_up

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

  if options.state
    find_app(:with_gear_groups => true).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 = find_app(:with_gear_groups => true)

    case options.gears
    when 'quota'
      opts = {:as => :gear, :split_cells_on => /\s*\t/, :header => ['Gear', 'Cartridges', 'Used', 'Limit'], :align => [nil, nil, :right, :right]}
      table_from_gears('echo "$(du --block-size=1 -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 = find_app(:with_gear_groups => true).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'])

  elsif options.configuration
    display_app_configurations(find_app)
    paragraph { say "Use 'rhc configure-app' to change the configuration values of this application." }

  else
    app = find_app(:include => :cartridges)
    display_app(app, app.cartridges, nil, options.verbose)
  end

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

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

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.