Module: Puppet_X::Coi::Jboss::Provider::Datasource

Includes:
BuildinsUtils, Constants
Defined in:
lib/puppet_x/coi/jboss/provider/datasource.rb

Overview

A class for JBoss datasource provider

Defined Under Namespace

Modules: Static Classes: PostWildFlyProvider, PreWildFlyProvider

Constant Summary

Constants included from Constants

Constants::ABSENTLIKE, Constants::ABSENTLIKE_WITH_S

Instance Method Summary collapse

Instance Method Details

#controllerObject

Standard getter for domain controller



130
131
132
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 130

def controller
  getproperty :controller
end

#createObject

Method that creates datasource in JBoss instance



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 9

def create
  cmd = [ "#{create_delete_cmd} add --name=#{@resource[:name]}" ]
  jta_opt(cmd)
  cmd.push "--jndi-name=#{@resource[:jndiname].inspect}"
  cmd.push "--driver-name=#{@resource[:drivername].inspect}"
  cmd.push "--min-pool-size=#{@resource[:minpoolsize].inspect}"
  cmd.push "--max-pool-size=#{@resource[:maxpoolsize].inspect}"
  cmd.push "--user-name=#{@resource[:username].inspect}"
  cmd.push "--password=#{@resource[:password].inspect}"
  if @resource[:xa]
    xa_properties = xa_datasource_properties_wrapper(createXaProperties)
    cmd.push "--xa-datasource-properties=#{xa_properties}"
  else
    cmd.push "--connection-url=#{connectionUrl.inspect}"
  end
  @resource[:options].each do |attribute, value|
    cmd.push "--#{attribute}=#{value.inspect}"
  end

  bringUp 'Datasource', cmd.join(' ')
  setenabled true
end

#dbnameObject



264
265
266
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 264

def dbname
  connectionHash()[:DatabaseName]
end

#dbname=(value) ⇒ Object

Standard setter



269
270
271
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 269

def dbname= value
  writeConnection :DatabaseName, value
end

#destroyObject

Method that remove datasource from JBoss instance



33
34
35
36
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 33

def destroy
  cmd = "#{create_delete_cmd} remove --name=#{@resource[:name]}"
  bringDown 'Datasource', cmd
end

#drivernameObject

Standard getter



156
157
158
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 156

def drivername
  getattrib 'driver-name'
end

#drivername=(value) ⇒ Object

Standard setter



161
162
163
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 161

def drivername= value
  setattrib 'driver-name', value
end

#enabledObject



226
227
228
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 226

def enabled
  getattrib('enabled').to_s
end

#enabled=(value) ⇒ Object

Standard setter



231
232
233
234
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 231

def enabled= value
  Puppet.debug "Enabling datasource #{@resource[:name]} to #{value}"
  setenabled value
end

#exists?Boolean

Method that checks if resource is present in the system

Returns:

  • (Boolean)

    true if there is such resource



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 80

def exists?
  prepare_resource
  if @resource[:dbname].nil?
    @resource[:dbname] = @resource[:name]
  end
  @data = nil
  cmd = compilecmd "#{datasource_path}:read-resource(recursive=true)"
  res = executeAndGet cmd
  if(res[:result] == false)
      Puppet.debug "Datasorce (xa: #{xa?}) `#{@resource[:name]}` does NOT exist"
      return false
  end
  Puppet.debug "Datasorce (xa: #{xa?}) `#{@resource[:name]}` exists: #{res[:data].inspect}"
  @data = res[:data]
  return true
end

#getattrib(name, default = nil) ⇒ Object



273
274
275
276
277
278
279
280
281
282
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 273

def getattrib name, default=nil
  if not @readed
    exists?
    @readed = true
  end
  if not @data.nil? and @data.key? name
    return @data[name]
  end
  return default
end

#getproperty(name, default = nil) ⇒ Object

Method get properties.

Parameters:

  • name (String)

    a key for representing name.



103
104
105
106
107
108
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 103

def getproperty name, default=nil
  if @property_hash.nil? or (@property_hash.respond_to? :key? and not @property_hash.key? name) or @property_hash[name].nil?
    return default
  end
  return @property_hash[name]
end

#hostObject



246
247
248
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 246

def host
  connectionHash()[:ServerName].to_s
end

#host=(value) ⇒ Object

Standard setter



251
252
253
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 251

def host= value
  writeConnection :ServerName, value
end

#jdbcschemeObject



236
237
238
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 236

def jdbcscheme
  connectionHash()[:Scheme]
end

#jdbcscheme=(value) ⇒ Object

Standard setter



241
242
243
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 241

def jdbcscheme= value
  writeConnection :Scheme, value
end

#jndinameObject

Standard getter for jndiname under wich the datasource wrapper will be bound



145
146
147
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 145

def jndiname
  getattrib 'jndi-name'
end

#jndiname=(value) ⇒ Object

Standard setter



150
151
152
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 150

def jndiname= value
  setattrib 'jndi-name', value
end

#jtaObject



289
290
291
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 289

def jta
  provider_impl.jta
end

#jta=(value) ⇒ Object

Standard setter for jta



294
295
296
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 294

def jta= value
  provider_impl.jta = value
end

#jta_opt(cmd) ⇒ Object

Standard setter for jta_opt



314
315
316
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 314

def jta_opt(cmd)
  provider_impl.jta_opt(cmd)
end

#maxpoolsizeObject

Standard getter



177
178
179
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 177

def maxpoolsize
  getattrib('max-pool-size').to_s
end

#maxpoolsize=(value) ⇒ Object

Standard setter



182
183
184
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 182

def maxpoolsize= value
  setattrib 'max-pool-size', value
end

#minpoolsizeObject

Standard getter



167
168
169
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 167

def minpoolsize
  getattrib('min-pool-size').to_s
end

#minpoolsize=(value) ⇒ Object

Standard setter



172
173
174
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 172

def minpoolsize= value
  setattrib 'min-pool-size', value
end

#nameObject



97
98
99
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 97

def name
  @property_hash[:name]
end

#optionsObject

Standard getter



208
209
210
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 208

def options
  managed_fetched_options
end

#options=(value) ⇒ Object

Standard setter



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 213

def options= value
  managed_fetched_options.each do |key, fetched_value|
    if ABSENTLIKE.include?(value)
      expected_value = nil
    else
      expected_value = value[key]
    end
    if expected_value != fetched_value
      setattrib(key, expected_value)
    end
  end
end

#passwordObject

Standard getter



198
199
200
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 198

def password
  getattrib('password')
end

#password=(value) ⇒ Object

Standard setter



203
204
205
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 203

def password= value
  setattrib 'password', value
end

#portObject



255
256
257
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 255

def port
  connectionHash()[:PortNumber].to_i
end

#port=(value) ⇒ Object

Standard setter



260
261
262
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 260

def port= value
  writeConnection :PortNumber, value
end

#prepare_resourcehash

Method that prepares resource that will be used later

Returns:

  • (hash)

    resource



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 57

def prepare_resource
  if @resource.nil?
    @resource = {}
  end
  if @resource[:name].nil?
    @resource[:name] = @property_hash[:name]
  end
  if @resource[:controller].nil?
    @resource[:controller] = controller
  end
  if @resource[:runasdomain].nil?
    @resource[:runasdomain] = runasdomain
  end
  if @resource[:profile].nil?
    @resource[:profile] = profile
  end
  if @resource[:xa].nil?
    @resource[:xa] = xa
  end
end

#profileObject

Standard getter for domain profile in JBoss server



135
136
137
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 135

def profile
  getproperty :profile, default_profile
end

#runasdomainObject

Standard getter for runasdomain



140
141
142
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 140

def runasdomain
  getproperty :runasdomain
end

#setattrib(name, value) ⇒ Object



284
285
286
287
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 284

def setattrib name, value
  setattribute datasource_path, name, value
  @data[name] = value
end

#setenabled(setting) ⇒ Object

Method that control whether given data source should be enabled or not



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 39

def setenabled setting
  Puppet.debug "setenabled #{setting.inspect}"
  cmd = compilecmd "#{datasource_path}:read-attribute(name=enabled)"
  res = executeAndGet cmd
  enabled = res[:data]
  Puppet.debug "Enabling datasource #{@resource[:name]} = #{enabled}: #{setting}"
  if enabled != setting
    if setting
      cmd = compilecmd "#{datasource_path}:enable(persistent=true)"
    else
      cmd = compilecmd "#{datasource_path}:disable(persistent=true)"
    end
    bringUp "Datasource enable set to #{setting.to_s}", cmd
  end
end

#usernameObject

Standard getter



188
189
190
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 188

def username
  getattrib('user-name')
end

#username=(value) ⇒ Object

Standard setter



193
194
195
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 193

def username= value
  setattrib 'user-name', value
end

#xaObject



109
110
111
112
113
114
115
116
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 109

def xa
  setting = getproperty :xa, nil
  if not setting.nil?
    return setting
  else
    return xa?
  end
end

#xa=(value) ⇒ Object

Method indicate that given data source should XA or Non-XA Default is equal to ‘false’

Parameters:

  • value (Boolean)

    a value of xa, can be true or false



121
122
123
124
125
126
127
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 121

def xa= value
  actual = getproperty :xa, false
  if actual.to_s != value.to_s
    destroy
    create
  end
end

#xa?Boolean

Method that checks if we want to run xa resource

Returns:

  • (Boolean)


300
301
302
303
304
305
306
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 300

def xa?
  if not @resource[:xa].nil?
    return @resource[:xa]
  else
    return false
  end
end

#xa_datasource_properties_wrapper(parameters) ⇒ Object

Standard setter for xa_datasource_properties_wrapper



309
310
311
# File 'lib/puppet_x/coi/jboss/provider/datasource.rb', line 309

def xa_datasource_properties_wrapper(parameters)
  provider_impl.xa_datasource_properties_wrapper(parameters)
end