Class: Hawkular::Operations::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Hawkular::Operations::Client
- Includes:
- WebSocket::Client
- Defined in:
- lib/hawkular/operations/operations_api.rb
Overview
Client class to interact with the agent via websockets
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#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.
-
#close_connection! ⇒ Object
Closes the WebSocket connection.
-
#disable_deployment(hash, &callback) ⇒ Object
Disable a WildFly deployment.
-
#enable_deployment(hash, &callback) ⇒ Object
Enable a WildFly deployment.
-
#export_jdr(resource_path, &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, 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 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_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.
63 64 65 66 67 68 69 70 71 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 |
# File 'lib/hawkular/operations/operations_api.rb', line 63 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 'no parameter ":host" or ":entrypoint" given' if args[:host].nil? super(args[:host], args[:credentials], args[:options]) url = "ws#{args[:use_secure_connection] ? 's' : ''}://#{args[:host]}/hawkular/command-gateway/ui/ws" creds = args[:credentials] base64_creds = ["#{creds[:username]}:#{creds[:password]}"].pack('m').delete("\r\n") = { headers: { 'Authorization' => 'Basic ' + base64_creds, 'Hawkular-Tenant' => args[:options][:tenant], 'Accept' => 'application/json' } } @logger = Hawkular::Logger.new @ws = Simple.connect url, do |client| client.on(:message, once: true) do |msg| = msg.data.to_msg_hash logger.log("Sent WebSocket message: #{}") case [:operationName] when 'WelcomeResponse' @session_id = [:data]['sessionId'] end end end sleep args[:wait_time] end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger
34 35 36 |
# File 'lib/hawkular/operations/operations_api.rb', line 34 def logger @logger end |
#session_id ⇒ Object
Returns the value of attribute session_id
34 35 36 |
# File 'lib/hawkular/operations/operations_api.rb', line 34 def session_id @session_id end |
#ws ⇒ Object
Returns the value of attribute ws
34 35 36 |
# File 'lib/hawkular/operations/operations_api.rb', line 34 def ws @ws end |
Instance Method Details
#add_datasource(hash, &callback) ⇒ Object
Adds a new datasource
269 270 271 272 273 274 |
# File 'lib/hawkular/operations/operations_api.rb', line 269 def add_datasource(hash, &callback) required = [:resourcePath, :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
158 159 160 161 162 163 164 165 166 |
# File 'lib/hawkular/operations/operations_api.rb', line 158 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 = [:resource_path, :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
287 288 289 290 291 292 293 |
# File 'lib/hawkular/operations/operations_api.rb', line 287 def add_jdbc_driver(hash, &callback) required = [:resource_path, :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 |
#close_connection! ⇒ Object
Closes the WebSocket connection
114 115 116 |
# File 'lib/hawkular/operations/operations_api.rb', line 114 def close_connection! @ws.close end |
#disable_deployment(hash, &callback) ⇒ Object
Disable a WildFly deployment
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/hawkular/operations/operations_api.rb', line 220 def disable_deployment(hash, &callback) required = [:resource_path, :deployment_name] check_pre_conditions hash, required, &callback cp = ::Hawkular::Inventory::CanonicalPath.parse hash[:resource_path] server_path = cp.up.to_s hash[:resource_path] = server_path 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
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/hawkular/operations/operations_api.rb', line 199 def enable_deployment(hash, &callback) required = [:resource_path, :deployment_name] check_pre_conditions hash, required, &callback cp = ::Hawkular::Inventory::CanonicalPath.parse hash[:resource_path] server_path = cp.up.to_s hash[:resource_path] = server_path 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_path, &callback) ⇒ Object
Exports the JDR report
299 300 301 302 303 304 |
# File 'lib/hawkular/operations/operations_api.rb', line 299 def export_jdr(resource_path, &callback) fail 'resource_path must be specified' if resource_path.nil? check_pre_conditions(&callback) invoke_specific_operation({ resourcePath: resource_path }, '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, operationName [String]
124 125 126 127 128 129 |
# File 'lib/hawkular/operations/operations_api.rb', line 124 def invoke_generic_operation(hash, &callback) required = [:resourcePath, :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 found here git.io/v2h1a (Use only the first part of the name without the Request/Response suffix), e.g. RemoveDatasource (and not RemoveDatasourceRequest)
138 139 140 141 142 143 144 |
# File 'lib/hawkular/operations/operations_api.rb', line 138 def invoke_specific_operation(operation_payload, operation_name, &callback) fail 'Operation must be specified' if operation_name.nil? required = [:resourcePath] 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
241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/hawkular/operations/operations_api.rb', line 241 def restart_deployment(hash, &callback) required = [:resource_path, :deployment_name] check_pre_conditions hash, required, &callback cp = ::Hawkular::Inventory::CanonicalPath.parse hash[:resource_path] server_path = cp.up.to_s hash[:resource_path] = server_path 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
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/hawkular/operations/operations_api.rb', line 177 def undeploy(hash, &callback) hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true required = [:resource_path, :deployment_name] check_pre_conditions hash, required, &callback cp = ::Hawkular::Inventory::CanonicalPath.parse hash[:resource_path] server_path = cp.up.to_s hash[:resource_path] = server_path 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
316 317 318 319 320 |
# File 'lib/hawkular/operations/operations_api.rb', line 316 def update_collection_intervals(hash, &callback) required = [:resourcePath, :metricTypes, :availTypes] check_pre_conditions hash, required, &callback invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback) end |