Class: Mortar::Command::Validate

Inherits:
Base
  • Object
show all
Defined in:
lib/mortar/command/validate.rb

Overview

check script syntax

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #ask_public, #config_parameters, #get_error_message_context, #git, #initialize, #initialize_embedded_project, #luigi_parameters, namespace, #pig_parameters, #project, #register_api_call, #register_do, #register_project, #spark_script_arguments, #validate_project_name, #validate_project_structure

Methods included from Helpers

#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #full_host, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #pending_github_team_state_message, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file

Constructor Details

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

Instance Method Details

#indexObject

validate [PIGSCRIPT]

Validate a pig script. Checks script for problems with:

* Pig syntax
* Python syntax
* S3 data access

-p, –parameter NAME=VALUE # Set a pig parameter value in your script. -f, –param-file PARAMFILE # Load pig parameter values from a file. -g, –pigversion PIG_VERSION # Set pig version. Options are <PIG_VERSION_OPTIONS>.



34
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
# File 'lib/mortar/command/validate.rb', line 34

def index
  pigscript_name = shift_argument
  unless pigscript_name
    error("Usage: mortar validate PIGSCRIPT\nMust specify PIGSCRIPT.")
  end
  validate_arguments!
  pigscript = validate_script!(pigscript_name)
  
  if pigscript.is_a? Mortar::Project::ControlScript
    error "Currently Mortar does not support validating control scripts"
  end
  
  git_ref = sync_code_with_cloud()
  
  validate_id = nil
  action("Starting validate") do
    validate_id = api.post_validate(project.name, pigscript.name, git_ref, 
      :pig_version => pig_version.version, 
      :project_script_path => pigscript.rel_path,
      :parameters => pig_parameters).body["validate_id"]
  end
      
  validate_result = nil
  display
  ticking(polling_interval) do |ticks|
    validate_result = api.get_validate(validate_id).body
    is_finished =
      Mortar::API::Validate::STATUSES_COMPLETE.include?(validate_result["status_code"])
     
    redisplay("[#{spinner(ticks)}] Checking your script for problems with: Pig syntax, Python syntax, and S3 data access",
      is_finished) # only display newline on last message
    if is_finished
      display
      break
    end
  end
  
  case validate_result['status_code']
  when Mortar::API::Validate::STATUS_FAILURE
    error_message = "Validate failed with #{validate_result['error_type'] || 'error'}"
    if line_number = validate_result["line_number"]
      error_message += " at Line #{line_number}"
      if column_number = validate_result["column_number"]
        error_message += ", Column #{column_number}"
      end
    end
    error_context = get_error_message_context(validate_result['error_message'])
    error_message += ":\n\n#{validate_result['error_message']}\n\n#{error_context}"
    error(error_message)
  when Mortar::API::Validate::STATUS_KILLED
    error("Validate killed by user.")
  when Mortar::API::Validate::STATUS_SUCCESS
    display("Your script is valid.")
  else
    raise RuntimeError, "Unknown validate status: #{validate_result['status']} for validate_id: #{validate_id}"
  end
end