Class: Pcrd::CLI
- Inherits:
-
Thor
- Object
- Thor
- Pcrd::CLI
- Defined in:
- lib/pcrd/cli.rb
Constant Summary collapse
- PASTEL =
Pastel.new
Class Method Summary collapse
Instance Method Summary collapse
- #analyze ⇒ Object
- #cleanup ⇒ Object
- #cutover ⇒ Object
- #migrate ⇒ Object
- #readiness ⇒ Object
- #status ⇒ Object
- #verify ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
10 11 12 |
# File 'lib/pcrd/cli.rb', line 10 def self.exit_on_failure? true end |
Instance Method Details
#analyze ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/pcrd/cli.rb', line 39 def analyze config = load_config! Commands::Analyze.new(config, ).run rescue Commands::Analyze::Error => e raise Thor::Error, "ERROR: #{e.}" rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" end |
#cleanup ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'lib/pcrd/cli.rb', line 239 def cleanup config = load_config! Commands::Cleanup.new(config, ).run rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Error => e raise Thor::Error, "ERROR: #{e.}" end |
#cutover ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/pcrd/cli.rb', line 166 def cutover config = load_config! unless [:"maintenance-confirmed"] say "\nThe application must be in maintenance mode before continuing." say "Maintenance mode options:" say " pgBouncer: PAUSE <database>" say " Kubernetes: kubectl scale --replicas=0 deployment/app" say " Rails: enable maintenance middleware" say "" answer = ask("Is the application in maintenance mode? [y/N]") return unless answer.strip.downcase == "y" end source_pool = Connection::Client.new(config.source) target_pool = Connection::Client.new(config.target) printer = Output::CutoverPrinter.new say "\nRunning cutover sequence..." orchestrator = Cutover::Orchestrator.new( source_pool: source_pool, target_pool: target_pool, config: config ) result = orchestrator.run(on_progress: ->(msg) { say " #{msg}" }) printer.print(result) source_pool.close target_pool.close exit(result.passed ? 0 : 1) rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" end |
#migrate ⇒ Object
73 74 75 76 77 78 79 80 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 109 110 111 112 113 |
# File 'lib/pcrd/cli.rb', line 73 def migrate config = load_config! preflight_only = [:"preflight-only"] || [:"dry-run"] unless preflight_only raise Thor::Error, "ERROR: migrate requires a 'target' section in your config.\n\n" \ "Use --preflight-only to validate without a target connection." if config.target.nil? raise Thor::Error, "ERROR: migrate requires a 'migrate' section in your config." if config.migrate.nil? end result = Preflight.new(config, ).run Output::PreflightPrinter.new.print(result) if preflight_only exit(result.passed ? 0 : 1) return end unless result.passed raise Thor::Error, "Preflight failed. Fix the issue(s) above before running migrate." end unless [:yes] answer = ask("Proceed with migration? [y/N]") return unless answer.strip.downcase == "y" end orchestrator = Migration::Orchestrator.new(config: config, options: ) trap("INT") { orchestrator.request_stop } trap("TERM") { orchestrator.request_stop } orchestrator.run rescue Replication::Error => e raise Thor::Error, "ERROR: #{e.}\n\nReplication stopped. Resume with --resume once the cause is resolved." rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Error => e raise Thor::Error, "ERROR: #{e.}" end |
#readiness ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'lib/pcrd/cli.rb', line 143 def readiness config = load_config! result = Commands::Readiness.new(config, ).run Output::ReadinessPrinter.new.print(result) rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Error => e raise Thor::Error, "ERROR: #{e.}" end |
#status ⇒ Object
121 122 123 124 125 126 |
# File 'lib/pcrd/cli.rb', line 121 def status config = load_config! Commands::Status.new(config, ).run rescue Config::LoadError => e raise Thor::Error, "ERROR: #{e.}" end |
#verify ⇒ Object
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/pcrd/cli.rb', line 214 def verify config = load_config! result = Commands::Verify.new(config, ).run Output::CutoverPrinter.new.print_verify(result) exit(result.passed ? 0 : 1) rescue Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Error => e raise Thor::Error, "ERROR: #{e.}" end |