* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
#include "AbstractParseUnit.h"
#include <thread>
#include "DataBaseManager.h"
#include "DbTraceDataBase.h"
#include "TextTraceDatabase.h"
namespace Dic::Module::FullDb {
template <typename DatabaseType> bool AbstractParseUnit<DatabaseType>::Handle(const ParseUnitParams ¶ms) {
std::string error;
bool res = Parse(params, error);
SendNotify(params, res, error);
if (!error.empty()) {
ServerLog::Warn("Execute parse unit failed, error:", error);
}
return res;
}
template <typename DatabaseType>
bool AbstractParseUnit<DatabaseType>::Parse(const ParseUnitParams ¶ms, std::string &error) {
std::string unitName = GetUnitName();
auto database = Timeline::DataBaseManager::Instance().GetTraceDatabaseByRankId(params.dbId);
if (!database) {
error = StringUtil::FormatString("Failed to parse unit, the database is not exist. Unit name:{}", unitName);
return false;
}
auto typedDatabase = std::dynamic_pointer_cast<DatabaseType>(database);
if (!typedDatabase) {
error = StringUtil::FormatString("Failed to cast database to expected type. Unit name:{}", unitName);
return false;
}
if (typedDatabase->CheckValueFromStatusInfoTable(unitName, FINISH_STATUS)) {
ServerLog::Info("The parser unit status is completed, skip paring, unit name:", unitName);
return true;
}
if (!PreCheck(params, typedDatabase, error)) {
return false;
}
if (!HandleParseProcess(params, typedDatabase, error)) {
return false;
}
typedDatabase->UpdateValueIntoStatusInfoTable(unitName, FINISH_STATUS);
return true;
}
template <typename DatabaseType>
void AbstractParseUnit<DatabaseType>::SendNotify(
const ParseUnitParams ¶ms, bool parseRes, const std::string &error) {
auto event = std::make_unique<ParseUnitCompletedEvent>();
event->body.parseResult = parseRes;
event->body.unitName = GetUnitName();
event->body.errorMsg = error;
event->body.dbId = params.dbId;
event->moduleName = MODULE_TIMELINE;
event->result = true;
SendEvent(std::move(event));
}
template class AbstractParseUnit<Timeline::VirtualTraceDatabase>;
template class AbstractParseUnit<DbTraceDataBase>;
template class AbstractParseUnit<TextTraceDatabase>;
}