Beispiel #1
0
void CCommandPra::CmdAppStart(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	if (a_clsRecvP.IsFlagNotify() == false) {
		g_pclsLogPra->WARNING("CMD 'APP_START', not set notify flag");
	}

	CCmdBase clsBase;
	if (clsBase.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) {
		g_pclsLogPra->ERROR("CMD 'APP_START', invalied body format");
		return;
	}

	if (clsBase.m_bIsAll) {
		// 전체 프로세스 실행 요청
		a_clsPM.Run(-1);
	} else {
		// 지정 프로세스의 실행 요청
		list<pair<int, string> >::iterator iter = clsBase.m_lstTarget.begin();
		for (; iter != clsBase.m_lstTarget.end(); ++iter) {
			a_clsPM.Run(iter->first);
		}
	}

	return;
}
Beispiel #2
0
void CCommandPra::CmdCli(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CCliReq clsCliReq;
	
	string strBody = a_clsRecvP.GetPayload();
	if (clsCliReq.DecodeMessage(strBody) != CCliApi::RESULT_OK) {
		g_pclsLogPra->ERROR("CMD 'CLI' invalied body message");
		return;
	}

	string strCliCmd = clsCliReq.GetCmdName();
	if (strCliCmd.compare("DISP-PRC") == 0) {
		return CmdCli_DispProc(a_clsRecvP, clsCliReq, a_clsPM);
	} else if (strCliCmd.compare("INIT-PRC") == 0) {
		return CmdCli_InitProc(a_clsRecvP, clsCliReq, a_clsPM);
	} else if (strCliCmd.compare("START-PRC") == 0) {
		return CmdCli_StartProc(a_clsRecvP, clsCliReq, a_clsPM);
	} else if (strCliCmd.compare("STOP-PRC") == 0) {
		return CmdCli_StopProc(a_clsRecvP, clsCliReq, a_clsPM);
	} else {
		g_pclsLogPra->WARNING("CMD 'CLI', not support command");
		return;
	}

	return;
}
Beispiel #3
0
void CCommandPra::CmdAppKill(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	if (a_clsRecvP.IsFlagNotify() == false) {
		g_pclsLogPra->WARNING("CMD 'APP_KILL', not set notify flag");
	}

	CCmdBase clsBase;
	if (clsBase.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) {
		g_pclsLogPra->ERROR("CMD 'APP_KILL', invalied body format");
		return;
	}

	if (clsBase.m_bIsAll) {
		// 전체 프로세스 강제 종료
		a_clsPM.StopForceibly();
	} else {
		// 지정 프로세스의 강제 종료
		auto iter = clsBase.m_lstTarget.begin();
		for (; iter != clsBase.m_lstTarget.end(); ++iter) {
			a_clsPM.StopForceibly(iter->first);
		}
	}

	return;
}
Beispiel #4
0
int CEmsInfo::ReceiveStaRequestProcess(CProtocol &cProto)
{
    std::vector<char> vecPayload;
    CSessionInfo *cSessionInfo = NULL;
    CStmReqApi cDecApi;
    char *szPayload = NULL;
    char chFlag = 0;
    time_t tm = 0;

    tm = time(NULL);

    chFlag = cProto.GetFlag();

    if(chFlag != CProtocol::FLAG_REQUEST){
        STA_LOG(STA_ERR,"Invalid Flag(flag=%d)\n",chFlag);
        return STA_NOK;
    }

    cProto.GetPayload(vecPayload);

    cSessionInfo = new CSessionInfo();

    cSessionInfo->SetReceiveTime(tm);

    szPayload = new char[vecPayload.size() + 1];

    strncpy(szPayload, &vecPayload[0], vecPayload.size());
    szPayload[vecPayload.size()] = '\0';
    cSessionInfo->SetReceiveData(szPayload, vecPayload.size());

    DEBUG_LOG("RECEIVE DATA (Wait 3 time)\n");
    m_lstPendingQueue.push_back(cSessionInfo);

    return STA_OK;
}
Beispiel #5
0
void CCommandPra::CmdAppLogLevel(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CConfigPra& clsCfg = CConfigPra::Instance();
	CAppQueue& clsQ = CAppQueue::Instance();
	
	CCmdAppLogLevel clsLog;				// Notify parsing
	string strBody;

	CCmdAppCtl clsCtl;					// APP에 보낼 body 메세지
	CProtocol clsSendP;					// APP에 보낼 message


	if (a_clsRecvP.IsFlagNotify() == false) {
		g_pclsLogPra->WARNING("CMD, 'LOG_LEVEL' not set notify flag");
	}

	if (clsLog.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) {
		g_pclsLogPra->ERROR("CMD, 'LOG_LEVEL' invalied body format");
		return;
	}
	
	// 프로세스 보낼 메세지 구성
	clsCtl.m_strAction = "LOG_LEVEL";
	clsCtl.m_nOption = clsLog.m_nLogLevel;

	clsSendP.SetCommand(CMD_APP_CTL);
	clsSendP.SetFlagRequest();
	clsSendP.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo);
	clsSendP.SetSequence();
	clsSendP.SetPayload(clsCtl.RequestGen());

	if (clsLog.m_bIsAll) {
		// 전체 프로세스 loglevel 변경 요청
		vector<CProcessManager::ST_APPINFO> vecInfo;
		a_clsPM.GetAppInfo(vecInfo, CProcStatus::RUNNING);
		for (size_t i=0; i < vecInfo.size(); ++i) {
			clsSendP.SetDestination(clsCfg.m_nNodeNo, vecInfo[i].m_nProcNo);
			
			if (clsQ.SendCmd(clsSendP, vecInfo[i].m_strProcName.c_str()) == false) {
				g_pclsLogPra->ERROR("APP loglevel send failed");
			}
		}

	} else {
		// 지정 프로세스의 loglevel 변경 요청
		list<pair<int, string> >::iterator iter = clsLog.m_lstTarget.begin();
		for (; iter != clsLog.m_lstTarget.end(); ++iter) {
			clsSendP.SetDestination(clsCfg.m_nNodeNo, iter->first);
			
			if (clsQ.SendCmd(clsSendP, iter->second.c_str()) == false) {
				g_pclsLogPra->ERROR("APP loglevel send failed");
			}
		}
	}

	return;
}
int CClaInterface::RegRspFunc(CProtocol &cProto)
{
	CCliRegRspApi cRspApi;
	string strPayload;

	strPayload = cProto.GetPayload();

	cRspApi.DecodeMessage(strPayload);

	if(cRspApi.GetCode() != CCliRegRspApi::RESULT_CODE_REG_SUCCESS){
		return RESULT_REG_FAILED;
	}

	return RESULT_OK;
}
Beispiel #7
0
void CCommandPra::CmdAppStatus(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CCmdBase clsBase;
	bool bIsError = false;
	string strBody;


	if (a_clsRecvP.IsFlagRequest() == false) {
		strBody = clsBase.ErrorGen(1, "not set request flag");
		bIsError = true;
		goto JumpSend;
	}

	if (clsBase.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) {
		strBody = clsBase.ErrorGen(1, "invalied body format");
		bIsError = true;
		goto JumpSend;
	}

	GetAppStatus(a_clsPM, clsBase);
	strBody = clsBase.ResponseGen();

JumpSend:
	CProtocol clsResp;
	clsResp.SetResponse(a_clsRecvP);
	if (bIsError) {
		clsResp.SetFlagError();
	}
	clsResp.SetPayload(strBody);

	if (CModuleIPC::Instance().SendMesg(clsResp) == false) {
		g_pclsLogPra->ERROR("CMD, send message failed, %s", 
								CModuleIPC::Instance().m_strErrorMsg.c_str());
		clsResp.Print(g_pclsLogPra, LV_ERROR, true);
	}

	#ifdef PRA_DEBUG
	g_pclsLogPra->DEBUG("Send message");
	clsResp.Print(g_pclsLogPra, LV_DEBUG, true);
	#endif
	
	return;
}
Beispiel #8
0
void CCommandPra::CmdBatchStart(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CCmdBatchStart clsBatch;
	bool bIsError = false;
	string strBody;
	CProcStatus::EN_STATUS nStatus = CProcStatus::NONE;


	if (a_clsRecvP.IsFlagRequest() == false) {
		strBody = clsBatch.ErrorGen(1, "not set request flag");
		bIsError = true;
		goto JumpSend;
	}

	if (clsBatch.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) {
		strBody = clsBatch.ErrorGen(1, "invalied body format");
		bIsError = true;
		goto JumpSend;
	}

	// 배치 프로세스 실행
	a_clsPM.Run(clsBatch.m_nProcNo);

	// batch exit wait
	usleep(100);
	a_clsPM.CheckExit(clsBatch.m_nProcNo);


	nStatus = a_clsPM.GetStatus(clsBatch.m_nProcNo);
	switch (nStatus) {
		case CProcStatus::RUNNING :
			clsBatch.m_strStatus = "pending";
			break;
		case CProcStatus::STOPPED :
			clsBatch.m_strStatus = "normal";
			clsBatch.m_nExitCd = a_clsPM.GetExitCode(clsBatch.m_nProcNo);
			break;
		default :
			clsBatch.m_strStatus = "failed";
	}
	strBody = clsBatch.ResponseGen();

JumpSend:
	CProtocol clsResp;
	clsResp.SetResponse(a_clsRecvP);
	if (bIsError) {
		clsResp.SetFlagError();
	}
	clsResp.SetPayload(strBody);

	if (CModuleIPC::Instance().SendMesg(clsResp) == false) {
		g_pclsLogPra->ERROR("CMD, send message failed, %s", 
								CModuleIPC::Instance().m_strErrorMsg.c_str());
		clsResp.Print(g_pclsLogPra, LV_ERROR, true);
	}

	#ifdef PRA_DEBUG
	g_pclsLogPra->DEBUG("Send message");
	clsResp.Print(g_pclsLogPra, LV_DEBUG, true);
	#endif

	return;
}
Beispiel #9
0
void CCommandPra::CmdAppInit(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CConfigPra& clsCfg = CConfigPra::Instance();
	CAppQueue& clsQ = CAppQueue::Instance();
	
	CCmdAppInit clsInit;				// Request body parsing
	CCmdAppInit::ST_RESPONSE stResponse;
	string strBody;
	bool bIsError = false;
			
	CCmdAppCtl clsCtl;					// APP에 보낼 body 메세지
	CProtocol clsSendP;					// APP에 보낼 message


	if (a_clsRecvP.IsFlagRequest() == false) {
		strBody = clsInit.ErrorGen(1, "CMD 'APP_INIT', not set request flag");
		bIsError = true;
		goto JumpSend;
	}

	if (clsInit.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) {
		strBody = clsInit.ErrorGen(1, "CMD 'APP_INIT', invalied body format");
		bIsError = true;
		goto JumpSend;
	}
	
	// 프로세스 보낼 메세지 구성
	clsCtl.m_strAction = "INIT";
	clsSendP.SetCommand(CMD_APP_CTL);
	clsSendP.SetFlagNotify();
	clsSendP.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo);
	clsSendP.SetSequence();
	clsSendP.SetPayload(clsCtl.RequestGen());

	if (clsInit.m_bIsAll) {
		// 전체 프로세스 init 요청
		vector<CProcessManager::ST_APPINFO> vecInfo;
		a_clsPM.GetAppInfo(vecInfo, CProcStatus::RUNNING);
		for (size_t i=0; i < vecInfo.size(); ++i) {
			clsSendP.SetDestination(clsCfg.m_nNodeNo, vecInfo[i].m_nProcNo);
			
			stResponse.m_nProcNo = vecInfo[i].m_nProcNo;
			stResponse.m_strProcName = vecInfo[i].m_strProcName;
			stResponse.m_bSuccess = true;
			
			if (clsQ.SendCmd(clsSendP, vecInfo[i].m_strProcName.c_str()) == false) {
				g_pclsLogPra->ERROR("APP init send failed");
				stResponse.m_bSuccess = false;
			}
			
			clsInit.m_lstResponse.push_back(stResponse);
		}

	} else {
		// 지정 프로세스의 init 요청
		list<pair<int, string> >::iterator iter = clsInit.m_lstTarget.begin();
		for (; iter != clsInit.m_lstTarget.end(); ++iter) {
			clsSendP.SetDestination(clsCfg.m_nNodeNo, iter->first);
			
			stResponse.m_nProcNo = iter->first;
			stResponse.m_strProcName = iter->second;
			stResponse.m_bSuccess = true;
			
			if (clsQ.SendCmd(clsSendP, iter->second.c_str()) == false) {
				g_pclsLogPra->ERROR("APP init send failed");
				stResponse.m_bSuccess = false;
			}

			clsInit.m_lstResponse.push_back(stResponse);
		}
	}
	strBody = clsInit.ResponseGen();

JumpSend:
	CProtocol clsResp;
	clsResp.SetResponse(a_clsRecvP);
	if (bIsError) {
		clsResp.SetFlagError();
	}
	clsResp.SetPayload(strBody);

	if (CModuleIPC::Instance().SendMesg(clsResp) == false) {
		g_pclsLogPra->ERROR("CMD, send message failed, %s", 
								CModuleIPC::Instance().m_strErrorMsg.c_str());
		clsResp.Print(g_pclsLogPra, LV_ERROR, true);
	}

	#ifdef PRA_DEBUG
	g_pclsLogPra->DEBUG("Send message");
	clsResp.Print(g_pclsLogPra, LV_DEBUG, true);
	#endif
	
	return;
}
Beispiel #10
0
int CMain::ReceiveIpcHandler()
{
	int cmdCode = 0;
	string strCmdCode;
	CGlobal *cGlob = NULL;
	CModuleIPC *cIpc = NULL;
	CProtocol cProto;
	char chFlag = 0;
	int nRet = 0;

	cGlob = CGlobal::GetInstance();

	cIpc = cGlob->GetModuleIPC();

	nRet = cIpc->RecvMesg(cGlob->GetLocalProcNo(), cProto, -1);
	if(nRet < 0){
		CLA_LOG(CLA_ERR,false,"Message receive failed(ERR:%s)\n", cIpc->m_strErrorMsg.c_str());
		return CLA_NOK;
	}
	else if(nRet == 0){
		return CLA_OK;
	}

	chFlag = cProto.GetFlag();

	if((chFlag != CProtocol::FLAG_RESPONSE)){
		CLA_LOG(CLA_ERR,false,"Invalid Flag(flag=%d)\n",chFlag);
		return CLA_NOK;
	}

	strCmdCode = cProto.GetCommand();

	cmdCode = CGlobal::GetCmdCode(strCmdCode);

	switch(cmdCode){
		case CMD_CLI_COMMAND:
			{
				unsigned int fd = 0;
				unsigned int nSessionId = 0;
				CCliPeer *cPeer = NULL;
				CSession *cSession = NULL;
				CCliRsp decRsp;
				string strPayload;

				nSessionId = cProto.GetSequence();

				cSession = FindSession(nSessionId);
				if(cSession == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find session(id=%d)\n",nSessionId);
					return CLA_NOK;
				}

				strPayload = cProto.GetPayload();

				decRsp.DecodeMessage(strPayload);

				decRsp.SetSessionId(cSession->GetClcSessionId());

				decRsp.EncodeMessage(strPayload);

				cProto.SetPayload(strPayload);
				cProto.SetSequence(cSession->GetClcSessionId());

				fd = cSession->GetPeerFd();

				cPeer = FindPeerByFd(fd);
				if(cPeer == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find peer(fd=%d)\n",fd);
					delete cSession;
					return CLA_NOK;
				}

				if(cPeer->GetTimestamp() != cSession->GetPeerTimestamp()){
					CLA_LOG(CLA_ERR,false,"Can not find peer(timestamp=%lu, %lu)\n", 
							cPeer->GetTimestamp() ,cSession->GetPeerTimestamp());
					delete cSession;
					return CLA_NOK;
				}

				/* update hist */
				UpdateHist(cPeer, cSession, &decRsp);

				cPeer->Send(cProto);

				delete cSession;
			}
			break;
		default :
			CLA_LOG(CLA_ERR,false,"Invalid cmdCode(%s)\n",cProto.GetCommand().c_str());
			return CLA_NOK;

	};


	return CLA_OK;
}
Beispiel #11
0
int CEmsInfo::ReceiveResourceProcess(CProtocol &cProto)
{
    int nRet = 0;
    std::vector<char> vecPayload;
    string strTableName;
    CStaAnsApi cDecApi;
    CStmAnsApi cEncApi;
    char chFlag = 0;
    CTableData *cTableData = NULL;
    list<string> *lstPrimaryKey = NULL;
    list<int> *lstValue = NULL;
    list<CCollectValue*> *lstCollectValue = NULL;
    CCollectValue *cCollectValue = NULL;

    if(chFlag != CProtocol::FLAG_RESPONSE){
        STA_LOG(STA_ERR,"Invalid Flag(flag=%d)\n",chFlag);
        return STA_NOK;
    }

    cProto.GetPayload(vecPayload);

    nRet = cDecApi.DecodeMessage(&vecPayload[0], vecPayload.size());
    if(nRet != CStmApi::RESULT_OK){
        STA_LOG(STA_ERR,"Message decoding failed(nRet=%d)\n",nRet);
        return STA_NOK;
    }

    lstCollectValue = new list<CCollectValue*>;
    while(1){
        cTableData = cDecApi.GetFirstTableData();
        if(cTableData == NULL){
            break;
        }

        strTableName = cTableData->GetTableName();
        if(strTableName.size() == 0){
            STA_LOG(STA_ERR,"table name not exist\n");
            delete cTableData;
            continue;
        }

        lstPrimaryKey = cTableData->GetPrimaryKey();
        lstValue = cTableData->GetValue();

        cCollectValue = new CCollectValue();
        cCollectValue->SetPrimaryKey(lstPrimaryKey);
        cCollectValue->SetValue(lstValue);

        lstCollectValue->push_back(cCollectValue);

        delete cTableData;
    }/* end of while(1) */

    cEncApi.SetCollectValue(lstCollectValue);

    nRet = cEncApi.EncodeMessage(m_chMessageBuffer, MAX_MESSAGE_BUFFER_LEN, &m_nMessageBufferLen);
    if(nRet != CStmApi::RESULT_OK){
        STA_LOG(STA_ERR,"Message encoding failed(ret=%d)\n",nRet);
        return STA_NOK;
    }

    SendProcess(CMD_STS_STA_RESOURCE, CProtocol::FLAG_RESPONSE, m_chMessageBuffer, m_nMessageBufferLen);

    return STA_OK;
}