Module: Puppet_X::Coi::Jboss::Provider::ConfigNode

Defined in:
lib/puppet_x/coi/jboss/provider/confignode.rb

Overview

A module for ConfigNode

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 4

def create
  trace 'create'
  if exists?
    return
  end
  ret = bringUp 'Configuration node', "#{compiledpath}:add(#{compileprops})"
  invalidate
  return ret
end

#destroyObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 14

def destroy
  trace 'destroy'
  if not exists?
    return
  end
  if status == :running
    doStop
  end
  ret = bringDown 'Configuration node', "#{compiledpath}:remove()"
  invalidate
  return ret
end

#ensureObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 72

def ensure
  trace 'ensure'

  exists?
  if @data.nil?
    @property_hash[:ensure] = :absent
    traceout 'ensure()', :absent
    return :absent
  end
  if not @data['status'].nil?
    st = @data['status'].upcase
    if st == 'DISABLED'
      @property_hash[:ensure] = :disabled
      traceout 'ensure()', :disabled
      return :disabled
    end
    if ['RUNNING', 'STARTED'].include? st
      @property_hash[:ensure] = :running
      traceout 'ensure()', :running
      return :running
    else
      @property_hash[:ensure] = :stopped
      traceout 'ensure()', :stopped
      return :stopped
    end
  end
  if not @data['enabled'].nil?
    if @data['enabled']
      @property_hash[:ensure] = :enabled
      traceout 'ensure()', :enabled
      return :enabled
    else
      @property_hash[:ensure] = :disabled
      traceout 'ensure()', :disabled
      return :disabled
    end
  end
  if @data.length > 0
    @property_hash[:ensure] = :present
    traceout 'ensure()', :present
    return :present
  end
end

#ensure=(value) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 116

def ensure= value
  trace 'ensure=(%s)' % [ value.inspect ]
  case value
    when :present then create
    when :absent then destroy
    when :running then doStart
    when :stopped then doStop
    when :enabled then doEnable
    when :disabled then doDisable
  end
  traceout 'ensure=(%s)' % value.inspect, value.inspect
  return value
end

#exists?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 27

def exists?
  trace 'exists?'
  if @clean
    return (not @data.nil?)
  end
  # TODO: This line is probably useless, resource path cannot be nil (at lesat when creating type with Puppet::Type.type(:jboss_confignode).new(raw) )
  @resource[:path] = @resource[:name] if @resource[:path].nil?
  @resource[:properties] = {} if @resource[:properties].nil?
  @resource[:properties].each do |key, value|
    if value == "undef" or value == :undef
      @resource[:properties][key] = nil
    end
  end

  res = executeAndGet "#{compiledpath}:read-resource(include-runtime=true, include-defaults=false)"
  if res[:result]
    @data = {}
    res[:data].each do |key, value|
      props = @resource[:properties]
      @data[key] = value
      if not @property_hash.key? :properties
        @property_hash[:properties] = {}
      end
      if props.key? key
        @property_hash[:properties][key] = value
      end
    end
    @clean = true
    traceout 'status()', true
    return true
  end
  @clean = true
  @data = nil
  traceout 'status()', false
  return false
end

#propertiesObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 130

def properties
  trace 'properties()'

  if @data.nil?
    traceout 'properties()', {}
    return {}
  else
    hash = {}
    @property_hash[:properties] = {} if @property_hash[:properties].nil?
    @property_hash[:properties].each do |k, v|
      if v.nil? or !!v == v or v.is_a? Numeric or v.is_a? Hash or v.is_a? Array
        hash[k.to_s] = v
      else
        hash[k.to_s] = v.to_s
      end
    end
    traceout 'properties()', hash
    return hash
  end
end

#properties=(newprops) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 151

def properties= newprops
  trace 'properties=(%s)' % newprops.inspect

  # Sorting by value to process `nil` values first
  sorted = newprops.sort do |a, b|
    if a[1] == b[1]
      0
    elsif a[1].nil? and not b[1].nil?
      -1
    elsif not a[1].nil? and b[1].nil?
      1
    else
      0
    end
  end
  sorted.each do |arr|
    key, value = arr
    if not @data.key? key or @data[key] != value
      writekey key, value
      Puppet.notice "JBoss::Property: Key `#{key}` with value `#{value.inspect}` for path `#{compiledpath}` has been set."
    end
  end
end

#statusObject



64
65
66
67
68
69
70
# File 'lib/puppet_x/coi/jboss/provider/confignode.rb', line 64

def status
  trace 'status'
  meth = self.method 'ensure'
  ret = meth.call
  traceout 'status()', ret
  return ret
end