Module: Chef::Knife::HadoopBase
- Included in:
- HadoopHdfsCreate, HadoopHdfsList, HadoopHdfsSnapshot, HadoopHdfsUpdate, HadoopHdfsUsage, HadoopMapredJobKill, HadoopMapredJobList, HadoopSetup
- Defined in:
- lib/chef/knife/hadoop_base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #db_connection ⇒ Object
- #hdfs_connection ⇒ Object
- #locate_config_value(key) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
Class Method Details
.included(includer) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 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 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/knife/hadoop_base.rb', line 29 def self.included(includer) includer.class_eval do deps do require 'readline' require 'chef/json_compat' end option :namenode_username, :short => "-U USERNAME", :long => "--namenode-username USERNAME", :description => "NameNode Username", :proc => Proc.new { |key| Chef::Config[:knife][:namenode_username] = key } option :namenode_password, :short => "-P PASSWORD", :long => "--namenode-password PASSWORD", :description => "NameNode password", :proc => Proc.new { |key| Chef::Config[:knife][:namenode_password] = key } option :namenode_host, :short => "-H HOST", :long => "--namenode-host HOST", :description => "NameNode FQDN or IP address", :proc => Proc.new { |endpoint| Chef::Config[:knife][:namenode_host] = endpoint } option :namenode_port, :short => "-A PORT", :long => "--namenode-port PORT", :description => "NameNode port", :proc => Proc.new { |key| Chef::Config[:knife][:namenode_port] = key } option :db_type, :short => "-T DATABASETYPE", :long => "--database-type DATABASETYPE", :description => "PostgreSQL or Sqlite Database to use for Hadoop Management Data", :proc => Proc.new { |key| Chef::Config[:knife][:db] = key } option :db, :short => "-D DATABASE", :long => "--database DATABASE", :description => "PostgreSQL Database to use for Hadoop Management Data", :proc => Proc.new { |key| Chef::Config[:knife][:db] = key } option :db_username, :short => "-B DBUSERNAME", :long => "--db-username DBUSERNAME", :description => "PostgreSQL DB Username", :proc => Proc.new { |key| Chef::Config[:knife][:db_username] = key } option :db_password, :short => "-C DBPASSWORD", :long => "--db-password DBPASSWORD", :description => "PostgreSQL DB Password", :proc => Proc.new { |key| Chef::Config[:knife][:db_password] = key } option :db_host, :short => "-I DBHOST", :long => "--db-host DBHOST", :description => "PostgreSQL DB Host", :proc => Proc.new { |key| Chef::Config[:knife][:db_host] = key } option :db_port, :short => "-F DBPORT", :long => "--db-port DBPORT", :description => "PostgreSQL DB Port", :proc => Proc.new { |key| Chef::Config[:knife][:db_port] = key } end end |
Instance Method Details
#db_connection ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/chef/knife/hadoop_base.rb', line 112 def db_connection Chef::Log.debug("db_type: #{Chef::Config[:knife][:db_type]}") Chef::Log.debug("db: #{Chef::Config[:knife][:db]}") Chef::Log.debug("db_username: #{Chef::Config[:knife][:db_username]}") Chef::Log.debug("db_password: #{Chef::Config[:knife][:db_password]}") Chef::Log.debug("db_host: #{Chef::Config[:knife][:db_host]}") Chef::Log.debug("db_port: #{Chef::Config[:knife][:db_port]}") db_type = "#{Chef::Config[:knife][:db_type]}".downcase case db_type when 'postgres' @db_connection ||= begin db_connection = Sequel.postgres("#{Chef::Config[:knife][:db]}", :user=>"#{Chef::Config[:knife][:db_username]}", :password => "#{Chef::Config[:knife][:db_password]}", :host => "#{Chef::Config[:knife][:db_host]}", :port => "#{Chef::Config[:knife][:db_port]}", :max_connections => 10) end when 'sqlite' @db_connection ||= begin db_connection = Sequel.sqlite("#{Chef::Config[:knife][:db]}") end end end |
#hdfs_connection ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/chef/knife/hadoop_base.rb', line 100 def hdfs_connection Chef::Log.debug("username: #{Chef::Config[:knife][:namenode_username]}") Chef::Log.debug("password: #{Chef::Config[:knife][:namenode_password]}") Chef::Log.debug("host: #{Chef::Config[:knife][:namenode_host]}") Chef::Log.debug("port: #{Chef::Config[:knife][:namenode_port]}") @hdfs_connection ||= begin hdfs_connection = WebHDFS::Client.new("#{Chef::Config[:knife][:namenode_host]}", "#{Chef::Config[:knife][:namenode_port]}", "#{Chef::Config[:knife][:namenode_username]}") end end |
#locate_config_value(key) ⇒ Object
135 136 137 138 |
# File 'lib/chef/knife/hadoop_base.rb', line 135 def locate_config_value(key) key = key.to_sym Chef::Config[:knife][key] || config[key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
140 141 142 143 144 |
# File 'lib/chef/knife/hadoop_base.rb', line 140 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |