Skip to content

Commit

Permalink
MAPR-HBASE-199: Command 'processlist' fails with ERROR: Unexpected en…
Browse files Browse the repository at this point in the history
…d of file from server on secure cluster
  • Loading branch information
Sercan Tekin authored and sercanCyberVision committed Dec 24, 2020
1 parent bd84cc9 commit 41ec48a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
36 changes: 22 additions & 14 deletions hbase-shell/src/main/ruby/hbase/taskmonitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,37 @@ def initialize(configuration)
def tasksOnHost(filter,host)

java_import 'java.net.URL'
java_import 'java.net.SocketException'
java_import 'java.io.InputStreamReader'
java_import 'org.apache.hbase.thirdparty.com.google.gson.JsonParser'

infoport = @admin.getClusterStatus().getLoad(host).getInfoServerPort().to_s

# Note: This condition use constants from hbase-server
#if ([email protected]().getBoolean(org.apache.hadoop.hbase.http.ServerConfigurationKeys::HBASE_SSL_ENABLED_KEY,
# org.apache.hadoop.hbase.http.ServerConfigurationKeys::HBASE_SSL_ENABLED_DEFAULT))
# schema = "http://"
#else
# schema = "https://"
#end
schema = "http://"
url = schema + host.hostname + ":" + infoport + "/rs-status?format=json&filter=" + filter

json = URL.new(url).openStream
begin
schema = "http://"
url = schema + host.hostname + ':' + infoport + '/rs-status?format=json&filter=' + filter
json = URL.new(url).openStream
rescue SocketException => e
# Let's try with https when SocketException occur
schema = "https://"
url = schema + host.hostname + ':' + infoport + '/rs-status?format=json&filter=' + filter
# MAPR-HBASE-199 in secure cluster, authentication is required, we have mapr negotiation here as system command
cmd = "curl -s -k -H \"Authorization: MAPR-Negotiate $(java -cp `mapr classpath` com.mapr.security.client.examples.MapRClient "\
"gettoken -url \"#{url}\" 2> /dev/null | grep 'Obtained challenge string' | "\
"sed -E 's/Obtained challenge string (.*)/\\1/')\" \"#{url}\" | python -m json.tool"
json = %x(#{cmd})
end

parser = JsonParser.new

# read and parse JSON
begin
tasks_array_list = parser.parse(InputStreamReader.new(json, 'UTF-8')).getAsJsonArray
ensure
json.close
if schema == "http://"
tasks_array_list = parser.parse(InputStreamReader.new(json, 'UTF-8')).getAsJsonArray
json.close
else
tasks_array_list = parser.parse(json).getAsJsonArray
end
end
# convert to an array of TaskMonitor::Task instances
tasks = []
Expand Down
7 changes: 4 additions & 3 deletions hbase-shell/src/main/ruby/shell/commands/processlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def help
end

def command(*args)

# MAPR-HBASE-199 skipping ssl certificate check, otherwise response is 401
# this is required to get server names, authentication will be handled in taskmonitor.rb
args.push('-k')

if ['all','general','handler','rpc','operation'].include? args[0]
# if the first argument is a valid filter specifier, use it as such
filter = args[0]
Expand All @@ -57,9 +60,7 @@ def command(*args)
else
taskmonitor.tasks(filter,hosts)
end

end

end
end
end

0 comments on commit 41ec48a

Please sign in to comment.