Class: VcoWorkflows::Cli::Query

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/vcoworkflows/cli/query.rb

Overview

Query

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

Thor



30
31
32
# File 'lib/vcoworkflows/cli/query.rb', line 30

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#queryObject

Process the subcommand rubocop:disable CyclomaticComplexity, PerceivedComplexity



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
# File 'lib/vcoworkflows/cli/query.rb', line 36

def query
  config = VcoWorkflows::Config.new(url:        options[:server],
                                    username:   options[:username],
                                    password:   options[:password],
                                    verify_ssl: options[:verify_ssl])

  if options[:dry_run]
    puts "\nQuerying against vCO REST endpoint:\n  #{options[:server]}"
    puts "Will search for workflow: '#{workflow}'"
    puts "Will query workflow by GUID (#{options[:id]})" if options[:id]
    return
  end

  # Get the workflow
  puts "\nRetrieving workflow '#{workflow}' ..."
  wf = VcoWorkflows::Workflow.new(workflow,
                                  id:     options[:id],
                                  config: config)

  puts ''
  if options[:execution_id]
    puts "Fetching data for execution #{options[:execution_id]}..."
    execution = wf.token(options[:execution_id])
    if options[:state]
      puts "Execution started at #{Time.at(execution.start_date / 1000)}"
      puts "Execution #{execution.state} at #{Time.at(execution.end_date / 1000)}"
    else
      puts ''
      if options[:show_json]
        puts execution.to_json
      else
        puts execution
      end
    end

    if options[:logs]
      puts ''
      wflog = wf.log(options[:execution_id])
      if options[:show_json]
        puts wflog.to_json
      else
        puts wflog
      end
    end
  else
    puts wf unless options[:executions]
  end

  # Last thing we're checking for, so if it's not wanted, just return
  return unless options[:executions]
  puts "\nWorkflow:   #{wf.name}"
  puts "ID:           #{wf.id}"
  puts "Description:  #{wf.description}"
  puts "Version:      #{wf.version}"
  puts "\nExecutions: "
  executions = {}
  wf.executions.each_value { |attrs| executions[attrs['startDate']] = attrs }
  keys = executions.keys.sort
  keys = keys.slice(keys.size - options[:last], keys.size) if options[:last] > 0
  keys.each do |timestamp|
    dataline = timestamp.to_s
    dataline << " [#{executions[timestamp]['id']}]"
    dataline << " #{executions[timestamp]['state']}"
    puts dataline
  end
end