334 lines
8.7 KiB
C++
334 lines
8.7 KiB
C++
#include "pub_logger_api/logger.h"
|
|
#include "boost/timer.hpp"
|
|
#include "boost/format.hpp"
|
|
#include "pub_utility_api/FileUtil.h"
|
|
#include "pub_utility_api/CommonConfigParse.h"
|
|
#include "pub_utility_api/TimeUtil.h"
|
|
#include "pub_utility_api/I18N.h"
|
|
|
|
#include "PredifineForSeqServer.h"
|
|
#include "CMethodFailedAction.h"
|
|
#include "CNodeAction.h"
|
|
#include "CNodeFunc.h"
|
|
#include "CNodeSeq.h"
|
|
#include "CMbCommunicateInfo.h"
|
|
#include "CMethodAction.h"
|
|
|
|
CMethodFailedAction::CMethodFailedAction(
|
|
CMethodAction& actionPro,
|
|
CNodeAction& action)
|
|
:m_objMethodAction(actionPro),
|
|
m_objAction(action),
|
|
m_nFailedTime(0),
|
|
m_nUiTimerToSendSeconds(5)
|
|
{
|
|
loadConfig();
|
|
}
|
|
|
|
CMethodFailedAction::~CMethodFailedAction()
|
|
{
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedPro(const SActionErrorInfo& erroInfo)
|
|
{
|
|
//1 获取失败处理方式
|
|
ACTION_FAILED_STRAGE failType = m_objAction.failStrage();
|
|
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行失败处理流程,失败处理方式:[%s]",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.description().c_str(),
|
|
failStrageStr(failType).c_str()
|
|
);
|
|
|
|
//2 变更状态
|
|
m_objMethodAction.changeStateToFailed(erroInfo);
|
|
|
|
//3 增加一次执行失败次数
|
|
m_nFailedTime++;
|
|
|
|
//4 根据不同的处理方式,执行不同的流程
|
|
if (failType == ACTION_FAILED_STRAGE_AUTO_RETYR)
|
|
{
|
|
//自动重试
|
|
return doFailedAutoRetry();
|
|
}
|
|
else if (failType == ACTION_FAILED_STRAGE_AUTO_STOP)
|
|
{
|
|
//终止
|
|
return doFailedStop(erroInfo);
|
|
}
|
|
else if (failType == ACTION_FAILED_STRAGE_AUTO_SKIP)
|
|
{
|
|
//跳过 修改状态后 直接返回成功
|
|
if (doFailedAutoRetry())
|
|
{
|
|
return true;
|
|
}
|
|
return doFailedSkip(erroInfo);
|
|
}
|
|
else if (failType == ACTION_FAILED_STRAGE_USER_INTERVENE)
|
|
{
|
|
//处理人工干预
|
|
return doFailedUi(erroInfo);
|
|
}
|
|
else if (failType == ACTION_FAILED_STRAGE_STOP_FUNC)
|
|
{
|
|
m_objAction.getNodeFunc().setFinishState(true);
|
|
return doFailedStopFun(erroInfo);
|
|
}
|
|
|
|
// 其他都是异常状态
|
|
BOOST_ASSERT(false);
|
|
return true;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedAutoRetry()
|
|
{
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行自动重试处理流程 总重试:[%d] 已重试:[%d]",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str(),
|
|
m_objAction.retryTime(),
|
|
alreadyRetryTime()
|
|
);
|
|
|
|
//是否允许重试,如果没有重试次数了,则不可重试
|
|
if (isEnableRetry())
|
|
{
|
|
//开始重新执行节点
|
|
return m_objMethodAction.startExecuteNode();
|
|
}
|
|
|
|
//超过重试次数了 不允许再次重试
|
|
return false;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedUi(
|
|
const SActionErrorInfo& erroInfo)
|
|
{
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行人工干预处理流程",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str()
|
|
);
|
|
|
|
//1 先重置人工干预 结果
|
|
m_objAction.resetUiResult();
|
|
|
|
uint64 endTime = iot_public::getUTCTimeSec() + (2*24*60*60);//2天
|
|
SOpResultUi sResult;
|
|
if (!timeToSendUIRequest(
|
|
endTime,
|
|
sResult,
|
|
erroInfo))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
UI_OP_RESULT_TYPE result = sResult.eResult;
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行人工干预处理流程,干预状态[%s] "
|
|
"执行人ID[%d] 执行人用户组[%d] 主机名[%s]",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str(),
|
|
COpResultUi::UiOpTypeStr(result).c_str(),
|
|
sResult.actor.user_id,
|
|
sResult.actor.user_grounp_id,
|
|
sResult.actor.host_name.c_str()
|
|
);
|
|
|
|
if (result ==
|
|
UI_TYPE_RETYR)
|
|
{
|
|
//人工干预重试 不计入 失败次数
|
|
m_nFailedTime = 0;
|
|
return doFailedAutoRetry();
|
|
}
|
|
else if (result ==
|
|
UI_TYPE_STOP)
|
|
{
|
|
m_objMethodAction.changeStateToStop(erroInfo);
|
|
return false;
|
|
}
|
|
else if (result ==
|
|
UI_TYPE_SKIP)
|
|
{
|
|
m_objMethodAction.changeStateToSkip(erroInfo);
|
|
return true;
|
|
}
|
|
else if (result ==
|
|
UI_TYPE_INIT)
|
|
{
|
|
return doFailedUiTimeOut();
|
|
}
|
|
|
|
BOOST_ASSERT(false);
|
|
return false;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedStop(
|
|
const SActionErrorInfo& erroInfo)
|
|
{
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行终止处理流程",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str()
|
|
);
|
|
//终止
|
|
m_objMethodAction.changeStateToStop(erroInfo);
|
|
return false;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedSkip(
|
|
const SActionErrorInfo& erroInfo)
|
|
{
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行跳过处理流程",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str()
|
|
);
|
|
|
|
m_objMethodAction.changeStateToSkip(erroInfo);
|
|
return true;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedStopFun(const SActionErrorInfo& erroInfo)
|
|
{
|
|
LOGINFO("动作: [%s]-[%s]-[%s] 执行终止功能处理流程",
|
|
m_objAction.getNodeSeq().description().c_str(),
|
|
m_objAction.getNodeFunc().description().c_str(),
|
|
m_objAction.description().c_str()
|
|
);
|
|
//终止
|
|
m_objMethodAction.changeStateToStop(erroInfo);
|
|
return true;
|
|
}
|
|
|
|
bool CMethodFailedAction::doFailedUiTimeOut()
|
|
{
|
|
boost::format formater(I18N("动作: [%s]-[%s]-[%s] 人工干预超时,执行失败"));
|
|
std::string desc = (
|
|
formater
|
|
% m_objAction.getNodeSeq().description()
|
|
% m_objAction.getNodeFunc().description()
|
|
% m_objAction.description()
|
|
).str();
|
|
|
|
LOGINFO(desc.c_str());
|
|
|
|
m_objMethodAction.changeStateToFailed(
|
|
SActionErrorInfo(enumCode_ERRO_ACTION_UI_TIMEOUT,
|
|
desc));
|
|
return false;
|
|
}
|
|
|
|
bool CMethodFailedAction::sendUiRequest(
|
|
const SActionErrorInfo& erroInfo)
|
|
{
|
|
CMbCommunicateInfo& mb
|
|
= m_objAction.getNodeSeq().getMbCmmInfo();
|
|
|
|
return mb.sendUiRequest(m_objAction, erroInfo);
|
|
}
|
|
|
|
bool CMethodFailedAction::isEnableRetry() const
|
|
{
|
|
//一失败 就已经是 +1 了, 所以必须要 >= 才满足条件
|
|
if (m_objAction.retryTime() >= m_nFailedTime)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int CMethodFailedAction::alreadyRetryTime() const
|
|
{
|
|
//已经重试次数 是失败次数的-1 如果失败次数为0 重试次数也是0
|
|
return (m_nFailedTime == 0) ? 0 : (m_nFailedTime - 1);
|
|
}
|
|
|
|
bool CMethodFailedAction::timeToSendUIRequest(
|
|
uint64 endTime,
|
|
SOpResultUi& sResult,
|
|
const SActionErrorInfo& erroInfo)
|
|
{
|
|
bool bRet = false;
|
|
while(!bRet)
|
|
{
|
|
uint64 curTime = iot_public::getUTCTimeSec();
|
|
if(curTime > endTime)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//2 发送人工干预请求
|
|
if (!sendUiRequest(erroInfo))
|
|
{
|
|
//发送失败则直接返回false;
|
|
break;
|
|
}
|
|
|
|
sResult = m_objAction.getUiResult(m_nUiTimerToSendSeconds);
|
|
UI_OP_RESULT_TYPE result = sResult.eResult;
|
|
if (result != UI_TYPE_INIT)
|
|
{
|
|
bRet = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return bRet;
|
|
}
|
|
|
|
std::string CMethodFailedAction::failStrageStr(ACTION_FAILED_STRAGE type)
|
|
{
|
|
std::string strRet;
|
|
switch (type)
|
|
{
|
|
case ACTION_FAILED_STRAGE_USER_INTERVENE:
|
|
strRet = I18N("人工干预");
|
|
break;
|
|
case ACTION_FAILED_STRAGE_AUTO_RETYR:
|
|
strRet = I18N("自动重试");
|
|
break;
|
|
case ACTION_FAILED_STRAGE_AUTO_STOP:
|
|
strRet = I18N("自动终止");
|
|
break;
|
|
case ACTION_FAILED_STRAGE_AUTO_SKIP:
|
|
strRet = I18N("自动跳过");
|
|
break;
|
|
case ACTION_FAILED_STRAGE_STOP_FUNC:
|
|
strRet = I18N("终止功能");
|
|
break;
|
|
default:
|
|
strRet = I18N("未知的处理方式");
|
|
break;
|
|
}
|
|
|
|
return strRet;
|
|
}
|
|
|
|
bool CMethodFailedAction::loadConfig()
|
|
{
|
|
iot_public::CCommonConfigParse configParse;
|
|
if (iotSuccess != configParse.load(iot_public::CFileUtil::getPathOfCfgFile("proc_param_cfg.xml")))
|
|
{
|
|
LOGERROR("加载配置文件proc_param_cfg.xml失败");
|
|
return false;
|
|
}
|
|
|
|
|
|
if ((iotSuccess != configParse.getIntValue(
|
|
SEQUENCE_PROCESSNAME,
|
|
CONFING_UI_TIMER_TO_SEND_SECONDS,
|
|
m_nUiTimerToSendSeconds)))
|
|
{
|
|
LOGERROR("获取配置参数失败");
|
|
return false;
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|