def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS:
                    source_host = source_instance.hostname
                    change_slave_priority_file(
                        host=source_host, original_value=0, final_value=100)
                    change_slave_priority_instance(
                        instance=source_instance, final_value=100)

                    target_instance = source_instance.future_instance
                    target_host = target_instance.hostname
                    change_slave_priority_file(
                        host=target_host, original_value=100, final_value=0)
                    change_slave_priority_instance(
                        instance=target_instance, final_value=0)

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS_SENTINEL:
                    failover_sentinel(host=source_instance.hostname,
                                      sentinel_host=source_instance.address,
                                      sentinel_port=source_instance.port,
                                      service_name=workflow_dict['databaseinfra'].name)
                    break

            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 undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS:
                    source_host = source_instance.hostname
                    change_slave_priority_file(host=source_host, original_value=0, final_value=100)
                    change_slave_priority_instance(instance=source_instance, final_value=100)

                    target_instance = source_instance.future_instance
                    target_host = target_instance.hostname
                    change_slave_priority_file(host=target_host, original_value=100, final_value=0)
                    change_slave_priority_instance(instance=target_instance, final_value=0)

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS_SENTINEL:
                    failover_sentinel(host=source_instance.hostname,
                                      sentinel_host=source_instance.address,
                                      sentinel_port=source_instance.port,
                                      service_name=workflow_dict['databaseinfra'].name)
                    break

            return True
        except Exception:
            traceback = full_stack()

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

            return False
예제 #3
0
    def undo(self):
        if not self.is_valid:
            return

        change_slave_priority_instance(self.target_instance,
                                       self.original_value)
        change_slave_priority_file(self.target_instance.hostname,
                                   self.final_value, self.original_value)
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:

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

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS:
                    source_host = source_instance.hostname
                    change_slave_priority_file(
                        host=source_host, original_value=0, final_value=100)
                    change_slave_priority_instance(
                        instance=source_instance, final_value=100)

                    target_instance = source_instance.future_instance
                    target_host = target_instance.hostname
                    change_slave_priority_file(
                        host=target_host, original_value=100, final_value=0)
                    change_slave_priority_instance(
                        instance=target_instance, final_value=0)

            attempts = 1
            max_attempts = 10
            while True:

                sentinel_instance = driver.get_non_database_instances()[0]
                failover_sentinel(host=sentinel_instance.hostname,
                                  sentinel_host=sentinel_instance.address,
                                  sentinel_port=sentinel_instance.port,
                                  service_name=databaseinfra.name)

                sleep(30)

                sentinel_client = driver.get_sentinel_client(sentinel_instance)
                master_address = sentinel_client.discover_master(databaseinfra.name)[0]

                source_is_master = False
                for source_instance in workflow_dict['source_instances']:
                    if source_instance.address == master_address:
                        source_is_master = True
                        LOG.info("{} is master".format(source_instance))
                        break

                if source_is_master:
                    break

                if attempts >= max_attempts:
                    raise Exception('It could not switch the master.')

                attempts += 1
                LOG.info("There was something wrong in sentinel failover.")
                LOG.info("Trying again ( {} of {} )".format(attempts, max_attempts))

            return True
        except Exception:
            traceback = full_stack()

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

            return False
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:

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

            for source_instance in workflow_dict['source_instances']:
                if source_instance.instance_type == source_instance.REDIS:
                    source_host = source_instance.hostname
                    change_slave_priority_file(host=source_host,
                                               original_value=0,
                                               final_value=100)
                    change_slave_priority_instance(instance=source_instance,
                                                   final_value=100)

                    target_instance = source_instance.future_instance
                    target_host = target_instance.hostname
                    change_slave_priority_file(host=target_host,
                                               original_value=100,
                                               final_value=0)
                    change_slave_priority_instance(instance=target_instance,
                                                   final_value=0)

            attempts = 1
            max_attempts = 10
            while True:

                sentinel_instance = driver.get_non_database_instances()[0]
                failover_sentinel(host=sentinel_instance.hostname,
                                  sentinel_host=sentinel_instance.address,
                                  sentinel_port=sentinel_instance.port,
                                  service_name=databaseinfra.name)

                sleep(30)

                sentinel_client = driver.get_sentinel_client(sentinel_instance)
                master_address = sentinel_client.discover_master(
                    databaseinfra.name)[0]

                source_is_master = False
                for source_instance in workflow_dict['source_instances']:
                    if source_instance.address == master_address:
                        source_is_master = True
                        LOG.info("{} is master".format(source_instance))
                        break

                if source_is_master:
                    break

                if attempts >= max_attempts:
                    raise Exception('It could not switch the master.')

                attempts += 1
                LOG.info("There was something wrong in sentinel failover.")
                LOG.info("Trying again ( {} of {} )".format(
                    attempts, max_attempts))

            return True
        except Exception:
            traceback = full_stack()

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

            return False