Class: KijiRest::Server
- Inherits:
-
Object
- Object
- KijiRest::Server
- Defined in:
- lib/kijirest/server.rb
Overview
Class that wraps the starting/stopping of a KijiREST server. assumes that this is running as a non-privileged user that has permissions to read/write to the location where KIJI_REST is installed
Constant Summary collapse
- KIJI_REST_HOME =
"/opt/wibi/kiji-rest"
Instance Method Summary collapse
-
#initialize(kiji_rest_home = KIJI_REST_HOME) ⇒ Server
constructor
A new instance of Server.
-
#new_client ⇒ Object
Returns a new client instance.
-
#start(zk_quorum = ".env", visible_instances = ["default"], wait_for_load = false) ⇒ Object
Start a server given a zookeeper quorum and array of visible instances.
-
#stop(wait_for_shutdown = false) ⇒ Object
Stops the server optionally waiting for the server to shutdown param: wait_for_shutdown determines whether or not to wait for the server to have shutdown before returning.
Constructor Details
#initialize(kiji_rest_home = KIJI_REST_HOME) ⇒ Server
Returns a new instance of Server.
31 32 33 34 35 36 37 38 |
# File 'lib/kijirest/server.rb', line 31 def initialize(kiji_rest_home = KIJI_REST_HOME) @kiji_server_location = kiji_rest_home unless raise "#{ENV['USER']} not authorized to run KijiREST server!" end @http_port = 8080 reload_configuration! end |
Instance Method Details
#new_client ⇒ Object
Returns a new client instance.
102 103 104 |
# File 'lib/kijirest/server.rb', line 102 def new_client Client.new("http://localhost:#{@http_port}") end |
#start(zk_quorum = ".env", visible_instances = ["default"], wait_for_load = false) ⇒ Object
Start a server given a zookeeper quorum and array of visible instances. This will modify the configuration.yml and launch the server. param: zk_quorum is the list of zookeeper servers. Default is .env param: visible_instances is an array of instance names that are to be visible by clients
of the REST server.
param: wait_for_load specifies whether or not to block until the server has come up. If the
server fails to come up after some period of time, an exception will be raised.
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 |
# File 'lib/kijirest/server.rb', line 47 def start(zk_quorum = ".env", visible_instances = ["default"], wait_for_load = false) if running? raise "KijiREST appears to be running." else #Update the configuration file to reflect the desired options dropwizard_config = YAML.load_file(qualify_file("/conf/configuration.yml")) #Do a bit of string checking so that we aren't adding kiji:// prefix twice. prefix="kiji://" prefix = "" if zk_quorum[0..6] == "kiji://" kiji_uri = "#{prefix}#{zk_quorum}" dropwizard_config["cluster"] = kiji_uri dropwizard_config["instances"] = visible_instances f = File.new(qualify_file("/conf/configuration.yml"), "w") f.puts(dropwizard_config.to_yaml) f.close #Now start the service launch_command = qualify_file("/bin/kiji-rest start") %x{#{launch_command}} if wait_for_load (1..20).each {|i| break if running? sleep 2 } unless running? raise "KijiREST failed to start!" end end end end |
#stop(wait_for_shutdown = false) ⇒ Object
Stops the server optionally waiting for the server to shutdown param: wait_for_shutdown determines whether or not to wait for the server to have shutdown
before returning.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/kijirest/server.rb', line 82 def stop(wait_for_shutdown = false) pid_file = qualify_file("kiji-rest.pid") launch_command = qualify_file("/bin/kiji-rest stop") if File.exist?(pid_file) %x{#{launch_command}} if wait_for_shutdown (1..20).each {|i| break unless running? sleep 2 } if running? raise "KijiREST failed to stop." end end else raise "KijiREST not running!" end end |