Class: Zillabyte::Command::RPC

Inherits:
Flows show all
Defined in:
lib/zillabyte/cli/rpc.rb

Overview

remote procedure call a component

Constant Summary

Constants inherited from Flows

Flows::MAX_POLL_SECONDS, Flows::POLL_SLEEP

Constants inherited from Base

Base::META_COLUMNS

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Flows

#authorize, #delete, #info, #live_run, #local, #on_exit, #pause, #prep, #pull, #push, #resume, #scale

Methods inherited from Base

#api, #initialize, namespace

Methods included from Helpers

#app, #ask, #command, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #friendly_dir, #get_flow_ui_link, #get_info, #get_rich_info, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #truncate_message, #version_okay?, #with_tty

Constructor Details

This class inherits a constructor from Zillabyte::Command::Base

Instance Method Details

#detailsObject

rpc:details ID

List details for an rpc.

–output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



176
177
178
# File 'lib/zillabyte/cli/rpc.rb', line 176

def details
  super
end

#errorsObject

rpc:errors ID

Show recent errors generated by the rpc.

–output_type OUTPUT_TYPE # Specify an output type i.e. json HIDDEN



187
188
189
# File 'lib/zillabyte/cli/rpc.rb', line 187

def errors
  super
end

#killObject

rpc:kill ID

Kills the RPC.

–config CONFIG_FILE # Use the given config file –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



212
213
214
# File 'lib/zillabyte/cli/rpc.rb', line 212

def kill
  super
end

#logsObject

rpc:logs ID [OPERATION_NAME]

Streams logs for the rpc from our cluster.

–operation OPERATION_NAME # Specify the operation to show logs for -v, –verbose LEVEL # Sets the verbosity (error, info, debug) [default: info] –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN



200
201
202
# File 'lib/zillabyte/cli/rpc.rb', line 200

def logs
  super
end

#resultsObject

rpc:results ID RUN_ID

Returns results from the RPC for the input corresponding to RUN_ID. If the result is not available yet, this method waits until it is. Alternatively, a list of RUN_IDs may be supplied in a CSV with 2 columns: [“query”,run_id] using –input_file. This file can be generated by “zillabyte rpc” if –output_file is specified.

–input_file INTPUT_FILE # Input csv file containing queries and run_ids



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/zillabyte/cli/rpc.rb', line 119

def results
  component_id = options[:id] || shift_argument

  if component_id.nil?
    component_id = read_name_from_conf(options)
  end

  type = options[:output_type]
  file = options[:input_file]

  run_ids = get_run_ids_from_command_line_or_file(file)
  wait_for_results(component_id, run_ids, type)
end

#startObject

rpc:start ID [INPUT_1] [INPUT_2] …

Starts the rpc and optionally submits the inputs from the command line. The input parameters MUST be listed in the same order as that given in the component inputs. TO SUBMIT MULTIPLE queries, use the –input_file switch to specify a CSV file containing the queries without listing any inputs on the command line. Each line of the file should correspond to a unique query.

–forever # Let the RPC run until killed –async # Run the command asynchronously –input_file INTPUT_FILE # Input csv file containing parameters for multiple queries –output_file OUTPUT_FILE # Output csv file containing query parameters and run ids –output_type OUTPUT_TYPE # Specify an output type i.e. json #HIDDEN –no_logs # Don’t show log output

Examples:

Single query: $ zillabyte rpc ‘web_screenshot’ ‘google.com’

Multiple queries: $ zillabyte rpc ‘web_screenshot’ –input_file ‘url_list.csv’



35
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
102
103
# File 'lib/zillabyte/cli/rpc.rb', line 35

def start
  require("csv")
  
  component_id = options[:id] || shift_argument

  if component_id.nil?
    component_id = read_name_from_conf(options)
  end

  async = options[:async] || false
  forever = options[:forever] || false
  type = options[:output_type]
  file = options[:input_file]
  out_file = options[:output_file]
  no_logs = options[:no_logs] || type

  component_args = []
  if file
    CSV.foreach(file) {|line| component_args << line}
  else
    args = []
    while(true) do
      next_arg = shift_argument
      break if next_arg.nil?
      args << next_arg
    end
    component_args << args if !args.empty?
  end

  opts = {:rpc_inputs => component_args} if component_args.size != 0
  if forever
    opts[:forever] = 1
    display "Running until killed..."
  end
  res = api.components.rpc(component_id, opts)
  
  input_par_for_id = {}
  if res['error']
    error("error: #{res['error_message']}", type)
  else
    if type.nil?
      display "Request submitted to component ##{res['id']}. "
      display "No output file given. Use --output_file to capture raw output" unless out_file
      display "Use --no_logs to skip log output." unless no_logs
    end

    if res["execute_ids"]
      input_par_for_id = res["execute_ids"].invert
      if out_file
        CSV.open(out_file, "w") {|csv| res["execute_ids"].to_a.each {|elem| csv << elem}}
      end
    end
  end

  if async
    # Async -- return right away.. 
    display "The run ids are (query: run_id):"
    res["execute_ids"].each do |pars, id|
      display "\t #{pars}: #{id}"
    end
    display "Please use \"zillabyte rpc:status\" and \"zillabyte rpc:results\" to check on the status of your query and to retrieve your results.\nYou may also wish to check \"zillabyte logs\" for errors."
  else
    # Sync -- poll until it's done...
    if res["execute_ids"] 
      run_ids = res["execute_ids"].values
      wait_for_results(component_id, run_ids, type, input_par_for_id, no_logs)
    end
  end
end

#statusObject

rpc:status ID RUN_ID

Returns the current status of the RPC query corresponding to RUN_ID. Alternatively, a list of RUN_IDs may be supplied in a CSV with 2 columns: [“query”,run_id] using –input_file. This file can be generated by “zillabyte rpc” if –output_file is specified.

–input_file INTPUT_FILE # Input csv file containing queries and run_ids



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/zillabyte/cli/rpc.rb', line 145

def status

  component_id = options[:id] || shift_argument
  if component_id.nil?
    component_id = read_name_from_conf(options)
  end

  type = options[:output_type]
  file = options[:input_file]

  run_ids = get_run_ids_from_command_line_or_file(file)

  res = api.components.get_rpc_results(component_id, {:execute_ids => run_ids})
  if res['error']
    error("error: #{res['error_message']}", type)
  else
    if type.nil?
      res["results"].each do |id, hash|
        display "#{id}: #{hash["status"]}"
      end
    end
  end
end