22.1 Overview
22.2 Enabling the Provision to Get API Table Info from the Main Agent
22.3 Updating the API Table values in the Standby Agent
In the real time environment there is a lot of possibility for the Agent to crash. At this moment a Standby Agent can be made to run, reading the values from the Main Agent. The Standby Agent can also be made to run along with the Main Agent and periodical updation of data is done in the Standby Agent, in this case. This avoids loss of data. Transferring the MIB data to the Standby Agent is possible. To transfer the data of the API Tables (like Trap Forwarding Tables, Proxy Tables, Access Control Table etc.,) which keeps changing frequently during runtime is quite difficult.
Agent Toolkit has a provision to get the API Table info from the Main Agent. For this purpose, a separate thread is started in the Agent and this thread takes the responsibility of updating the values of the API Tables in a Hash Table, within the Main Agent and also converting them to a byte array (serialized form) format. When the Main Agent crashes, the latest values of the API Tables are converted to a Byte Array (serialized form) and transferred to the Standby Agent. The Standby Agent de-serializes the data and stores it back in a Hash Table. Using the key (Table name) , the values are identified and updated in the respective tables. To know how this provision can be enabled and how the API Table information are converted to a byteArray, go through the topics following.
22.2 Enabling the Failover Support for API Tables
To enable the Provision for getting the API Table Info, use the option available in MIB Compiler UI or the API calls.
Using MIB Compiler UI
Create a Project and Load a MIB.
Go to Project -> Settings menu in the MIB Compiler UI.
Choose the General Panel.
Enable Generate Code to get APITablesInfo option. This enables the Provision.
Using API Calls
Enabling the UI option, generates the following code in the Main File of
the Agent toward the end of the file. Adding this code in the generated
Main file without enabling the UI option also enables the provision to
get the api table information.
|
|
Note: By default View Based Access for v1/v2c Agents (vaclTable) is not implemented in the Agent. Hence, ensure whether the vaclTable implementation is made in the Agent before adding the code for transferring the details of vaclTable to the Hash Table. This can be checked in the viv2Authentication -> vaclTable Panel in the MIB Compiler UI. (Project -> Settings menu). |
|
/** * This method is to make avail of the Provision. * You have to call this method Periodically in a Separate Thread * and Update the Standby Agent, so as to avoid the API Table data. * You also have to instrument the Transferring portion of the * API Table details to the Standby Agent. */
public void getAPITablesInfo(){
Hashtable apiTablesHash = null; boolean isAPIModified = false;
if (aclTable.isModified()){ if (apiTablesHash == null){ apiTablesHash = new Hashtable(); }
apiTablesHash.put("AclTable", aclTable.getTableVector()); isAPIModified = true; aclTable.setModified(false); }
if (vaclTable.isModified()){ if (apiTablesHash == null){ apiTablesHash = new Hashtable(); }
apiTablesHash.put("VaclTable", vaclTable.getTableVector()); isAPIModified = true; vaclTable.setModified(false); }
if (forwardingTable.isModified()){ if (apiTablesHash == null){ apiTablesHash = new Hashtable(); }
apiTablesHash.put("V1V2TrapForwardingTable", forwardingTable.getTableVector()); isAPIModified = true; forwardingTable.setModified(false); }
if (isAPIModified){ retur n convertHashtableToByteArray(apiTablesHash); } return null;
/** * This method is for Converting the API Tables Info Hashtable * in to a Byte[] format so that, it can be transferred easily. * @param apiHash - The Hashtable with the API table details. * @return - Byte[] format of the apiHash. */
public byte[] convertHashtableToByteArray(Hashtable apiTablesHash){ try{ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(apiTablesHash); out.flush(); out.close(); return byteOut.toByteArray(); } catch(IOException ioe){ System.out.println("Exception while writing"); } return null; }
class Updater implements Runnable{ AdventNetSnmpAgent agentRef; public Updater(AdventNetSnmpAgent agent){ agentRef = agent; }
public void run(){ while(true){ agentRef.getAPITablesInfo(); try{ Thread.sleep(5000); }catch(Exception e){ e.printStackTrace(); } } } } |
As per these codes the Existing Agent keeps updating a Hash table with the API Table values periodically. Periodical updation is done only if the values of the API tables are modified. Else the method will be called but no updation is done in the Hash Table.
On Agent crash, the Hash Table details are converted to a Byte Array (serialized format) and are made available to the Standby Agent. The byte Array details can be transferred to the standby Agent as you prefer. i.e., the transfer method or communication part purely lies on the hands of the user.
22.3 Updating the API Table values in the Standby Agent
The Standby Agent that receives the ByteArray converts it back to a Hash Table (de-serializes). The Hash Table information uses the key or the Table name for identification. Say for example : the key accessControlTable indicates that particular byteArray represents the values of the Acl Table. The values get updated accordingly. Similarly the keys for other tables like vaclTable and Trap Forwarding Tables are :
The following method takes the values from the Hash table in the Standby Agent and updates it in the respective tables.
|
** * The method is for Converting the Hashtable in to a Byte[] format * at the Receiver side, The StandBy Agent. * @param apiTablesArr The byte[] with the API Tables info. * @return The Hashtable for the API Tables Info. */
public Hashtable convertByteArrayToHashtable(byte[] apiTablesArr){ try{ ByteArrayInputStream byteIn = new ByteArrayInputStream(apiTablesArr); ObjectInputStream ois = new ObjectInputStream(byteIn); return (Hashtable )ois.readObject(); }catch(IOException ioe){ System.out.println("Exception while creating the Input Stream"); }catch(ClassNotFoundException cce){ System.out.println("Exception while downcasting the byte array"); } return null; } |