def execute_start_command(self):
        # Connect to the new master
        if self._new_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        return_val = MHA_online_change_helper.CODE_SUCCESS

        # Remove the read_only flag
        self.debug_message("Removing the read_only flag from the new master")
        self._new_master.unset_read_only()

        # If we have to manage the VIP, then assign the VIP on the new master
        if self._new_master_config_helper.get_manage_vip() == True:
            self.debug_message("Assigning the VIP to the new master")
            is_vip_assigned = MHA_VIP_helper.assign_vip(
                    config_helper=self._new_master_config_helper,
                    host_ip=self._new_master_ip,
                    ssh_user=None,
                    ssh_port=self._new_master_ssh_port,
                    ssh_options=self._ssh_options)

            if is_vip_assigned == False:
                return_val = MHA_online_change_helper.CODE_ERR_GENERAL

        # Disconnect from the new master
        self._new_master.disconnect()

        return return_val
    def execute_start_command(self):
        # Connect to the new master
        if self._new_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        return_val = MHA_online_change_helper.CODE_SUCCESS

        # Remove the read_only flag
        self.debug_message("Removing the read_only flag from the new master")
        self._new_master.unset_read_only()

        # If we have to manage the VIP, then assign the VIP on the new master
        if self._new_master_config_helper.get_manage_vip() == True:
            self.debug_message("Assigning the VIP to the new master")
            is_vip_assigned = MHA_VIP_helper.assign_vip(
                config_helper=self._new_master_config_helper,
                host_ip=self._new_master_ip,
                ssh_user=None,
                ssh_port=self._new_master_ssh_port,
                ssh_options=self._ssh_options)

            if is_vip_assigned == False:
                return_val = MHA_online_change_helper.CODE_ERR_GENERAL

        # Disconnect from the new master
        self._new_master.disconnect()

        return return_val
    def rollback_stop_command(self):
	# Connect to the original master
        if self._orig_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL
	
	rollback_error = 0

	# remove the read_only flag from the orignal master
	self.debug_message("Removing the read_only flag from original master")
	if self._orig_master.unset_read_only() == False:
	    self.debug_message("\tError, please try manually")
	    rollback_error += 1

        # If we have to manage the VIP, then add the VIP back on the original master
        if self._orig_master_config_helper.get_manage_vip() == True:
            self.debug_message("Assigning back the VIP to the original master")
            is_vip_assigned = MHA_VIP_helper.assign_vip(
                    config_helper=self._orig_master_config_helper,
                    host_ip=self._orig_master_ip,
                    ssh_user=None,
                    ssh_port=self._orig_master_ssh_port,
                    ssh_options=self._ssh_options)

            if is_vip_assigned == False:
                rollback_error += 1

	if rollback_error > 0:
	    self.debug_message("Rollback FAILED, there were %s errors" % rollback_error)
	else:
	    self.debug_message("Rollback completed OK")

	# Disconnect from the original master and restore binlogging
	self._orig_master.disconnect()

	return MHA_online_change_helper.CODE_ERR_GENERAL
    def execute_start_command(self, orig_master_host, orig_master_ip, 
                                new_master_host, new_master_ip, new_master_port,
                                ssh_user, ssh_options, ssh_port):
        config_helper = MHA_config_helper(host=new_master_host)
        
        new_master = MySQL_helper(host=new_master_ip, 
                                    user=config_helper.get_mysql_user(),
                                    password=config_helper.get_mysql_password(),
                                    port=new_master_port)

        if ssh_port is None:
            ssh_port = 22

        # Connect to the new master
        if new_master.connect() == False:
            return MHA_IP_failover_helper.CODE_ERR_GENERAL

        # If we have to manage the VIP, then assign the VIP to the new master
        if config_helper.get_manage_vip() == True:
            return_val = MHA_VIP_helper.assign_vip(config_helper=config_helper,
                                                host_ip=new_master_ip,
                                                ssh_user=ssh_user,
                                                ssh_port=ssh_port,
                                                ssh_options=ssh_options)

        if return_val == False:
            new_master.disconnect()
            return MHA_IP_failover_helper.CODE_ERR_GENERAL

        # Remove the read_only flag
        self.debug_message("Removing the read_only flag from the new master")
        new_master.unset_read_only()

        # Disconnect from the new master
        new_master.disconnect()

        return MHA_IP_failover_helper.CODE_SUCCESS
    def execute_stopssh_command(self, orig_master_host, orig_master_ip, 
                                ssh_user, ssh_options, ssh_port):
        config_helper = MHA_config_helper(host=orig_master_host)

        #orig_master = MySQL_helper(host=orig_master_ip, 
        #                            user=config_helper.get_mysql_user(),
        #                            password=config_helper.get_mysql_password())

        if ssh_port is None:
            ssh_port = 22

        # If we have to manage the VIP, then remove the VIP from the original master
        if config_helper.get_manage_vip() == True:
            return_val = MHA_VIP_helper.remove_vip(config_helper=config_helper,
                                                host_ip=orig_master_ip,
                                                ssh_user=ssh_user,
                                                ssh_port=ssh_port,
                                                ssh_options=ssh_options)
        if return_val == True:
            exit_code = MHA_IP_failover_helper.CODE_SUCCESS
        else:
            exit_code = MHA_IP_failover_helper.CODE_ERR_GENERAL

        return exit_code
Example #6
0
    def execute_start_command(self, orig_master_host, orig_master_ip,
                              new_master_host, new_master_ip, ssh_user,
                              ssh_options, ssh_port):
        config_helper = MHA_config_helper(host=new_master_host)

        new_master = MySQL_helper(host=new_master_ip,
                                  user=config_helper.get_mysql_user(),
                                  password=config_helper.get_mysql_password())

        if ssh_port is None:
            ssh_port = 22

        # Connect to the new master
        if new_master.connect() == False:
            return MHA_IP_failover_helper.CODE_ERR_GENERAL

        # If we have to manage the VIP, then assign the VIP to the new master
        if config_helper.get_manage_vip() == True:
            return_val = MHA_VIP_helper.assign_vip(config_helper=config_helper,
                                                   host_ip=new_master_ip,
                                                   ssh_user=ssh_user,
                                                   ssh_port=ssh_port,
                                                   ssh_options=ssh_options)

        if return_val == False:
            new_master.disconnect()
            return MHA_IP_failover_helper.CODE_ERR_GENERAL

        # Remove the read_only flag
        self.debug_message("Removing the read_only flag from the new master")
        new_master.unset_read_only()

        # Disconnect from the new master
        new_master.disconnect()

        return MHA_IP_failover_helper.CODE_SUCCESS
Example #7
0
    def execute_stopssh_command(self, orig_master_host, orig_master_ip,
                                ssh_user, ssh_options, ssh_port):
        config_helper = MHA_config_helper(host=orig_master_host)

        orig_master = MySQL_helper(host=orig_master_ip,
                                   user=config_helper.get_mysql_user(),
                                   password=config_helper.get_mysql_password())

        if ssh_port is None:
            ssh_port = 22

        # If we have to manage the VIP, then remove the VIP from the original master
        if config_helper.get_manage_vip() == True:
            return_val = MHA_VIP_helper.remove_vip(config_helper=config_helper,
                                                   host_ip=orig_master_ip,
                                                   ssh_user=ssh_user,
                                                   ssh_port=ssh_port,
                                                   ssh_options=ssh_options)
        if return_val == True:
            exit_code = MHA_IP_failover_helper.CODE_SUCCESS
        else:
            exit_code = MHA_IP_failover_helper.CODE_ERR_GENERAL

        return exit_code
    def rollback_stop_command(self):
        # Connect to the original master
        if self._orig_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        rollback_error = 0

        # remove the read_only flag from the orignal master
        self.debug_message("Removing the read_only flag from original master")
        if self._orig_master.unset_read_only() == False:
            self.debug_message("\tError, please try manually")
            rollback_error += 1

        # If we have to manage the VIP, then add the VIP back on the original master
        if self._orig_master_config_helper.get_manage_vip() == True:
            self.debug_message("Assigning back the VIP to the original master")
            is_vip_assigned = MHA_VIP_helper.assign_vip(
                config_helper=self._orig_master_config_helper,
                host_ip=self._orig_master_ip,
                ssh_user=None,
                ssh_port=self._orig_master_ssh_port,
                ssh_options=self._ssh_options)

            if is_vip_assigned == False:
                rollback_error += 1

        if rollback_error > 0:
            self.debug_message("Rollback FAILED, there were %s errors" %
                               rollback_error)
        else:
            self.debug_message("Rollback completed OK")

# Disconnect from the original master and restore binlogging
        self._orig_master.disconnect()

        return MHA_online_change_helper.CODE_ERR_GENERAL
    def execute_stop_command(self):
	# Connect to the new master
	if self._new_master.connect() == False:
	    return MHA_online_change_helper.CODE_ERR_GENERAL

	# Set read_only=1 on the new master to avoid any data inconsistency
	self.debug_message("Setting read_only=1 on the new master ...")
	self._new_master.set_read_only()
	if self._new_master.is_read_only() == False:
	    return MHA_online_change_helper.CODE_ERR_GENERAL

	# Disconnect from the new master because we do not want to change anything on it now
	self._new_master.disconnect()

	# Connect to the original master
	if self._orig_master.connect() == False:
	    return MHA_online_change_helper.CODE_ERR_GENERAL

	# we execute everything below in try..finally because we have to 
        # disconnect and enable log_bin at all cost
	try:
            # Setting read_only=1 on the original master
            self._orig_master.set_read_only()
            if self._orig_master.is_read_only() == False:
                return MHA_online_change_helper.CODE_ERR_GENERAL

            # If we have to manage the VIP, then remove the VIP from the original master
            if self._orig_master_config_helper.get_manage_vip() == True:
                self.debug_message("Removing the VIP from the original master")
                is_vip_removed = MHA_VIP_helper.remove_vip(
                        config_helper=self._orig_master_config_helper,
                        host_ip=self._orig_master_ip,
                        ssh_user=None,
                        ssh_port=self._orig_master_ssh_port,
                        ssh_options=self._ssh_options)

                if is_vip_removed == False:
                    return MHA_online_change_helper.CODE_ERR_GENERAL

	    # Wait upto 5 seconds for all connected threads to disconnect
            self.debug_message("Waiting 5s for all connected threads to disconnect")
	    slept_seconds = 0
	    while slept_seconds < 5:
	        threads = self.get_connected_threads(self._orig_master)
	        if len(threads) > 0:
		    time.sleep(1)
                    slept_seconds += 1
	        else:
		    break

	    # Terminate all threads
	    self.debug_message("Terminating all application threads ...")
	    threads = self.get_connected_threads(self._orig_master)
	    if threads == False:
	        return MHA_online_change_helper.CODE_ERR_GENERAL

	    for thread in threads:
	        self.debug_message("\tTerminating thread Id => %s, User => %s, Host => %s" % 
                                    (thread['Id'], thread['User'], thread['Host']))
	        self._orig_master.kill_connection(connection_id=thread['Id'])
	finally:
	    # Disconnect from the original master and restore binlogging
	    self._orig_master.disconnect()

	return MHA_online_change_helper.CODE_SUCCESS
    def execute_stop_command(self):
        # Connect to the new master
        if self._new_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        # Set read_only=1 on the new master to avoid any data inconsistency
        self.debug_message("Setting read_only=1 on the new master ...")
        self._new_master.set_read_only()
        if self._new_master.is_read_only() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        # Disconnect from the new master because we do not want to change anything on it now
        self._new_master.disconnect()

        # Connect to the original master
        if self._orig_master.connect() == False:
            return MHA_online_change_helper.CODE_ERR_GENERAL

        # we execute everything below in try..finally because we have to
        # disconnect and enable log_bin at all cost
        try:
            # Setting read_only=1 on the original master
            self._orig_master.set_read_only()
            if self._orig_master.is_read_only() == False:
                return MHA_online_change_helper.CODE_ERR_GENERAL

            # If we have to manage the VIP, then remove the VIP from the original master
            if self._orig_master_config_helper.get_manage_vip() == True:
                self.debug_message("Removing the VIP from the original master")
                is_vip_removed = MHA_VIP_helper.remove_vip(
                    config_helper=self._orig_master_config_helper,
                    host_ip=self._orig_master_ip,
                    ssh_user=None,
                    ssh_port=self._orig_master_ssh_port,
                    ssh_options=self._ssh_options)

                if is_vip_removed == False:
                    return MHA_online_change_helper.CODE_ERR_GENERAL

        # Wait upto 5 seconds for all connected threads to disconnect
            self.debug_message(
                "Waiting 5s for all connected threads to disconnect")
            slept_seconds = 0
            while slept_seconds < 5:
                threads = self.get_connected_threads(self._orig_master)
                if len(threads) > 0:
                    time.sleep(1)
                    slept_seconds += 1
                else:
                    break

        # Terminate all threads
            self.debug_message("Terminating all application threads ...")
            threads = self.get_connected_threads(self._orig_master)
            if threads == False:
                return MHA_online_change_helper.CODE_ERR_GENERAL

            for thread in threads:
                self.debug_message(
                    "\tTerminating thread Id => %s, User => %s, Host => %s" %
                    (thread['Id'], thread['User'], thread['Host']))
                self._orig_master.kill_connection(connection_id=thread['Id'])
        finally:
            # Disconnect from the original master and restore binlogging
            self._orig_master.disconnect()

        return MHA_online_change_helper.CODE_SUCCESS