class Nutella::Start

Public Instance Methods

run(args=nil) click to toggle source
# File lib/commands/start.rb, line 8
def run(args=nil)

  # If the current directory is not a nutella application, return
  unless Nutella.current_app.exist?
    console.warn 'The current directory is not a nutella application'
    return
  end

  begin
    run_id, params = parse_cli_arguments args
  rescue StandardError => e
    console.error e.message
    return
  end

  app_id, app_path = fetch_app_details

  if no_app_bot_to_start app_id, app_path, params
    console.warn "Run #{run} not created: your application bots are already started and you specified no regular bots exclusively for this run"
    return
  end

  return if run_exist?( app_id, run_id)

  return unless start_all_components(app_id, app_path, run_id, params)

  return unless Nutella.runlist.add?(app_id, run_id, app_path)

  print_confirmation(run_id, params, app_id, app_path)
end

Private Instance Methods

app_bots_started?( app_id ) click to toggle source

Returns true if the app bots have been started already

# File lib/commands/start.rb, line 74
def app_bots_started?( app_id )
  Tmux.session_exist? Tmux.app_bot_session_name app_id
end
fetch_app_details() click to toggle source

Fetches the app_id and app_path

# File lib/commands/start.rb, line 59
def fetch_app_details
  # Extract app_id
  app_id = Nutella.current_app.config['name']
  return app_id, Dir.pwd
end
no_app_bot_to_start(app_id, app_path, params) click to toggle source

Returns true if both the list of run level bots is empty and the app bots have been started already

# File lib/commands/start.rb, line 68
def no_app_bot_to_start(app_id, app_path, params)
  ComponentsList.run_level_bots_list(app_path, params).empty? && app_bots_started?(app_id)
end
parse_cli_arguments( args ) click to toggle source

Parses command line arguments

# File lib/commands/start.rb, line 45
def parse_cli_arguments( args )
  # Parse run_id
  run_id = parse_run_id_from args
  # Extract parameters
  params = parse_cli_parameters args
  # Check that we are not using 'with' and 'without' options at the same time
  unless params[:with].empty? || params[:without].empty?
    raise StandardError.new 'You can\'t use both --with and --without at the same time'
  end
  return run_id, params
end
print_confirmation( run_id, params, app_id, app_path ) click to toggle source
print_monitoring_details( app_id, run_id ) click to toggle source
run_exist?( app_id, run_id) click to toggle source

Check that the run_id we are trying to start has not been started already

# File lib/commands/start.rb, line 80
def run_exist?( app_id, run_id)
  if Nutella.runlist.include?(app_id, run_id)
    # If the run_id is already in the list, check that it is actually live
    if Tmux.session_exist? Tmux.session_name(app_id, run_id)
      console.error 'Impossible to start nutella app: an instance of this app with the same run_id is already running!'
      console.error "You might want to kill it with 'nutella stop #{run_id}'"
      return true
    end
  end
  false
end
start_all_components( app_id, app_path, run_id, params ) click to toggle source

Starts all the components at all levels for this run

# File lib/commands/start.rb, line 94
def start_all_components( app_id, app_path, run_id, params )
  # Start the internal broker
  return false unless ComponentsStarter.start_internal_broker
  # Start mongo db
  return false unless ComponentsStarter.start_mongo_db
  # Start all framework-level components (if needed)
  return false unless ComponentsStarter.start_framework_components
  # Start all app-level bots (if any, if needed)
  return false unless ComponentsStarter.start_app_bots(app_id, app_path)
  # Start all run-level bots
  false unless ComponentsStarter.start_run_bots(ComponentsList.run_level_bots_list(app_path, params), app_path, app_id, run_id)
  true
end