Class: CLISplash::Transfers

Inherits:
Thor
  • Object
show all
Includes:
Splash::Exiter, Splash::Helpers, Splash::Loggers, Splash::Transfers
Defined in:
lib/splash/cli/transfers.rb

Overview

Thor inherited class for transfers management

Constant Summary

Constants included from Splash::Loggers

Splash::Loggers::ALIAS, Splash::Loggers::LEVELS

Constants included from Splash::Constants

Splash::Constants::AUTHOR, Splash::Constants::BACKENDS_STRUCT, Splash::Constants::CONFIG_FILE, Splash::Constants::COPYRIGHT, Splash::Constants::DAEMON_LOGMON_SCHEDULING, Splash::Constants::DAEMON_METRICS_SCHEDULING, Splash::Constants::DAEMON_PID_FILE, Splash::Constants::DAEMON_PROCESS_NAME, Splash::Constants::DAEMON_PROCMON_SCHEDULING, Splash::Constants::DAEMON_STDERR_TRACE, Splash::Constants::DAEMON_STDOUT_TRACE, Splash::Constants::DEFAULT_RETENTION, Splash::Constants::EMAIL, Splash::Constants::EXECUTION_TEMPLATE, Splash::Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Splash::Constants::LICENSE, Splash::Constants::LOGGERS_STRUCT, Splash::Constants::PID_PATH, Splash::Constants::PROMETHEUS_ALERTMANAGER_URL, Splash::Constants::PROMETHEUS_PUSHGATEWAY_URL, Splash::Constants::PROMETHEUS_URL, Splash::Constants::TRACE_PATH, Splash::Constants::TRANSPORTS_STRUCT, Splash::Constants::VERSION, Splash::Constants::WEBADMIN_IP, Splash::Constants::WEBADMIN_PID_FILE, Splash::Constants::WEBADMIN_PID_PATH, Splash::Constants::WEBADMIN_PORT, Splash::Constants::WEBADMIN_PROCESS_NAME, Splash::Constants::WEBADMIN_PROXY, Splash::Constants::WEBADMIN_STDERR_TRACE, Splash::Constants::WEBADMIN_STDOUT_TRACE

Constants included from Splash::Exiter

Splash::Exiter::EXIT_MAP

Instance Method Summary collapse

Methods included from Splash::Loggers

#change_logger, #get_logger, #get_session

Methods included from Splash::Config

#get_config, #rehash_config

Methods included from Splash::ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Splash::Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Methods included from Splash::Exiter

#splash_exit, #splash_return

Methods included from Splash::Transfers

#prepare_tx, #push, #run_txs, #save_data

Instance Method Details

#full_executeObject



32
33
34
35
# File 'lib/splash/cli/transfers.rb', line 32

def full_execute
  acase = run_as_root :run_txs
  splash_exit acase
end

#get_result(name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/splash/cli/transfers.rb', line 43

def get_result(name)
  log = get_logger
  log.item "Transfer : #{name}"
  config = get_config
  data = TxRecords::new(name).get_all_records.select {|item|
    record =item.keys.first
    value=item[record]
    record == options[:date]}.first
  if data.nil? then
    log.ko "Result for #{name} on date #{options[:date]} not found"
    splash_exit case: :not_found, :more => "Result inexistant"
  else
    record = options[:date]
    value = data[record]
    failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
    if value[:end_date].nil? then
      log.item "Event : #{record} STATUS : #{value[:status]}"
    else
      log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
    end
    log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
    log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
    unless value[:wanted].nil?
      log.arrow "Files wanted :" unless value[:wanted].empty?
      value[:wanted].each do |file|
        log.flat  "    * #{file}"
      end
    end
    unless value[:done].nil?
      log.arrow "Files done :" unless value[:done].empty?
      value[:done].each do |file|
        log.flat  "    * #{file}"
      end
    end
    unless failed then
      log.arrow "Nb failure : #{failed}"
    end

  end
  splash_exit case: :quiet_exit
end

#history(name) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/splash/cli/transfers.rb', line 91

def history(name)
  log = get_logger
  log.item "Transfer : #{name}"
  config = get_config
  if options[:table] then
    table = TTY::Table.new do |t|
      t << ["Start Date", "End date", "time", "Files count","File count error","Status"]
      t << ['','','','','','']
      TxRecords::new(name).get_all_records.each do |item|
        record =item.keys.first
        value=item[record]
        start_date = record
        end_date = (value[:end_date].nil?)? '': value[:end_date]
        time  = (value[:time].nil?)? '': value[:time]
        count = (value[:count].nil?)? '': value[:count]
        failed = (value[:count].nil? or value[:done].nil?)? '': value[:count].to_i - value[:done].count
        status = value[:status]
        t << [start_date, end_date, time, count, failed, status]

      end
    end
    if check_unicode_term  then
      puts table.render(:unicode)
    else
      puts table.render(:ascii)
    end

  else
    TxRecords::new(name).get_all_records.each do |item|
      record =item.keys.first
      value=item[record]
      failed = (value[:count].nil? or value[:done].nil?)? 'undef': value[:count].to_i - value[:done].count
      if value[:end_date].nil? then
        log.item "Event : #{record} STATUS : #{value[:status]}"
      else
        log.item "Tx Begin : #{record} => end : #{value[:end_date]} STATUS : #{value[:status]}"
      end
      log.arrow "Tx Time : #{value[:time]}" unless value[:time].nil?
      log.arrow "nb files : #{value[:count]}" unless value[:count].nil?
      unless value[:wanted].nil?
        log.arrow "Files wanted :" unless value[:wanted].empty?
        value[:wanted].each do |file|
          log.flat  "    * #{file}"
        end
      end
      unless value[:done].nil?
        log.arrow "Files done :" unless value[:done].empty?
        value[:done].each do |file|
          log.flat  "    * #{file}"
        end
      end
      unless failed then
        log.arrow "Nb failure : #{failed}"
      end

    end
  end
  splash_exit case: :quiet_exit
end

#listObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/splash/cli/transfers.rb', line 186

def list
  log = get_logger
  log.info "Splash configured transfer :"
  tx_record_set = get_config.transfers
  log.ko 'No configured transfers found' if tx_record_set.empty?
  tx_record_set.each do |record|
    log.item "Transfer : #{record[:name]} Description : #{record[:desc]}"
    if options[:detail] then
      log.arrow "Type : #{record[:type].to_s}"
      log.arrow "Backup file after copy : #{record[:backup].to_s}"
      log.arrow "Local spool"
      log.flat "   * Path : #{record[:local][:path]}"
      log.flat "   * User : #{record[:local][:user]}"
      log.arrow "Remote spool"
      log.flat "   * Path : #{record[:remote][:path]}"
      log.flat "   * User : #{record[:remote][:user]}"
      log.flat "   * Host : #{record[:remote][:host]}"
      log.arrow "Post execution"
      log.flat "   * Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
      log.flat "   * Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
    end
  end
  splash_exit case: :quiet_exit
end

#prepare(name) ⇒ Object



21
22
23
24
# File 'lib/splash/cli/transfers.rb', line 21

def prepare(name)
  acase = run_as_root :prepare_tx, name
  splash_exit acase
end

#show(transfer) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/splash/cli/transfers.rb', line 154

def show(transfer)
  log = get_logger
  transfer_record_set = get_config.transfers.select{|item| item[:name] == transfer.to_sym }
  unless transfer_record_set.empty? then
    record = transfer_record_set.first
    log.info "Splash transfer : #{record[:name]}"
    log.item "Description : /#{record[:desc]}/"
    log.item "Type : #{record[:type].to_s}"
    log.item "Backup file after copy : #{record[:backup].to_s}"
    log.item "Local spool"
    log.arrow "Path : #{record[:local][:path]}"
    log.arrow "User : #{record[:local][:user]}"
    log.item "Remote spool"
    log.arrow "Path : #{record[:remote][:path]}"
    log.arrow "User : #{record[:remote][:user]}"
    log.arrow "Host : #{record[:remote][:host]}"
    log.item "Post execution"
    log.arrow "Remote command : #{record[:post][:remote_command]}" unless record[:post][:remote_command].nil?
    log.arrow "Local command : #{record[:post][:local_command]}" unless record[:post][:local_command].nil?
    splash_exit case: :quiet_exit
  else
    splash_exit case: :not_found, :more => "log not configured"
  end
end