Class: OozieApi

Inherits:
Object
  • Object
show all
Extended by:
OozieJobs
Includes:
HTTParty
Defined in:
lib/oozie_api.rb

Overview

so oozie responds in json, only accepts XML, and if there’s an error the response is in HTML

Class Method Summary collapse

Methods included from OozieJobs

conf_xml_to_properties_hash, coordinators, definition, info, kill_job, log, properties_hash_to_conf_xml, resume_job, start_job, submit_job, suspend_job, workflows

Class Method Details

.oozie_get(resource, fmt = :plain) ⇒ Object

def self.extended(other)

other.send :include, HTTParty

end



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oozie_api.rb', line 24

def self.oozie_get(resource, fmt = :plain)
  response = nil
  begin
    response = get(@@prefix + resource)
  rescue StandardError => ex
    raise OozieException.new(ex)
  end

  case fmt
  when :plain
    response.body

  when :json
    begin
      MultiJson.decode(response.body)  
    rescue StandardError => e
      ex_message = response.headers['oozie-error-code'] ? "#{response.headers['oozie-error-code']}: #{response.headers['oozie-error-message']}": response.body
      error = OozieException.new(ex_message)
      raise error
    end
  end
end

.oozie_post(resource, fmt = :plain, params = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/oozie_api.rb', line 47

def self.oozie_post(resource, fmt = :plain, params={})
  response = nil
  begin
    response = post(@@prefix + resource, params)
  rescue StandardError => ex
    raise OozieException.new(ex)
  end

  case fmt
  when :plain
    response.body

  when :json
    begin
      MultiJson.decode(response.body)  
    rescue StandardError => e
      ex_message = response.headers['oozie-error-code'] ? "#{response.headers['oozie-error-code']}: #{response.headers['oozie-error-message']}" : response.body
      error = OozieException.new(ex_message)
      raise error
    end
  end


end

.oozie_put(resource, fmt = :plain, opts = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/oozie_api.rb', line 72

def self.oozie_put(resource, fmt = :plain, opts={})
  response = nil
  begin
    response = put(@@prefix + resource)
  rescue StandardError => ex
    raise OozieException.new(ex)
  end

  case fmt
  when :plain
    response.body

  when :json
    begin
      MultiJson.decode(response.body)  
    rescue StandardError => e
      ex_message = response.headers['oozie-error-code'] ? "#{response.headers['oozie-error-code']}: #{response.headers['oozie-error-message']}": response.body
      error = OozieException.new(ex_message)
      raise error
    end
  end

end

.setup(url) ⇒ Object



14
15
16
17
18
# File 'lib/oozie_api.rb', line 14

def self.setup(url)
  @@prefix = url
  @@prefix += "/oozie" unless url.include?("/oozie")
  @@prefix += "/v0" unless url.include?("/v0")
end