void Workflows::Reload(void) { Logger::Log(LOG_NOTICE,"[ Workflows ] Reloading workflows definitions"); pthread_mutex_lock(&lock); // Clean current tasks std::map<std::string,Workflow *>::iterator it; for(it=workflows.begin();it!=workflows.end();++it) delete it->second; workflows.clear(); // Update DB db; DB db2(&db); db.Query("SELECT Workflow_name FROM t_workflow"); while(db.FetchRow()) { std::string Workflow_name(db.GetField(0)); workflows[Workflow_name] = new Workflow(&db2,db.GetField(0)); } pthread_mutex_unlock(&lock); }
int PING::GetPeerInfo(std::vector<PEER_INFO> &a_vecPeerInfo) { int ret = 0; char szBuff[DEF_MEM_BUF_1024]; char szQuery[DEF_MEM_BUF_1024]; char szImageNo[DEF_MEM_BUF_64]; char szIP[DEF_MEM_BUF_64]; char szPeerNo[DEF_MEM_BUF_64]; char szPeerName[DEF_MEM_BUF_64]; char szPkgName[DEF_MEM_BUF_64]; char szPeerType[DEF_MEM_BUF_64]; DB *pclsDB = m_pclsMain->GetDBConn(); if(NULL == pclsDB) { m_pclsLog->ERROR("Fail to DB Conncnect in PING Checker"); return -1; } FetchMaria fData; fData.Set(szIP, sizeof(szIP)); fData.Set(szImageNo, sizeof(szImageNo)); memset(szQuery, 0x00, sizeof(szQuery)); snprintf(szQuery, sizeof(szQuery), "SELECT IP, IMAGE_NO FROM TAT_NODE " "WHERE " "NODE_NO='%d'" , m_pclsMain->GetNodeID() ); m_pclsLog->DEBUG("Query : %s", szQuery); ret = pclsDB->Query(&fData, szQuery, strlen(szQuery)); if(ret < 0) { m_pclsLog->ERROR("Fail to Query (%s) [%d:%s]", szQuery, ret, pclsDB->GetErrorMsg(ret)); return -1; } if(fData.Fetch() == false) return -1; m_strMyIP.assign(szIP); memset(szQuery, 0x00, sizeof(szQuery)); snprintf(szQuery, sizeof(szQuery), "SELECT A.TARGET_ID AS IMAGE_NO " "FROM TAT_LINE_DEF A, TAT_NODE_GUI B " "WHERE " "A.TARGET_ID = B.IMAGE_NO " "AND A.SOURCE_TYPE='NO' " "AND A.SOURCE_ID='%s' " "UNION ALL " "SELECT A.SOURCE_ID AS IMAGE_NO " "FROM TAT_LINE_DEF A, TAT_NODE_GUI B " "WHERE " "A.SOURCE_ID = B.IMAGE_NO " "AND A.TARGET_TYPE='NO' " "AND A.TARGET_ID='%s'" , szImageNo , szImageNo ); m_pclsLog->DEBUG("Query : %s", szQuery); fData.Clear(); fData.Set(szImageNo, sizeof(szImageNo)); ret = pclsDB->Query(&fData, szQuery, strlen(szQuery)); if(ret < 0) { m_pclsLog->ERROR("Fail to Query (%s) [%d:%s]", szQuery, ret, pclsDB->GetErrorMsg(ret)); return -1; } if( false == fData.Fetch() ) return 0; memset(szBuff, 0x00, sizeof(szBuff)); snprintf(szBuff, sizeof(szBuff), "'%s'", szImageNo); while(true) { if( false == fData.Fetch() ) break; strcat(szBuff, ", '"); strcat(szBuff, szImageNo); strcat(szBuff, "'"); } memset(szQuery, 0x00, sizeof(szQuery)); snprintf(szQuery, sizeof(szQuery), "SELECT NODE_NAME, NODE_NO, IP, PKG_NAME, NODE_TYPE FROM TAT_NODE WHERE IMAGE_NO IN (%s)", szBuff); m_pclsLog->DEBUG("Query : %s", szQuery); fData.Clear(); fData.Set(szPeerName, sizeof(szPeerName)); fData.Set(szPeerNo, sizeof(szPeerNo)); fData.Set(szIP, sizeof(szIP)); fData.Set(szPkgName, sizeof(szPkgName)); fData.Set(szPeerType, sizeof(szPeerType)); ret = pclsDB->Query(&fData, szQuery, strlen(szQuery)); if(ret < 0) { m_pclsLog->ERROR("Fail to Query (%s) [%d:%s]", szQuery, ret, pclsDB->GetErrorMsg(ret)); return -1; } PEER_INFO stPeerInfo; while(true) { if( false == fData.Fetch() ) break; // memset(&stPeerInfo, 0x00, sizeof(PEER_INFO)); stPeerInfo.strPeerName.assign(szPeerName); stPeerInfo.strPeerIP.assign(szIP); stPeerInfo.nPeerNo = atoi(szPeerNo); stPeerInfo.nStatus = DEF_PEER_STATUS_INIT; stPeerInfo.strPeerType.assign(szPeerType); stPeerInfo.strPkgName.assign(szPkgName); a_vecPeerInfo.push_back(stPeerInfo); } for(uint32_t i = 0; i < a_vecPeerInfo.size(); i ++) { m_pclsLog->INFO("[%d], Peer %s, PeerIP %s", i, a_vecPeerInfo[i].strPeerName.c_str(), a_vecPeerInfo[i].strPeerIP.c_str()); } return 0; }