Class: Hadupils::Commands::MkTmpFile

Inherits:
SimpleCommand show all
Includes:
Options::Directory
Defined in:
lib/hadupils/commands.rb

Instance Attribute Summary collapse

Attributes inherited from SimpleCommand

#params

Instance Method Summary collapse

Methods included from Options::Directory

#perform_directory?

Methods inherited from SimpleCommand

run, #successful?

Constructor Details

#initialize(params) ⇒ MkTmpFile

Returns a new instance of MkTmpFile.



101
102
103
104
105
# File 'lib/hadupils/commands.rb', line 101

def initialize(params)
  super(params)
  Hadupils::Extensions::Dfs::TmpFile.reset_tmpfile!
  @tmpdir_path = Hadupils::Extensions::Dfs::TmpFile.tmpfile_path
end

Instance Attribute Details

#tmpdir_pathObject (readonly)

Returns the value of attribute tmpdir_path.



99
100
101
# File 'lib/hadupils/commands.rb', line 99

def tmpdir_path
  @tmpdir_path
end

Instance Method Details

#runObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/hadupils/commands.rb', line 107

def run
  # Similar to shell mktemp, but for Hadoop DFS!
  # Creates a new tmpdir and puts the full tmpdir_path to STDOUT
  # Makes a tmp file by default; a tmp directory with '-d' flag
  fs_cmd = perform_directory? ? '-mkdir' : '-touchz'
  stdout, exitstatus = Hadupils::Commands::Hadoop.run ['fs', fs_cmd, tmpdir_path]
  if successful? exitstatus
    stdout, exitstatus = Hadupils::Commands::Hadoop.run ['fs', '-chmod', '700', tmpdir_path]
    if successful? exitstatus
      puts tmpdir_path
    else
      $stderr.puts "Failed to dfs -chmod 700 dfs tmpdir: #{tmpdir_path}"
    end
  else
    $stderr.puts "Failed creating dfs tmpdir: #{tmpdir_path}"
  end
  [nil, exitstatus]
end