Esempio n. 1
0
bool CCommandPra::ProcMesgApp(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	CConfigPra& clsCfg = CConfigPra::Instance();

	#ifdef PRA_DEBUG
	g_pclsLogPra->DEBUG("Recvive message form App");
	a_clsRecvP.Print(g_pclsLogPra, LV_DEBUG, true);
	#endif
	
	int nDstNode = 0;
	int nDstProc = 0; 
	a_clsRecvP.GetDestination(nDstNode, nDstProc);
	
	// TODO
	// APP에서 ATOM node, proc no을 알수 없어 0으로 지정한 경우
	// command에 따라 ATOM node, procno을 재지정 해준다.
	// 이럴 경우 APP에서 추가 명령이 발생할 때 마다 수정이 필요하므로
	// 향후 개선이 필요하다.
	if (nDstNode == 0 && nDstProc == 0) {
		int nCmd = atoi(a_clsRecvP.GetCommand().c_str());
		switch (nCmd) {
			case CMD_NODELIST :
				CAddress::Instance().LookupAtom("ATOM_NM", nDstNode, nDstProc);
				a_clsRecvP.SetDestination(nDstNode, nDstProc);
				break;
		}
	}

	// PRA가 처리해 할 명령인가?
	if (nDstProc == clsCfg.m_nProcNo) {
		return Command(a_clsRecvP, a_clsPM);
	}

	// agent에 메세지 전송
	CModuleIPC& clsIPC = CModuleIPC::Instance();
	if (clsIPC.SendMesg(a_clsRecvP) == false) {
		g_pclsLogPra->ERROR("CMD, mode ipc send failed");
		a_clsRecvP.Print(g_pclsLogPra, LV_INFO);
		return false;
	}

	// APP의 Alive 주기적 검사를 줄이기 위해 APP에서 메세지가 왔다면
	// 이를 APP가 정상적으로 Alive 중인것으로 판단.
	int nSrcNode = 0;
	int nSrcProc = 0;
	a_clsRecvP.GetSource(nSrcNode, nSrcProc);
	if (nSrcProc > 0) {
		a_clsPM.AliveOk(nSrcProc);
	}

	return true;
}
Esempio n. 2
0
bool CCommandPra::Command(CProtocol& a_clsRecvP, CProcessManager& a_clsPM)
{
	int nCmd = atoi(a_clsRecvP.GetCommand().c_str());
	switch (nCmd) {
		case CMD_PING :
			CmdPing(a_clsRecvP);
			break;
		case CMD_PRA_RECONFIG :
			CmdAppReconfig(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_STATUS :
			CmdAppStatus(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_START :
			CmdAppStart(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_STOP :
			CmdAppStop(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_KILL :
			CmdAppKill(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_INIT :
			CmdAppInit(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_SUSPEND :
			CmdAppSuspend(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_RESUME :
			CmdAppResume(a_clsRecvP, a_clsPM);
			break;
		case CMD_APP_LOGLEVEL :
			CmdAppLogLevel(a_clsRecvP, a_clsPM);
			break;
		case CMD_STS_APP :
			CmdStaticApp(a_clsRecvP, a_clsPM);
			break;
		case CMD_BATCH_START :
			CmdBatchStart(a_clsRecvP, a_clsPM);
			break;
		case CMD_CLI_COMMAND :
			CmdCli(a_clsRecvP, a_clsPM);
			break;
		default :
			g_pclsLogPra->ERROR("CMD, not support command");
			a_clsRecvP.Print(g_pclsLogPra, LV_INFO, true);
			return false;
	}
	
	return true;
}
Esempio n. 3
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;
}