Skip to content

Commit

Permalink
Speed up startup by delayed loading (#32)
Browse files Browse the repository at this point in the history
* Speed up startup by delayed loading

* Fix spec requires
  • Loading branch information
kke committed Aug 9, 2017
1 parent 88fa58f commit 2963680
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 53 deletions.
8 changes: 4 additions & 4 deletions lib/kontena/plugin/digital_ocean/master/create_command.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'securerandom'
require_relative '../prompts'
require 'kontena/plugin/digital_ocean/prompts'

module Kontena::Plugin::DigitalOcean::Master
class CreateCommand < Kontena::Command
Expand All @@ -17,13 +16,14 @@ class CreateCommand < Kontena::Command
option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
option "--version", "VERSION", "Define installed Kontena version", default: 'latest'


def execute
suppress_warnings # until DO merges resource_kit pr #32
do_token = ask_do_token

require_relative '../../../machine/digital_ocean'
require 'securerandom'
require 'kontena/machine/digital_ocean'

do_token = ask_do_token
do_region = ask_droplet_region(do_token)
do_size = ask_droplet_size(do_token, do_region)
do_ssh_key_id = ask_ssh_key(do_token)
Expand Down
5 changes: 3 additions & 2 deletions lib/kontena/plugin/digital_ocean/master/terminate_command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'kontena/plugin/digital_ocean/prompts'

module Kontena::Plugin::DigitalOcean::Master
class TerminateCommand < Kontena::Command
include Kontena::Cli::Common
Expand All @@ -10,10 +12,9 @@ class TerminateCommand < Kontena::Command

def execute
suppress_warnings # until DO merges resource_kit pr #32
require 'kontena/machine/digital_ocean'
do_token = ask_do_token
confirm_command(name) unless forced?

require_relative '../../../machine/digital_ocean'
destroyer = destroyer(do_token)
destroyer.run!(name)
ensure
Expand Down
11 changes: 2 additions & 9 deletions lib/kontena/plugin/digital_ocean/master_command.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require_relative 'master/create_command'
require_relative 'master/terminate_command'

class Kontena::Plugin::DigitalOcean::MasterCommand < Kontena::Command

subcommand "create", "Create a new master to DigitalOcean", Kontena::Plugin::DigitalOcean::Master::CreateCommand
subcommand "terminate", "Terminate DigitalOcean master", Kontena::Plugin::DigitalOcean::Master::TerminateCommand

def execute
end
subcommand "create", "Create a new master to DigitalOcean", load_subcommand('kontena/plugin/digital_ocean/master/create_command')
subcommand "terminate", "Terminate DigitalOcean master", load_subcommand('kontena/plugin/digital_ocean/master/terminate_command')
end
14 changes: 3 additions & 11 deletions lib/kontena/plugin/digital_ocean/node_command.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
require_relative 'nodes/create_command'
require_relative 'nodes/restart_command'
require_relative 'nodes/terminate_command'

class Kontena::Plugin::DigitalOcean::NodeCommand < Kontena::Command

subcommand "create", "Create a new node to DigitalOcean", Kontena::Plugin::DigitalOcean::Nodes::CreateCommand
subcommand "restart", "Restart DigitalOcean node", Kontena::Plugin::DigitalOcean::Nodes::RestartCommand
subcommand "terminate", "Terminate DigitalOcean node", Kontena::Plugin::DigitalOcean::Nodes::TerminateCommand

def execute
end
subcommand "create", "Create a new node to DigitalOcean", load_subcommand('kontena/plugin/digital_ocean/nodes/create_command')
subcommand "restart", "Restart DigitalOcean node", load_subcommand('kontena/plugin/digital_ocean/nodes/restart_command')
subcommand "terminate", "Terminate DigitalOcean node", load_subcommand('kontena/plugin/digital_ocean/nodes/terminate_command')
end
6 changes: 2 additions & 4 deletions lib/kontena/plugin/digital_ocean/nodes/create_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../prompts'
require 'kontena/plugin/digital_ocean/prompts'

module Kontena::Plugin::DigitalOcean::Nodes
class CreateCommand < Kontena::Command
Expand All @@ -17,13 +17,11 @@ class CreateCommand < Kontena::Command

def execute
suppress_warnings # until DO merges resource_kit pr #32
require 'kontena/machine/digital_ocean'
require_api_url
require_current_grid

do_token = ask_do_token

require_relative '../../../machine/digital_ocean'

do_region = ask_droplet_region(do_token)
coreos_channel = self.channel || ask_channel
do_size = ask_droplet_size(do_token, do_region)
Expand Down
5 changes: 2 additions & 3 deletions lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../prompts'
require 'kontena/plugin/digital_ocean/prompts'

module Kontena::Plugin::DigitalOcean::Nodes
class RestartCommand < Kontena::Command
Expand All @@ -11,12 +11,11 @@ class RestartCommand < Kontena::Command

def execute
suppress_warnings # until DO merges resource_kit pr #32
require 'kontena/machine/digital_ocean'
require_api_url
require_current_grid
do_token = ask_do_token

require_relative '../../../machine/digital_ocean'

node_name = ask_node(require_token)
client = DropletKit::Client.new(access_token: do_token)
droplet = client.droplets.all.find{|d| d.name == node_name}
Expand Down
4 changes: 2 additions & 2 deletions lib/kontena/plugin/digital_ocean/nodes/terminate_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../prompts'
require 'kontena/plugin/digital_ocean/prompts'

module Kontena::Plugin::DigitalOcean::Nodes
class TerminateCommand < Kontena::Command
Expand All @@ -12,14 +12,14 @@ class TerminateCommand < Kontena::Command

def execute
suppress_warnings # until DO merges resource_kit pr #32
require 'kontena/machine/digital_ocean'
require_api_url
require_current_grid
token = require_token
node_name = ask_node(token)
do_token = ask_do_token
confirm_command(node_name) unless forced?

require_relative '../../../machine/digital_ocean'
grid = client(require_token).get("grids/#{current_grid}")
destroyer = destroyer(client(token), do_token)
destroyer.run!(grid, node_name)
Expand Down
11 changes: 2 additions & 9 deletions lib/kontena/plugin/digital_ocean_command.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require_relative 'digital_ocean/master_command'
require_relative 'digital_ocean/node_command'

class Kontena::Plugin::DigitalOceanCommand < Kontena::Command

subcommand 'master', 'DigitalOcean master related commands', Kontena::Plugin::DigitalOcean::MasterCommand
subcommand 'node', 'DigitalOcean node related commands', Kontena::Plugin::DigitalOcean::NodeCommand

def execute
end
subcommand 'master', 'DigitalOcean master related commands', load_subcommand('kontena/plugin/digital_ocean/master_command')
subcommand 'node', 'DigitalOcean node related commands', load_subcommand('kontena/plugin/digital_ocean/node_command')
end
6 changes: 3 additions & 3 deletions lib/kontena_cli_plugin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'kontena_cli'
require_relative 'kontena/plugin/digital_ocean'
require_relative 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean'
require 'kontena/cli/subcommand_loader'

Kontena::MainCommand.register("digitalocean", "DigitalOcean specific commands", Kontena::Plugin::DigitalOceanCommand)
Kontena::MainCommand.register("digitalocean", "DigitalOcean specific commands", Kontena::Cli::SubcommandLoader.new('kontena/plugin/digital_ocean_command'))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/master/create_command'

describe Kontena::Plugin::DigitalOcean::Master::CreateCommand do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/master/terminate_command'

describe Kontena::Plugin::DigitalOcean::Master::TerminateCommand do

Expand Down
2 changes: 1 addition & 1 deletion spec/kontena/plugin/digital_ocean/master_command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/master_command'

describe Kontena::Plugin::DigitalOcean::MasterCommand do

Expand Down
2 changes: 1 addition & 1 deletion spec/kontena/plugin/digital_ocean/node_command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/node_command'

describe Kontena::Plugin::DigitalOcean::NodeCommand do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/nodes/create_command'

describe Kontena::Plugin::DigitalOcean::Nodes::CreateCommand do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'kontena/plugin/digital_ocean_command'
require 'kontena/plugin/digital_ocean/nodes/terminate_command'

describe Kontena::Plugin::DigitalOcean::Nodes::TerminateCommand do

Expand Down

0 comments on commit 2963680

Please sign in to comment.