Class: Chef::Knife::HadoopHdfsList

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

Instance Method Summary collapse

Methods included from HadoopBase

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

Instance Method Details

#runObject



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

def run
  $stdout.sync = true
  
  hdfs_list = [
    ui.color('Directory',        :bold),
    ui.color('accessTime',       :bold),
    ui.color('blockSize',        :bold),
    ui.color('group',            :bold),
    ui.color('length',           :bold),
    ui.color('modificationTime', :bold),
    ui.color('owner',            :bold),
    ui.color('pathSuffix',       :bold),
    ui.color('permission',       :bold),
    ui.color('replication',      :bold),
    ui.color('type',             :bold)
  ]
  
  #There has to be a more elegant way to do the below iteration :-)

  hdfs_layout = hdfs_connection.list("#{Chef::Config[:knife][:dir]}") 
  hdfs_layout.each do |item|
    hdfs_list << "#{Chef::Config[:knife][:dir]}"
    item.each do |k, v|
      if "#{k}" == 'accessTime'
         hdfs_list << item['accessTime'].to_s
      elsif "#{k}" == 'blockSize'
         hdfs_list << item['blockSize'].to_s
      elsif "#{k}" == 'group'
         hdfs_list << item['group'].to_s
      elsif "#{k}" == 'length'
         hdfs_list << item['length'].to_s
      elsif "#{k}" == 'modificationTime'
         hdfs_list << item['modificationTime'].to_s
      elsif "#{k}" == 'owner'
         hdfs_list << item['owner'].to_s
      elsif "#{k}" == 'pathSuffix'
         hdfs_list << item['pathSuffix'].to_s
      elsif "#{k}" == 'permission'
         hdfs_list << item['permission'].to_s
      elsif "#{k}" == 'replication'
         hdfs_list << item['replication'].to_s
      elsif "#{k}" == 'type'
         hdfs_list << item['type'].to_s
      else
        ui.error ("WebHDFS is not responding. Please debug")
      end
    end 
  end
  puts ui.list(hdfs_list, :uneven_columns_across, 11)
end