Class: Hawkular::Operations::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Operations::Client
- Includes:
- MonitorMixin, WebSocket::Client
- Defined in:
- lib/hawkular/operations/operations_api.rb
Overview
Client class to interact with the agent via websockets
Constant Summary
Constants inherited from BaseClient
BaseClient::HawkularConnectionException, BaseClient::HawkularException
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#ws ⇒ Object
Returns the value of attribute ws.
Attributes inherited from BaseClient
Instance Method Summary collapse
-
#add_datasource(hash, &callback) ⇒ Object
Adds a new datasource.
-
#add_deployment(hash, &callback) ⇒ Object
Deploys an archive file into WildFly.
-
#add_jdbc_driver(hash, &callback) ⇒ Object
Adds a new datasource.
- #base64_credentials ⇒ Object
-
#close_connection! ⇒ Object
Closes the WebSocket connection.
- #connect ⇒ Object
-
#disable_deployment(hash, &callback) ⇒ Object
Disable a WildFly deployment.
-
#enable_deployment(hash, &callback) ⇒ Object
Enable a WildFly deployment.
-
#export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback) ⇒ Object
Exports the JDR report.
-
#initialize(args) ⇒ Client
constructor
Initialize new Client.
-
#invoke_generic_operation(hash, &callback) ⇒ Object
Invokes a generic operation on the WildFly agent (the operation name must be specified in the hash) Note: if success and failure callbacks are omitted, the client will not wait for the Response message which the operation is about to run, feedId [String], operationName [String].
-
#invoke_specific_operation(operation_payload, operation_name, &callback) ⇒ Object
Invokes operation on the WildFly agent that has it’s own message type the resource on which the operation is about to run, feedId [String] found here git.io/v2h1a (Use only the first part of the name without the Request/Response suffix), e.g.
-
#restart_deployment(hash, &callback) ⇒ Object
Restart a WildFly deployment.
-
#undeploy(hash, &callback) ⇒ Object
Undeploy a WildFly deployment.
-
#update_collection_intervals(hash, &callback) ⇒ Object
Updates the collection intervals.
Methods inherited from BaseClient
#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url, #url_with_websocket_scheme
Methods included from ClientUtils
Constructor Details
#initialize(args) ⇒ Client
Initialize new Client
There are two ways of passing in the target host/port: via :host and via :entrypoint. If both are given, then :entrypoint will be used.
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 |
# File 'lib/hawkular/operations/operations_api.rb', line 86 def initialize(args) args = { credentials: {}, options: {}, wait_time: 0.5, use_secure_connection: false, entrypoint: nil }.merge(args) if args[:entrypoint] uri = URI.parse(args[:entrypoint].to_s) args[:host] = "#{uri.host}:#{uri.port}" args[:use_secure_connection] = %w[https wss].include?(uri.scheme) ? true : false end fail Hawkular::ArgumentError, 'no parameter ":host" or ":entrypoint" given' if args[:host].nil? super(args[:host], args[:credentials], args[:options]) @logger = Hawkular::Logger.new @url = "ws#{args[:use_secure_connection] ? 's' : ''}://#{args[:host]}/hawkular/command-gateway/ui/ws" @credentials = args[:credentials] @tenant = args[:options][:tenant] @wait_time = args[:wait_time] end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
31 32 33 |
# File 'lib/hawkular/operations/operations_api.rb', line 31 def logger @logger end |
#ws ⇒ Object
Returns the value of attribute ws.
31 32 33 |
# File 'lib/hawkular/operations/operations_api.rb', line 31 def ws @ws end |
Instance Method Details
#add_datasource(hash, &callback) ⇒ Object
Adds a new datasource
294 295 296 297 298 299 300 |
# File 'lib/hawkular/operations/operations_api.rb', line 294 def add_datasource(hash, &callback) required = %i[resourceId feedId xaDatasource datasourceName jndiName driverName driverClass connectionUrl] check_pre_conditions hash, required, &callback invoke_specific_operation(hash, 'AddDatasource', &callback) end |
#add_deployment(hash, &callback) ⇒ Object
Deploys an archive file into WildFly
190 191 192 193 194 195 196 197 198 |
# File 'lib/hawkular/operations/operations_api.rb', line 190 def add_deployment(hash, &callback) hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false required = %i[resource_id feed_id destination_file_name binary_content] check_pre_conditions hash, required, &callback operation_payload = prepare_payload_hash([:binary_content], hash) invoke_operation_helper(operation_payload, 'DeployApplication', hash[:binary_content], &callback) end |
#add_jdbc_driver(hash, &callback) ⇒ Object
Adds a new datasource
314 315 316 317 318 319 320 321 |
# File 'lib/hawkular/operations/operations_api.rb', line 314 def add_jdbc_driver(hash, &callback) required = %i[resource_id feed_id driver_jar_name driver_name module_name driver_class binary_content] check_pre_conditions hash, required, &callback operation_payload = prepare_payload_hash([:binary_content], hash) invoke_operation_helper(operation_payload, 'AddJdbcDriver', hash[:binary_content], &callback) end |
#base64_credentials ⇒ Object
113 114 115 |
# File 'lib/hawkular/operations/operations_api.rb', line 113 def base64_credentials ["#{@credentials[:username]}:#{@credentials[:password]}"].pack('m').delete("\r\n") end |
#close_connection! ⇒ Object
Closes the WebSocket connection
145 146 147 |
# File 'lib/hawkular/operations/operations_api.rb', line 145 def close_connection! @ws && @ws.close end |
#connect ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/hawkular/operations/operations_api.rb', line 117 def connect return if @connecting || (@ws && @ws.open?) @connecting = true = { headers: { 'Authorization' => 'Basic ' + base64_credentials, 'Hawkular-Tenant' => @tenant, 'Accept' => 'application/json' } } @ws = Simple.connect @url, do |client| client.on(:message, once: true) do |msg| = msg.data.to_msg_hash logger = Hawkular::Logger.new logger.log("Sent WebSocket message: #{}") end end Timeout.timeout(@wait_time) { sleep 0.1 until @ws.open? } ensure @connecting = false end |
#disable_deployment(hash, &callback) ⇒ Object
Disable a WildFly deployment
249 250 251 252 253 254 255 256 257 |
# File 'lib/hawkular/operations/operations_api.rb', line 249 def disable_deployment(hash, &callback) required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'DisableApplication', &callback) end |
#enable_deployment(hash, &callback) ⇒ Object
Enable a WildFly deployment
230 231 232 233 234 235 236 237 238 |
# File 'lib/hawkular/operations/operations_api.rb', line 230 def enable_deployment(hash, &callback) required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'EnableApplication', &callback) end |
#export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback) ⇒ Object
Exports the JDR report
server should be deleted. False, by default.
330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/hawkular/operations/operations_api.rb', line 330 def export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback) fail Hawkular::ArgumentError, 'resource_id must be specified' if resource_id.nil? fail Hawkular::ArgumentError, 'feed_id must be specified' if feed_id.nil? check_pre_conditions(&callback) invoke_specific_operation({ resourceId: resource_id, feedId: feed_id, deleteImmediately: delete_immediately, senderRequestId: sender_request_id }, 'ExportJdr', &callback) end |
#invoke_generic_operation(hash, &callback) ⇒ Object
Invokes a generic operation on the WildFly agent (the operation name must be specified in the hash) Note: if success and failure callbacks are omitted, the client will not wait for the Response message which the operation is about to run, feedId [String], operationName [String]
155 156 157 158 159 160 |
# File 'lib/hawkular/operations/operations_api.rb', line 155 def invoke_generic_operation(hash, &callback) required = %i[resourceId feedId operationName] check_pre_conditions hash, required, &callback invoke_operation_helper(hash, &callback) end |
#invoke_specific_operation(operation_payload, operation_name, &callback) ⇒ Object
Invokes operation on the WildFly agent that has it’s own message type the resource on which the operation is about to run, feedId [String] found here git.io/v2h1a (Use only the first part of the name without the Request/Response suffix), e.g. RemoveDatasource (and not RemoveDatasourceRequest)
169 170 171 172 173 174 175 |
# File 'lib/hawkular/operations/operations_api.rb', line 169 def invoke_specific_operation(operation_payload, operation_name, &callback) fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil? required = %i[resourceId feedId] check_pre_conditions operation_payload, required, &callback invoke_operation_helper(operation_payload, operation_name, &callback) end |
#restart_deployment(hash, &callback) ⇒ Object
Restart a WildFly deployment
268 269 270 271 272 273 274 275 276 |
# File 'lib/hawkular/operations/operations_api.rb', line 268 def restart_deployment(hash, &callback) required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'RestartApplication', &callback) end |
#undeploy(hash, &callback) ⇒ Object
Undeploy a WildFly deployment
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/hawkular/operations/operations_api.rb', line 210 def undeploy(hash, &callback) hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'UndeployApplication', &callback) end |
#update_collection_intervals(hash, &callback) ⇒ Object
Updates the collection intervals.
MetricTypeId must be of form MetricTypeSet~MetricTypeName AvailTypeId must be of form AvailTypeSet~AvailTypeName
353 354 355 356 357 |
# File 'lib/hawkular/operations/operations_api.rb', line 353 def update_collection_intervals(hash, &callback) required = %i[resourceId feedId metricTypes availTypes] check_pre_conditions hash, required, &callback invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback) end |