Module: Utils::WlsAccess
Constant Summary collapse
- DEFAULT_FILE =
get_wls_setting_file
Class Method Summary collapse
Instance Method Summary collapse
-
#controller(content, parameters = {}) ⇒ Object
controller, this should determine based on the connect url if we do wlst(t3) or rest(http).
- #rest(action, domain, domain_values, parameters = {}) ⇒ Object
- #wlst(content, parameters = {}) ⇒ Object
- #wlst2(content, action, domain, domain_values, parameters = {}) ⇒ Object
Methods included from Settings
#configuration, #get_wls_setting_file, #read_from_yaml, #setting_for, #settings
Class Method Details
.included(parent) ⇒ Object
16 17 18 |
# File 'lib/utils/wls_access.rb', line 16 def self.included(parent) parent.extend(WlsAccess) end |
Instance Method Details
#controller(content, parameters = {}) ⇒ Object
controller, this should determine based on the connect url if we do wlst(t3) or rest(http)
21 22 23 24 25 26 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 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/utils/wls_access.rb', line 21 def controller(content, parameters = {}) action = '' unless parameters.nil? action = parameters['action'] Puppet.info "Executing: action #{action}" else Puppet.info 'Executing: for a create, modify or destroy' end # check all domains of wls_settings if we need to use wlst or rest(>12.2.1) domains = configuration wls_type = 'wlst' domains.each do |key, domainValues| Puppet.debug "domain found #{key}" wls_type = 'rest' if domainValues['connect_url'].include? "http" end if wls_type == 'wlst' case action when 'index' then # if index do all domains i = 1 csv_string = '' domains.each do |key, domainValues| Puppet.debug "domain found #{key}" result = wlst2 content, action, key, domains[key], parameters if i > 1 # with multi domain, remove first line if it is a header result = result.lines.to_a[1..-1].join end csv_string += result i += 1 end return convert_csv_data_to_hash(csv_string, [], :col_sep => ';') else key = parameters['attributes'][0]['domain'] wlst2 content, action, key, domains[key], parameters end else case action when 'index' then # if index do all domains all_items = [] domains.each do |key, domainValues| Puppet.debug "domain found #{key}" result = rest action, key, domains[key], parameters all_items.concat result end return all_items else key = parameters['attributes'][0]['domain'] rest action, key, domains[key], parameters end end end |
#rest(action, domain, domain_values, parameters = {}) ⇒ Object
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/utils/wls_access.rb', line 77 def rest(action, domain, domain_values, parameters = {}) case action when 'index' then all_items = [] weblogicUser = domain_values['weblogic_user'] || 'weblogic' weblogicConnectUrl = domain_values['connect_url'] || 'http://localhost:7001' weblogicPassword = domain_values['weblogic_password'] uri_string = "#{weblogicConnectUrl}#{parameters['rest_url']}" Puppet.debug uri_string uri = URI.parse(uri_string) http = Net::HTTP.new(uri.host, uri.port) # http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request.basic_auth weblogicUser, weblogicPassword request.add_field('Accept', 'application/json') response = http.request(request) case response when Net::HTTPSuccess items = JSON.parse(response.body)['items'] items.each do |item| name = item['name'] item['domain'] = domain item['name'] = "#{domain}/#{name}" all_items.push item end else fail response.body end all_items when 'create' then Puppet.info 'rest create action' Puppet.debug parameters['attributes'] execute_rest(domain_values, parameters, 'Post') return nil when 'modify' then Puppet.info 'rest modify action' Puppet.debug parameters['attributes'] execute_rest(domain_values, parameters, 'Post') return nil when 'destroy' then Puppet.info 'rest destroy action' Puppet.debug parameters['attributes'] execute_rest(domain_values, parameters, 'Delete') return nil end end |
#wlst(content, parameters = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/utils/wls_access.rb', line 150 def wlst(content, parameters = {}) script = 'wlstScript' action = '' unless parameters.nil? action = parameters['action'] Puppet.debug "Executing: #{script} with action #{action}" else Puppet.info "Executing: #{script} for a create,modify or destroy" end tmpFile = Tempfile.new([script, '.py']) tmpFile.write(content) tmpFile.close FileUtils.chmod(0555, tmpFile.path) csv_string = '' domains = configuration case action when 'index' then # if index do all domains i = 1 domains.each do |key, values| Puppet.debug "domain found #{key}" csv_domain_string = execute_wlst(script, tmpFile, parameters, key, values, :return_output => true) if i > 1 # with multi domain, remove first line if it is a header csv_domain_string = csv_domain_string.lines.to_a[1..-1].join end csv_string += csv_domain_string i += 1 end convert_csv_data_to_hash(csv_string, [], :col_sep => ';') when 'execute' then domains.each do |key, values| # check content if we do this for the right domain if content.include? "real_domain='" + key csv_string = execute_wlst(script, tmpFile, parameters, key, values, :return_output => true) else Puppet.info "Skip WLST for domain #{key}" end end convert_csv_data_to_hash(csv_string, [], :col_sep => ';') else # Puppet.info "domain found #{domain}" domains.each do |key, values| # check content if we do this for the right domain if content.include? "real_domain='" + key Puppet.info "Got the right domain #{key} script, now execute WLST" execute_wlst(script, tmpFile, parameters, key, values, :return_output => false) else Puppet.info "Skip WLST for domain #{key}" end end end end |
#wlst2(content, action, domain, domain_values, parameters = {}) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/utils/wls_access.rb', line 132 def wlst2(content, action, domain, domain_values, parameters = {}) script = 'wlstScript' tmpFile = Tempfile.new([script, '.py']) tmpFile.write(content) tmpFile.close FileUtils.chmod(0555, tmpFile.path) case action when 'index' then execute_wlst(script, tmpFile, parameters, domain, domain_values, :return_output => true) when 'execute' then execute_wlst(script, tmpFile, parameters, domain, domain_values, :return_output => true) else execute_wlst(script, tmpFile, parameters, domain, domain_values, :return_output => false) end end |