コード例 #1
0
   INT32 _omaTask::initJsEnv()
   {
      INT32 rc     = SDB_OK ;
      INT32 tmpRc  = SDB_OK ;
      INT32 errNum = 0 ;
      const CHAR *pDetail = NULL ;
      BSONObj obj ;
      BSONObj retObj ;
      _omaInitEnv runCmd( _taskID, obj ) ;

      rc = runCmd.init( NULL ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDWARNING, "Failed to init for running js script, "
                 "rc = %d", rc ) ;
         goto error ;
      }
      rc = runCmd.doit( retObj ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDWARNING, "Failed to init for running js script, "
                 "rc = %d", rc ) ;
         goto error ;
      }
      rc = omaGetIntElement ( retObj, OMA_FIELD_ERRNO, errNum ) ;
      if ( rc )
      {
         PD_LOG( PDERROR, "Failed to get errno from js after initializing "
                 "environment for execting js script, rc = %d", rc ) ;
         goto error ;
      }
      if ( SDB_OK != errNum )
      {
         rc = errNum ;
         tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ;
         if ( SDB_OK != tmpRc )
         {
            PD_LOG( PDERROR, "Failed to get error detail from js after "
                    "environment for execting js script, rc = %d", rc ) ;
         }
         else
         {
            PD_LOG( PDERROR, "Failed to init environment for execting js"
                    "script, rc = %d, detail = %s", rc, pDetail ) ;
         }
         goto error ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
コード例 #2
0
   INT32 _omaAddHostSubTask::doit()
   {
      INT32 rc = SDB_OK ;
      INT32 tmpRc = SDB_OK ;

      _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_RUNNING ) ;
      
      while( TRUE )
      {
         AddHostInfo *pInfo           = NULL ;
         AddHostResultInfo resultInfo = { "", "", OMA_TASK_STATUS_INIT,
                                          OMA_TASK_STATUS_DESC_INIT,
                                          SDB_OK, "" } ;
         CHAR flow[OMA_BUFF_SIZE + 1] = { 0 } ;
         const CHAR *pDetail          = NULL ;
         const CHAR *pIP              = NULL ;
         const CHAR *pHostName        = NULL ;
         INT32 errNum                 = 0 ;
         BSONObj retObj ;

         pInfo = _pTask->getAddHostItem() ;
         if ( NULL == pInfo )
         {
            PD_LOG( PDEVENT, "No hosts need to add now, sub task[%s] exits",
                    _taskName.c_str() ) ;
            goto done ;
         }

         pIP                  = pInfo->_item._ip.c_str() ;
         pHostName            = pInfo->_item._hostName.c_str() ;
         resultInfo._ip       = pIP ;
         resultInfo._hostName = pHostName ;

         ossSnprintf( flow, OMA_BUFF_SIZE, "Adding host[%s]", pIP ) ;
         resultInfo._status     = OMA_TASK_STATUS_RUNNING ;
         resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ;
         resultInfo._errno      = SDB_OK ;
         resultInfo._detail     = "" ;
         resultInfo._flow.push_back( flow ) ;
         tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
         if ( tmpRc )
         {
            PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                    "rc = %d", pIP, tmpRc ) ;
         }

         _omaAddHost runCmd( *pInfo ) ;
         rc = runCmd.init( NULL ) ;
         if ( rc )
         {
            PD_LOG( PDERROR, "Failed to init for adding "
                    "host[%s], rc = %d", pIP, rc ) ;
            pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
            if ( NULL == pDetail || 0 == *pDetail )
               pDetail = "Failed to init for adding host " ;
            ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ;
            resultInfo._status     = OMA_TASK_STATUS_FINISH ;
            resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
            resultInfo._errno      = rc ;
            resultInfo._detail     = pDetail ;
            resultInfo._flow.push_back( flow ) ;
            rc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
            if ( rc )
            {
               PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                       "rc = %d", pIP, rc ) ;
            }
            continue ;
         }
         rc = runCmd.doit( retObj ) ;
         if ( rc )
         {
            PD_LOG( PDERROR, "Failed to do adding host[%s], rc = %d", pIP, rc ) ;
            tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ;
            if ( SDB_OK != tmpRc )
            {
               pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
               if ( NULL == pDetail || 0 == *pDetail )
                  pDetail = "Not exeute js file yet" ;
            }
            ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ;
            resultInfo._status     = OMA_TASK_STATUS_FINISH ;
            resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
            resultInfo._errno      = rc ;
            resultInfo._detail     = pDetail ;
            resultInfo._flow.push_back( flow ) ;
            tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
            if ( tmpRc )
            {
               PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                       "rc = %d", pIP, tmpRc ) ;
            }
            continue ;
         }
         rc = omaGetIntElement ( retObj, OMA_FIELD_ERRNO, errNum ) ;
         if ( rc )
         {
            PD_LOG( PDERROR, "Failed to get errno from js after "
                    "adding host[%s], rc = %d", pIP, rc ) ;
            pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
            if ( NULL == pDetail || 0 == *pDetail )
               pDetail = "Failed to get errno from js after adding host" ;
            ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ;
            resultInfo._status     = OMA_TASK_STATUS_FINISH ;
            resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
            resultInfo._errno      = rc ;
            resultInfo._detail     = pDetail ;
            resultInfo._flow.push_back( flow ) ;
            tmpRc =_pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
            if ( tmpRc )
            {
               PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                       "rc = %d", pIP, tmpRc ) ;
            }
            continue ;
         }
         if ( SDB_OK != errNum )
         {
            rc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to get error detail from js after "
                       "adding host[%s], rc = %d", pIP, rc ) ;
               pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
               if ( NULL == pDetail || 0 == *pDetail )
                  pDetail = "Failed to get error detail from js after adding host" ;
            }
            ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to add host[%s]", pIP ) ;
            resultInfo._status     = OMA_TASK_STATUS_FINISH ;
            resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
            resultInfo._errno      = errNum ;
            resultInfo._detail     = pDetail ;
            resultInfo._flow.push_back( flow ) ;
            tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
            if ( tmpRc )
            {
               PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                       "rc = %d", pIP, tmpRc ) ;
            }
            continue ;
         }
         else
         {
            ossSnprintf( flow, OMA_BUFF_SIZE, "Finish adding host[%s]", pIP ) ;
            PD_LOG ( PDEVENT, "Success to add host[%s]", pIP ) ;
            resultInfo._status     = OMA_TASK_STATUS_FINISH ;
            resultInfo._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
            resultInfo._flow.push_back( flow ) ;
            tmpRc = _pTask->updateProgressToTask( pInfo->_serialNum, resultInfo ) ;
            if ( tmpRc )
            {
               PD_LOG( PDWARNING, "Failed to update add host[%s]'s progress, "
                       "rc = %d", pIP, tmpRc ) ;
            }
         }
      }

   done:
      _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_FINISH ) ;
      _pTask->notifyUpdateProgress() ;
      return SDB_OK ;
   }
コード例 #3
0
   INT32 _omaInstDBBusSubTask::doit()
   {
      INT32 rc = SDB_OK ;
      INT32 tmpRc = SDB_OK ;
      OMA_TASK_STATUS taskStatus ;

      _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_RUNNING ) ;

      while( TRUE )
      {
         string instRGName ;

         instRGName = _pTask->getDataRGToInst() ;
         if ( instRGName.empty() )
         {
            PD_LOG( PDEVENT, "No data group need to install now, "
                    "sub task[%s] exits", _taskName.c_str() ) ;
            goto done ;
         }

         while( TRUE )
         {
            InstDBBusInfo *pInfo         = NULL ;
            InstDBResult instResult ;
                                        
            CHAR flow[OMA_BUFF_SIZE + 1] = { 0 } ;
            const CHAR *pDetail          = NULL ;
            const CHAR *pHostName        = NULL ;
            const CHAR *pSvcName         = NULL ;
            INT32 errNum                 = 0 ;
            BSONObj retObj ;

            pInfo = _pTask->getDataNodeInfo( instRGName ) ;
            if ( NULL == pInfo )
            {
               PD_LOG( PDEVENT, "Finish installing group[%s] in task[%s]",
                       instRGName.c_str(), _taskName.c_str() ) ;
               break ;
            }

            taskStatus = _pTask->getTaskStatus() ;
            if ( OMA_TASK_STATUS_RUNNING != taskStatus )
            {
               PD_LOG ( PDERROR, "Task's status is: [%d], stop running sub "
                        "task[%s]", taskStatus, _taskName.c_str() ) ;
               goto done ;
            }

            pHostName              = pInfo->_instInfo._hostName.c_str() ;
            pSvcName               = pInfo->_instInfo._svcName.c_str() ;
            instResult._errno      = SDB_OK ;
            instResult._detail     = "" ;
            instResult._hostName   = pHostName ;
            instResult._svcName    = pSvcName ;
            instResult._role       = ROLE_DATA ;
            instResult._groupName  = pInfo->_instInfo._dataGroupName ;
            instResult._status     = OMA_TASK_STATUS_RUNNING ;
            instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ;

            ossSnprintf( flow, OMA_BUFF_SIZE, "Installing data node[%s:%s]",
                         pHostName, pSvcName ) ;
            instResult._status     = OMA_TASK_STATUS_RUNNING ;
            instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_RUNNING ) ;
            instResult._flow.push_back( flow ) ;
            rc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum,
                                               instResult, TRUE ) ;
            if ( rc )
            {
               PD_LOG( PDWARNING, "Failed to update install data node[%s:%s]'s "
                       "progress, rc = %d", pHostName, pSvcName, rc ) ;
            }
            _omaInstallDataNode runCmd( _taskID, _pTask->getTmpCoordSvcName(),
                                        pInfo->_instInfo ) ;
            rc = runCmd.init( NULL ) ;
            if ( rc )
            {
               
               PD_LOG( PDERROR, "Failed to init to install data node[%s:%s], "
                       "rc = %d", pHostName, pSvcName, rc ) ;
               pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
               if ( NULL == pDetail || 0 == *pDetail )
                  pDetail = "Failed to init to install data node" ;
               goto build_error_result ;
            }
            rc = runCmd.doit( retObj ) ;
            if ( rc )
            {
               PD_LOG( PDERROR, "Failed to install data node[%s:%s], rc = %d",
                       pHostName, pSvcName, rc ) ;
               tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ;
               if ( SDB_OK != tmpRc )
               {
                  pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
                  if ( NULL == pDetail || 0 == *pDetail )
                     pDetail = "Not exeute js file yet" ;
               }
               goto build_error_result ;
            }
            rc = omaGetIntElement ( retObj, OMA_FIELD_ERRNO, errNum ) ;
            if ( rc )
            {
               PD_LOG( PDERROR, "Failed to get errno from js after "
                       "installing data node[%s:%s], rc = %d",
                       pHostName, pSvcName, rc ) ;
               pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
               if ( NULL == pDetail || 0 == *pDetail )
                  pDetail = "Failed to get errno from js after "
                            "installing data node" ;
               goto build_error_result ;
            }
            if ( SDB_OK != errNum )
            {
               rc = errNum ;
               tmpRc = omaGetStringElement ( retObj, OMA_FIELD_DETAIL, &pDetail ) ;
               if ( SDB_OK != tmpRc )
               {
                  PD_LOG( PDERROR, "Failed to get error detail from js after "
                          "installing data node[%s:%s], rc = %d",
                          pHostName, pSvcName, tmpRc ) ;
                  pDetail = pmdGetThreadEDUCB()->getInfo( EDU_INFO_ERROR ) ;
                  if ( NULL == pDetail || 0 == *pDetail )
                     pDetail = "Failed to get error detail from js "
                               "after installing data node" ;
               }
               goto build_error_result ;
            }
            else
            {
               ossSnprintf( flow, OMA_BUFF_SIZE, "Finish installing data "
                            "node[%s:%s]", pHostName, pSvcName ) ;
               PD_LOG ( PDEVENT, "Success to install data node[%s:%s]",
                        pHostName, pSvcName ) ;
               instResult._status     = OMA_TASK_STATUS_FINISH ;
               instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_FINISH ) ;
               instResult._flow.push_back( flow ) ;
               rc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum,
                                                  instResult, TRUE ) ;
               if ( rc )
               {
                  PD_LOG( PDWARNING, "Failed to update install data "
                          "node[%s:%s]'s progress, rc = %d",
                          pHostName, pSvcName, rc ) ;
               }
            }
            continue ; // if we success, nerver go to "build_error_result"
         
         build_error_result:
            ossSnprintf( flow, OMA_BUFF_SIZE, "Failed to install data "
                         "node[%s:%s], going to rollback",
                         pHostName, pSvcName ) ;
            instResult._status     = OMA_TASK_STATUS_ROLLBACK ;
            instResult._statusDesc = getTaskStatusDesc( OMA_TASK_STATUS_ROLLBACK ) ;
            instResult._errno      = rc ;
            instResult._detail     = pDetail ;
            instResult._flow.push_back( flow ) ;
            tmpRc = _pTask->updateProgressToTask( pInfo->_nodeSerialNum,
                                                  instResult, TRUE ) ;
            if ( SDB_OK != tmpRc )
            {
               PD_LOG( PDWARNING, "Failed to update install coord[%s:%s]'s "
                       "progress, rc = %d", pHostName, pSvcName, tmpRc ) ;
            }
            goto error ;
         } // while
         
      } // while

   done:
      _pTask->setSubTaskStatus( _taskName, OMA_TASK_STATUS_FINISH ) ;
      _pTask->notifyUpdateProgress() ;
      return rc ;
   error:
      goto done ;
   }