Class: Chef::Knife::HadoopHdfsSnapshot

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

Instance Method Summary collapse

Methods included from HadoopBase

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

Instance Method Details

#runObject



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
91
92
93
94
95
# File 'lib/chef/knife/hadoop_hdfs_snapshot.rb', line 46

def run
  $stdout.sync = true
  dataset = db_connection.from("#{Chef::Config[:knife][:table]}")
  list = hdfs_connection.list("#{Chef::Config[:knife][:dir]}")
  list.each do |item|
    item.each do |k, v|
      if "#{k}" == 'accessTime'
        @accessTime = item['accessTime']
      elsif "#{k}" == 'blockSize'
        @blockSize = item['blockSize']
      elsif "#{k}" == 'group'
        @group = item['group']
      elsif "#{k}" == 'length'
        @length = item['length']
      elsif "#{k}" == 'modificationTime'
        @modificationTime = item['modificationTime']
      elsif "#{k}" == 'owner'
        @owner = item['owner']
      elsif "#{k}" == 'pathSuffix'
        @pathSuffix = item['pathSuffix']
      elsif "#{k}" == 'permission'
        @permission = item['permission']
      elsif "#{k}" == 'replication'
        @replication = item['replication']
      elsif "#{k}" == 'type'
        @type = item['type']
      else
        puts "Cannot read key value pairs. Please debug"
      end
    end

    db_connection.transaction do
          dataset.insert(
            :directory => "#{Chef::Config[:knife][:dir]}",
            :accessTime => "#{@accessTime}",
            :blockSize =>  "#{@blockSize}",
            :group =>  "#{@group}",
            :length =>  "#{@length}",
            :modificationTime =>  "#{@modificationTime}",
            :owner =>  "#{@owner}",
            :pathSuffix =>  "#{@pathSuffix}",
            :permission =>  "#{@permission}",
            :replication => "#{@replication}",
            :type =>  "#{@type}",
            :created_at => @created_at = Time.now
            ) 
    end      
  end
  ui.msg ("Created snapshot in #{Chef::Config[:knife][:table]} at #{@created_at}")         
end