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
Methods included from ResultParser
Constructor Details
#initialize(params = {}) ⇒ Invoker
Returns a new instance of Invoker.
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 |
# File 'lib/rboss/cli/invoker.rb', line 43 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.
41 42 43 |
# File 'lib/rboss/cli/invoker.rb', line 41 def domain_host @domain_host end |
#domain_server ⇒ Object
Returns the value of attribute domain_server.
41 42 43 |
# File 'lib/rboss/cli/invoker.rb', line 41 def domain_server @domain_server end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def server @server end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
40 41 42 |
# File 'lib/rboss/cli/invoker.rb', line 40 def user @user end |
Instance Method Details
#command ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rboss/cli/invoker.rb', line 83 def command command = "#{jboss_cli} --connect" command << " --controller=#@server" if @server if @user command << " --user='#@user'" unless @password puts 'Input server password: '.blue.bold @password = STDIN.noecho(&:gets).chomp puts 'Password saved for this session!'.green end command << " --password='#@password'" end command end |
#execute(commands) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/rboss/cli/invoker.rb', line 160 def execute(commands) commands = [commands] if commands.is_a? String exec = "#{command} --command#{commands.size > 1 ? 's' : ''}=\"#{commands.join ','}\"" @logger.debug exec result = `#{exec}`.chomp @logger.debug result result end |
#gets_and_invoke(path, operation, parameters) ⇒ Object
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 150 151 152 153 154 155 156 157 158 |
# File 'lib/rboss/cli/invoker.rb', line 113 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 = '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 = name.bold.blue required = detail['required'] default_value = detail['default'] << ' | ' << RBoss::Colorizers.type(parameter_type).colorize(parameter_type) << ' | ' << 'Required'.red if required << ' | ' << 'Optional'.cyan unless required << ' | ' << "[#{default_value}]".blue if default_value << "\n" << detail['description'].bold puts input = get_input while required and input.empty? puts 'Required parameter!'.red input = get_input end end if input.empty? puts 'Parameter skipped!'.yellow next end begin builder << {:name => name, :value => parameter_type.convert(input)} rescue Exception => e puts 'Your input could not be converted:'.yellow puts e..red puts '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}") format result end |
#invoke(operation, resources, parameters) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rboss/cli/invoker.rb', line 98 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
169 170 171 |
# File 'lib/rboss/cli/invoker.rb', line 169 def result(commands) eval_result(execute commands) end |