Class: Hodor::Oozie::Job
- Inherits:
-
Object
show all
- Defined in:
- lib/hodor/api/oozie/job.rb
Defined Under Namespace
Classes: Configuration
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Job
Returns a new instance of Job.
22
23
24
25
|
# File 'lib/hodor/api/oozie/job.rb', line 22
def initialize
@index = -1
@rest_call = session.last_query
end
|
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
12
13
14
|
# File 'lib/hodor/api/oozie/job.rb', line 12
def columns
@columns
end
|
#conf ⇒ Object
Returns the value of attribute conf.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def conf
@conf
end
|
#id ⇒ Object
Returns the value of attribute id.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def id
@id
end
|
#index ⇒ Object
Returns the value of attribute index.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def index
@index
end
|
#parent_id ⇒ Object
Returns the value of attribute parent_id.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def parent_id
@parent_id
end
|
#rest_call ⇒ Object
Returns the value of attribute rest_call.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def rest_call
@rest_call
end
|
#skip_to ⇒ Object
Returns the value of attribute skip_to.
11
12
13
|
# File 'lib/hodor/api/oozie/job.rb', line 11
def skip_to
@skip_to
end
|
Instance Method Details
#child_columns ⇒ Object
119
120
121
122
123
124
125
126
|
# File 'lib/hodor/api/oozie/job.rb', line 119
def child_columns
first_child = children.first
if first_child
first_child.class.default_columns
else
nil
end
end
|
#children ⇒ Object
43
44
45
46
47
48
|
# File 'lib/hodor/api/oozie/job.rb', line 43
def children
if @children.nil?
@children = expand
end
@children
end
|
#children_title ⇒ Object
128
129
130
|
# File 'lib/hodor/api/oozie/job.rb', line 128
def children_title
"#{self.class.name.split('::').last} Children"
end
|
#conf_map ⇒ Object
177
178
179
180
181
182
|
# File 'lib/hodor/api/oozie/job.rb', line 177
def conf_map
io = StringIO.new(conf || "")
handler = Configuration.new()
Ox.sax_parse(handler, io)
handler.map
end
|
#definition ⇒ Object
188
189
190
|
# File 'lib/hodor/api/oozie/job.rb', line 188
def definition
session.get_job_state(id, "show=definition")
end
|
#display_as_array(columns, ellipsis = false) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/hodor/api/oozie/job.rb', line 102
def display_as_array(columns, ellipsis = false)
row = columns.inject([]) { |cols, head|
if ellipsis
val = "..."
else
display_override = "display_#{head.to_s}".to_sym
if respond_to?(display_override)
val = method(display_override.to_s).call
else
val = instance_variable_get("@#{head}")
val = display_as_time(val) if val.is_a?(Time)
end
end
cols << sanitize(val, 80)
}
end
|
#display_as_time(val) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/hodor/api/oozie/job.rb', line 50
def display_as_time(val)
display_date = val.strftime("%Y-%m-%d %H:%M")
cur_date = Time.now.strftime("%Y-")
if display_date[0..4].eql?(cur_date)
display_date[5..-1]
else
display_date
end
end
|
#display_children ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/hodor/api/oozie/job.rb', line 132
def display_children
if children.nil? || children.length == 0
nil
else
headings = child_columns.map { |head|
head.to_s.split('_').map { |w| w.capitalize }.join(' ')
}
children.each_with_index { |c, i|
c.set_index(i)
}
truncated = children.length > session.len
childrows = truncated ? children[0..session.len-1] : children
rows = childrows.inject([]) { |result, v|
result << v.display_as_array(child_columns)
result
}
rows[rows.length-1][0] = "#{rows[rows.length-1][0]}+" if truncated
{ headings: headings, rows: rows }
end
end
|
#display_properties ⇒ Object
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
|
# File 'lib/hodor/api/oozie/job.rb', line 73
def display_properties
if self.class.respond_to?(:suppress_properties)
suppress = self.class.suppress_properties
else
suppress = false
end
props = suppress ? nil :
instance_variables.map { |var| var[1..-1] }.select { |var| !var.eql?("index") }
if props
rows = props.inject([]) { |result, prop|
display_override = "display_#{prop.to_s}".to_sym
if respond_to?(display_override)
val = method(display_override.to_s).call
else
val = instance_variable_get("@#{prop}")
if val.is_a?(Time)
val = display_as_time(val)
else
val = val
end
end
result << [prop, sanitize(val)]
}
{ rows: rows }
else
nil
end
end
|
#expand ⇒ Object
39
40
41
|
# File 'lib/hodor/api/oozie/job.rb', line 39
def expand
nil
end
|
#indexed_job_id ⇒ Object
31
32
33
|
# File 'lib/hodor/api/oozie/job.rb', line 31
def indexed_job_id
nil
end
|
#log ⇒ Object
184
185
186
|
# File 'lib/hodor/api/oozie/job.rb', line 184
def log
session.get_job_state(id, "show=log")
end
|
#oozie ⇒ Object
18
19
20
|
# File 'lib/hodor/api/oozie/job.rb', line 18
def oozie
Hodor::Oozie
end
|
#parse_time(timestamp) ⇒ Object
35
36
37
|
# File 'lib/hodor/api/oozie/job.rb', line 35
def parse_time timestamp
Time.strptime(timestamp, "%a, %d %b %Y %H:%M:%S %Z") if timestamp
end
|
#sanitize(val, max_length = 120) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/hodor/api/oozie/job.rb', line 60
def sanitize val, max_length = 120
sval = val.to_s.gsub(/\s+/, ' ')
if sval.length > max_length
sval.to_s[0..max_length-3] + '...'
else
sval
end
end
|
#session ⇒ Object
14
15
16
|
# File 'lib/hodor/api/oozie/job.rb', line 14
def session
Hodor::Oozie::Session.instance
end
|
#set_index(i) ⇒ Object
27
28
29
|
# File 'lib/hodor/api/oozie/job.rb', line 27
def set_index(i)
@index = i
end
|
#title ⇒ Object
69
70
71
|
# File 'lib/hodor/api/oozie/job.rb', line 69
def title
"#{self.class.name.split('::').last} Properties"
end
|