Class: Chef::Knife::HadoopMapredJobList

Inherits:
Chef::Knife show all
Includes:
HadoopBase
Defined in:
lib/chef/knife/hadoop_mapred_job_list.rb

Instance Method Summary collapse

Methods included from HadoopBase

#db_connection, #hdfs_connection, included, #locate_config_value, #msg_pair

Instance Method Details

#runObject



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
# File 'lib/chef/knife/hadoop_mapred_job_list.rb', line 47

def run
  $stdout.sync = true

  Chef::Log.debug("username: #{Chef::Config[:knife][:mapred_mgmt_host]}")
  Chef::Log.debug("password: #{Chef::Config[:knife][:mapred_mgmt_port]}")

  job_list = [
    ui.color('jobid',           :bold),
    ui.color('mapComplete',     :bold),
    ui.color('name',            :bold),
    ui.color('priority',        :bold),
    ui.color('reduceComplete',  :bold),
    ui.color('schedulingInfo',  :bold),
    ui.color('startTime',       :bold),
    ui.color('state',           :bold),
    ui.color('user',            :bold)
  ]
  
  filter = "#{Chef::Config[:knife][:filter]}".downcase
  case filter
  when 'all'
    response = RestClient.get "http://#{Chef::Config[:knife][:mapred_mgmt_host]}:#{Chef::Config[:knife][:mapred_mgmt_port]}/job/list"
    collection = JSON.parse(response)
    collection.each do |item|
      job_list << item['jobid']
      job_list << item['mapComplete']
      job_list << item['name']
      job_list << item['priority']
      job_list << item['reduceComplete']
      job_list << item['schedulingInfo']
      job_list << item['startTime']
      job_list << item['state']
      job_list << item['user']
    end
  when 'user'
    response = RestClient.get "http://#{Chef::Config[:knife][:mapred_mgmt_host]}:#{Chef::Config[:knife][:mapred_mgmt_port]}/job/list"
    collection = JSON.parse(response)
    collection.each do |item|
     if "#{Chef::Config[:knife][:name]}" == item['user']
        job_list << item['jobid']
        job_list << item['mapComplete']
        job_list << item['name']
        job_list << item['priority']
        job_list << item['reduceComplete']
        job_list << item['schedulingInfo']
        job_list << item['startTime']
        job_list << item['state']
        job_list << item['user']
      end
    end
  end
  puts ui.list(job_list, :uneven_columns_across, 9)
end