def __init__(self, host='localhost', port=None, isHttps=False):
        if port is None:
            if (Hadoop.isEncrypted() or Ambari.is_ambari_encrypted() and Machine.isHumboldt() == False):
                port = 8443
                isHttps = True
            else:
                port = 8080
        if isHttps or self.isCloudbreak():
            self.baseUrl = 'https://' + host
        else:
            self.baseUrl = 'http://' + host

        if self.isCloudbreak():
            self.baseUrl = self.baseUrl + '/ambari'
        else:
            self.baseUrl = self.baseUrl + ':' + str(port)

        if Machine.isHumboldt():
            self.username_password = Config.get('ambari', 'AMBARI_USERNAME', 'admin') + ':HdpCli123!'
            ambari_gateway = Config.get('machine', 'GATEWAY').replace("-ssh", "")
            self.baseUrl = 'https://%s' % ambari_gateway
        elif Machine.getInstaller() == 'cloudbreak':
            self.username_password = Config.get('ambari', 'AMBARI_USERNAME', 'admin') + ':cloudbreak1'
        else:
            self.username_password = Config.get('ambari', 'AMBARI_USERNAME', 'admin'
                                                ) + ':' + Config.get('ambari', 'AMBARI_PASSWORD', 'admin')

        self.urlLogin = self.baseUrl + '#/login'
        self.urlGetClusters = self.baseUrl + '/api/v1/clusters'
        self.urlGetAmbClusters = self.baseUrl + '/api/v1/services'
        self.urlConfig = '/configurations'
        self.backupDataJson = dict()
        self.logger = logging.getLogger(__name__)
示例#2
0
    def get_client_properties(self):
        from beaver.component.kafka import Kafka
        from beaver.component.ambari import Ambari

        Kafka.alterUser(
            userName=self.client_username,
            config="'SCRAM-SHA-256=[iterations=8192,password=%s],"
            "SCRAM-SHA-512=[password=%s]'" % (self.client_password, self.client_password)
        )

        is_ambari_enc = Ambari.is_ambari_encrypted()
        kafka_jaas_config = Ambari.getConfig(
            "kafka_jaas_conf", webURL=Ambari.getWebUrl(is_hdp=False, is_enc=is_ambari_enc)
        )

        replacement_jaas_entry = self.jaas_entry
        if not Kafka._isSecure:
            replacement_jaas_entry = "\nKafkaServer {%s\n};" % self.jaas_entry

        if self.to_be_replaced + replacement_jaas_entry not in kafka_jaas_config['content']:
            print "old : %s" % kafka_jaas_config['content']
            kafka_jaas_config['content'] = kafka_jaas_config['content'].replace(
                self.to_be_replaced, self.to_be_replaced + replacement_jaas_entry
            )
            print "new : %s" % kafka_jaas_config['content']
        Ambari.setConfig(
            "kafka_jaas_conf", kafka_jaas_config, webURL=Ambari.getWebUrl(is_hdp=False, is_enc=is_ambari_enc)
        )
        Ambari.restart_services_with_stale_configs()
        time.sleep(20)
        return {'sasl.jaas.config': self.jaas_entry.replace("\n", " "), 'sasl.mechanism': 'SCRAM-SHA-256'}
示例#3
0
 def is_smm_service_installed(cls, cluster_name):
     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 == 404:
         return False
     return True
示例#4
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
示例#5
0
    def get_host_uri(cls, ambari_properties):
        from beaver.component.ambari import Ambari
        if Ambari.is_ambari_encrypted():
            port = 8443
            protocol = 'https'
        else:
            port = 8080
            protocol = 'http'

        HOST_URL = protocol + '://' + ambari_properties.get('HOST').split(':')[0] + ":" + str(port)
        print "HOST_URL = ", HOST_URL
        return HOST_URL
示例#6
0
 def get_hosts(cls):
     """
     Return the hosts where smm is running. Detection is done using ambari.
     :return: String
     """
     hosts = Ambari.getServiceHosts(
         "STREAMSMSGMGR",
         cls.smm_master,
         cluster=cls.get_ambari_cluster_name(),
         is_hdp=False,
         is_enc=Ambari.is_ambari_encrypted()
     )
     if not hosts:
         logger.error('SMM instance is not installed on any of hosts in the cluster')
     logger.info("SMM installed on: %s " % hosts)
     return hosts
示例#7
0
 def is_secure(cls):
     url = "%s/api/v1/clusters/%s" % (
         Ambari.getWebUrl(is_enc=Ambari.is_ambari_encrypted()), 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
示例#8
0
 def get_ambari_url(cls):
     if not cls._ambari_url:
         is_ambari_encrypted = Ambari.is_ambari_encrypted()
         cls._ambari_url = Ambari.getWebUrl(is_enc=is_ambari_encrypted)
         logger.info("ambari url is: %s" % cls._ambari_url)
     return cls._ambari_url
示例#9
0
 def get_ambari_cluster_name(cls, refresh=False):
     if not cls._cluster_name or refresh:
         cls._cluster_name = Ambari.getClusterName(is_hdp=False, is_enc=Ambari.is_ambari_encrypted())
     return cls._cluster_name
示例#10
0
 def get_ambari_server_ssl(cls):
     if cls._ambari_server_ssl is None:
         cls._ambari_server_ssl = Ambari.is_ambari_encrypted()
     return cls._ambari_server_ssl