Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 b89a94b22 -> a06f69dd5


AMBARI-22505 : Kafka service check fails when using a non-root user in 
kerberized environment (ydavis via mradhakrishnan)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a06f69dd
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a06f69dd
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a06f69dd

Branch: refs/heads/branch-2.6
Commit: a06f69dd50d311dd7502352fd59d2dfc072bc505
Parents: b89a94b
Author: Madhuvanthi Radhakrishnan <mradhakrish...@hortonworks.com>
Authored: Thu Nov 30 11:52:11 2017 -0800
Committer: Madhuvanthi Radhakrishnan <mradhakrish...@hortonworks.com>
Committed: Thu Nov 30 11:52:11 2017 -0800

----------------------------------------------------------------------
 .../KAFKA/0.8.1/package/scripts/service_check.py    | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a06f69dd/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/service_check.py
 
b/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/service_check.py
index 0f3a417..3c1a3ab 100644
--- 
a/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/service_check.py
+++ 
b/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/service_check.py
@@ -19,8 +19,10 @@ limitations under the License.
 """
 from resource_management.libraries.script.script import Script
 from resource_management.libraries.functions.validate import 
call_and_match_output
+from resource_management.core import shell
 from resource_management.libraries.functions.format import format
 from resource_management.core.logger import Logger
+from resource_management.core.exceptions import Fail
 from resource_management.core import sudo
 import subprocess
 
@@ -31,16 +33,20 @@ class ServiceCheck(Script):
 
     # TODO, Kafka Service check should be more robust , It should get all the 
broker_hosts
     # Produce some messages and check if consumer reads same no.of messages.
-    
+
     kafka_config = self.read_kafka_config()
     topic = "ambari_kafka_service_check"
     create_topic_cmd_created_output = "Created topic 
\"ambari_kafka_service_check\"."
     create_topic_cmd_exists_output = "Topic \"ambari_kafka_service_check\" 
already exists."
     source_cmd = format("source {conf_dir}/kafka-env.sh")
-    topic_exists_cmd = format("{kafka_home}/bin/kafka-topics.sh --zookeeper 
{kafka_config[zookeeper.connect]} --topic {topic} --list")
-    topic_exists_cmd_p = subprocess.Popen(topic_exists_cmd.split(" "), 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    topic_exists_cmd_out, topic_exists_cmd_err = 
topic_exists_cmd_p.communicate()
-    # run create topic command only if the topic doesn't exists
+    topic_exists_cmd = format(source_cmd + " ; " + 
"{kafka_home}/bin/kafka-topics.sh --zookeeper {kafka_config[zookeeper.connect]} 
--topic {topic} --list")
+    topic_exists_cmd_code, topic_exists_cmd_out = shell.call(topic_exists_cmd, 
logoutput=True, quiet=False, user=params.kafka_user)
+
+    if topic_exists_cmd_code > 0:
+      raise Fail("Error encountered when attempting to list topics: 
{0}".format(topic_exists_cmd_out))
+
+
+  # run create topic command only if the topic doesn't exists
     if topic not in topic_exists_cmd_out:
       create_topic_cmd = format("{kafka_home}/bin/kafka-topics.sh --zookeeper 
{kafka_config[zookeeper.connect]} --create --topic {topic} --partitions 1 
--replication-factor 1")
       command = source_cmd + " ; " + create_topic_cmd

Reply via email to