def do(self, workflow_dict):
        try:
            master_source_instance = workflow_dict['source_instances'][0]

            master_target_instance = workflow_dict['source_instances'][
                0].future_instance
            slave_target_instance = workflow_dict['source_instances'][
                1].future_instance

            master_log_file, master_log_pos = get_replication_info(
                master_target_instance)

            change_master_to(instance=master_target_instance,
                             master_host=master_source_instance.address,
                             bin_log_file=workflow_dict['binlog_file'],
                             bin_log_position=workflow_dict['binlog_pos'])

            change_master_to(instance=slave_target_instance,
                             master_host=master_target_instance.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            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):
     if not self.is_valid:
         return
     master_instance = self.master_instance
     master_host = master_instance.hostname
     log_file, log_pos = get_replication_information_from_file(master_host)
     change_master_to(self.instance, master_host.address, log_file, log_pos)
    def do(self, workflow_dict):
        try:
            master_source_instance = workflow_dict['source_instances'][0]

            master_target_instance = workflow_dict['source_instances'][0].future_instance
            slave_target_instance = workflow_dict['source_instances'][1].future_instance

            master_log_file, master_log_pos = get_replication_info(master_target_instance)

            change_master_to(instance=master_target_instance,
                             master_host=master_source_instance.address,
                             bin_log_file=workflow_dict['binlog_file'],
                             bin_log_position=workflow_dict['binlog_pos'])

            change_master_to(instance=slave_target_instance,
                             master_host=master_target_instance.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            return True
        except Exception:
            traceback = full_stack()

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

            return False
Пример #4
0
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:
            target_instances = workflow_dict[
                'databaseinfra'].instances.filter(future_instance=None)

            target_instance_zero = target_instances[0]

            source_instance_zero = workflow_dict['source_instances'][0]
            source_instance_one = workflow_dict['source_instances'][1]

            master_log_file, master_log_pos = get_replication_info(
                source_instance_one)
            change_master_to(instance=source_instance_zero,
                             master_host=source_instance_one.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            master_log_file, master_log_pos = get_replication_info(
                source_instance_zero)
            change_master_to(instance=target_instance_zero,
                             master_host=source_instance_zero.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)
            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']

            master_host = workflow_dict['host']
            master_instance = Instance.objects.get(hostname=master_host)

            secondary_host = workflow_dict['not_primary_hosts'][0]
            secondary_instance = Instance.objects.get(hostname=secondary_host)

            master_log_file, master_log_pos = get_replication_information_from_file(
                host=master_host)

            return_code, output = use_database_initialization_script(
                databaseinfra=databaseinfra, host=master_host, option='start')
            if return_code != 0:
                raise Exception(str(output))

            return_code, output = use_database_initialization_script(
                databaseinfra=databaseinfra,
                host=secondary_host,
                option='start')
            if return_code != 0:
                raise Exception(str(output))

            LOG.info("Waiting 1 minute to continue")
            sleep(60)

            change_master_to(instance=master_instance,
                             master_host=secondary_host.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            change_master_to(instance=secondary_instance,
                             master_host=master_host.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            start_slave(instance=master_instance)
            start_slave(instance=secondary_instance)

            LOG.info("Waiting 30 seconds to continue")
            sleep(30)
            set_infra_read_ip(slave_host=workflow_dict['host'],
                              infra_name=databaseinfra.name)

            set_infra_write_ip(
                master_host=workflow_dict['not_primary_hosts'][0],
                infra_name=databaseinfra.name)

            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):
     log_file, log_pos = get_replication_information_from_file(
         self.instance.hostname)
     master_instance = self.driver.get_master_instance()
     change_master_to(self.instance, master_instance.hostname.address,
                      log_file, log_pos)
     change_master_to(master_instance, self.instance.hostname.address,
                      log_file, log_pos)
    def do(self, workflow_dict):
        try:

            databaseinfra = workflow_dict['databaseinfra']

            master_host = workflow_dict['host']
            master_instance = Instance.objects.get(hostname=master_host)

            secondary_host = workflow_dict['not_primary_hosts'][0]
            secondary_instance = Instance.objects.get(hostname=secondary_host)

            master_log_file, master_log_pos = get_replication_information_from_file(host=master_host)

            return_code, output = use_database_initialization_script(databaseinfra=databaseinfra,
                                                                     host=master_host,
                                                                     option='start')
            if return_code != 0:
                raise Exception(str(output))

            return_code, output = use_database_initialization_script(databaseinfra=databaseinfra,
                                                                     host=secondary_host,
                                                                     option='start')
            if return_code != 0:
                raise Exception(str(output))

            LOG.info("Waiting 1 minute to continue")
            sleep(60)

            change_master_to(instance=master_instance,
                             master_host=secondary_host.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            change_master_to(instance=secondary_instance,
                             master_host=master_host.address,
                             bin_log_file=master_log_file,
                             bin_log_position=master_log_pos)

            start_slave(instance=master_instance)
            start_slave(instance=secondary_instance)

            LOG.info("Waiting 30 seconds to continue")
            sleep(30)
            set_infra_read_ip(slave_host=workflow_dict['host'],
                              infra_name=databaseinfra.name)

            set_infra_write_ip(master_host=workflow_dict['not_primary_hosts'][0],
                               infra_name=databaseinfra.name)

            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):
        pair = self.restore.instances_pairs()[0]
        log_file, log_pos = get_replication_information_from_file(
            pair.master.hostname)

        secondary = pair.master
        if self.instance == secondary:
            secondary = pair.slave

        change_master_to(self.instance, secondary.hostname.address, log_file,
                         log_pos)
Пример #9
0
 def do(self):
     if not self.is_valid:
         return
     instance = self.instance
     instance.address = self.host.address
     client = self.driver.get_client(instance)
     client.query('show master status')
     r = client.store_result()
     row = r.fetch_row(maxrows=0, how=1)
     log_file = row[0]['File']
     log_pos = row[0]['Position']
     change_master_to(self.master_instance, self.host.address, log_file, log_pos)
Пример #10
0
 def do(self):
     if not self.is_valid:
         return
     instance = self.instance
     instance.address = self.host.address
     client = self.driver.get_client(instance)
     client.query('show master status')
     r = client.store_result()
     row = r.fetch_row(maxrows=0, how=1)
     log_file = row[0]['File']
     log_pos = row[0]['Position']
     change_master_to(self.master_instance, self.host.address, log_file, log_pos)
Пример #11
0
    def do(self):
        pair = self.restore.instances_pairs()[0]
        log_file, log_pos = get_replication_information_from_file(
            pair.master.hostname
        )

        secondary = pair.master
        if self.instance == secondary:
            secondary = pair.slave

        change_master_to(
            self.instance, secondary.hostname.address, log_file, log_pos
        )
Пример #12
0
 def do(self):
     if not self.is_valid:
         return
     log_file, log_pos = get_replication_information_from_file(self.host)
     change_master_to(self.master_instance, self.host.address, log_file,
                      log_pos)
Пример #13
0
 def _change_master_to(self, instance, master):
     log_file, log_position = get_replication_info(master)
     change_master_to(instance, master.address, log_file, log_position)
Пример #14
0
 def do(self):
     if not self.is_valid:
         return
     log_file, log_pos = get_replication_information_from_file(self.host)
     change_master_to(self.master_instance, self.host.address, log_file, log_pos)