コード例 #1
0
    def do(self, workflow_dict):
        try:
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'],
                                                          databaseinfra=databaseinfra)

            client = databaseinfra.get_driver().get_client(None)
            rsconf = client.local.system.replset.find_one()
            member_ids = []
            for member in rsconf['members']:
                member_ids.append(member['_id'])

            max_member_id = max(member_ids)
            secundary_one_member_id = max_member_id + 1
            secundary_two_member_id = max_member_id + 2
            arbiter_member_id = max_member_id + 3

            context_dict = {
                'CONNECT_STRING': connect_string,
                'SECUNDARY_ONE': "{}:{}".format(workflow_dict['target_instances'][0].address, workflow_dict['target_instances'][0].port),
                'SECUNDARY_TWO': "{}:{}".format(workflow_dict['target_instances'][1].address, workflow_dict['target_instances'][1].port),
                'ARBITER': "{}:{}".format(workflow_dict['target_instances'][2].address, workflow_dict['target_instances'][2].port),
                'SECUNDARY_ONE_MEMBER_ID': secundary_one_member_id,
                'SECUNDARY_TWO_MEMBER_ID': secundary_two_member_id,
                'ARBITER_MEMBER_ID': arbiter_member_id,
            }

            script = test_bash_script_error()
            script += build_add_replica_set_members_script()

            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)

            return_code = exec_remote_command(server=host.address,
                                              username=cs_host_attr.vm_user,
                                              password=cs_host_attr.vm_password,
                                              command=script,
                                              output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #2
0
    def do(self, workflow_dict):
        try:
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'],
                                                          databaseinfra=databaseinfra)
            context_dict = {
                'CONNECT_STRING': connect_string,
            }

            script = test_bash_script_error()
            script += build_switch_primary_to_new_instances_script()

            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)

            return_code = exec_remote_command(server=host.address,
                                              username=cs_host_attr.vm_user,
                                              password=cs_host_attr.vm_password,
                                              command=script,
                                              output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            sleep(30)
            driver = databaseinfra.get_driver()
            client = driver.get_client(instance=None)
            rsconf = client['local'].system.replset.find_one()
            priority_0 = rsconf['members'][0].get('priority', 1)
            priority_1 = rsconf['members'][1].get('priority', 1)
            if priority_0 != 0 or priority_1 != 0:
                errormsg = "The priority of the old mongodb instances should be zero."
                LOG.error(errormsg)
                raise Exception(errormsg)
            replSetGetStatus = client.admin.command('replSetGetStatus')
            if 'PRIMARY' not in (replSetGetStatus['members'][3]['stateStr'],
                                 replSetGetStatus['members'][4]['stateStr']):
                errormsg = "One of the new instances should be PRIMARY."
                LOG.error(errormsg)
                raise Exception(errormsg)

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
    def do(self, workflow_dict):
        try:

            instances = workflow_dict['instances']
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = util.build_mongodb_connect_string(instances=instances,
                                                               databaseinfra=databaseinfra)

            script = test_bash_script_error()
            script += util.build_cp_mongodb_binary_file()
            script += util.build_stop_database_script(clean_data=False)
            script += util.build_change_release_alias_script()
            script += util.build_start_database_script()
            script += util.build_authschemaupgrade_script()
            script += util.build_change_limits_script()
            script += util.build_change_in_serverstatus_file_script()
            script += util.build_reinstal_mongo_gen_script()
            script += util.build_remove_reprecated_index_counter_metrics()

            context_dict = {
                'SOURCE_PATH': '/mnt/software/db/mongodb',
                'TARGET_PATH': '/usr/local/',
                'MONGODB_RELEASE_FILE': 'mongodb-linux-x86_64-3.0.8.tgz',
                'MONGODB_RELEASE_FOLDER': 'mongodb-linux-x86_64-3.0.8',
                'CONNECT_STRING': connect_string,
            }

            script = build_context_script(context_dict, script)
            output = {}

            host = instances[0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)

            return_code = exec_remote_command(server=host.address,
                                              username=cs_host_attr.vm_user,
                                              password=cs_host_attr.vm_password,
                                              command=script,
                                              output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True

        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0023)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #4
0
    def do(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']
            target_instances = []

            for source_instance in workflow_dict['source_instances']:
                target_instances.append(source_instance.future_instance)

            connect_string = build_mongodb_connect_string(
                instances=target_instances, databaseinfra=databaseinfra)

            context_dict = {
                'CONNECT_STRING':
                connect_string,
                'SECUNDARY_ONE':
                "{}:{}".format(workflow_dict['source_instances'][0].address,
                               workflow_dict['source_instances'][0].port),
                'SECUNDARY_TWO':
                "{}:{}".format(workflow_dict['source_instances'][1].address,
                               workflow_dict['source_instances'][1].port),
                'ARBITER':
                "{}:{}".format(workflow_dict['source_instances'][2].address,
                               workflow_dict['source_instances'][2].port),
            }

            script = test_bash_script_error()
            script += build_remove_replica_set_members_script()

            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)
            return_code = exec_remote_command(
                server=host.address,
                username=cs_host_attr.vm_user,
                password=cs_host_attr.vm_password,
                command=script,
                output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #5
0
    def do(self, workflow_dict):
        try:

            instances = workflow_dict['instances']
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = util.build_mongodb_connect_string(
                instances=instances, databaseinfra=databaseinfra)

            script = test_bash_script_error()
            script += util.build_cp_mongodb_binary_file()
            script += util.build_stop_database_script(clean_data=False)
            script += util.build_change_release_alias_script()
            script += util.build_start_database_script()
            script += util.build_authschemaupgrade_script()
            script += util.build_addrole_mongo3_script()
            script += util.build_change_limits_script()

            context_dict = {
                'SOURCE_PATH': '/mnt/software/db/mongodb',
                'TARGET_PATH': '/usr/local/',
                'MONGODB_RELEASE_FILE': 'mongodb-linux-x86_64-3.0.12.tgz',
                'MONGODB_RELEASE_FOLDER': 'mongodb-linux-x86_64-3.0.12',
                'CONNECT_STRING': connect_string,
            }

            script = build_context_script(context_dict, script)
            output = {}

            host = instances[0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)

            return_code = exec_remote_command(
                server=host.address,
                username=cs_host_attr.vm_user,
                password=cs_host_attr.vm_password,
                command=script,
                output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True

        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0023)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #6
0
    def do(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']
            instances = workflow_dict['instances']
            driver = databaseinfra.get_driver()

            connect_string = util.build_mongodb_connect_string(
                instances=instances, databaseinfra=databaseinfra)

            arbiter_instance = driver.get_non_database_instances()[0]
            LOG.info(
                'Changing Arbiter binaries {}...'.format(arbiter_instance))
            self.change_instance_binaries(instance=arbiter_instance,
                                          connect_string=connect_string,
                                          is_primary=False)

            secondary_instance = driver.get_slave_instances()[0]
            LOG.info(
                'Changing Secondary binaries {}...'.format(secondary_instance))
            self.change_instance_binaries(instance=secondary_instance,
                                          connect_string=connect_string,
                                          is_primary=False)

            master_instance = driver.get_master_instance()

            LOG.info('Switching Databases')
            driver.check_replication_and_switch(instance=secondary_instance)
            new_secondary = master_instance

            LOG.info(
                'Changing old master binaries {}...'.format(new_secondary))
            self.change_instance_binaries(instance=new_secondary,
                                          connect_string=connect_string,
                                          is_primary=True)

            LOG.info('Switching Databases')
            driver.check_replication_and_switch(instance=new_secondary)

            return True

        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0023)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #7
0
    def do(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']
            target_instances = []

            for source_instance in workflow_dict['source_instances']:
                target_instances.append(source_instance.future_instance)

            connect_string = build_mongodb_connect_string(instances=target_instances,
                                                          databaseinfra=databaseinfra)

            context_dict = {
                'CONNECT_STRING': connect_string,
                'SECUNDARY_ONE': "{}:{}".format(workflow_dict['source_instances'][0].address, workflow_dict['source_instances'][0].port),
                'SECUNDARY_TWO': "{}:{}".format(workflow_dict['source_instances'][1].address, workflow_dict['source_instances'][1].port),
                'ARBITER': "{}:{}".format(workflow_dict['source_instances'][2].address, workflow_dict['source_instances'][2].port),
            }

            script = test_bash_script_error()
            script += build_remove_replica_set_members_script()

            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)
            return_code = exec_remote_command(server=host.address,
                                              username=cs_host_attr.vm_user,
                                              password=cs_host_attr.vm_password,
                                              command=script,
                                              output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            for source_instance in workflow_dict['source_instances']:
                source_instance.delete()
                LOG.info("Source instance deleted")

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
    def do(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']
            instances = workflow_dict['instances']
            driver = databaseinfra.get_driver()

            connect_string = util.build_mongodb_connect_string(instances=instances,
                                                               databaseinfra=databaseinfra)

            arbiter_instance = driver.get_non_database_instances()[0]
            LOG.info('Changing Arbiter binaries {}...'.format(arbiter_instance))
            self.change_instance_binaries(instance=arbiter_instance,
                                          connect_string=connect_string,
                                          run_authschemaupgrade=False)

            secondary_instance = driver.get_slave_instances()[0]
            LOG.info('Changing Secondary binaries {}...'.format(secondary_instance))
            self.change_instance_binaries(instance=secondary_instance,
                                          connect_string=connect_string,
                                          run_authschemaupgrade=False)

            master_instance = driver.get_master_instance()

            LOG.info('Switching Databases')
            driver.check_replication_and_switch(instance=secondary_instance)
            new_secondary = master_instance

            LOG.info('Changing old master binaries {}...'.format(new_secondary))
            self.change_instance_binaries(instance=new_secondary,
                                          connect_string=connect_string,
                                          run_authschemaupgrade=True)

            LOG.info('Switching Databases')
            driver.check_replication_and_switch(instance=new_secondary)

            return True

        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0023)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #9
0
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = build_mongodb_connect_string(
                instances=workflow_dict['source_instances'],
                databaseinfra=databaseinfra)

            context_dict = {
                'CONNECT_STRING': connect_string,
            }

            script = test_bash_script_error()
            script += build_switch_primary_to_old_instances_script()
            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)
            return_code = exec_remote_command(
                server=host.address,
                username=cs_host_attr.vm_user,
                password=cs_host_attr.vm_password,
                command=script,
                output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #10
0
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = build_mongodb_connect_string(instances=workflow_dict['source_instances'],
                                                          databaseinfra=databaseinfra)

            context_dict = {
                'CONNECT_STRING': connect_string,
            }

            script = test_bash_script_error()
            script += build_switch_primary_to_old_instances_script()
            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)
            return_code = exec_remote_command(server=host.address,
                                              username=cs_host_attr.vm_user,
                                              password=cs_host_attr.vm_password,
                                              command=script,
                                              output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
コード例 #11
0
    def do(self, workflow_dict):
        try:
            databaseinfra = workflow_dict['databaseinfra']

            connect_string = build_mongodb_connect_string(
                instances=workflow_dict['source_instances'],
                databaseinfra=databaseinfra)

            client = databaseinfra.get_driver().get_client(None)
            rsconf = client.local.system.replset.find_one()
            member_ids = []
            for member in rsconf['members']:
                member_ids.append(member['_id'])

            max_member_id = max(member_ids)
            secundary_one_member_id = max_member_id + 1
            secundary_two_member_id = max_member_id + 2
            arbiter_member_id = max_member_id + 3

            context_dict = {
                'CONNECT_STRING':
                connect_string,
                'SECUNDARY_ONE':
                "{}:{}".format(workflow_dict['target_instances'][0].address,
                               workflow_dict['target_instances'][0].port),
                'SECUNDARY_TWO':
                "{}:{}".format(workflow_dict['target_instances'][1].address,
                               workflow_dict['target_instances'][1].port),
                'ARBITER':
                "{}:{}".format(workflow_dict['target_instances'][2].address,
                               workflow_dict['target_instances'][2].port),
                'SECUNDARY_ONE_MEMBER_ID':
                secundary_one_member_id,
                'SECUNDARY_TWO_MEMBER_ID':
                secundary_two_member_id,
                'ARBITER_MEMBER_ID':
                arbiter_member_id,
            }

            script = test_bash_script_error()
            script += build_add_replica_set_members_script()

            script = build_context_script(context_dict, script)
            output = {}

            host = workflow_dict['source_instances'][0].hostname
            cs_host_attr = CS_HostAttr.objects.get(host=host)

            return_code = exec_remote_command(
                server=host.address,
                username=cs_host_attr.vm_user,
                password=cs_host_attr.vm_password,
                command=script,
                output=output)
            LOG.info(output)
            if return_code != 0:
                raise Exception(str(output))

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False