Class: RBoss::Cli::Invoker
- Inherits:
-
Object
- Object
- RBoss::Cli::Invoker
- Includes:
- Mappings, ResultParser, Platform
- Defined in:
- lib/rboss/cli/invoker.rb
Constant Summary
Constants included from ResultParser
ResultParser::BOOLEAN, ResultParser::INT, ResultParser::LIST, ResultParser::LONG, ResultParser::OBJECT, ResultParser::STRING
Instance Attribute Summary collapse
-
#domain_host ⇒ Object
Returns the value of attribute domain_host.
-
#domain_server ⇒ Object
Returns the value of attribute domain_server.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #command ⇒ Object
- #execute(commands) ⇒ Object
- #gets_and_invoke(path, operation, parameters) ⇒ Object
-
#initialize(params = {}) ⇒ Invoker
constructor
A new instance of Invoker.
- #invoke(operation, resources, parameters) ⇒ Object
- #result(commands) ⇒ Object
Methods included from Mappings
load_default_resources, load_resource, load_resources, resource_mappings
Methods included from Platform
#clear, #jboss_cli, #run_conf, #run_conf_template, #twiddle
Methods included from ResultParser
Constructor Details
#initialize(params = {}) ⇒ Invoker
Returns a new instance of Invoker.
42 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 |
# File 'lib/rboss/cli/invoker.rb', line 42 def initialize(params = {}) params = { :jboss_home => ENV['JBOSS_HOME'], }.merge! params @jboss_home = params[:jboss_home] @server = params[:server] @host = params[:host] @port = params[:port] @server ||= [@host, @port].join ':' if @host and @port @user = params[:user] @password = params[:password] @logger = params[:logger] unless @logger @logger = Logger::new STDOUT @logger.level = params[:log_level] || Logger::INFO formatter = Yummi::Formatter::LogFormatter.new do |severity, | "#{severity} : #{}" end @logger.formatter = formatter end @skip_optional = params[:skip_optional] end |
Instance Attribute Details
#domain_host ⇒ Object
Returns the value of attribute domain_host.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def domain_host @domain_host end |
#domain_server ⇒ Object
Returns the value of attribute domain_server.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def domain_server @domain_server end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
39 40 41 |
# File 'lib/rboss/cli/invoker.rb', line 39 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
39 40 41 |
# File 'lib/rboss/cli/invoker.rb', line 39 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
39 40 41 |
# File 'lib/rboss/cli/invoker.rb', line 39 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
39 40 41 |
# File 'lib/rboss/cli/invoker.rb', line 39 def server @server end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
39 40 41 |
# File 'lib/rboss/cli/invoker.rb', line 39 def user @user end |
Instance Method Details
#command ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/rboss/cli/invoker.rb', line 78 def command command = "#{jboss_cli} --connect" command << " --controller=#@server" if @server command << " --user='#@user'" if @user command << " --password='#@password'" if @password command end |
#execute(commands) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/rboss/cli/invoker.rb', line 149 def execute(commands) commands = [commands] if commands.is_a? String exec = "#{command} --command#{commands.size > 1 ? 's' : ''}=\"#{commands.join ','}\"" @logger.debug exec `#{exec}`.chomp end |
#gets_and_invoke(path, operation, parameters) ⇒ Object
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 |
# File 'lib/rboss/cli/invoker.rb', line 101 def gets_and_invoke(path, operation, parameters) result = result("#{path}:read-operation-description(name=#{operation})") props = result['request-properties'] props ||= {} builder = CommandBuilder::new operation help_printed = false info = Yummi::colorize('Please input the requested parameters', :yellow) props.each do |name, detail| next if (@skip_optional and (not detail['required'] or detail['default'])) parameter_type = detail['type'] input = parameters[name] unless input puts info unless help_printed help_printed = true = Yummi::colorize(name, :intense_blue) required = detail['required'] default_value = detail['default'] << ' | ' << RBoss::Colorizers.type(parameter_type).colorize(parameter_type) << ' | ' << Yummi::colorize('Required', :red) if required << ' | ' << Yummi::colorize('Optional', :cyan) unless required << ' | ' << Yummi::colorize("[#{default_value}]", :blue) if default_value << "\n" << Yummi::colorize(detail['description'], 'bold.black') puts input = get_input while required and input.empty? puts Yummi::colorize('Required parameter!', :red) input = get_input end end if input.empty? puts Yummi::colorize('Parameter skipped!', :yellow) next end begin builder << {:name => name, :value => parameter_type.convert(input)} rescue Exception => e puts Yummi::colorize('Your input could not be converted:', :yellow) puts Yummi::colorize(e., :red) puts Yummi::colorize('This will not affect other inputs, you can continue to input other values.', :yellow) puts 'Press ENTER to continue' gets end end result = result("#{path}:#{builder}") #TODO print a table using the returned parameters YAML::dump(result).on_box end |
#invoke(operation, resources, parameters) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rboss/cli/invoker.rb', line 86 def invoke(operation, resources, parameters) buff = '' resources.each do |key, resource_names| if resource_mappings.has_key? key mapping = resource_mappings[key] resource = RBoss::Cli::Resource::new(self, mapping) resource.context[:domain_host] = @domain_host resource.context[:domain_server] = @domain_server result = resource.invoke(operation, resource_names, parameters) buff << result.to_s if result end end buff end |
#result(commands) ⇒ Object
156 157 158 |
# File 'lib/rboss/cli/invoker.rb', line 156 def result(commands) eval_result(execute commands) end |