Class: Aspera::Cli::Plugins::Orchestrator

Inherits:
BasicAuth show all
Defined in:
lib/aspera/cli/plugins/orchestrator.rb

Overview

Aspera Orchestrator

Constant Summary

Constants inherited from Base

Base::FILTER_ARGS

Instance Attribute Summary

Attributes inherited from Base

#context, #help_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicAuth

#basic_auth_api, #basic_auth_params

Methods inherited from Base

#action_for, #add_manual_header, application_name, #bulk_result, command, command_registry, commands_under, #config, crud_commands, declare_options, define_action_method, #dispatch_child, #dispatch_from_registry, #dispatch_leaf, #entity_create, #entity_delete, entity_display_name, #entity_list, #entity_modify, #entity_res_path, #entity_show, #execute_action, #execute_leaf, file_matcher, #formatter, #generate_help, #http_config, #invoke_action, option, #options, #persistency, #presets, #progress_bar, #query_read_delete, #resolve_argument, root_setup, #transfer, use_options, used_option_sources

Constructor Details

#initialize(**_) ⇒ Orchestrator

Returns a new instance of Orchestrator.



64
65
66
67
68
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 64

def initialize(**_)
  super
  @api_orch = nil
  options.parse_options!
end

Class Method Details

.detect(address_or_url) ⇒ Hash, NilClass

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 21

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?(%r{^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

#action_healthObject



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 199

def action_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
  Result::ObjectList.new(nagios.status_list)
end

#action_workflows_start(wf_id:, external_parameters:) ⇒ Object

2.1/2.2 Initiate a workorder (async / synchronous)



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 212

def action_workflows_start(wf_id:, external_parameters:, **)
  call_params = {format: :json}
  # get external parameters if any
  external_parameters.each do |name, value|
    call_params["external_parameters[#{name}]"] = value
  end
  # synchronous call ?
  call_params['synchronous'] = true if options.get_option(:synchronous, mandatory: true)
  # expected result for synchro call ?
  result_location = options.get_option(:result)
  unless result_location.nil?
    fields = result_location.split(':')
    Aspera.assert(fields.length == 2, type: Cli::BadArgument) { "Expects: work_step:result_name : #{result_location}" }
    call_params['explicit_output_step'] = fields[0]
    call_params['explicit_output_variable'] = fields[1]
    # implicitly, call is synchronous
    call_params['synchronous'] = true
  end
  result_data = call_ao("initiate/#{wf_id}", args: call_params)
  call_params['synchronous'] ? Result::Text.new(result_data) : Result::SingleObject.new(result_data)
end

#setup_apiHash

Build the Orchestrator REST API from CLI options.

Returns:

  • (Hash)

    ctx with no extra keys (stores api in @api_orch instance var)



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
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 172

def setup_api(**)
  auth_params =
    case options.get_option(:auth_style, mandatory: true)
    when :arg_pass
      {
        type:      :url,
        url_query: {
          'login'    => options.get_option(:username, mandatory: true),
          'password' => options.get_option(:password, mandatory: true)
        }
      }
    when :head_basic
      {
        type:     :basic,
        username: options.get_option(:username, mandatory: true),
        password: options.get_option(:password, mandatory: true)
      }
    when :apikey
      Aspera.error_not_implemented
    end
  @api_orch = Rest.new(
    base_url: options.get_option(:url, mandatory: true),
    auth: auth_params
  )
  {}
end

#wizard(wizard, app_url) ⇒ Hash

Returns :preset_value, :test_args.

Parameters:

  • wizard (Wizard)

    The wizard object

  • app_url (String)

    Tested URL

Returns:

  • (Hash)

    :preset_value, :test_args



48
49
50
51
52
53
54
55
56
57
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 48

def wizard(wizard, app_url)
  return {
    preset_value: {
      url:      app_url,
      username: options.get_option(:username, mandatory: true),
      password: options.get_option(:password, mandatory: true)
    },
    test_args:    'workflow list'
  }
end