Ejemplo n.º 1
0
 def _ports(self, cluster_id):
     ports_per_one_host = int(
         askInt(text='How many ports do you need per one host?',
                default='3'))
     self._print('Ok. %s' % ports_per_one_host)
     offset = 100
     start_port = config.start_port + cluster_id * offset
     end_port = start_port + ports_per_one_host - 1
     start_port = askInt(text='Type start port?', default=str(start_port))
     self._print('Ok. %s' % start_port)
     end_port = askInt(text='Type end port?', default=str(end_port))
     self._print('Ok. %s' % end_port)
     return start_port, end_port
Ejemplo n.º 2
0
def host_for_monitor(host_list):
    formatted = []
    for i, v in enumerate(host_list):
        formatted.append('    ({}) {}'.format(i + 1, v))
    stringfied_list = '\n'.join(formatted)
    msg = '\n'.join(message.get('ask_host_for_monitor'))
    msg = msg.format(list=stringfied_list)
    target_num = int(askInt(msg, default='1'))
    while True:
        if target_num > 0 and target_num <= len(host_list):
            break
        msg = message.get('error_select_number').format(
            max_number=len(host_list))
        logger.error(msg)
        target_num = int(askInt(''))
    return host_list[target_num - 1]
Ejemplo n.º 3
0
def ssd_count(save, default=None):
    logger.debug('ask ssd count')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['ssd_count']
    result = int(askInt(message.get('ask_ssd_count'), default=str(default)))
    if result <= 0:
        logger.error(message.get('error_ssd_count_less_than_1'))
        return ssd_count(save=save, default=default)
    if save:
        deploy_history['ssd_count'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 4
0
def ssd_count(save, default=None):
    logger.debug('ask ssd count')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['ssd_count']
    q = 'How many sdd would you like to use?'
    result = int(askInt(q, default=str(default)))
    if result <= 0:
        logger.warn("The number of ssd must be greater than 0. try again.")
        return ssd_count(save=save, default=default)
    if save:
        deploy_history['ssd_count'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 5
0
def replicas(save, default=None):
    logger.debug('ask replicas')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['replicas']
    result = askInt(message.get('ask_replicas'), default=str(default))
    result = int(result)
    if result < 0:
        logger.error(message.get('error_replicas_less_than_0'))
        return replicas(save, default=default)
    if save:
        deploy_history['replicas'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 6
0
def replicas(save, default=None):
    logger.debug('ask replicas')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['replicas']
    q = 'How many replicas would you like to create on each master?'
    result = int(askInt(q, default=str(default)))
    if result < 0:
        msg = [
            'The number of master must be greater than or equal to 0.',
            'try again.',
        ]
        logger.error(' '.join(msg))
        return replicas(save, default=default)
    if save:
        deploy_history['replicas'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
Ejemplo n.º 7
0
 def monitor(self):
     """Monitor thriftserver (using tail -f)
     """
     cur_cluster_id = config.get_cur_cluster_id()
     logger.info('Start monitor cluster_id: %s' % cur_cluster_id)
     ip_list = config.get_node_ip_list()
     i = 1
     msg = ''
     for ip in ip_list:
         msg += '%d) %s\n' % (i, ip)
         i += 1
     target_num = int(askInt(text=msg, default='1'))
     logger.info('Ok. %s' % target_num)
     target_index = target_num - 1
     ip = ip_list[target_index]
     client = get_ssh(ip)
     envs = config.get_env_dict(ip, 0)
     tl = envs['sr2_redis_log']  # TODO: change redis log path
     command = 'tail -f {tl}/*'.format(tl=tl)
     ssh_execute_async(client=client, command=command)
Ejemplo n.º 8
0
def run_monitor():
    """Run monitor command

    Monitor remote logs
    """
    ip_list = get_node_ip_list()
    i = 1
    msg = ''
    for ip in ip_list:
        msg += '%d) %s\n' % (i, ip)
        i += 1
    target_num = int(askInt(text=msg, default='1'))
    logger.info('Ok. %s' % target_num)
    target_index = target_num - 1
    ip = ip_list[target_index]
    client = get_ssh(ip)
    envs = get_env_dict(ip, 0)
    redis_log = envs['sr2_redis_log']
    command = 'tail -f {redis_log}/*'.format(redis_log=redis_log)
    ssh_execute_async(client=client, command=command)
Ejemplo n.º 9
0
def master_ports(save, cluster_id, default_count=None):
    logger.debug('ask master ports')
    deploy_history = config.get_deploy_history()
    if not default_count:
        default_count = deploy_history['master_count']
    q = 'How many masters would you like to create on each host?'
    m_count = int(askInt(q, default=str(default_count)))
    if m_count <= 0:
        logger.warn("The number of master must be greater than 0. try again.")
        return master_ports(cluster_id, default_count)
    logger.info('OK, {}'.format(m_count))
    if save:
        deploy_history['master_count'] = m_count
        config.save_deploy_history(deploy_history)

    start_m_ports = START_PORT + cluster_id * MASTER_OFFSET
    end_m_ports = start_m_ports + m_count - 1
    if start_m_ports == end_m_ports:
        default_m_ports = str(start_m_ports)
    else:
        default_m_ports = '{}-{}'.format(start_m_ports, end_m_ports)

    q = [
        'Please type ports separate with comma(,) ',
        'and use hyphen(-) for range.',
    ]
    while True:
        result = ask(''.join(q), default=default_m_ports)
        result = map(lambda x: x.strip(), result.split(','))
        valid = True
        m_ports = set()
        pattern = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            matched = pattern.match(item)
            if matched:
                s, e = map(int, item.split('-'))
                if s > e:
                    logger.error('Invalid range: {}'.format(item))
                    valid = False
                    break
                m_ports.update(range(s, e + 1))
                continue
            # single number
            elif item.decode('utf-8').isdecimal():
                m_ports.add(int(item))
                continue
            else:
                logger.error('Invalid input: {}'.format(item))
                valid = False
                break
        if not valid:
            continue
        out_of_range = []
        for port in m_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = 'Use port between {} and {}: {}'.format(
                PORT_MININUM,
                PORT_MAXIMUM,
                out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(m_ports) != m_count:
            q2 = [
                "You type count '{}' at first, ".format(m_count),
                "but now count is '{}'. ".format(len(m_ports)), 'try again.'
            ]
            logger.error(''.join(q2))
            continue
        if valid:
            break
    m_ports = sorted(list(m_ports))
    logger.info('OK, {}'.format(result))
    return m_ports
Ejemplo n.º 10
0
 def _set_slots(self):
     total_slot_count = self.config['total_slot_count']
     text = 'How many slots do you want to move (from 1 to %d)?' % \
            total_slot_count
     self.move_slot_count = int(askInt(text))
Ejemplo n.º 11
0
def master_ports(save, cluster_id, default_count=None):
    logger.debug('ask master ports')
    deploy_history = config.get_deploy_history()
    if not default_count:
        default_count = deploy_history['master_count']
    msg = message.get('ask_master_count')
    m_count = int(askInt(msg, default=str(default_count)))
    if m_count <= 0:
        logger.error(message.get('error_master_count_less_than_1'))
        return master_ports(cluster_id, default_count)
    logger.info('OK, {}'.format(m_count))
    if save:
        deploy_history['master_count'] = m_count
        config.save_deploy_history(deploy_history)

    start_m_ports = START_PORT + cluster_id * MASTER_OFFSET
    end_m_ports = start_m_ports + m_count - 1
    if start_m_ports == end_m_ports:
        default_m_ports = str(start_m_ports)
    else:
        default_m_ports = '{}-{}'.format(start_m_ports, end_m_ports)

    while True:
        result = ask(message.get('ask_ports'), default=default_m_ports)
        result = list(map(lambda x: x.strip(), result.split(',')))
        valid = True
        m_ports = set()
        pattern = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            matched = pattern.match(item)
            if matched:
                s, e = map(int, item.split('-'))
                if s > e:
                    msg = message.get('error_invalid_range').format(value=item)
                    logger.error(msg)
                    valid = False
                    break
                m_ports.update(range(s, e + 1))
                continue
            # single number
            elif utils.is_number(item):
                m_ports.add(int(item))
                continue
            else:
                msg = message.get('error_invalid_input').format(value=item)
                logger.error(msg)
                valid = False
                break
        if not valid:
            continue
        out_of_range = []
        for port in m_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = message.get('error_port_range').format(
                minimum=PORT_MININUM,
                maximum=PORT_MAXIMUM,
                value=out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(m_ports) != m_count:
            msg = message.get('error_port_count_different').format(
                advance=m_count,
                current=len(m_ports),
            )
            logger.error(msg)
            continue
        if valid:
            break
    m_ports = sorted(list(m_ports))
    logger.info('OK, {}'.format(result))
    return m_ports
Ejemplo n.º 12
0
 def _ssd_count(self, default):
     ssd_count = int(askInt(text='SSD count?', default=str(default)))
     return ssd_count