示例#1
0
 def get_streamline_service_status(cls, cluster_name):
     service_state = None
     url = Ambari.getWebUrl(is_hdp=False) + "/api/v1/clusters/%s/services/STREAMLINE" % cluster_name
     retcode, retdata, retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
         service_state = jsoncontent["ServiceInfo"]["state"]
     return service_state
示例#2
0
 def get_smm_service_status(cls, cluster_name):
     service_state = None
     url = Ambari.getWebUrl(
         is_hdp=False, is_enc=Ambari.is_ambari_encrypted()
     ) + "/api/v1/clusters/%s/services/STREAMSMSGMGR" % cluster_name
     retcode, retdata, retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
         service_state = jsoncontent["ServiceInfo"]["state"]
     return service_state
示例#3
0
 def runQuery(cls, qparams=None):
     if not qparams:
         qparams = {}
     searchurl = cls._es_http_url + "/_search"
     if qparams:
         searchurl += "?" + "&".join(
             [key + "=" + value for key, value in qparams.items()])
     code, data, _headers = util.httpRequest(searchurl)
     assert code == 200
     return util.getJSON(data)
示例#4
0
 def is_secure(cls):
     url = "%s/api/v1/clusters/%s" % (Ambari.getWebUrl(), Ambari.getClusterName())
     retcode = None
     for i in range(10):
         retcode, retdata, retheaders = Ambari.performRESTCall(url)
         if retcode == 200:
             jsoncontent = util.getJSON(retdata)
             try:
                 if jsoncontent['Clusters']['security_type'] == "KERBEROS":
                     return True
             except:
                 pass
         util.sleep(5)
     return False
 def getServiceHosts(cls, host, service, component, cluster='cl1'):
     hosts = []
     url = "%s/api/v1/clusters/%s/services/%s/components/%s" % (
         cls.getweburl(host), cluster, service, component)
     retcode, retdata, retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
         try:
             hosts = [
                 hc['HostRoles']['host_name']
                 for hc in jsoncontent['host_components']
             ]
         except:
             hosts = []
     return hosts
示例#6
0
 def checkKafkaStatusOnMetronHost(cls, metron_host):
     kafka_status = None
     url = Ambari.getWebUrl(
         is_hdp=False
     ) + "/api/v1/clusters/%s/hosts/%s/host_components/%s" % (
         cls.get_ambari_cluster_name(), metron_host, cls.kafka_broker)
     retcode, retdata, _retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
         try:
             kafka_status = jsoncontent['HostRoles']['state']
         except Exception:
             logger.error('Kafka broker is not running on the Metron host')
             kafka_status = None
     return kafka_status
示例#7
0
    def waitForSuccessfulEvents(self, metrics, timeout=120, interval=10):
        modmetrics = []
        if not self._mport:
            return
        for metric in metrics:
            items = metric.split()
            assert len(items) == 4, "Invalid metric definition: " + metric
            type = items[0].upper()
            assert type in (
                'SOURCE', 'CHANNEL',
                'SINK'), "Invalid metric type '%s' in definition: %s" % (
                    items[0], metric)
            if type == 'SOURCE':
                metricType = 'EventAcceptedCount'
            elif type == 'CHANNEL':
                metricType = 'EventTakeSuccessCount'
            else:
                metricType = 'EventDrainSuccessCount'
            modmetric = "int(jsoncontent['%s.%s']['%s']) %s %s" % (
                type, items[1], metricType, items[2], items[3])
            modmetrics.append(modmetric)

        starttime = time.time()
        url = "http://%s:%d/metrics" % (Machine.getfqdn(), self._mport)
        while time.time() - starttime < timeout:
            retcode, retdata, retheaders = util.httpRequest(url)
            if retcode == 200:
                jsoncontent = util.getJSON(retdata)
                satisfy = True
                for metric in modmetrics:
                    try:
                        if not eval(metric):
                            satisfy = False
                            break
                    except KeyError:
                        satisfy = False
                if satisfy:
                    return
            time.sleep(interval)
示例#8
0
 def getMetronRestProperty(cls, param_name):
     '''
     Return the property value for given Metron Rest property from Ambari config using REST API
     :return: List
     '''
     metron_rest_prop = None
     url = Ambari.getWebUrl(
         is_hdp=False
     ) + "/api/v1/clusters/%s/configurations?type=%s&tag=%s" % (
         cls.get_ambari_cluster_name(), cls.metron_rest_config_type,
         cls.metron_config_tag)
     retcode, retdata, _retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
     try:
         metron_rest_prop = [
             hc['properties'][param_name] for hc in jsoncontent['items']
         ]
     except Exception:
         logger.error('Metron rest property %s variable is not set',
                      param_name)
     metron_rest_prop = None
     return metron_rest_prop
示例#9
0
 def getMetronHome(cls):
     '''
     Return the path to Metron Home from Ambari config using REST API
     :return: String
     '''
     metron_home = None
     url = Ambari.getWebUrl(
         is_hdp=False
     ) + "/api/v1/clusters/%s/configurations?type=%s&tag=%s" % (
         cls.get_ambari_cluster_name(), cls.metron_config_type,
         cls.metron_config_tag)
     retcode, retdata, _retheaders = Ambari.performRESTCall(url)
     if retcode == 200:
         jsoncontent = util.getJSON(retdata)
         try:
             metron_home = [
                 hc['properties']['metron_home']
                 for hc in jsoncontent['items']
             ]
         except Exception:
             logger.error('Metron Home variable is not set')
             metron_home = None
     return metron_home