Esempio n. 1
0
File: api.py Progetto: nrc/tiup
 def evict_store_leaders(self, host=None, port=None):
     _store_id = self.current_store_info(host=host, port=port)[0]
     if not _store_id:
         return
     # _current_schedulers = self.display_scheduler()
     # if 'evict-leader-scheduler-{}'.format(_store_id) not in _current_schedulers:
     #     _headers = {'Content-Type': 'application/json'}
     #     _url = self.__url(self.uris['schedulers'])
     #     _scheduler = {'name': 'evict-leader-scheduler',
     #                   'store_id': _store_id}
     #     utils.request_url(
     #         _url, data=json.dumps(_scheduler), method='POST', headers=_headers)
     _headers = {'Content-Type': 'application/json'}
     _url = self.__url(self.uris['schedulers'])
     _scheduler = {'name': 'evict-leader-scheduler', 'store_id': _store_id}
     utils.request_url(_url,
                       data=json.dumps(_scheduler),
                       method='POST',
                       headers=_headers)
     while True:
         _store_leader_count = self.current_store_info(host=host,
                                                       port=port)[1]
         if not _store_leader_count:
             return
         utils.wait(5)
Esempio n. 2
0
File: api.py Progetto: nrc/tiup
 def remove_evict(self, host, port):
     _store_id, _store_leader_count = self.current_store_info(host=host,
                                                              port=port)
     # _current_schedulers = self.display_scheduler()
     # if 'evict-leader-scheduler-{}'.format(_store_id) in _current_schedulers:
     #     _remove_evict_url = '{}/{}'.format(self.__url(
     #         self.uris['schedulers']), 'evict-leader-scheduler-{}'.format(_store_id))
     #     utils.request_url(_remove_evict_url, method='DELETE')
     _remove_evict_url = '{}/{}'.format(
         self.__url(self.uris['schedulers']),
         'evict-leader-scheduler-{}'.format(_store_id))
     utils.request_url(_remove_evict_url, method='DELETE')
Esempio n. 3
0
File: api.py Progetto: nrc/tiup
 def __req(self, url=None, method='GET'):
     if not url:
         raise exceptions.TiOPSArgumentError('No URL specified to request.')
     resp, code = utils.request_url(url, method=method)
     if not code or not (code >= 200 and code < 400):
         raise exceptions.TiOPSRequestError(url, code, resp)
     return resp
Esempio n. 4
0
File: api.py Progetto: nrc/tiup
 def delete_drainer(self, node_id=None):
     _drainer_info = [
         x for x in self.config['drainer_servers'] if x['uuid'] == node_id
     ][0]
     _url = '{}://{}:{}{}/{}/close'.format(self.scheme, _drainer_info['ip'],
                                           _drainer_info['port'],
                                           self.uris['action'], node_id)
     _content, _code = utils.request_url(url=_url, method='PUT')
     if _code == 200 and 'success' in json.loads(_content)['message']:
         return True
     return False
Esempio n. 5
0
File: api.py Progetto: nrc/tiup
 def evict_pd_leader(self, uuid=None):
     if not uuid:
         raise exceptions.TiOPSArgumentError(
             'UUID is not set, can not transfer leader from None.')
     _members = self.__req(self.__url(self.uris['members']))
     if len(json.loads(_members)['members']) == 1:
         # force continue when there is only one PD
         logging.warning('Only 1 PD node, skip leader transfer.')
         return
     while True:
         curr_leader = self.pd_leader()
         if uuid != curr_leader:
             return
         _url = '{}/resign'.format(self.__url(self.uris['leader']))
         try:
             utils.request_url(_url, method='POST')
         except Exception as e:
             logging.warning('Failed to transfer PD leader: {}'.format(e))
             pass
         utils.wait(5)
Esempio n. 6
0
File: api.py Progetto: nrc/tiup
 def _avialable_node(self):
     _num = len(self.config['pump_servers'])
     if not _num:
         return None, None, None, None
     _count = 0
     for _pump_node in self.config['pump_servers']:
         _count += 1
         _ip = _pump_node['ip']
         _port = _pump_node['port']
         _pump_content, _pump_code = utils.request_url(
             '{}://{}:{}{}'.format(self.scheme, _ip, _port,
                                   self.uris['pump_status']))
         if _pump_code != 200:
             if _count == _num:
                 return None, None, None, None
             continue
         _drainer_content, _drainer_code = utils.request_url(
             '{}://{}:{}{}'.format(self.scheme, _ip, _port,
                                   self.uris['drainer_status']))
         return _ip, _port, json.loads(_pump_content), json.loads(
             _drainer_content)
Esempio n. 7
0
File: api.py Progetto: nrc/tiup
 def pd_label(self, method='GET', label=None):
     _url = self.__url(self.uris['config'])
     if method == 'GET':
         _config = self.__req(_url)
         _data = json.loads(_config)
         _label = _data['replication']['location-labels']
         return _label
     elif method == 'POST':
         _headers = {'Content-Type': 'application/json'}
         _label = {'location-labels': label}
         while True:
             _result = utils.request_url(_url,
                                         data=json.dumps(_label),
                                         method='POST',
                                         headers=_headers)
             if _result[1] == 200:
                 break
Esempio n. 8
0
File: api.py Progetto: nrc/tiup
 def tikv_label(self, method='GET', label=None, host=None, port=None):
     _store_id = self.current_store_info(host=host, port=port)[0]
     if method == 'GET':
         _url = '{}/{}'.format(self.__url(self.uris['store']), _store_id)
         _store_info = self.__req(_url)
         _data = json.loads(_store_info)
         if 'labels' not in _data['store']:
             return False
         elif _data['store']['labels']:
             return True
         else:
             return False
     elif method == 'POST':
         _url = '{}/{}/label'.format(self.__url(self.uris['store']),
                                     _store_id)
         _headers = {'Content-Type': 'application/json'}
         while True:
             _result = utils.request_url(_url,
                                         data=label,
                                         method='POST',
                                         headers=_headers)
             if _result[1] == 200:
                 break