def delete(self): url = '{0}/datafiles/{1}'.format( self.config.get_controller_url(self.fabric), self.resource) try: result = requests.delete(url) except RequestException as e: raise PinotException(e) if result.status_code != 200: raise PinotException(result.text) return True
def get_zk_root(self, fabric): try: return self.config['fabrics'][fabric]['zk_root'] except KeyError: error = 'Failed getting zookeeper root from config' self.logger.exception(error) raise PinotException(error)
def get_fabrics(self): try: return self.config['fabrics'].keys() except KeyError: error = 'Failed getting list of fabrics from config' self.logger.exception(error) raise PinotException(error)
def get_controller_url(self, fabric): try: return self.config['fabrics'][fabric]['controller_url'] except KeyError: error = 'Failed getting controller url from config' self.logger.exception(error) raise PinotException(error)
def create_broker_tenant(self, name, instances): url = '{0}/tenants'.format(self.config.get_controller_url(self.fabric)) try: result = requests.post(url, json={ 'tenantRole': 'broker', 'numberOfInstances': instances, 'tenantName': name, }) except RequestException: error = 'Failed hitting {0}'.format(url) self.logger.exception(error) raise PinotException(error) if result.status_code != 200: raise PinotException(result.text) return True
def run_pql(self, pql): host = self.config.get_controller_url(self.fabric) url = '{0}/pql'.format(host) try: r = requests.get(url, params={'pql': pql}) except RequestException: error = 'Failed hitting {0}'.format(url) self.logger.exception(error) raise PinotException(error) try: result = r.json() except ValueError: result = r.text raise PinotException(result) return {'success': True, 'result': result}
def get_resources(self): host = self.config.get_controller_url(self.fabric) url = '{0}/tenants?type=server'.format(host) try: r = requests.get(url) except RequestException: error = 'Failed hitting {0}'.format(url) self.logger.exception(error) raise PinotException(error) try: data = r.json() except ValueError: error = 'Failed parsing json data' self.logger.exception(error) raise PinotException(error) return map(lambda x: x.split('_O')[0], data['SERVER_TENANTS'])
def create_table(self, settings): try: data = { 'tableName': settings['name'], 'tableConfig': { 'retention.TimeUnit': settings['retention_unit'], 'retention.TimeValue': settings['retention_value'], 'segment.pushFrequency': settings['push_frequency'], 'segment.pushType': settings['push_type'], 'replication': settings['replication'], 'schemaName': settings['schema'] }, 'tableIndexConfig': { 'invertedIndexColumns': settings['inverted_index_columns'], 'loadMode': settings['loadmode'], 'lazyLoad': settings['lazyload'] }, 'tenants': { 'broker': settings['broker_tenant'], 'server': settings['server_tenant'], }, 'tableType': settings['type'], 'metadata': { 'd2.name': settings['d2'] } } except KeyError as e: raise PinotException('Missing key: {0}'.format(e)) url = '{0}/tables'.format(self.config.get_controller_url(self.fabric)) try: result = requests.post(url, json=data) except RequestException as e: raise PinotException(e) if result.status_code != 200: raise PinotException(result.text) return True
def get_handle(self): host = self.config.get_zk_host(self.fabric) if not self.zk: try: self.zk = KazooClient(hosts=host) self.zk.start() except kazoo.exceptions.KazooException: error = 'Failed connecting to zk {0}'.format(host) self.logger.exception(error) raise PinotException(error) return self.zk