in ambari-infra-solr-client/src/main/python/solrDataManager.py [0:0]
def query_solr(solr_kinit_command, url, curl_command, action, data=None):
if solr_kinit_command:
run_kinit(solr_kinit_command, "Solr")
try:
cmd = curl_command.split()
if data:
cmd.append("--data-binary")
cmd.append(data)
logger.debug("%s data from solr:\n%s", action, ' '.join(cmd))
process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
except Exception as e:
print()
logger.warn("Could not execute curl command:\n%s", ' '.join(cmd))
logger.warn(str(e))
sys.exit()
out, err = process.communicate()
if process.returncode != 0:
print()
logger.warn("Could not execute curl command:\n%s", ' '.join(cmd))
logger.warn(str(err))
sys.exit()
true = True # needed to be able to eval 'true' in the returned json
rsp = eval(str(out))
if rsp["responseHeader"]["status"] != 0:
print()
logger.warn("Could not execute solr query:\n%s", unquote(url))
logger.warn(rsp["error"]["msg"])
sys.exit()
return rsp