Class: Puppet_X::Coi::Jboss::Provider::AbstractJbossCli

Inherits:
Puppet::Provider
  • Object
show all
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

Constructor Details

#initialize(resource = nil) ⇒ AbstractJbossCli

Default constructor that will also initialize 3 external object, system_runner, compilator and command executor

Parameters:

  • resource, (Puppet::Resource)

    standard Puppet resource that we need to call super



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

Parameters:

  • typename (String)

    is a name of resource

  • cmd (String)

    jboss command that will be executed



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

Parameters:

  • typename (String)

    is a name of resource

  • cmd (String)

    command that will be executed



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

Parameters:

  • jboss (String)

    command

Returns:

  • (String)

    compiled 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_controllerString

Method that returns name of the controller that we will use when connecting to jboss instance

Returns:

  • (String)

    controller



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_profileString

Method that return name of the profile that we need to add at the start of jboss command

Returns:

  • (String)

    profile



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_runasdomainBoolean

Method that returns value that teels us if we need to run jboss in domain

Returns:

  • (Boolean)

    runasdomain indicates if we want to run jboss in domain mode



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

Parameters:

  • resource (Hash)

    standard Puppet resource

Returns:

  • (Hash)

    conf hash that contains information that are need to execute command



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

Parameters:

  • jbosscmd (String)

    jboss command that will be executed



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

Parameters:

  • jbosscmd (String)

    jboss command



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

Parameters:

  • cmd (String)

    is a jboss command

  • runasdomain (Boolean)

    if we want to run jboss in domain mode

  • ctrlcfg (Hash)

    configuration hash

  • retry_count (Integer)

    is a number of times we want to retry execution of command after failure

  • retry_timeout (Integer)

    timmeout after which we assume that command failed to execute



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

Parameters:

  • typename (String)

    name of resource

  • cmd (String)

    jboss command

  • way (String)

    name of the action



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

Parameters:

  • jbosscmd (String)

    jboss command



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

Parameters:



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_runasdomainBoolean

Method that tells us if we want to run jboss in domain mode

Returns:

  • (Boolean)


67
68
69
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 67

def is_runasdomain
  @resource[:runasdomain]
end

#jboss_productString

Standard getter for jboss_product

Returns:

  • (String)

    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

Returns:

  • (String)

    jbossas



166
167
168
# File 'lib/puppet_x/coi/jboss/provider/abstract_jboss_cli.rb', line 166

def jbossas?
  @cli_executor.jbossas?
end

#jbossclibinString

Method that returns jboss-cli command path

Returns:

  • (String)

    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

#jbosshomeString

Method that returns jboss home value

Returns:

  • (String)

    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

#jbosslogString

Method that returns value of log

Returns:

  • (String)

    value of configuration for console 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

Returns:

  • (Object)

    actually set value



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_executorObject

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_cliObject

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