Class: PuppetX::Wildfly::OperationRequest
- Inherits:
-
Object
- Object
- PuppetX::Wildfly::OperationRequest
- Defined in:
- lib/puppet_x/wildfly/operation_request.rb
Instance Method Summary collapse
- #add(resource, state, recursive, headers) ⇒ Object
- #deploy(name, source, server_group, headers) ⇒ Object
- #deploy_operations(name, source, server_group) ⇒ Object
-
#deployment_checksum(name) ⇒ Object
deployment.
- #diff(desired_state, resource) ⇒ Object
- #evaluate(command) ⇒ Object
-
#exec(command, ignore_failed_outcome = false) ⇒ Object
cli.
-
#exists?(resource) ⇒ Boolean
resource.
-
#initialize(api_client) ⇒ OperationRequest
constructor
A new instance of OperationRequest.
- #operation ⇒ Object
- #read(resource, recursive = false) ⇒ Object
- #remove(resource, headers) ⇒ Object
- #split(resource, state) ⇒ Object
- #undeploy(name, server_group, headers) ⇒ Object
- #undeploy_operations(name, server_group) ⇒ Object
- #update(resource, state, recursive, headers) ⇒ Object
- #update_deploy(name, source, server_group, headers) ⇒ Object
- #update_deploy_operations(name, source, server_group) ⇒ Object
Constructor Details
#initialize(api_client) ⇒ OperationRequest
Returns a new instance of OperationRequest.
9 10 11 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 9 def initialize(api_client) @api_client = api_client end |
Instance Method Details
#add(resource, state, recursive, headers) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 49 def add(resource, state, recursive, headers) if recursive resources = split(resource, state) operations = resources.map { |(atomic_resource, atomic_state)| operation.add(atomic_resource).with(atomic_state).build } @api_client.submit(operation.composite(*operations).headers(headers).build) else @api_client.submit(operation.add(resource).with(state).headers(headers).build) end end |
#deploy(name, source, server_group, headers) ⇒ Object
96 97 98 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 96 def deploy(name, source, server_group, headers) @api_client.submit(operation.composite(*deploy_operations(name, source, server_group)).headers(headers).build) end |
#deploy_operations(name, source, server_group) ⇒ Object
100 101 102 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 100 def deploy_operations(name, source, server_group) [operation.add_content(name, source).build, operation.target(server_group).deploy(name).build] end |
#deployment_checksum(name) ⇒ Object
deployment
88 89 90 91 92 93 94 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 88 def deployment_checksum(name) response = read("/deployment=#{name}") bytes_value = response['content'].first['hash']['BYTES_VALUE'] decoded = Base64.decode64(bytes_value) decoded.unpack('H*').first end |
#diff(desired_state, resource) ⇒ Object
76 77 78 79 80 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 76 def diff(desired_state, resource) current_state = read(resource) to_update = desired_state.reject { |key, value| value == current_state[key] } to_update.map { |attribute, value| operation.write_attribute(resource, attribute, value).build } end |
#evaluate(command) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 20 def evaluate(command) condition, command = command.split(/\sof\s/) variable, operator, value = condition.gsub(/[()]/, '').split("\s") response = exec(command, :ignore_failed_outcome => true) return response[variable].nil? if value == 'undefined' condition = if operator == 'has' "#{response[variable].inspect}.include?(#{value})" else "'#{response[variable]}' #{operator} '#{value}'" end eval(condition) end |
#exec(command, ignore_failed_outcome = false) ⇒ Object
cli
15 16 17 18 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 15 def exec(command, ignore_failed_outcome = false) detyped_request = CLICommand.new(command).to_detyped_request @api_client.submit(detyped_request, ignore_failed_outcome) end |
#exists?(resource) ⇒ Boolean
resource
39 40 41 42 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 39 def exists?(resource) response = @api_client.submit(operation.read(resource).build, :ignore_failed_outcome => true) response['outcome'] == 'success' end |
#operation ⇒ Object
120 121 122 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 120 def operation OperationBuilder.new end |
#read(resource, recursive = false) ⇒ Object
44 45 46 47 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 44 def read(resource, recursive = false) response = @api_client.submit(operation.read(resource).with(:recursive => recursive).build) response['result'] end |
#remove(resource, headers) ⇒ Object
82 83 84 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 82 def remove(resource, headers) @api_client.submit(operation.remove(resource).headers(headers).build) end |
#split(resource, state) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 69 def split(resource, state) child_hashes = state.reject { |_, v| !v.is_a?(Hash) } child_resources = child_hashes.reduce([]) { |resources, (k, v)| resources.concat(v.reduce([]) { |r2, (k2, v2)| r2.concat(split("#{resource}/#{k}=#{k2}", v2)) }) } base_state = [resource, state.reject { |_, v| v.is_a?(Hash) }] [base_state].concat(child_resources) end |
#undeploy(name, server_group, headers) ⇒ Object
104 105 106 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 104 def undeploy(name, server_group, headers) @api_client.submit(operation.composite(*undeploy_operations(name, server_group)).headers(headers).build) end |
#undeploy_operations(name, server_group) ⇒ Object
108 109 110 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 108 def undeploy_operations(name, server_group) [operation.target(server_group).undeploy(name).build, operation.remove_content(name).build] end |
#update(resource, state, recursive, headers) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 59 def update(resource, state, recursive, headers) if recursive resources = split(resource, state) operations = resources.map { |(atomic_resource, atomic_state)| diff(atomic_state, atomic_resource) }.flatten @api_client.submit(operation.composite(*operations).headers(headers).build) else @api_client.submit(operation.composite(*diff(state, resource)).headers(headers).build) end end |
#update_deploy(name, source, server_group, headers) ⇒ Object
112 113 114 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 112 def update_deploy(name, source, server_group, headers) @api_client.submit(operation.composite(*update_deploy_operations(name, source, server_group)).headers(headers).build) end |
#update_deploy_operations(name, source, server_group) ⇒ Object
116 117 118 |
# File 'lib/puppet_x/wildfly/operation_request.rb', line 116 def update_deploy_operations(name, source, server_group) undeploy_operations(name, server_group).push(*deploy_operations(name, source, server_group)) end |