Class: Houdah::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/houdah/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, port = 9290, user = "houdah", timeout = 60) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
# File 'lib/houdah/client.rb', line 5

def initialize(server, port=9290, user="houdah", timeout=60)
  socket = Thrift::Socket.new(server, port)
  socket.timeout = timeout * 10000
  @transport = Thrift::BufferedTransport.new(socket)
  @transport.open
  protocol = Thrift::BinaryProtocol.new(@transport)
  @client = Hadoop::API::Jobtracker::Jobtracker::Client.new(protocol)
  @context = Hadoop::API::RequestContext.new(:confOptions => { 'effective_user' => user })
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/houdah/client.rb', line 4

def client
  @client
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/houdah/client.rb', line 4

def context
  @context
end

Class Method Details

.run(*args) ⇒ Object



56
57
58
59
60
61
# File 'lib/houdah/client.rb', line 56

def self.run(*args)
  c = Client.new *args
  result = yield c
  c.close
  result
end

Instance Method Details

#call(method, *args) ⇒ Object



52
53
54
# File 'lib/houdah/client.rb', line 52

def call(method, *args)
  @client.send method, @context, *args
end

#closeObject



48
49
50
# File 'lib/houdah/client.rb', line 48

def close
  @transport.close
end

#jobs(type = :running) ⇒ Object

Get jobs. Type can be :running, :completed, :killed, :failed, or :all



20
21
22
23
24
25
26
27
28
29
# File 'lib/houdah/client.rb', line 20

def jobs(type=:running)
  results = case type
            when :running then call(:getRunningJobs) 
            when :completed then call(:getCompletedJobs)
            when :failed then call(:getFailedJobs)
            when :killed then call(:getKilledJobs)
            else call(:getAllJobs)
            end
  results.jobs.map { |j| Job.new(self, j) }
end

#nameObject



15
16
17
# File 'lib/houdah/client.rb', line 15

def name
  call :getJobTrackerName
end

#queuesObject



44
45
46
# File 'lib/houdah/client.rb', line 44

def queues
  call :getQueues
end

#statusObject



40
41
42
# File 'lib/houdah/client.rb', line 40

def status
  call :getClusterStatus
end

#trackers(type = :active) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/houdah/client.rb', line 31

def trackers(type=:active)
  results = case type
            when :active then call(:getActiveTrackers)
            when :blacklisted then call(:getBlacklistedTrackers)
            when :all then call(:getAllTrackers)
            end
  results.trackers.map { |t| Tracker.new(self, t) }
end