📄 hbservercontainer.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const HBServerContainer_cxx_Version = "$Id: HBServerContainer.cxx,v 1.22 2002/02/25 05:46:19 sprajpat Exp $";#include "ProvisionInterface.hxx"#include "HBServerContainer.hxx"#include "ReadLockHelper.hxx"#include "WriteLockHelper.hxx"#include "ServerWithSnmp.hxx"#include "HeartbeatUtil.h"#include "VIoException.hxx"static const string RSfilename("ListOfRedirectServers");static const string MSfilename("ListOfMarshalServers");static const string FSfilename("ListOfFeatureServers");static const string JSfilename("ListOfJtapiServers");static const string POSfilename("ListOfPdpServers");static const string CDRfilename("ListOfCdrServers");static const string GlobConfigfilename("GlobalConfigData");Sptr < HBServerContainer > HBServerContainer::theRSSrvContainer = 0;/** * Return the one Server container or create it if it doesn't already exist. * @return Reference to the singleton */HBServerContainer&HBServerContainer::instance(){ if ( theRSSrvContainer == 0 ) { theRSSrvContainer = new HBServerContainer; } return *theRSSrvContainer;}/** * Constructor */HBServerContainer::HBServerContainer() : BaseServerContainer(){ /// get config data from PS configRedirectServers(); configMarshalServers(); configFeatureServers(); configJtapiServers(); configPolicyServers(); configCdrServers(); /// register interest in the following files try { ProvisionInterface::instance().registerForUpdate( updateHBRedirectServers, RSfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBRedirectServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBMarshalServers, MSfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBMarshalServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBFeatureServers, FSfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBFeatureServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBJtapiServers, JSfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBJtapiServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBPolicyServers, POSfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBPolicyServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBCdrServers, CDRfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBCdrServers, reason %s", e.getDescription().c_str()); } try { ProvisionInterface::instance().registerForUpdate( updateHBHeartbeatParms, GlobConfigfilename, ProvisionInterface::VCONFIG); } catch (VException& e) { cpLog(LOG_ALERT, "Failed updateHBHeartbeatParms, reason %s", e.getDescription().c_str()); } displayLists();}/** * Get Servers from Provisioning */voidHBServerContainer::getServersFromPS( const ServerType type, vector < Data > & retList){ /// get instance of Provisioning Server ProvisionInterface& pif = ProvisionInterface::instance(); try { Sptr < list < string > > tmpList = new list < string > ; switch (type) { case SERVER_RS: { pif.getRedirectServers( *tmpList ); } break; case SERVER_JS: { pif.getJtapiServers( *tmpList ); } break; case SERVER_FS: { pif.getFeatureServers( *tmpList ); } break; case SERVER_MS: { pif.getMarshalServers( *tmpList ); } break; case SERVER_POS: { pif.getPolicyServers( *tmpList ); } break; case SERVER_CDR: { pif.getCdrServers( *tmpList ); } break; default: break; } /// add server to vector for (list < string > ::iterator i = tmpList->begin(); i != tmpList->end(); ++i) { /// check for duplicate entries in list bool duplicateEntryFound = false; for (vector < Data > ::iterator j = retList.begin(); j != retList.end(); ++j) { char buf[156]; j->getData(buf, 156); string serverInList = buf; if ( *i == serverInList ) { duplicateEntryFound = true; break; } } if (duplicateEntryFound) { cpLog( LOG_ALERT, "*** Duplicate Entry Found In LIST: %s ***", i->c_str() ); cpLog( LOG_ALERT, "*** DO NOT add to Container ***"); } else { Data addressPort(*i); cpLog( LOG_DEBUG, "ip:port=%s", addressPort.logData()); retList.push_back( addressPort ); } } } catch (VException& e) { cpLog(LOG_ALERT, "Failed to connect to Provisioning Server, reason %s", e.getDescription().c_str()); }}/** * Remove Duplicates entries in the List of Servers passed in. * @param list list of servers to be added to server container. */voidHBServerContainer::removeDuplicatesFromList( vector < Data > & list ){ ReadLockHelper tableHelper(tableLock); bool done = false; while (!done) { TableIter iter; bool duplicateEntryFound = false; for (vector < Data > ::iterator i = list.begin(); i != list.end(); ++i) { iter = serverList.find(*i); if (iter != serverList.end()) { cpLog( LOG_ALERT, "*** Duplicate Entry Found in CONTAINER: %s ***", i->logData() ); cpLog( LOG_ALERT, "*** DO NOT add to Container ***"); duplicateEntryFound = true; list.erase(i); break; } } if (!duplicateEntryFound) done = true; }}/** * Configure Redirect Servers */voidHBServerContainer::configRedirectServers(){ WriteLockHelper rsHelper(rsLock); /// get RSlist getServersFromPS( SERVER_RS, itsRSList ); removeDuplicatesFromList(itsRSList); /// create Redirect Servers for (vector < Data > ::iterator i = itsRSList.begin(); i != itsRSList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new RS: %s", i->logData() ); /// get server id Data smartServer(*i); addServerWithSnmp( smartServer, SERVER_RS ); /// display updated data display( smartServer ); }}/** * Configure Marshal Servers */voidHBServerContainer::configMarshalServers(){ WriteLockHelper msHelper(msLock); /// get MSlist getServersFromPS( SERVER_MS, itsMSList ); removeDuplicatesFromList(itsMSList); /// create Marshal Servers for (vector < Data > ::iterator i = itsMSList.begin(); i != itsMSList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new MS: %s", i->logData() ); /// get server id Data smartServer(*i); /// create new Marshal addServerWithSnmp( smartServer, SERVER_MS ); /// display updated data display( smartServer ); }}/** * Configure Feature Servers */voidHBServerContainer::configFeatureServers(){ WriteLockHelper fsHelper(fsLock); /// get FSlist getServersFromPS( SERVER_FS, itsFSList ); removeDuplicatesFromList(itsFSList); /// create Feature Servers for (vector < Data > ::iterator i = itsFSList.begin(); i != itsFSList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new FS: %s", i->logData() ); /// get server id Data smartServer(*i); /// create new Feature addServerWithSnmp( smartServer, SERVER_FS ); /// display updated data display( smartServer ); }}/** * Configure Jtapi Servers */voidHBServerContainer::configJtapiServers(){ WriteLockHelper jsHelper(jsLock); /// get JSlist getServersFromPS( SERVER_JS, itsJSList ); removeDuplicatesFromList(itsJSList); /// create Jtapi Servers for (vector < Data > ::iterator i = itsJSList.begin(); i != itsJSList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new JS: %s", i->logData() ); /// get server id Data smartServer(*i); /// create new Marshal addServerWithSnmp( smartServer, SERVER_JS ); /// display updated data display( smartServer ); }}/** * Configure Policy Servers */voidHBServerContainer::configPolicyServers(){ WriteLockHelper posHelper(posLock); /// get POSlist getServersFromPS( SERVER_POS, itsPOSList ); removeDuplicatesFromList(itsPOSList); /// create Policy Servers for (vector < Data > ::iterator i = itsPOSList.begin(); i != itsPOSList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new POS: %s", i->logData() ); /// get server id Data smartServer(*i); addServerWithSnmp( smartServer, SERVER_POS ); /// display updated data display( smartServer ); }}/** * Configure CDR Servers */voidHBServerContainer::configCdrServers(){ WriteLockHelper cdrHelper(cdrLock); /// get CDRlist getServersFromPS( SERVER_CDR, itsCDRList ); removeDuplicatesFromList(itsCDRList); /// create Cdr Servers for (vector < Data > ::iterator i = itsCDRList.begin(); i != itsCDRList.end(); ++i) { cpLog( LOG_DEBUG, "from PS new CDR: %s", i->logData() ); /// get server id Data smartServer(*i); addServerWithSnmp( smartServer, SERVER_CDR ); /// display updated data display( smartServer ); }}/** * Destructor */HBServerContainer::~HBServerContainer( ){}/** * Get List of All Servers in Server Container * @param listofServers list of all servers in server container */voidHBServerContainer::getListofAllServers( Sptr < vector < Data > > & listofServers ){ ReadLockHelper rsHelper(rsLock); ReadLockHelper msHelper(msLock); ReadLockHelper fsHelper(fsLock); ReadLockHelper jsHelper(jsLock); ReadLockHelper posHelper(posLock); ReadLockHelper cdrHelper(cdrLock); cpLog( LOG_DEBUG_HB, "HBServerContainer::getListofAllServers"); for (vector < Data > ::iterator i = itsRSList.begin(); i != itsRSList.end(); ++i) { listofServers->push_back(*i); } for (vector < Data > ::iterator i = itsMSList.begin(); i != itsMSList.end(); ++i) { listofServers->push_back(*i); } for (vector < Data > ::iterator i = itsFSList.begin(); i != itsFSList.end(); ++i) { listofServers->push_back(*i); } for (vector < Data > ::iterator i = itsJSList.begin(); i != itsJSList.end(); ++i) { listofServers->push_back(*i); } for (vector < Data > ::iterator i = itsPOSList.begin(); i != itsPOSList.end(); ++i) { listofServers->push_back(*i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -