require 'flydata/command/base' require 'flydata/command/conf' require 'flydata/command/login' require 'flydata/command/sender' require 'flydata/command/helper' module Flydata module Command class Setup < Base ALL_DONE_MESSAGE_TEMPLATE = <<-EOM Congratulations! FlyData has started uploading your data. To complete your installation and to add the `flydata` command, please run the following from the command line. $ source ~/.bashrc What's next? - Check data on Redshift (%s) - Check your FlyData usage on the FlyData Dashboard (%s) - To manage the FlyData Agent, use the 'flydata' command (type 'flydata' for help) - If you encounter an issue, please check our documentation (https://www.flydata.com/resources/) or contact our customer support team (support@flydata.com) Thank you for using FlyData! EOM INITIAL_SYNC_MESSAGE_TEMPLATE = <<-EOM FlyData Agent has been installed on your server successfully. To complete your installation and to add the `flydata` command, please run the following from the command line. $ source ~/.bashrc What's next? 1. Generate a script to create tables on Redshift by running the following command. $ flydata sync:generate_table_ddl > create_table.sql 2. Create tables on Redshift by running the 'create_table.sql' script on your Redshift cluster. 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. 3. Start Sync Run the following command on your server. The command will start synchronizing data between MySQL and Redshift! $ flydata start EOM NO_DE_CANCEL_MESSAGE_TEMPLATE = <<-EOM FlyData Agent has been installed on your server successfully. However, you need to create at least a data entry before you can start using FlyData. What's next? 1. Create a data entry from the dashboard (%s) 2. Reinstall FlyData Agent by running the install command on the dashboard EOM def initial_run # Surprisingly, Helper's start method kills the process after starting # the helper thanks to ServerEngine. So the command needs to run in a # separate process. system "flydata helper:restart" Flydata::Command::Login.new.run unless flydata.credentials.authenticated? Flydata::Command::Conf.new.copy_templates puts de_exists = !!retrieve_data_entries.first if de_exists && source.setup.initial_run_need_restart? sender = Flydata::Command::Sender.new if sender.process_exist? Flydata::Command::Sender.new.restart(quiet: true) end end last_message = de_exists ? source.setup.initial_run_complete_message : :no_de_cancel msgs = standard_messages if msgs.has_key?(last_message) last_message = msgs[last_message] end puts last_message end def run(options = {}, &block) unless data_entry raise "No data entry exists. Please create one from FlyData Console (#{dashboard_url})" end # 'flydata setup' command is deprecated raise "You can set up FlyData on FlyData Console (#{dashboard_url})" end private def standard_messages { all_done: ALL_DONE_MESSAGE_TEMPLATE % [redshift_console_url, dashboard_url], initial_sync: INITIAL_SYNC_MESSAGE_TEMPLATE, no_de_cancel: NO_DE_CANCEL_MESSAGE_TEMPLATE % [dashboard_url], } end end end end