TSG-1531 tfe 代码整理, 将多插件公用的基础代码移动到 tfe init 阶段

1.将 kafka 的初始化从 pangu init 阶段移动到 tfe init 阶段
	2.将 device id 的获取从 pangu init 阶段移动到 tfe init 阶段
	3.将 kafka 的配置项从 pangu.conf 移动到 tfe.conf
	4.将 maat  的配置项从 pangu.conf 移动到 tfe.conf
This commit is contained in:
luwenpeng
2020-06-24 16:40:53 +08:00
parent b4683daf32
commit 03d05dd73e
11 changed files with 223 additions and 192 deletions

View File

@@ -3,6 +3,7 @@
#include <tfe_kafka_logger.h>
#include <cache_evbase_client.h>
#include <tfe_utils.h>
#include <tfe_resource.h>
#include "pangu_logger.h"
@@ -14,13 +15,8 @@ struct json_spec
struct pangu_logger
{
int entry_id;
unsigned int en_sendlog;
unsigned int en_sendlog_meta;
unsigned int en_sendlog_body;
const char *device_id;
void* global_logger;
void* local_logger;
unsigned long long send_cnt;
@@ -45,101 +41,29 @@ enum _log_action //Bigger action number is prior.
__LG_ACTION_MAX
};
static const char* tfe_device_id_create(const char* profile, const char* section, void* local_logger)
{
int ret=-1;
size_t device_id_size=0;
char *tsg_sn_file=NULL, *device_id;
const char *device_def_id = "DFT2201925000001";
cJSON *json=NULL,*item=NULL;
char device_id_filepath[TFE_STRING_MAX] = { 0 };
ret = MESA_load_profile_string_def(profile, section, "device_id_filepath",device_id_filepath,sizeof(device_id_filepath), NULL);
if(ret<0)
{
TFE_LOG_ERROR(local_logger,"Pangu log init failed, no device_path in profile %s section %s.", profile, section);
goto finish;
}
tsg_sn_file = tfe_read_file(device_id_filepath, &device_id_size);
if(tsg_sn_file==NULL)
{
TFE_LOG_ERROR(local_logger,"Pangu log init failed, %s not existed.", tsg_sn_file);
goto finish;
}
json=cJSON_Parse(tsg_sn_file);
if(json==NULL)
{
TFE_LOG_ERROR(local_logger, "invalid device parameter: file = %s", tsg_sn_file);
goto finish;
}
item=cJSON_GetObjectItem(json, "sn");
if(unlikely(!item || !cJSON_IsString(item)))
{
TFE_LOG_ERROR(local_logger, "Invalid device parameter: %s invalid json format", tsg_sn_file);
}
device_id = tfe_strdup(item->valuestring);
cJSON_Delete(json);
return device_id;
finish:
return device_def_id;
}
struct pangu_logger* pangu_log_handle_create(const char* profile, const char* section, void* local_logger)
{
int ret=-1;
char nic_name[64]={0};
char brokerlist[TFE_STRING_MAX] = { 0 };
char topic_name[TFE_STRING_MAX] = { 0 };
struct tango_cache_parameter *log_file_upload_para=NULL;
struct pangu_logger* instance=ALLOC(struct pangu_logger,1);
instance->local_logger=local_logger;
TFE_LOG_INFO(local_logger,"Pangu log is inititating from %s section %s.", profile, section);
MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0);
MESA_load_profile_uint_def(profile, section, "en_sendlog", &instance->en_sendlog, 1);
MESA_load_profile_uint_def(profile, section, "en_sendlog_meta", &instance->en_sendlog_meta, 1);
MESA_load_profile_uint_def(profile, section, "en_sendlog_body", &instance->en_sendlog_body, 1);
if (!instance->en_sendlog)
{
instance->en_sendlog_body = 0;
instance->en_sendlog_meta = 0;
}
TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE");
TFE_LOG_INFO(local_logger, "Pangu sendlog meta : %s", instance->en_sendlog_meta ? "ENABLE" : "DISABLE");
TFE_LOG_INFO(local_logger, "Pangu sendlog body : %s", instance->en_sendlog_body ? "ENABLE" : "DISABLE");
TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE");
if (!instance->en_sendlog)
{
return instance;
}
MESA_load_profile_string_def(profile, section, "NIC_NAME",nic_name,sizeof(nic_name),"eth0");
MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0);
instance->device_id = tfe_device_id_create(profile, section, local_logger);
TFE_LOG_INFO(local_logger, "Pangu device id : %s", instance->device_id);
ret=MESA_load_profile_string_def(profile, section,"KAFKA_BROKERLIST", brokerlist, sizeof(brokerlist), NULL);
if(ret<0)
{
TFE_LOG_ERROR(local_logger,"Pangu log init failed, no brokerlist in profile %s section %s.", profile, section);
goto error_out;
}
MESA_load_profile_string_def(profile, section,"KAFKA_TOPIC", topic_name, sizeof(topic_name), "POLICY-EVENT-LOG");
TFE_LOG_INFO(local_logger, "Pangu kafka brokerlist : %s", brokerlist);
TFE_LOG_INFO(local_logger, "Pangu kafka topic : %s", topic_name);
instance->kafka_logger = tfe_kafka_logger_create(instance->en_sendlog, nic_name, brokerlist, topic_name, local_logger);
if (instance->kafka_logger == NULL)
{
TFE_LOG_ERROR(local_logger,"Pangu log init failed, error to create kafka logger.");
goto error_out;
}
instance->device_id = (const char *)tfe_bussiness_resouce_get(DEVICE_ID);
instance->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
if (instance->kafka_logger && !instance->kafka_logger->enable)
{
TFE_LOG_ERROR(local_logger, "Pangu sendlog ENABLE, but tfe kafka logger DISABLED.");
goto error_out;
}
log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger);
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);