示例#1
0
   INT32 _SDB_KRCB::init ()
   {
      INT32 rc = SDB_OK ;
      INT32 index = 0 ;
      IControlBlock *pCB = NULL ;

      _mainEDU.setName( "Main" ) ;
#if defined (_LINUX )
      _mainEDU.setThreadID ( ossPThreadSelf() ) ;
#endif
      _mainEDU.setTID ( ossGetCurrentThreadID() ) ;
      if ( NULL == pmdGetThreadEDUCB() )
      {
         pmdDeclareEDUCB( &_mainEDU ) ;
      }

      // get hostname
      rc = ossGetHostName( _hostName, OSS_MAX_HOSTNAME ) ;
      PD_RC_CHECK( rc, PDERROR, "Failed to get host name, rc: %d", rc ) ;

      _init = TRUE ;

      // Init all registered cb
      for ( index = 0 ; index < SDB_CB_MAX ; ++index )
      {
         pCB = _arrayCBs[ index ] ;
         if ( !pCB )
         {
            continue ;
         }
         if ( SDB_OK != ( rc = pCB->init() ) )
         {
            PD_LOG( PDERROR, "Init cb[Type: %d, Name: %s] failed, rc: %d",
                    pCB->cbType(), pCB->cbName(), rc ) ;
            goto error ;
         }
      }

      // Activate all registered cb after initilization complete
      for ( index = 0 ; index < SDB_CB_MAX ; ++index )
      {
         pCB = _arrayCBs[ index ] ;
         if ( !pCB )
         {
            continue ;
         }
         if ( SDB_OK != ( rc = pCB->active() ) )
         {
            PD_LOG( PDERROR, "Active cb[Type: %d, Name: %s] failed, rc: %d",
                    pCB->cbType(), pCB->cbName(), rc ) ;
            goto error ;
         }
      }

      _isActive = TRUE ;

      _curTime.sample() ;

   done:
      return rc ;
   error:
      goto done ;
   }
示例#2
0
   INT32 omClusterNotifier::_updateNotifier()
   {
      INT32 rc = SDB_OK ;
      BSONObj selector ;
      BSONObj matcher ;
      BSONObj order ;
      BSONObj hint ;
      BSONObjBuilder builder ;
      SINT64 contextID = -1 ;

      BSONObjBuilder resultBuilder ;
      BSONObj result ;
      pmdKRCB *pKrcb     = pmdGetKRCB() ;
      _SDB_DMSCB *pDMSCB = pKrcb->getDMSCB() ;
      _SDB_RTNCB *pRTNCB = pKrcb->getRTNCB() ;

      matcher  = BSON( OM_HOST_FIELD_CLUSTERNAME << _clusterName ) ;
      selector = BSON( OM_HOST_FIELD_NAME << ""
                       << OM_HOST_FIELD_IP << "" 
                       << OM_HOST_FIELD_USER << ""
                       << OM_HOST_FIELD_PASSWORD << ""
                       << OM_HOST_FIELD_AGENT_PORT << "" ) ;

      rc = rtnQuery( OM_CS_DEPLOY_CL_HOST, selector, matcher, order, hint, 0, 
                     _cb, 0, -1, pDMSCB, pRTNCB, contextID );
      if ( rc )
      {
         PD_LOG( PDERROR, "fail to query table:%s,rc=%d", OM_CS_DEPLOY_CL_HOST, 
                 rc ) ;
         goto error ;
      }

      _mapTargetAgents.clear() ;
      _vHostTable.clear() ;
      while ( TRUE )
      {
         rtnContextBuf buffObj ;
         SINT64 startingPos = 0 ;
         rc = rtnGetMore ( contextID, 1, buffObj, startingPos, _cb, pRTNCB ) ;
         if ( rc )
         {
            if ( SDB_DMS_EOC == rc )
            {
               rc = SDB_OK ;
               break ;
            }

            contextID = -1 ;
            PD_LOG( PDERROR, "failed to get record from table:%s,rc=%d", 
                    OM_CS_DEPLOY_CL_HOST, rc ) ;
            goto error ;
         }

         BSONObj record( buffObj.data() ) ;
         omHostContent tmp ;
         tmp.hostName    = record.getStringField( OM_HOST_FIELD_NAME ) ;
         tmp.ip          = record.getStringField( OM_HOST_FIELD_IP ) ;
         tmp.serviceName = record.getStringField( OM_HOST_FIELD_AGENT_PORT ) ;
         tmp.user        = record.getStringField( OM_HOST_FIELD_USER ) ;
         tmp.passwd      = record.getStringField( OM_HOST_FIELD_PASSWORD ) ;

         _vHostTable.push_back( tmp ) ;
         _mapTargetAgents.insert( _MAPAGENT_VALUE( tmp.hostName, tmp ) ) ;
      }

      if ( _mapTargetAgents.size() > 0 )
      {
         CHAR localHost[ OSS_MAX_HOSTNAME + 1 ] ;
         ossGetHostName( localHost, OSS_MAX_HOSTNAME ) ;
         _MAPAGENT_ITER iter = _mapTargetAgents.find( localHost ) ;
         if ( iter == _mapTargetAgents.end() )
         {
            omHostContent content ;
            content.hostName = localHost ;
            content.ip       = "127.0.0.1" ;
            string serviceName ;
            _getAgentService( serviceName ) ;
            content.serviceName = serviceName ;
            content.user        = "" ;
            content.passwd      = "" ;

            _mapTargetAgents.insert( 
                                _MAPAGENT_VALUE( content.hostName, content ) ) ;
         }
      }
   done:
      return rc ;
   error:
      if ( -1 != contextID )
      {
         pRTNCB->contextDelete ( contextID, _cb ) ;
      }
      goto done ;
   }
示例#3
0
INT32 _ossSocket::getHostName ( CHAR *pName, INT32 nameLen )
{
   return ossGetHostName( pName, nameLen ) ;
}
示例#4
0
   void omClusterNotifier::_getAgentService( string &serviceName )
   {
      INT32 rc = SDB_OK ;
      CHAR conf[OSS_MAX_PATHSIZE + 1] = { 0 } ;
      po::options_description desc ( "Config options" ) ;
      po::variables_map vm ;
      CHAR hostport[OSS_MAX_HOSTNAME + 6] = { 0 } ;
      serviceName = boost::lexical_cast<string>( SDBCM_DFT_PORT ) ;
      rc = ossGetHostName( hostport, OSS_MAX_HOSTNAME ) ;
      if ( rc != SDB_OK )
      {
         PD_LOG( PDERROR, "get host name failed:rc=%d", rc ) ;
         goto error ;
      }

      ossStrncat ( hostport, SDBCM_CONF_PORT, ossStrlen(SDBCM_CONF_PORT) ) ;

      desc.add_options()
         (SDBCM_CONF_DFTPORT, po::value<string>(), "sdbcm default "
         "listening port")
         (hostport, po::value<string>(), "sdbcm specified listening port")
      ;

      rc = ossGetEWD ( conf, OSS_MAX_PATHSIZE ) ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to get excutable file's working "
                  "directory" ) ;
         goto error ;
      }

      if ( ( ossStrlen ( conf ) + ossStrlen ( SDBCM_CONF_PATH_FILE ) + 2 ) >
           OSS_MAX_PATHSIZE )
      {
         PD_LOG ( PDERROR, "Working directory too long" ) ;
         rc = SDB_INVALIDARG ;
         goto error ;
      }

      ossStrncat( conf, OSS_FILE_SEP, 1 );
      ossStrncat( conf, SDBCM_CONF_PATH_FILE,
                  ossStrlen( SDBCM_CONF_PATH_FILE ) );
      rc = utilReadConfigureFile ( conf, desc, vm ) ;
      if ( rc )
      {
         PD_LOG ( PDERROR, "Failed to read configure file, rc = %d", rc ) ;
         goto error ;
      }
      else if ( vm.count( hostport ) )
      {
         serviceName = vm[hostport].as<string>() ;
      }
      else if ( vm.count( SDBCM_CONF_DFTPORT ) )
      {
         serviceName = vm[SDBCM_CONF_DFTPORT].as<string>() ;
      }
      else
      {
         serviceName = boost::lexical_cast<string>( SDBCM_DFT_PORT ) ;
      }

   done:
      return ;
   error:
      goto done ;
   }