Class: Puppet_X::Coi::Jboss::Provider::AbstractJbossCli
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet_X::Coi::Jboss::Provider::AbstractJbossCli
- Defined in:
- lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb
Overview
Base class for all JBoss providers
Constant Summary collapse
- DEFAULT_SHELL_EXECUTOR =
Puppet_X::Coi::Jboss::Internal::Executor::ShellExecutor.new
- @@bin =
"bin/jboss-cli.sh"
- @@contents =
nil
Instance Method Summary collapse
-
#bringDown(typename, cmd) ⇒ Object
Method that delegates execution of command.
-
#bringUp(typename, cmd) ⇒ Object
Method that delegates execution of command.
-
#compilecmd(cmd) ⇒ String
Method that delegates compilation of jboss command.
-
#config_controller ⇒ String
Method that returns name of the controller that we will use when connecting to jboss instance.
-
#config_profile ⇒ String
Method that return name of the profile that we need to add at the start of jboss command.
-
#config_runasdomain ⇒ Boolean
Method that returns value that teels us if we need to run jboss in domain.
-
#controllerConfig(resource) ⇒ Hash
Method that make configuration hash from resource.
- #escape(value) ⇒ Object
-
#execute(jbosscmd) ⇒ Object
Method that configures every variable that is needed to execute the provided command.
-
#executeAndGet(jbosscmd) ⇒ Object
Method that executes command without any retry if command fails.
-
#executeAndGetResult(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) ⇒ Object
Method that delegates execution of command to cli_executor.
-
#executeWithFail(typename, cmd, way) ⇒ Object
Method that executes command and if command fails it prints information.
-
#executeWithoutRetry(jbosscmd) ⇒ Object
Method that executes command without any retry if command fails.
-
#execution_state_wrapper=(execution_state_wrapper) ⇒ Object
Standard setter for execution state wrapper.
-
#initialize(resource = nil) ⇒ AbstractJbossCli
constructor
Default constructor that will also initialize 3 external object, system_runner, compilator and command executor.
-
#is_runasdomain ⇒ Boolean
Method that tells us if we want to run jboss in domain mode.
-
#jboss_product ⇒ String
Standard getter for jboss_product.
-
#jbossas? ⇒ String
Standard getter for jbossas.
-
#jbossclibin ⇒ String
Method that returns jboss-cli command path.
-
#jbosshome ⇒ String
Method that returns jboss home value.
-
#jbosslog ⇒ String
Method that returns value of log.
-
#run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) ⇒ Object
Method that will prepare and delegate execution of command.
- #setattribute(path, name, value) ⇒ Object
-
#setattribute_raw(path, name, value) ⇒ Object
Low level set attribute method that sets value to property hash.
-
#shell_executor ⇒ Object
Standard getter for shell executor.
-
#shell_executor=(shell_executor) ⇒ Object
Standard setter for shell_executor.
-
#timeout_cli ⇒ Object
Standard getter for timeout_cli.
- #trace(method) ⇒ Object
- #traceout(method, retval) ⇒ Object
Constructor Details
#initialize(resource = nil) ⇒ AbstractJbossCli
Default constructor that will also initialize 3 external object, system_runner, compilator and command executor
12 13 14 15 16 17 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 12 def initialize(resource=nil) super(resource) @compilator = Puppet_X::Coi::Jboss::Internal::CommandCompilator.new @cli_executor = nil ensure_cli_executor end |
Instance Method Details
#bringDown(typename, cmd) ⇒ Object
Method that delegates execution of command
81 82 83 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 81 def bringDown(typename, cmd) executeWithFail(typename, cmd, 'to remove') end |
#bringUp(typename, cmd) ⇒ Object
Method that delegates execution of command
74 75 76 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 74 def bringUp(typename, cmd) executeWithFail(typename, cmd, 'to create') end |
#compilecmd(cmd) ⇒ String
Method that delegates compilation of jboss command
127 128 129 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 127 def compilecmd(cmd) @compilator.compile(@resource[:runasdomain], @resource[:profile], cmd) end |
#config_controller ⇒ String
Method that returns name of the controller that we will use when connecting to jboss instance
52 53 54 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 52 def config_controller Puppet_X::Coi::Jboss::Configuration::config_value :controller end |
#config_profile ⇒ String
Method that return name of the profile that we need to add at the start of jboss command
58 59 60 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 58 def config_profile Puppet_X::Coi::Jboss::Configuration::config_value :profile end |
#config_runasdomain ⇒ Boolean
Method that returns value that teels us if we need to run jboss in domain
46 47 48 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 46 def config_runasdomain Puppet_X::Coi::Jboss::Configuration::config_value :runasdomain end |
#controllerConfig(resource) ⇒ Hash
Method that make configuration hash from resource
149 150 151 152 153 154 155 156 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 149 def controllerConfig resource conf = { :controller => resource[:controller], :ctrluser => resource[:ctrluser], :ctrlpasswd => resource[:ctrlpasswd], } conf end |
#escape(value) ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 209 def escape value if value.respond_to? :to_str str = value.gsub(/([^\\])\"/, '\1\\"') else str = value end str.inspect end |
#execute(jbosscmd) ⇒ Object
Method that configures every variable that is needed to execute the provided command
87 88 89 90 91 92 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 87 def execute(jbosscmd) retry_count = @resource[:retry] retry_timeout = @resource[:retry_timeout] ctrlcfg = controllerConfig @resource @cli_executor.run_command(jbosscmd, is_runasdomain, ctrlcfg, retry_count, retry_timeout) end |
#executeAndGet(jbosscmd) ⇒ Object
Method that executes command without any retry if command fails
103 104 105 106 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 103 def executeAndGet(jbosscmd) ctrlcfg = controllerConfig @resource executeAndGetResult(jbosscmd, is_runasdomain, ctrlcfg, 0, 0) end |
#executeAndGetResult(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) ⇒ Object
Method that delegates execution of command to cli_executor
137 138 139 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 137 def executeAndGetResult(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) @cli_executor.executeAndGet(cmd, runasdomain, ctrlcfg, retry_count, retry_timeout) end |
#executeWithFail(typename, cmd, way) ⇒ Object
Method that executes command and if command fails it prints information
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 112 def executeWithFail(typename, cmd, way) executed = execute(cmd) if not executed[:result] ex = "\n#{typename} failed #{way}:\n[CLI command]: #{executed[:cmd]}\n[Error message]: #{executed[:lines]}" if not $add_log.nil? and $add_log > 0 ex = "#{ex}\n#{printlog $add_log}" end raise ex end executed end |
#executeWithoutRetry(jbosscmd) ⇒ Object
Method that executes command without any retry if command fails
96 97 98 99 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 96 def executeWithoutRetry(jbosscmd) ctrlcfg = controllerConfig @resource @cli_executor.run_command(jbosscmd, is_runasdomain, ctrlcfg, 0, 0) end |
#execution_state_wrapper=(execution_state_wrapper) ⇒ Object
Standard setter for execution state wrapper
231 232 233 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 231 def execution_state_wrapper=(execution_state_wrapper) @cli_executor.execution_state_wrapper = execution_state_wrapper end |
#is_runasdomain ⇒ Boolean
Method that tells us if we want to run jboss in domain mode
67 68 69 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 67 def is_runasdomain @resource[:runasdomain] end |
#jboss_product ⇒ String
Standard getter for jboss_product
160 161 162 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 160 def jboss_product @cli_executor.jboss_product end |
#jbossas? ⇒ String
Standard getter for jbossas
166 167 168 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 166 def jbossas? @cli_executor.jbossas? end |
#jbossclibin ⇒ String
Method that returns jboss-cli command path
24 25 26 27 28 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 24 def jbossclibin home = self.jbosshome path = "#{home}/#{@@bin}" path end |
#jbosshome ⇒ String
Method that returns jboss home value
34 35 36 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 34 def jbosshome Puppet_X::Coi::Jboss::Configuration::config_value :home end |
#jbosslog ⇒ String
Method that returns value of log
40 41 42 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 40 def jbosslog Puppet_X::Coi::Jboss::Configuration::config_value :console_log end |
#run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) ⇒ Object
Method that will prepare and delegate execution of command
142 143 144 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 142 def run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) @cli_executor.run_command(jbosscmd, runasdomain, ctrlcfg, retry_count, retry_timeout) end |
#setattribute(path, name, value) ⇒ Object
175 176 177 178 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 175 def setattribute(path, name, value) escaped = value.nil? ? nil : escape(value) setattribute_raw(path, name, escaped) end |
#setattribute_raw(path, name, value) ⇒ Object
Low level set attribute method that sets value to property hash
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 183 def setattribute_raw(path, name, value) Puppet.debug "#{name.inspect} setting to #{value.inspect} for path: #{path}" if value.nil? cmd = "#{path}:undefine-attribute(name=\"#{name.to_s}\")" else cmd = "#{path}:write-attribute(name=\"#{name.to_s}\", value=#{value})" end if is_runasdomain cmd = "/profile=#{@resource[:profile]}#{cmd}" end res = executeAndGet(cmd) Puppet.debug("Setting attribute response: #{res.inspect}") if not res[:result] raise "Cannot set #{name} for #{path}: #{res[:data]}" end @property_hash[name] = value end |
#shell_executor ⇒ Object
Standard getter for shell executor
225 226 227 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 225 def shell_executor @cli_executor.shell_executor end |
#shell_executor=(shell_executor) ⇒ Object
Standard setter for shell_executor
220 221 222 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 220 def shell_executor=(shell_executor) @cli_executor.shell_executor = shell_executor end |
#timeout_cli ⇒ Object
Standard getter for timeout_cli
171 172 173 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 171 def timeout_cli @cli_executor.timeout_cli end |
#trace(method) ⇒ Object
201 202 203 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 201 def trace method Puppet.debug '%s[%s] > IN > %s' % [self.class, @resource[:name], method] end |
#traceout(method, retval) ⇒ Object
205 206 207 |
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 205 def traceout method, retval Puppet.debug '%s[%s] > OUT > %s: %s' % [self.class, @resource[:name], method, retval.inspect] end |