Exemple #1
0
def deinitialize_mongodb(ip_list):
    for ip in ip_list:
        process.run('service mongod stop', ip)
        process.run('sleep 5', ip)
        process.run('rm -rf /var/lib/mongo/*', ip)
        process.run('mv -f /etc/mongod.conf.bak /etc/mongod.conf', ip)
        process.run('sed -i "/mongod/d" /etc/rc.local', ip)
Exemple #2
0
def get_node_throughput_and_iops():
    try:
        if do_or_not_do():
            current_time = handler.current_stamp()
            node_list = database.get_setting('NODE-LIST')
            node_list = list(set(node_list['mgmt'] + \
                node_list['meta'] + node_list['storage']))
            host_list = map(lambda node: process.run(
                'hostname', node), node_list)

            def get_throughput_and_iops(host):
                data = backend.get_node_throughput_and_iops(host)
                throughput_list = data['throughput'] or []
                iops_list = data['iops'] or []
                read_throughput = 0
                wriet_throughput = 0
                total_iops = 0
                if len(throughput_list) and len(iops_list):
                    throughput_list.reverse()
                    throughput_list = throughput_list[0:15]
                    iops_list.reverse()
                    iops_list = iops_list[0:15]
                    for throughput in throughput_list:
                        read_throughput += throughput['read']
                        wriet_throughput += throughput['write']
                    iops_list = map(lambda iops: iops['total'], iops_list)
                    total_iops = sum(iops_list)
                return {'throughput': {'read': read_throughput / 15, 'write': wriet_throughput / 15}, 'iops': total_iops / 15}
            data_list = map(get_throughput_and_iops, host_list)
            database.create_node_throughput_and_iops(
                current_time, host_list, data_list)
    except Exception as error:
        handler.log(handler.error(error), 2)
        handler.log('Run get node throughput and iops task failed!')
Exemple #3
0
def run_snapshot_schedule():
    try:
        if do_or_not_do():
            current_time = handler.current_time()
            schedule_is_running = database.get_is_running_snapshot_schedule()
            if schedule_is_running is not None:
                name = schedule_is_running['name']
                start_time = schedule_is_running['startTime']
                auto_disable_time = schedule_is_running['autoDisableTime']
                interval = schedule_is_running['interval']
                delete_round = schedule_is_running['deleteRound']
                time_gap_in_second = handler.iso2stamp(
                    current_time) - handler.iso2stamp(start_time)
                if time_gap_in_second >= interval and not (time_gap_in_second % interval) and (not auto_disable_time or time_gap_in_second <= auto_disable_time):
                    snapshot_setting = database.get_setting('SNAPSHOT-SETTING')
                    limit = snapshot_setting['auto']
                    count = database.count_snapshot(True)
                    name_to_create = name + '-' + \
                        process.run('date "+%Y%m%d%H%M%S"')
                    if count < limit:
                        database.create_snapshot(
                            name_to_create, '', True, current_time)
                        event.send('snapshot', 11, name_to_create, True)
                        create_status = backend.create_snapshot(
                            name_to_create, True)
                        if not create_status['errorId']:
                            database.update_snapshot_status(name_to_create)
                            event.send('snapshot', 12, name_to_create, True)
                        else:
                            database.delete_snapshot(name_to_create)
                            event.send('snapshot', 12, name_to_create, False)
                    elif delete_round:
                        auto_snapshots = database.get_auto_snapshot()
                        name_to_delete = auto_snapshots[0]['name']
                        database.update_snapshot_status(
                            name_to_delete, False, True, False)
                        delete_status = backend.delete_snapshot(name_to_delete)
                        if not delete_status['errorId']:
                            database.delete_snapshot(name_to_delete)
                            database.create_snapshot(
                                name_to_create, '', True, current_time)
                            event.send('snapshot', 11, name_to_create, True)
                            create_status = backend.create_snapshot(
                                name_to_create, True)
                            if not create_status['errorId']:
                                database.update_snapshot_status(name_to_create)
                                event.send('snapshot', 12,
                                           name_to_create, True)
                            else:
                                database.delete_snapshot(name_to_create)
                                event.send('snapshot', 12,
                                           name_to_create, False)
                        else:
                            database.update_snapshot_status(name_to_delete)
                elif auto_disable_time and time_gap_in_second > auto_disable_time:
                    database.disable_snapshot_schedule(name)
    except Exception as error:
        handler.log(handler.error(error), 2)
        handler.log('Run snapshot schedule task failed!')
Exemple #4
0
def disable_node_service(node_list):
    mgmt = node_list['mgmt']
    meta_and_storage = list(set(node_list['meta'] + node_list['storage']))
    for ip in mgmt:
        if ip in meta_and_storage:
            meta_and_storage.remove(ip)
    for ip in meta_and_storage:
        process.run('sed -i "/orcafs-gui/d" /etc/rc.local', ip)
        process.run('sed -i "/nginx/d" /etc/rc.local', ip)
        process.run('service orcafs-gui stop', ip)
        process.run('service nginx stop', ip)
Exemple #5
0
def enable_node_service(node_list):
    mgmt = node_list['mgmt']
    meta_and_storage = list(set(node_list['meta'] + node_list['storage']))
    for ip in mgmt:
        if ip in meta_and_storage:
            meta_and_storage.remove(ip)
    for ip in meta_and_storage:
        process.run(
            'sed -i "/OrcaFS/ a service orcafs-gui start" /etc/rc.local', ip)
        process.run('sed -i "/Nginx/ a service nginx start" /etc/rc.local', ip)
        process.run('service orcafs-gui start', ip)
        process.run('service nginx start', ip)
Exemple #6
0
def add_node_to_cluster(node_ip, node_type):
    if node_type == 'client':
        pass
    elif node_type == 'mgmt':
        pass
    else:
        node_list = database.get_setting('NODE-LIST')
        ip_list = node_list['mgmt'] + node_list['meta'] + node_list['storage']
        if node_ip not in ip_list:
            process.run('sed -i "/orcafs-gui/d" /etc/rc.local', node_ip)
            process.run('sed -i "/nginx/d" /etc/rc.local', node_ip)
            process.run('service orcafs-gui stop', node_ip)
            process.run('service nginx stop', node_ip)
    database.add_node_to_cluster(node_ip, node_type)
Exemple #7
0
def get_node_cpu_and_memory():
    try:
        if do_or_not_do():
            current_time = handler.current_stamp()
            node_list = database.get_setting('NODE-LIST')
            node_list = list(set(node_list['mgmt'] + \
                node_list['meta'] + node_list['storage']))
            host_list = map(lambda node: process.run(
                'hostname', node), node_list)
            data_list = map(backend.get_node_cpu_and_memory, host_list)
            database.create_node_cpu_and_memory(
                current_time, host_list, data_list)
    except Exception as error:
        handler.log(handler.error(error), 2)
        handler.log('Run get node cpu and memory task failed!')
Exemple #8
0
def empty_log(ip):
    process.run('> /var/log/mongodb/mongod.log', ip)
    process.run('> /var/log/orcafs-gui.log', ip)
Exemple #9
0
def reload_mongodb():
    mongodb_status = get_mongodb_status()
    mongodb_need_run = bool(int(process.run('grep -c "mongod" /etc/rc.local')))
    if not mongodb_status and mongodb_need_run:
        process.run('service mongod start')
Exemple #10
0
def get_mongodb_replset_config():
    command = '/usr/bin/mongo --quiet --eval "db.isMaster().hosts"'
    return json.loads(process.run(command))
Exemple #11
0
def get_mongodb_type():
    command = '/usr/bin/mongo --quiet --eval "rs.status().ok"'
    return int(process.run(command))  # 0 => single, 1 => replset
Exemple #12
0
def get_mongodb_is_master_or_not():
    command = '/usr/bin/mongo --quiet --eval "db.isMaster().ismaster"'
    if get_mongodb_process():
        return process.run(command) == 'true'
    else:
        return False
Exemple #13
0
def get_mongodb_status():
    command = '/usr/bin/mongo --quiet --eval "db.serverStatus().ok"'
    if get_mongodb_process():
        return process.run(command) == '1'
    else:
        return False
Exemple #14
0
def get_mongodb_process():
    command = 'ps aux|grep /usr/bin/mongod|grep grep -v|awk \'{print $2}\''
    return bool(process.run(command))
Exemple #15
0
def initialize_mongodb(param):
    ip_list = param['ip_list']
    replica_set = param['replica_set']
    if not replica_set:
        process.run('mv /etc/mongod.conf /etc/mongod.conf.bak')
        process.run(
            'cp /var/orcafs-gui/server-unified/conf/mongod.single.conf /etc/mongod.conf'
        )
        process.run('service mongod start')
        process.run('sed -i "/MongoDB/ a service mongod start" /etc/rc.local')
    else:

        def create_members_config(members):
            param = []
            for i in range(len(members)):
                param.append({'_id': i, 'host': members[i], 'priority': 2 - i})
            return param

        config = {'_id': 'orcafs', 'members': create_members_config(ip_list)}
        for ip in ip_list:
            process.run('mv /etc/mongod.conf /etc/mongod.conf.bak', ip)
            process.run(
                'cp /var/orcafs-gui/server-unified/conf/mongod.replset.conf /etc/mongod.conf',
                ip)
            process.run('service mongod start', ip)
            process.run(
                'sed -i "/MongoDB/ a service mongod start" /etc/rc.local', ip)
        process.run('/usr/bin/mongod --quiet --eval "rs.initiate(%s)"' %
                    json.dumps(config))
    process.run('sleep 20')