diff --git a/oam/oamcpp/liboamcpp.cpp b/oam/oamcpp/liboamcpp.cpp index dfaa71609..aab98c5b8 100644 --- a/oam/oamcpp/liboamcpp.cpp +++ b/oam/oamcpp/liboamcpp.cpp @@ -8832,6 +8832,92 @@ namespace oam return entry; } + + /****************************************************************************************** + * @brief waitForActive + * + * purpose: wait for system to be active + * + ******************************************************************************************/ + void Oam::waitForActive() + { + SystemStatus systemstatus; + SystemProcessStatus systemprocessstatus; + bool bfirst = true; + + for (int i = 0 ; i < 18 ; i ++) + { + sleep (10); + try + { + getSystemStatus(systemstatus); + if (systemstatus.SystemOpState == ACTIVE) + { + BRM::DBRM dbrm; + try { + int rc = dbrm.getSystemQueryReady(); + if (rc == -1 ) { + writeLog("waitForActive: getSystemQueryReady error return: startSystem failed", LOG_TYPE_ERROR); + exceptionControl("waitForActive", API_FAILURE); + } + + if ( rc != 0 ) + return; + + writeLog("waitForActive: getSystemQueryReady not ready", LOG_TYPE_DEBUG); + } + catch(...) + {} + } + + if (systemstatus.SystemOpState == FAILED) + { + exceptionControl("waitForActive", API_FAILURE); + } + + if (systemstatus.SystemOpState == MAN_OFFLINE) + { + exceptionControl("waitForActive", API_FAILURE); + } + + cout << "." << flush; + + // Check DMLProc for a switch to BUSY_INIT. + // In such a case, we need to print a message that rollbacks + // are occurring and will take some time. + if (bfirst) // Once we've printed our message, no need to waste cpu looking + { + getProcessStatus(systemprocessstatus); + for (unsigned int i = 0 ; i < systemprocessstatus.processstatus.size(); i++) + { + if (systemprocessstatus.processstatus[i].ProcessName == "DMLProc") + { + if (systemprocessstatus.processstatus[i].ProcessOpState == oam::ROLLBACK_INIT) + { + cout << endl << endl <<" System Not Ready, DMLProc is checking/processing rollback of abandoned transactions. Processing could take some time, please wait..." << flush; + bfirst = false; + } + // At this point, we've found our DMLProc, so there's no need to spin the for loop + // any further. + break; + } + } + } + } + catch (...) + { + // At some point, we need to give up, ProcMon just isn't going to respond. + if (i > 18) // 3 minutes + { + cout << endl << endl << "TIMEOUT: ProcMon not responding to getSystemStatus"; + break; + } + } + } + + exceptionControl("waitForActive", API_FAILURE); + } + /*************************************************************************** * PRIVATE FUNCTIONS diff --git a/oam/oamcpp/liboamcpp.h b/oam/oamcpp/liboamcpp.h index f23f73dbd..51c1f773c 100644 --- a/oam/oamcpp/liboamcpp.h +++ b/oam/oamcpp/liboamcpp.h @@ -2481,6 +2481,10 @@ namespace oam bool checkSystemRunning(); + /** @brief wait for system to be active + */ + EXPORT void waitForActive(); + private: int sendMsgToProcMgr3(messageqcpp::ByteStream::byte requestType, alarmmanager::AlarmList& alarmlist, const std::string date); diff --git a/oamapps/mcsadmin/mcsadmin.cpp b/oamapps/mcsadmin/mcsadmin.cpp index f7a6e2a38..935d081cc 100644 --- a/oamapps/mcsadmin/mcsadmin.cpp +++ b/oamapps/mcsadmin/mcsadmin.cpp @@ -77,62 +77,13 @@ bool SendToWES(Oam& oam, ByteStream bs); bool waitForActive() { Oam oam; - SystemStatus systemstatus; - SystemProcessStatus systemprocessstatus; - bool bfirst = true; - - for (int i = 0 ; i < 1200 ; i ++) + try { - sleep (3); - try - { - oam.getSystemStatus(systemstatus); - if (systemstatus.SystemOpState == ACTIVE) - { - return true; - } - if (systemstatus.SystemOpState == FAILED) - { - return false; - } - if (systemstatus.SystemOpState == MAN_OFFLINE) - { - return false; - } - cout << "." << flush; - - // Check DMLProc for a switch to BUSY_INIT. - // In such a case, we need to print a message that rollbacks - // are occurring and will take some time. - if (bfirst) // Once we've printed our message, no need to waste cpu looking - { - oam.getProcessStatus(systemprocessstatus); - for (unsigned int i = 0 ; i < systemprocessstatus.processstatus.size(); i++) - { - if (systemprocessstatus.processstatus[i].ProcessName == "DMLProc") - { - if (systemprocessstatus.processstatus[i].ProcessOpState == oam::ROLLBACK_INIT) - { - cout << endl << endl <<" System Not Ready, DMLProc is checking/processing rollback of abandoned transactions. Processing could take some time, please wait..." << flush; - bfirst = false; - } - // At this point, we've found our DMLProc, so there's no need to spin the for loop - // any further. - break; - } - } - } - } - catch (...) - { - // At some point, we need to give up, ProcMgr just isn't going to respond. - if (i > 60) // 3 minutes - { - cout << "ProcMgr not responding while waiting for system to start"; - break; - } - } + oam.waitForActive(); + return true; } + catch (...) + {} return false; } diff --git a/oamapps/postConfigure/helpers.cpp b/oamapps/postConfigure/helpers.cpp index b53a17302..f8cc46990 100644 --- a/oamapps/postConfigure/helpers.cpp +++ b/oamapps/postConfigure/helpers.cpp @@ -74,28 +74,21 @@ void callFree(const char* ) } - bool waitForActive() { - Oam oam; + Oam oam; + try + { + oam.waitForActive(); + return true; + } + catch (...) + {} - const string cmd = installDir + "/bin/mcsadmin getsystemstatus > /tmp/wait.log"; - system(cmd.c_str()); - - for ( int i = 0 ; i < 120 ; i ++ ) - { - if (oam.checkLogStatus("/tmp/wait.log", "System ACTIVE") ) - return true; - if ( oam.checkLogStatus("/tmp/wait.log", "System FAILED") ) - return false; - cout << "."; - cout.flush(); - sleep (10); - system(cmd.c_str()); - } - return false; + return false; } + void dbrmDirCheck() {