Class: Aspera::Cli::Plugins::Orchestrator
- Defined in:
- lib/aspera/cli/plugins/orchestrator.rb
Overview
Aspera Orchestrator
Constant Summary collapse
- ACTIONS =
%i[health info workflows workorders workstep plugins processes monitors].freeze
Constants inherited from Base
Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**_) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
Methods inherited from BasicAuth
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Base
#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #lookup_entity_generic, #options, percent_selector, #persistency, #query_read_delete, #transfer, #value_create_modify
Constructor Details
#initialize(**_) ⇒ Orchestrator
Returns a new instance of Orchestrator.
58 59 60 61 62 63 64 65 66 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 58 def initialize(**_) super @api_orch = nil .declare(:result, "Specify result value as: 'work_step:parameter'") .declare(:synchronous, 'Wait for completion', allowed: Allowed::TYPES_BOOLEAN, default: false) .declare(:ret_style, 'How return type is requested in api', allowed: %i[header arg ext], default: :arg) .declare(:auth_style, 'Authentication type', allowed: %i[arg_pass head_basic apikey], default: :head_basic) . end |
Class Method Details
.detect(address_or_url) ⇒ Hash, NilClass
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 20 def detect(address_or_url) address_or_url = "https://#{address_or_url}" unless address_or_url.match?(%r{^[a-z]{1,6}://}) urls = [address_or_url] urls.push("#{address_or_url}#{STANDARD_PATH}") unless address_or_url.end_with?(STANDARD_PATH) error = nil urls.each do |base_url| next unless base_url.match?('https?://') api = Rest.new(base_url: base_url) data, http = api.read(TEST_ENDPOINT, query: {format: :json}, ret: :both) next unless data['remote_orchestrator_info'] url = http.uri.to_s return { version: data['remote_orchestrator_info']['orchestrator-version'], url: url[0..url.index(TEST_ENDPOINT) - 2] } rescue StandardError => e error = e Log.log.debug{"detect error: #{e}"} end raise error if error return end |
Instance Method Details
#execute_action ⇒ Object
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 102 def execute_action auth_params = case .get_option(:auth_style, mandatory: true) when :arg_pass { type: :url, url_query: { 'login' => .get_option(:username, mandatory: true), 'password' => .get_option(:password, mandatory: true) } } when :head_basic { type: :basic, username: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) } when :apikey Aspera.error_not_implemented end @api_orch = Rest.new( base_url: .get_option(:url, mandatory: true), auth: auth_params ) command1 = .get_next_command(ACTIONS) case command1 when :health nagios = Nagios.new begin info = call_ao('remote_node_ping', format: 'xml', xml_arrays: false) nagios.add_ok('api', 'accessible') nagios.check_product_version('api', 'orchestrator', info['orchestrator-version']) rescue StandardError => e nagios.add_critical('node api', e.to_s) end Main.result_object_list(nagios.status_list) # 14. Ping the remote Instance when :info result = call_ao('remote_node_ping', format: 'xml', xml_arrays: false) return Main.result_single_object(result) # 12. Orchestrator Background Process status when :processes # TODO: Bug ? API has only XML format result = call_ao('processes_status', format: 'xml') return Main.result_object_list(result['process']) # 13. Orchestrator Monitor when :monitors result = call_ao('monitor_snapshot') return Main.result_single_object(result['monitor']) when :plugins # TODO: Bug ? only json format on url result = call_ao('plugin_version') return Main.result_object_list(result['Plugin']) when :workflows command = .get_next_command(%i[list status inputs details start export workorders outputs]) case command # 1. List all available workflows on the system when :list result = call_ao('workflows_list') return Main.result_object_list(result['workflows']['workflow'], fields: %w[id portable_id name published_status published_revision_id latest_revision_id last_modification]) # 2.1 Initiate a workorder - Asynchronous # 2.2 Initiate a workorder - Synchronous when :start result = { type: :single_object, data: nil } call_params = {format: :json} wf_id = instance_identifier # get external parameters if any .get_next_argument('external_parameters', mandatory: false, validation: Hash, default: {}).each do |name, value| call_params["external_parameters[#{name}]"] = value end # synchronous call ? call_params['synchronous'] = true if .get_option(:synchronous, mandatory: true) # expected result for synchro call ? result_location = .get_option(:result) unless result_location.nil? result[:type] = :status fields = result_location.split(':') raise Cli::BadArgument, "Expects: work_step:result_name : #{result_location}" if fields.length != 2 call_params['explicit_output_step'] = fields[0] call_params['explicit_output_variable'] = fields[1] # implicitly, call is synchronous call_params['synchronous'] = true end result[:type] = :text if call_params['synchronous'] result[:data] = call_ao("initiate/#{wf_id}", args: call_params) return result # 3. Fetch input specification for a workflow when :inputs result = call_ao("workflow_inputs_spec/#{instance_identifier}") return Main.result_single_object(result['workflow_inputs_spec']) # 4. Check the running status for all workflows # 5. Check the running status for a particular workflow when :status wf_id = instance_identifier result = call_ao(wf_id.eql?(SpecialValues::ALL) ? 'workflows_status' : "workflows_status/#{wf_id}") return Main.result_object_list(result['workflows']['workflow']) # 6. Check the detailed running status for a particular workflow when :details result = call_ao("workflow_details/#{instance_identifier}") return Main.result_object_list(result['workflows']['workflow']['statuses']) # 15. Fetch output specification for a particular work flow when :outputs result = call_ao("workflow_outputs_spec/#{instance_identifier}") return Main.result_object_list(result['workflow_outputs_spec']['output']) # 19.Fetch all workorders from a workflow when :workorders result = call_ao("work_orders_list/#{instance_identifier}") return Main.result_object_list(result['work_orders']) when :export result = call_ao("export_workflow/#{instance_identifier}", format: nil, http: true) return Main.result_text(result.body) end when :workorders command = .get_next_command(%i[status cancel reset output]) case command # 7. Check the status for a particular work order when :status wo_id = instance_identifier result = call_ao("work_order_status/#{wo_id}") return Main.result_single_object(result['work_order']) # 9. Cancel a Work Order when :cancel wo_id = instance_identifier result = call_ao("work_order_cancel/#{wo_id}") return Main.result_single_object(result['work_order']) # 11. Reset a Work order when :reset wo_id = instance_identifier result = call_ao("work_order_reset/#{wo_id}") return Main.result_single_object(result['work_order']) # 16. Fetch output of a work order when :output wo_id = instance_identifier result = call_ao("work_order_output/#{wo_id}", format: 'xml') return Main.result_object_list(result['variable']) end when :workstep command = .get_next_command(%i[status cancel]) case command # 8. Check the status of a Step when :status ws_id = instance_identifier result = call_ao("work_step_status/#{ws_id}") return Main.result_single_object(result) # 10. Cancel a Work Step when :cancel ws_id = instance_identifier result = call_ao("work_step_cancel/#{ws_id}") return Main.result_single_object(result) end else Aspera.error_unexpected_value(command) end end |
#wizard(wizard, app_url) ⇒ Hash
Returns :preset_value, :test_args.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 47 def wizard(wizard, app_url) return { preset_value: { url: app_url, username: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) }, test_args: 'workflow list' } end |