Beispiel #1
0
Datei: scale.py Projekt: nrc/tiup
    def _post(self, component=None, pattern=None, node=None, role=None):
        # if 'pd_servers' in self._diff:
        #    reload_pd = True
        # else:
        #    reload_pd = False
        self.topology.replace(self._new_topo)
        term.info('Update configuration.')
        ans = ansibleapi.ANSRunner(user=self.topology.user,
                                   topology=self.topology._topology(
                                       self._new_topo),
                                   tiargs=self._args)
        act = Action(ans=ans, topo=self.topology)
        if 'pd_servers' in self._diff:
            act.deploy_component(component='pd', pattern='pd_servers')
            act.deploy_component(component='tikv', pattern='tikv_servers')
            act.deploy_component(component='tidb', pattern='tidb_servers')
            act.deploy_component(component='pump', pattern='pump_servers')
            act.deploy_component(component='drainer',
                                 pattern='drainer_servers')

        act.deploy_component(component='prometheus',
                             pattern='monitoring_server')
        act.stop_component(component='prometheus', pattern='monitoring_server')
        act.start_component(component='prometheus',
                            pattern='monitoring_server')
        term.notice('Finished scaling out.')
Beispiel #2
0
 def __init__(self, args=None, topology=None):
     super(OprExec, self).__init__(args, topology)
     self.act = Action(ans=self.ans, topo=self.topology)
     self._result = {
         'failed': {},
         'success': {},
         'unreachable': {},
     }
Beispiel #3
0
Datei: scale.py Projekt: nrc/tiup
 def __init__(self, args=None, topology=None, new_srvs=None):
     if os.path.exists(topology.topology_file):
         term.warn(
             'Check TiDB cluster {} status, it may take a few minutes.'.
             format(topology.cluster_name))
         self.check_tombstone(topology, args)
     self._new_topo, self._diff = topology.add(new_srvs)
     topology.replace(self._new_topo, write=False)
     super(OprScaleOut, self).__init__(args, topology, action='deploy')
     self.act = Action(ans=self.ans, topo=self.topology)
Beispiel #4
0
Datei: scale.py Projekt: nrc/tiup
    def __init__(self, args=None, topology=None, node=None):
        if not node:
            msg = 'Node ID not specified.'
            term.error(msg)
            raise exceptions.TiOPSConfigError(msg)

        self._new_topo, self._diff = topology.remove(node)

        super(OprScaleIn, self).__init__(args, topology)
        self.act = Action(ans=self.ans, topo=self.topology)
Beispiel #5
0
 def __init__(self, args=None, topology=None):
     super(OprUpgrade, self).__init__(args, topology)
     self.act = Action(ans=self.ans, topo=self.topology)
     try:
         self.arg_ver = args.tidb_version
     except AttributeError:
         raise exceptions.TiOPSConfigError(
             '--tidb-version is not set when upgrade, abort.')
     try:
         self.force = args.force
     except AttributeError:
         self.force = False
Beispiel #6
0
Datei: scale.py Projekt: nrc/tiup
    def _post(self, component=None, pattern=None, node=None, role=None):
        ans = ansibleapi.ANSRunner(user=self.topology.user,
                                   topology=self.topology(),
                                   tiargs=self._args)
        act = Action(ans=ans, topo=self.topology)
        if 'pd_servers' in self._diff:
            act.deploy_component(component='pd', pattern='pd_servers')
            act.deploy_component(component='tikv', pattern='tikv_servers')
            act.deploy_component(component='tidb', pattern='tidb_servers')
            act.deploy_component(component='pump', pattern='pump_servers')
            act.deploy_component(component='drainer',
                                 pattern='drainer_servers')

        # self.deploy.deploy_component(component='prometheus', pattern='monitoring_server', ans=ans)
        # self.reload.do(component='prometheus', pattern='monitoring_server')

        term.notice('Finished scaling in.')
Beispiel #7
0
Datei: start.py Projekt: nrc/tiup
 def __init__(self, args=None, topology=None, demo=False):
     super(OprStart, self).__init__(args, topology, demo=demo)
     self.act = Action(ans=self.ans, topo=self.topology)
     self.demo = demo
Beispiel #8
0
Datei: stop.py Projekt: nrc/tiup
 def __init__(self, args=None, topology=None):
     super(OprStop, self).__init__(args, topology)
     self.act = Action(ans=self.ans, topo=self.topology)
Beispiel #9
0
def main(args=None):
    try:
        action = args.action
    except AttributeError:
        pass

    if action == 'version':
        print(term.plain(TiOPSVer()))
        exit(0)

    if action == 'quickdeploy':
        term.warn(
            'The quick deploy mode is for demo and testing, do NOT use in production!'
        )

        # do init
        _init = init.Init(args)
        try:
            _init.init(demo=True)
            _init.init_network(demo=True)
            _init.init_host(demo=True)
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)

        # do deploy
        topo = topology.Topology(args=args, merge=True)
        try:
            op.OprDeploy(args, topo, demo=True).do()
            op.OprStart(args, topo, demo=True).do()
            tm.TUIModule(topo, args=args).display()
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSRequestError as e:
            msg = "{}, URL {} returned {}, please check the network and try again.".format(
                e.msg, e.url, e.code)
            term.error(msg)
            sys.exit(1)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)

    elif action == 'bootstrap-local':
        _init = init.Init(args)
        try:
            _init.init()
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)
    elif action == 'bootstrap-ssh':
        _init = init.Init(args)
        try:
            _init.init_network()
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)
    elif action == 'bootstrap-host':
        _init = init.Init(args)
        try:
            _init.init_host()
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)
    else:
        try:
            if action not in ['deploy', 'display']:
                topo = topology.Topology(args)
        except TiOPSRuntimeError as e:
            tierror(e)
        except TiOPSException as e:
            term.debug(traceback.format_exc())
            term.fatal(str(e))
            sys.exit(1)

        if action == 'display':
            try:
                _cluster_name = args.cluster_name
            except AttributeError:
                _cluster_name = None
            try:
                if _cluster_name and len(_cluster_name) > 0:
                    topo = topology.Topology(args)
                    _list = False
                else:
                    topo = None
                    _list = True
                tm.TUIModule(topo, args=args).display(_list)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'deploy':
            topo = topology.Topology(args=args, merge=True)
            try:
                op.OprDeploy(args, topo).do()
                tm.TUIModule(topo, args=args).display()
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSRequestError as e:
                msg = "{}, URL {} returned {}, please check the network and try again.".format(
                    e.msg, e.url, e.code)
                term.error(msg)
                sys.exit(1)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'start':
            try:
                op.OprStart(args, topo).do(node=args.node_id, role=args.role)
                tm.TUIModule(topo, args=args, status=True).display()
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'stop':
            try:
                op.OprStop(args, topo).do(node=args.node_id, role=args.role)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'restart':
            try:
                op.OprRestart(args, topo).do(node=args.node_id, role=args.role)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'reload':
            try:
                op.OprReload(args, topo).do(node=args.node_id, role=args.role)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'upgrade':
            try:
                op.OprUpgrade(args, topo).do(node=args.node_id, role=args.role)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSRequestError as e:
                msg = "{}, URL {} returned {}, please check the network and try again.".format(
                    e.msg, e.url, e.code)
                term.error(msg)
                sys.exit(1)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'destroy':
            try:
                op.OprDestroy(args, topo).do()
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'edit-config':
            try:
                Action(topo=topo).edit_file()
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'scale-out':
            addTopo = utils.read_yaml(args.topology)
            try:
                op.OprScaleOut(args, topo, addTopo).do()
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'scale-in':
            try:
                op.OprScaleIn(args, topo, args.node_id).do(node=args.node_id)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
        elif action == 'exec':
            try:
                op.OprExec(args, topo).do(node=args.node_id, role=args.role)
            except TiOPSRuntimeError as e:
                tierror(e)
            except TiOPSException as e:
                term.debug(traceback.format_exc())
                term.fatal(str(e))
                sys.exit(1)
Beispiel #10
0
Datei: base.py Projekt: nrc/tiup
    def check_tombstone(self, topology=None, args=None):
        if not topology:
            topology = self.topology
        if not args:
            args = self._args
        _remove_uuid = []
        _cluster = ClusterAPI(topology)
        _binlog = BinlogAPI(topology)

        if _cluster.tikv_stores() and _cluster.tikv_tombstone():
            # get tombstone tikv node
            for _node in topology()['tikv_servers']:
                _tombstone = False
                if not _node['offline']:
                    continue

                # online tikv node list
                _online_list = [
                    x['store']['address']
                    for x in _cluster.tikv_stores()['stores']
                ]
                # tombstone status tikv list
                _tombstone_list = [
                    x['store']['address']
                    for x in _cluster.tikv_tombstone()['stores']
                ]

                _address = '{}:{}'.format(_node['ip'], _node['port'])

                # if node is online, skip it
                if _address in _online_list:
                    continue
                # if node is tombstone, will delete it from topology
                elif _address in _tombstone_list:
                    _remove_uuid.append(_node['uuid'])

        if _binlog.pump_status:
            # get tombstone pump node
            for _node in topology()['pump_servers']:
                _tombstone = False
                if not _node['offline']:
                    continue

                _online_list = [
                    x['nodeId']
                    for x in _binlog.pump_status['status'].itervalues()
                    if x['state'] != 'offline'
                ]
                _tombstone_list = [
                    x['nodeId']
                    for x in _binlog.pump_status['status'].itervalues()
                    if x['state'] == 'offline'
                ]

                if _node['uuid'] in _online_list:
                    continue
                elif _node['uuid'] in _tombstone_list:
                    _remove_uuid.append(_node['uuid'])

            for _node in topology()['drainer_servers']:
                _tombstone = False
                if not _node['offline']:
                    continue

                _online_list = [
                    x['nodeId'] for x in _binlog.drainer_status
                    if x['state'] != 'offline'
                ]
                _tombstone_list = [
                    x['nodeId'] for x in _binlog.drainer_status
                    if x['state'] == 'offline'
                ]

                if _node['uuid'] in _online_list:
                    continue
                elif _node['uuid'] in _tombstone_list:
                    _remove_uuid.append(_node['uuid'])

        if not _remove_uuid:
            return

        _new_topo, _diff = topology.remove(','.join(_remove_uuid), delete=True)
        ans = ansibleapi.ANSRunner(user=topology.user,
                                   topology=_diff,
                                   tiargs=args)
        act = Action(ans=ans, topo=topology)
        for service in [{
                'drainer': 'drainer_servers'
        }, {
                'pump': 'pump_servers'
        }, {
                'tikv': 'tikv_servers'
        }]:
            component, pattern = self.check_exist(service, _diff)
            if not component and not pattern:
                continue
            act.stop_component(component=component, pattern=pattern)
            act.destroy_component(component=component, pattern=pattern)

        topology.replace(_new_topo)