Previous Topic: Disabling Heartbeat in High Availability Scenarios: stop_is_alive()Next Topic: Enabling Heartbeats in High Availability Scenarios: start_is_alive()


Switching Over for High Availability Scenarios: switchover()

The switchover API function lets you perform switchover operations.

With full system, high availability scenarios, you can perform switchover operations to any replica server. When you want to switch over to non-failover replica servers, you call the execute_action API before you call the switchover API.

Note: The execute_action API is described in the examples.

Arguments

The switchover API function includes the arguments described in the following table:

Name

Type

Description

session_id

uint

The session ID that was returned by calling the create_session API.

scenario_id

uint

The scenario ID for which you want to perform switchover operations.

execute_sync

bool

Regulates whether to call this API synchronously or asynchronously.

run_reverse_scenario

bool

Run or do not run the backward scenario after the switchover operation occurs.

err_message

out string

Contains the reason for failure when this API fails.

Return Values

The return type is Boolean. When the return value is true, the API completed successfully. When the return value is false, the API did not complete successfully. If the return value is false, review the message to determine the reason the API failed.

Examples

Example 1

public bool switchover_example()
        {
            try
            {
                uint scenario_id = _ha_scenario_id;
                string err_messages = "";
                bool execute_sync = true;
                bool run_reverse_scenario = false;
                return get_mng().switchover(_session_id, scenario_id, execute_sync, run_reverse_scenario, out err_messages);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }

Example 2

public bool switchover_2nd_example()
        {
            try
            {
set_xcmd_data("switchover", "switchover_index","3" );
                uint scenario_id = _ha_scenario_id;
                string err_messages = "";
                bool execute_sync = true;
                bool run_reverse_scenario = false;
                return get_mng().switchover(_session_id, scenario_id, execute_sync, run_reverse_scenario, out err_messages);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }

Example 3

By default, Replication and High Availability performs switchover operations to the predefined failover, replica servers. With full system, high availability scenarios, you can switch over to non-failover replica servers. However, when you want to switch over to non-failover servers using the switchover API, you call the execute_action API before you call the switchover API as illustrated by the following example:

set_xcmd_data("switchover", "switchover_index","3" );

public bool set_xcmd_data(string cmd_name_str,string cmd_data_str,string cmd_value_str)
        {
            try
            {
                string result_data = "";
                string action_data;

                XmlDocument doc = new XmlDocument();
                XmlNode actions = doc.CreateNode(XmlNodeType.Element, xomngapi.WANSync_c.xo_actions, "");

                XmlNode commonNode = doc.CreateNode(XmlNodeType.Element, xomngapi.WANSync_c.action_common_lab, "");
                XmlAttribute attrSession = doc.CreateAttribute(xomngapi.WANSync_c.action_com_session_id);
                XmlAttribute attrScenario = doc.CreateAttribute(xomngapi.WANSync_c.action_com_scenario_id);
                XmlAttribute attrHostindex = doc.CreateAttribute(xomngapi.WANSync_c.action_com_host_index);
                XmlAttribute attrUsedfor = doc.CreateAttribute(xomngapi.WANSync_c.action_used_for);

                attrSession.Value = xomngapi.WANSync_c.WANSync.session_id.ToString();
                attrScenario.Value = this.id.ToString();
                attrUsedfor.Value = xomngapi.WANSync_c.action_x_command_data;

                commonNode.Attributes.Append(attrSession);
                commonNode.Attributes.Append(attrScenario);
                commonNode.Attributes.Append(attrHostindex);
                commonNode.Attributes.Append(attrUsedfor);

                XmlNode xo_cmd = doc.CreateNode(XmlNodeType.Element, xomngapi.WANSync_c.xo_cmd, "");
                XmlAttribute cmd_name = doc.CreateAttribute(xomngapi.WANSync_c.action_cmd_name);
                XmlAttribute cmd_data = doc.CreateAttribute(xomngapi.WANSync_c.action_cmd_data);
                XmlAttribute cmd_value = doc.CreateAttribute(xomngapi.WANSync_c.action_cmd_value);

                cmd_name.Value = cmd_name_str;
                cmd_data.Value = cmd_data_str;
                cmd_value.Value = cmd_value_str;

                xo_cmd.Attributes.Append(cmd_name);
                xo_cmd.Attributes.Append(cmd_data);
                xo_cmd.Attributes.Append(cmd_value);

                actions.AppendChild(commonNode);
                commonNode.AppendChild(xo_cmd);
                doc.AppendChild(actions);
                action_data = doc.OuterXml;
                string error;
                return get_mng().execute_action(action_data, true, out result_data, out error);
            }
            catch (System.Exception)
            {
                return false;
            }