Class: Flydata::Command::Setup

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/flydata/command/setup.rb

Constant Summary collapse

LOG_PATH_EXAMPLES =
%w(/var/log/httpd/access_log /var/log/apache2/access.log
/var/log/httpd-access.log /var/log/apache2/access_log
/var/log/messages /var/log/maillog /var/log/mysql/error.log
/home/*/deploy/shared/log/*.log)
OTHER =
'-- None of above --'
ENTER_TABLE_NAME =
'-- Create a table on Redshift from your logs --'
ALL_DONE_MESSAGE_TEMPLATE =
"Congratulations! FlyData has started uploading your data.\n\nTo complete your installation and to add the `flydata` command, please run the\nfollowing from the command line.\n\n    $ source ~/.bashrc\n\n\nWhat's next?\n\n    - Check data on Redshift (%s)\n    - Check your FlyData usage on the FlyData Dashboard (%s)\n    - To manage the FlyData Agent, use the 'flydata' command (type 'flydata' for\nhelp)\n    - If you encounter an issue,\n  please check our documentation (https://www.flydata.com/docs/) or\n  contact our customer support team ([email protected])\n\nThank you for using FlyData!\n"
INITIAL_SYNC_MESSAGE_TEMPLATE =
"FlyData Agent has been installed on your server successfully.\n\nTo complete your installation and to add the `flydata` command, please run the\nfollowing from the command line.\n\n    $ source ~/.bashrc\n\n\nWhat's next?\n\n1. Generate a script to create tables on Redshift by running the following command.\n\n    $ flydata sync:generate_table_ddl > create_table.sql\n\n2. Create tables on Redshift by running the 'create_table.sql' script on your Redshift cluster.\n    The script is auto-generated from your MySQL tables.  You can also edit the script to add extra Redshift parameters such as distkey and sortkey.  Once you run the script and create tables in Redshift, you are ready for the next step.  \n\n3. Start Sync\n    Run the following command on your server. The command will start synchronizing data between MySQL and Redshift!\n\n    $ flydata sync\n\n"
NO_DE_CANCEL_MESSAGE_TEMPLATE =
"FlyData Agent has been installed on your computer.\nHowever, you need to create at least a data entry before start using FlyData.\n\nWhat's next?\n\n1. Create a data entry from the dashboard (%s)\n\n2. Reinstall FlyData Agent by running the install command on the dashboard\n\n"

Instance Attribute Summary

Attributes inherited from Base

#opts

Instance Method Summary collapse

Methods included from Helpers

development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, format_menu_list, parse_command, retry_on, to_command_class, usage_text

Methods inherited from Base

#ask_input_table_name, #ask_yes_no, #choose_one, #flydata, #initialize, #newline, #register_crontab, #retrieve_data_entries, #separator

Constructor Details

This class inherits a constructor from Flydata::Command::Base

Instance Method Details

#initial_runObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/flydata/command/setup.rb', line 81

def initial_run
  data_port = flydata.data_port.get
  dashboard_url = "#{flydata.flydata_api_host}/dashboard"
  redshift_console_url = "#{flydata.flydata_api_host}/redshift_clusters/query/new"
  last_message = ALL_DONE_MESSAGE_TEMPLATE % [redshift_console_url, dashboard_url]

  run(quiet: true) do
    Flydata::Command::Conf.new.copy_templates
    puts
    if has_registered_redshift_entries?
      Flydata::Command::Sender.new.stop(quiet: true)
      true
    elsif has_registered_redshift_mysql_data_entries?
      de = retrieve_data_entries.first
      if File.exists?(Flydata::FileUtil::SyncFileManager.new(de).binlog_path)
        Flydata::Command::Sender.new.stop(quiet: true)
        true
      else
        last_message = INITIAL_SYNC_MESSAGE_TEMPLATE
        false
      end
    else
      last_message = NO_DE_CANCEL_MESSAGE_TEMPLATE % [dashboard_url]
      false
    end
  end
  puts last_message
end

#run(options = {}, &block) ⇒ Object



110
111
112
113
114
# File 'lib/flydata/command/setup.rb', line 110

def run(options = {}, &block)
  Flydata::Command::.new.run unless flydata.credentials.authenticated?
  ret = block_given? ? yield : _run
  Flydata::Command::Sender.new.restart(options) if ret
end