mirror of
https://github.com/emqx/neuron.git
synced 2026-10-30 07:45:59 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b491fecc92 | ||
|
|
c49f034cd5 | ||
|
|
3c7709f4ae | ||
|
|
0bf8b7903f | ||
|
|
ccb6a62366 | ||
|
|
0a21862ac6 | ||
|
|
36cb4f6f3d | ||
|
|
1efcf861fe | ||
|
|
70c3f60ca3 | ||
|
|
525723ce2b | ||
|
|
835cb6bef0 | ||
|
|
563b9152bc | ||
|
|
7088a3a1fc | ||
|
|
87e967b75c | ||
|
|
be841977b9 | ||
|
|
65fff4f60a | ||
|
|
d8edb81d5a | ||
|
|
1d3e929cd8 | ||
|
|
43f3f482ee | ||
|
|
66aa3f96d3 | ||
|
|
f24b7c0ae5 | ||
|
|
6a8eb564be | ||
|
|
03fa5acf45 | ||
|
|
bfc14549a9 | ||
|
|
b2647cc091 | ||
|
|
de5a085339 | ||
|
|
19d8cb10ca | ||
|
|
971b1cf621 | ||
|
|
ad733be727 | ||
|
|
adc131570a | ||
|
|
8fe052364d | ||
|
|
3f1595c8c1 | ||
|
|
695c17627e | ||
|
|
aa293a7c56 | ||
|
|
e30d9599a8 | ||
|
|
4ba50cfc7c | ||
|
|
3c176bc0c5 | ||
|
|
5427c304c8 | ||
|
|
454a49f7fb | ||
|
|
738c406e06 | ||
|
|
49c0253909 | ||
|
|
e57f141606 | ||
|
|
cee2260cfd | ||
|
|
2f2fc27b49 | ||
|
|
8d8afa3c84 | ||
|
|
d868b77154 | ||
|
|
71bf03badb | ||
|
|
18bb90b3cf | ||
|
|
49257b850b | ||
|
|
96f98d15b9 | ||
|
|
b87fee91c1 | ||
|
|
b8a49073ca | ||
|
|
746e010e7e | ||
|
|
2a292c11f1 | ||
|
|
b7c35347e2 | ||
|
|
8dfdcee740 | ||
|
|
7166b68293 | ||
|
|
c48aebce8d | ||
|
|
7dd05b453b | ||
|
|
c88b60c8c3 | ||
|
|
0b75c2afb0 | ||
|
|
58960f4be6 | ||
|
|
c9c35e02c6 | ||
|
|
e5e421f257 | ||
|
|
4d4887a6e3 | ||
|
|
d57b95b0a1 | ||
|
|
c1cafe3fc7 | ||
|
|
cdbb511140 | ||
|
|
d2b96f5ca8 | ||
|
|
6bdf31b660 | ||
|
|
369e49f7ce | ||
|
|
a2c81d3572 | ||
|
|
d3f0b52fb2 | ||
|
|
82fe13876f | ||
|
|
ed01dd060a | ||
|
|
f69328e01a | ||
|
|
e33d331ee3 | ||
|
|
542624189a | ||
|
|
90e7b0ec03 | ||
|
|
30579ef578 | ||
|
|
bc44bfeda1 | ||
|
|
73efd03cfa | ||
|
|
60c707cdde | ||
|
|
10b317c0d7 |
@@ -8,8 +8,8 @@ on:
|
||||
- published
|
||||
|
||||
env:
|
||||
VERSION: 2.4.6
|
||||
UI_VERSION: 2.4.4
|
||||
VERSION: 2.4.11
|
||||
UI_VERSION: 2.4.8
|
||||
BRANCH: v2.4
|
||||
|
||||
jobs:
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ if(NOT DISABLE_WERROR)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O1")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O0")
|
||||
|
||||
if(NOT DISABLE_ASAN)
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||
|
||||
@@ -207,8 +207,8 @@ typedef struct neu_resp_error {
|
||||
} neu_resp_error_t;
|
||||
|
||||
typedef struct {
|
||||
char node[NEU_NODE_NAME_LEN];
|
||||
bool auto_start;
|
||||
char node[NEU_NODE_NAME_LEN];
|
||||
neu_node_running_state_e state;
|
||||
} neu_req_node_init_t, neu_req_node_uninit_t, neu_resp_node_uninit_t;
|
||||
|
||||
typedef struct neu_req_add_plugin {
|
||||
|
||||
@@ -133,10 +133,11 @@ typedef enum {
|
||||
NEU_ERR_MQTT_SUSPENDED = 4015,
|
||||
NEU_ERR_MQTT_PUBLISH_OVER_LENGTH = 4016,
|
||||
|
||||
NEU_ERR_FILE_TOO_LONG = 4100,
|
||||
NEU_ERR_STRING_TOO_LONG = 4100,
|
||||
NEU_ERR_FILE_OPEN_FAILURE = 4101,
|
||||
NEU_ERR_FILE_READ_FAILURE = 4102,
|
||||
NEU_ERR_FILE_WRITE_FAILURE = 4103,
|
||||
NEU_ERR_FILE_READ_NULL = 4104,
|
||||
|
||||
NEU_ERR_PLUGIN_ERROR_START = 10000,
|
||||
NEU_ERR_PLUGIN_ERROR_END = 20000,
|
||||
|
||||
@@ -95,6 +95,8 @@ int neu_persister_create(const char *schema_dir);
|
||||
void neu_persister_destroy();
|
||||
|
||||
sqlite3 *neu_persister_get_db();
|
||||
int neu_persister_node_count();
|
||||
int neu_persister_tag_count();
|
||||
|
||||
/**
|
||||
* Persist nodes.
|
||||
|
||||
+203
-1
@@ -28,6 +28,7 @@ extern "C" {
|
||||
#include <netinet/in.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum {
|
||||
NEU_TYPE_INT8 = 1,
|
||||
@@ -109,7 +110,80 @@ typedef union {
|
||||
double d64;
|
||||
char str[NEU_VALUE_SIZE];
|
||||
uint8_t bytes[NEU_VALUE_SIZE];
|
||||
} neu_value_u;
|
||||
} __attribute__((packed)) neu_value_u;
|
||||
|
||||
static inline char *neu_value_str(neu_type_e type, neu_value_u value)
|
||||
{
|
||||
static __thread char str[32] = { 0 };
|
||||
|
||||
switch (type) {
|
||||
case NEU_TYPE_INT8:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
|
||||
value.i8);
|
||||
break;
|
||||
case NEU_TYPE_UINT8:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
|
||||
value.u8);
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
|
||||
value.i16);
|
||||
break;
|
||||
case NEU_TYPE_WORD:
|
||||
case NEU_TYPE_UINT16:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
|
||||
value.u16);
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %i", neu_type_string(type),
|
||||
value.i32);
|
||||
break;
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_UINT32:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
|
||||
value.u32);
|
||||
break;
|
||||
case NEU_TYPE_INT64: {
|
||||
long long int i = value.i64;
|
||||
snprintf(str, sizeof(str), "type: %s, value: %lld",
|
||||
neu_type_string(type), i);
|
||||
break;
|
||||
}
|
||||
case NEU_TYPE_LWORD:
|
||||
case NEU_TYPE_UINT64: {
|
||||
long long unsigned int i = value.u64;
|
||||
snprintf(str, sizeof(str), "type: %s, value: %llu",
|
||||
neu_type_string(type), i);
|
||||
break;
|
||||
}
|
||||
case NEU_TYPE_FLOAT:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %f", neu_type_string(type),
|
||||
value.f32);
|
||||
break;
|
||||
case NEU_TYPE_DOUBLE:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %f", neu_type_string(type),
|
||||
value.d64);
|
||||
break;
|
||||
case NEU_TYPE_BIT:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
|
||||
value.u8);
|
||||
break;
|
||||
case NEU_TYPE_BOOL:
|
||||
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
|
||||
value.boolean);
|
||||
break;
|
||||
case NEU_TYPE_STRING: {
|
||||
snprintf(str, sizeof(str), "type: %s, value: %c%c%c",
|
||||
neu_type_string(type), value.str[0], value.str[1],
|
||||
value.str[2]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
neu_type_e type;
|
||||
@@ -443,6 +517,134 @@ static inline void neu_htons_p(uint16_t *pu)
|
||||
neu_ntohs_p(pu);
|
||||
}
|
||||
|
||||
static inline uint16_t neu_get_u16(uint8_t *bytes)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int16_t neu_get_i16(uint8_t *bytes)
|
||||
{
|
||||
int16_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint32_t neu_get_u32(uint8_t *bytes)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int32_t neu_get_i32(uint8_t *bytes)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline float neu_get_f32(uint8_t *bytes)
|
||||
{
|
||||
float ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint64_t neu_get_u64(uint8_t *bytes)
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
t[4] = bytes[4];
|
||||
t[5] = bytes[5];
|
||||
t[6] = bytes[6];
|
||||
t[7] = bytes[7];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int64_t neu_get_i64(uint8_t *bytes)
|
||||
{
|
||||
int64_t ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
t[4] = bytes[4];
|
||||
t[5] = bytes[5];
|
||||
t[6] = bytes[6];
|
||||
t[7] = bytes[7];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline double neu_get_f64(uint8_t *bytes)
|
||||
{
|
||||
double ret = 0;
|
||||
uint8_t *t = NULL;
|
||||
|
||||
t = (uint8_t *) &ret;
|
||||
|
||||
t[0] = bytes[0];
|
||||
t[1] = bytes[1];
|
||||
t[2] = bytes[2];
|
||||
t[3] = bytes[3];
|
||||
t[4] = bytes[4];
|
||||
t[5] = bytes[5];
|
||||
t[6] = bytes[6];
|
||||
t[7] = bytes[7];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -34,8 +34,8 @@ static neu_plugin_t *ekuiper_plugin_open(void)
|
||||
|
||||
neu_plugin_common_init(&plugin->common);
|
||||
|
||||
zlog_info(neuron, "success to create plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
zlog_notice(neuron, "success to create plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ static int ekuiper_plugin_close(neu_plugin_t *plugin)
|
||||
int rv = 0;
|
||||
|
||||
free(plugin);
|
||||
zlog_info(neuron, "success to free plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
zlog_notice(neuron, "success to free plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ static int ekuiper_plugin_init(neu_plugin_t *plugin)
|
||||
|
||||
plugin->recv_aio = recv_aio;
|
||||
|
||||
plog_info(plugin, "plugin initialized");
|
||||
plog_notice(plugin, "plugin initialized");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ static int ekuiper_plugin_uninit(neu_plugin_t *plugin)
|
||||
free(plugin->host);
|
||||
free(plugin->url);
|
||||
|
||||
plog_info(plugin, "plugin uninitialized");
|
||||
plog_notice(plugin, "plugin uninitialized");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ static int parse_config(neu_plugin_t *plugin, const char *setting,
|
||||
*host_p = host.v.val_str;
|
||||
*port_p = port.v.val_int;
|
||||
|
||||
plog_info(plugin, "config host:%s port:%" PRIu16, *host_p, *port_p);
|
||||
plog_notice(plugin, "config host:%s port:%" PRIu16, *host_p, *port_p);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -201,7 +201,7 @@ static int ekuiper_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
goto error;
|
||||
}
|
||||
|
||||
plog_info(plugin, "config success");
|
||||
plog_notice(plugin, "config success");
|
||||
|
||||
free(plugin->host);
|
||||
plugin->host = host;
|
||||
@@ -220,7 +220,7 @@ static int ekuiper_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
error:
|
||||
free(url);
|
||||
free(host);
|
||||
plog_info(plugin, "config failure");
|
||||
plog_error(plugin, "config failure");
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ static int ekuiper_plugin_request(neu_plugin_t * plugin,
|
||||
switch (header->type) {
|
||||
case NEU_RESP_ERROR: {
|
||||
neu_resp_error_t *error = (neu_resp_error_t *) data;
|
||||
plog_info(plugin, "receive resp errcode: %d", error->error);
|
||||
plog_debug(plugin, "receive resp errcode: %d", error->error);
|
||||
break;
|
||||
}
|
||||
case NEU_REQRESP_TRANS_DATA: {
|
||||
@@ -259,7 +259,7 @@ static int ekuiper_plugin_request(neu_plugin_t * plugin,
|
||||
case NEU_REQ_UNSUBSCRIBE_GROUP:
|
||||
break;
|
||||
default:
|
||||
plog_notice(plugin, "unsupported request type: %d", header->type);
|
||||
plog_warn(plugin, "unsupported request type: %d", header->type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
"type": "int",
|
||||
"default": 512,
|
||||
"valid": {
|
||||
"min": 1
|
||||
"min": 1,
|
||||
"max": 512
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,9 @@ static neu_plugin_t *driver_open(void)
|
||||
|
||||
static int driver_close(neu_plugin_t *plugin)
|
||||
{
|
||||
plog_notice(plugin, "close and free `%s` plugin success",
|
||||
plugin->common.name);
|
||||
|
||||
free(plugin);
|
||||
|
||||
return 0;
|
||||
@@ -83,13 +86,17 @@ static int driver_init(neu_plugin_t *plugin)
|
||||
{
|
||||
plugin->events = neu_event_new();
|
||||
|
||||
plog_notice(plugin, "initialize `%s` plugin success", plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_uninit(neu_plugin_t *plugin)
|
||||
{
|
||||
neu_event_close(plugin->events);
|
||||
plog_info(plugin, "node; file uininit ok");
|
||||
|
||||
plog_notice(plugin, "uninitialize `%s` plugin success",
|
||||
plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -98,6 +105,8 @@ static int driver_start(neu_plugin_t *plugin)
|
||||
{
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_CONNECTED;
|
||||
|
||||
plog_notice(plugin, "start `%s` plugin success", plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -105,6 +114,8 @@ static int driver_stop(neu_plugin_t *plugin)
|
||||
{
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_DISCONNECTED;
|
||||
|
||||
plog_notice(plugin, "stop `%s` plugin success", plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -115,7 +126,7 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
|
||||
int ret = neu_parse_param((char *) config, &err_param, 1, &file_length);
|
||||
if (ret != 0) {
|
||||
plog_warn(plugin, "config:%s, decode error: %s", config, err_param);
|
||||
plog_error(plugin, "config:%s, decode error: %s", config, err_param);
|
||||
free(err_param);
|
||||
return -1;
|
||||
}
|
||||
@@ -138,8 +149,8 @@ static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
|
||||
static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag)
|
||||
{
|
||||
plog_debug(plugin, "validate tag success, name:%s, address:%s,type:%d ",
|
||||
tag->name, tag->address, tag->type);
|
||||
plog_notice(plugin, "validate tag success, name:%s, address:%s, type:%d ",
|
||||
tag->name, tag->address, tag->type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -152,5 +163,10 @@ static int driver_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
static int driver_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value)
|
||||
{
|
||||
return file_write(plugin, req, tag, value);
|
||||
int ret = file_write(plugin, req, tag, value);
|
||||
|
||||
plog_notice(plugin, "write response, ret: %d, tag_name: %s, type: %d", ret,
|
||||
tag->name, tag->type);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
+40
-10
@@ -62,7 +62,7 @@ int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
}
|
||||
|
||||
if ((f = fopen(tag->address, "rb+")) == NULL) {
|
||||
nlog_error("open file:%s", tag->address);
|
||||
nlog_warn("fail open to read and write file: %s", tag->address);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_OPEN_FAILURE;
|
||||
goto dvalue_result;
|
||||
@@ -71,8 +71,11 @@ int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
fseek(f, 0, SEEK_END);
|
||||
int size = ftell(f);
|
||||
if (size >= length) {
|
||||
nlog_warn(
|
||||
"the file length exceeds the set value, file: %s, length: %d",
|
||||
tag->address, size);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_TOO_LONG;
|
||||
dvalue.value.i32 = NEU_ERR_STRING_TOO_LONG;
|
||||
|
||||
fclose(f);
|
||||
goto dvalue_result;
|
||||
@@ -81,9 +84,23 @@ int file_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group)
|
||||
fseek(f, 0, SEEK_SET);
|
||||
int ret = fread(buf, sizeof(char), length, f);
|
||||
if (ret == 0) {
|
||||
nlog_error("read file failed:%s", tag->address);
|
||||
if (feof(f)) {
|
||||
nlog_warn("file is empty:%s", tag->address);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_NULL;
|
||||
} else if (ferror(f)) {
|
||||
nlog_warn("read file failed: %s", tag->address);
|
||||
clearerr(f);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_FAILURE;
|
||||
}
|
||||
fclose(f);
|
||||
goto dvalue_result;
|
||||
} else if (ret >= NEU_VALUE_SIZE) {
|
||||
nlog_warn("the file length exceeds the maximum, file: %s, ret: %d",
|
||||
tag->address, ret);
|
||||
dvalue.type = NEU_TYPE_ERROR;
|
||||
dvalue.value.i32 = NEU_ERR_FILE_READ_FAILURE;
|
||||
dvalue.value.i32 = NEU_ERR_STRING_TOO_LONG;
|
||||
|
||||
fclose(f);
|
||||
goto dvalue_result;
|
||||
@@ -121,19 +138,32 @@ static void plugin_group_free(neu_plugin_group_t *pgp)
|
||||
int file_write(neu_plugin_t *plugin, void *req, neu_datatag_t *tag,
|
||||
neu_value_u value)
|
||||
{
|
||||
FILE *fp = fopen(tag->address, "w");
|
||||
int ret = 0;
|
||||
FILE *fp = NULL;
|
||||
int ret = 0;
|
||||
int length = strlen(value.str);
|
||||
|
||||
if (length >= NEU_VALUE_SIZE) {
|
||||
nlog_warn("write file exceeds the maximum value, file: %s, length: %d",
|
||||
tag->address, length);
|
||||
ret = NEU_ERR_STRING_TOO_LONG;
|
||||
|
||||
if (0 == fwrite(value.str, sizeof(char), strlen(value.str), fp)) {
|
||||
nlog_error("write file failed:%s", tag->address);
|
||||
ret = NEU_ERR_FILE_WRITE_FAILURE;
|
||||
goto dvalue_result;
|
||||
}
|
||||
|
||||
fp = fopen(tag->address, "w");
|
||||
|
||||
if (0 == fwrite(value.str, sizeof(char), strlen(value.str), fp)) {
|
||||
nlog_warn("write file failed: %s", tag->address);
|
||||
ret = NEU_ERR_FILE_WRITE_FAILURE;
|
||||
|
||||
fclose(fp);
|
||||
goto dvalue_result;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
neu_datatag_string_ltoh(value.str, strlen(value.str));
|
||||
|
||||
dvalue_result:
|
||||
fclose(fp);
|
||||
plugin->common.adapter_callbacks->driver.write_response(
|
||||
plugin->common.adapter, req, ret);
|
||||
|
||||
|
||||
@@ -91,12 +91,14 @@ static int driver_init(neu_plugin_t *plugin)
|
||||
plugin->events = neu_event_new();
|
||||
plugin->stack = modbus_stack_create((void *) plugin, modbus_send_msg,
|
||||
modbus_value_handle, modbus_write_resp);
|
||||
plog_notice(plugin, "%s init success", plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_uninit(neu_plugin_t *plugin)
|
||||
{
|
||||
plog_notice(plugin, "%s uninit start", plugin->common.name);
|
||||
if (plugin->conn != NULL) {
|
||||
neu_conn_destory(plugin->conn);
|
||||
}
|
||||
@@ -107,7 +109,7 @@ static int driver_uninit(neu_plugin_t *plugin)
|
||||
|
||||
neu_event_close(plugin->events);
|
||||
|
||||
plog_info(plugin, "node: modbus uninit ok");
|
||||
plog_notice(plugin, "%s uninit success", plugin->common.name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -115,12 +117,14 @@ static int driver_uninit(neu_plugin_t *plugin)
|
||||
static int driver_start(neu_plugin_t *plugin)
|
||||
{
|
||||
neu_conn_start(plugin->conn);
|
||||
plog_notice(plugin, "%s start success", plugin->common.name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int driver_stop(neu_plugin_t *plugin)
|
||||
{
|
||||
neu_conn_stop(plugin->conn);
|
||||
plog_notice(plugin, "%s stop success", plugin->common.name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -137,8 +141,8 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
neu_parse_param((char *) config, &err_param, 3, &port, &host, &timeout);
|
||||
|
||||
if (ret != 0) {
|
||||
plog_warn(plugin, "config: %s, decode error: %s", (char *) config,
|
||||
err_param);
|
||||
plog_error(plugin, "config: %s, decode error: %s", (char *) config,
|
||||
err_param);
|
||||
free(err_param);
|
||||
free(host.v.val_str);
|
||||
return -1;
|
||||
@@ -150,8 +154,9 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
param.params.tcp_client.port = port.v.val_int;
|
||||
param.params.tcp_client.timeout = timeout.v.val_int;
|
||||
|
||||
plog_info(plugin, "config: host: %s, port: %" PRId64 ", timeout: %" PRId64,
|
||||
host.v.val_str, port.v.val_int, timeout.v.val_int);
|
||||
plog_notice(plugin,
|
||||
"config: host: %s, port: %" PRId64 ", timeout: %" PRId64,
|
||||
host.v.val_str, port.v.val_int, timeout.v.val_int);
|
||||
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_DISCONNECTED;
|
||||
if (plugin->conn != NULL) {
|
||||
@@ -181,13 +186,21 @@ static int driver_validate_tag(neu_plugin_t *plugin, neu_datatag_t *tag)
|
||||
|
||||
int ret = modbus_tag_to_point(tag, &point);
|
||||
if (ret == 0) {
|
||||
plog_debug(
|
||||
plog_notice(
|
||||
plugin,
|
||||
"validate tag success, name: %s, address: %s, type: %d, slave id: "
|
||||
"%d, start address: %d, n register: %d, area: %s",
|
||||
tag->name, tag->address, tag->type, point.slave_id,
|
||||
point.start_address, point.n_register,
|
||||
modbus_area_to_str(point.area));
|
||||
} else {
|
||||
plog_error(
|
||||
plugin,
|
||||
"validate tag error, name: %s, address: %s, type: %d, slave id: "
|
||||
"%d, start address: %d, n register: %d, area: %s",
|
||||
tag->name, tag->address, tag->type, point.slave_id,
|
||||
point.start_address, point.n_register,
|
||||
modbus_area_to_str(point.area));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -109,8 +109,8 @@ static int response(nng_aio *aio, char *content, enum nng_http_status status)
|
||||
nng_http_res_set_status(res, status);
|
||||
|
||||
nng_http_req *nng_req = nng_aio_get_input(aio, 0);
|
||||
nlog_notice("%s %s [%d]", nng_http_req_get_method(nng_req),
|
||||
nng_http_req_get_uri(nng_req), status);
|
||||
nlog_info("%s %s [%d]", nng_http_req_get_method(nng_req),
|
||||
nng_http_req_get_uri(nng_req), status);
|
||||
|
||||
nng_aio_set_output(aio, 0, res);
|
||||
nng_aio_finish(aio, 0);
|
||||
@@ -159,7 +159,14 @@ static inline void gen_global_metrics(const neu_metrics_t *metrics,
|
||||
static inline void
|
||||
gen_single_node_metrics(const neu_node_metrics_t *node_metrics, FILE *stream)
|
||||
{
|
||||
fprintf(stream,
|
||||
"# HELP node_type Driver(1) or APP(2)\n"
|
||||
"# TYPE node_type gauge\n"
|
||||
"node_type{node=\"%s\"} %d\n",
|
||||
node_metrics->name, node_metrics->type);
|
||||
|
||||
neu_metric_entry_t *e = NULL;
|
||||
|
||||
HASH_LOOP(hh, node_metrics->entries, e)
|
||||
{
|
||||
fprintf(stream,
|
||||
@@ -208,9 +215,28 @@ static void gen_all_node_metrics(const neu_metrics_t *metrics, int type_filter,
|
||||
neu_group_metrics_t *g = NULL;
|
||||
neu_node_metrics_t * n = NULL;
|
||||
|
||||
bool commented = false;
|
||||
HASH_LOOP(hh, metrics->node_metrics, n)
|
||||
{
|
||||
if (!(type_filter & n->type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!commented) {
|
||||
commented = true;
|
||||
fprintf(stream,
|
||||
"# HELP node_type Driver(1) or APP(2)\n"
|
||||
"# TYPE node_type gauge\n");
|
||||
}
|
||||
|
||||
fprintf(stream, "node_type{node=\"%s\"} %d\n", n->name, n->type);
|
||||
}
|
||||
|
||||
n = NULL;
|
||||
|
||||
HASH_LOOP(hh, metrics->registered_metrics, r)
|
||||
{
|
||||
bool commented = false;
|
||||
commented = false;
|
||||
HASH_LOOP(hh, metrics->node_metrics, n)
|
||||
{
|
||||
if (!(type_filter & n->type)) {
|
||||
@@ -282,8 +308,8 @@ void handle_get_metric(nng_aio *aio)
|
||||
const char *cat_param = neu_http_get_param(aio, "category", &cat_param_len);
|
||||
if (NULL != cat_param &&
|
||||
!parse_metrics_catgory(cat_param, cat_param_len, &cat)) {
|
||||
plog_info(plugin, "invalid metrics category: %.*s", (int) cat_param_len,
|
||||
cat_param);
|
||||
plog_error(plugin, "invalid metrics category: %.*s",
|
||||
(int) cat_param_len, cat_param);
|
||||
status = NNG_HTTP_STATUS_BAD_REQUEST;
|
||||
goto end;
|
||||
}
|
||||
|
||||
+17
-16
@@ -37,15 +37,15 @@ static void connect_cb(void *data)
|
||||
{
|
||||
neu_plugin_t *plugin = data;
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_CONNECTED;
|
||||
plog_info(plugin, "plugin `%s` connected", neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "plugin `%s` connected", neu_plugin_module.module_name);
|
||||
}
|
||||
|
||||
static void disconnect_cb(void *data)
|
||||
{
|
||||
neu_plugin_t *plugin = data;
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_DISCONNECTED;
|
||||
plog_info(plugin, "plugin `%s` disconnected",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "plugin `%s` disconnected",
|
||||
neu_plugin_module.module_name);
|
||||
}
|
||||
|
||||
static nng_http_server *server_init()
|
||||
@@ -54,7 +54,7 @@ static nng_http_server *server_init()
|
||||
nng_http_server *server = NULL;
|
||||
const char * host_port = "http://0.0.0.0:7000";
|
||||
|
||||
nlog_info("monitor bind url: %s", host_port);
|
||||
nlog_notice("monitor bind url: %s", host_port);
|
||||
|
||||
int ret = nng_url_parse(&url, host_port);
|
||||
if (0 != ret) {
|
||||
@@ -179,7 +179,7 @@ static inline void stop_heartbeart_timer(neu_plugin_t *plugin)
|
||||
if (plugin->heartbeat_timer) {
|
||||
neu_event_del_timer(plugin->events, plugin->heartbeat_timer);
|
||||
plugin->heartbeat_timer = NULL;
|
||||
plog_info(plugin, "heartbeat timer stopped");
|
||||
plog_notice(plugin, "heartbeat timer stopped");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ end:
|
||||
}
|
||||
plugin->heartbeat_timer = timer;
|
||||
|
||||
plog_info(plugin, "start_hearbeat_timer interval: %" PRIu64, interval);
|
||||
plog_notice(plugin, "start_hearbeat_timer interval: %" PRIu64, interval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -286,8 +286,8 @@ static int monitor_plugin_close(neu_plugin_t *plugin)
|
||||
nng_http_server_stop(plugin->api_server);
|
||||
nng_http_server_release(plugin->api_server);
|
||||
pthread_mutex_destroy(&plugin->mutex);
|
||||
plog_info(plugin, "Success to free plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "Success to free plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
free(plugin);
|
||||
|
||||
return rv;
|
||||
@@ -298,7 +298,7 @@ static int monitor_plugin_init(neu_plugin_t *plugin)
|
||||
int rv = 0;
|
||||
(void) plugin;
|
||||
|
||||
plog_info(plugin, "Initialize plugin: %s", neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "Initialize plugin: %s", neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -308,7 +308,8 @@ static int monitor_plugin_uninit(neu_plugin_t *plugin)
|
||||
|
||||
uninit_timers_and_mqtt(plugin);
|
||||
|
||||
plog_info(plugin, "Uninitialize plugin: %s", neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "Uninitialize plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -372,7 +373,7 @@ static int monitor_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
memmove(plugin->config, &config, sizeof(config));
|
||||
// `config` moved, do not call monitor_config_fini
|
||||
|
||||
plog_info(plugin, "config plugin `%s` success", plugin_name);
|
||||
plog_notice(plugin, "config plugin `%s` success", plugin_name);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@@ -423,7 +424,7 @@ static int monitor_plugin_start(neu_plugin_t *plugin)
|
||||
const char *plugin_name = neu_plugin_module.module_name;
|
||||
|
||||
if (NULL == plugin->mqtt_client) {
|
||||
plog_info(plugin, "mqtt client is NULL");
|
||||
plog_notice(plugin, "mqtt client is NULL");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -443,7 +444,7 @@ static int monitor_plugin_start(neu_plugin_t *plugin)
|
||||
end:
|
||||
if (0 == rv) {
|
||||
plugin->started = true;
|
||||
plog_info(plugin, "start plugin `%s` success", plugin_name);
|
||||
plog_notice(plugin, "start plugin `%s` success", plugin_name);
|
||||
} else {
|
||||
plog_error(plugin, "start plugin `%s` failed, error %d", plugin_name,
|
||||
rv);
|
||||
@@ -456,13 +457,13 @@ static int monitor_plugin_stop(neu_plugin_t *plugin)
|
||||
{
|
||||
if (plugin->mqtt_client) {
|
||||
neu_mqtt_client_close(plugin->mqtt_client);
|
||||
plog_info(plugin, "mqtt client closed");
|
||||
plog_notice(plugin, "mqtt client closed");
|
||||
}
|
||||
|
||||
stop_heartbeart_timer(plugin);
|
||||
plugin->started = false;
|
||||
plog_info(plugin, "stop plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "stop plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,12 +75,12 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// ssl, optional
|
||||
int ret = neu_parse_param(setting, NULL, 1, ssl);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no ssl");
|
||||
plog_notice(plugin, "setting no ssl");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (false == ssl->v.val_bool) {
|
||||
plog_info(plugin, "setting ssl disabled");
|
||||
plog_notice(plugin, "setting ssl disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// cert, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, cert);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no cert");
|
||||
plog_notice(plugin, "setting no cert");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// keypass, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, keypass);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no keypass");
|
||||
plog_notice(plugin, "setting no keypass");
|
||||
} else if (0 == strlen(keypass->v.val_str)) {
|
||||
plog_error(plugin, "setting invalid keypass");
|
||||
return -1;
|
||||
@@ -280,13 +280,13 @@ int monitor_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
// username, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, &username);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no username");
|
||||
plog_notice(plugin, "setting no username");
|
||||
}
|
||||
|
||||
// password, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, &password);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no password");
|
||||
plog_notice(plugin, "setting no password");
|
||||
}
|
||||
|
||||
ret = parse_ssl_params(plugin, setting, &ssl, &ca, &cert, &key, &keypass);
|
||||
@@ -313,48 +313,54 @@ int monitor_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
config->key = key.v.val_str;
|
||||
config->keypass = keypass.v.val_str;
|
||||
|
||||
plog_info(plugin, "config client-id : %s", config->client_id);
|
||||
plog_info(plugin, "config event-topic-prefix: %s",
|
||||
config->event_topic_prefix);
|
||||
plog_info(plugin, "config heartbeat-interval: %" PRIu64,
|
||||
config->heartbeat_interval);
|
||||
plog_info(plugin, "config heartbeat-topic : %s", config->heartbeat_topic);
|
||||
plog_info(plugin, "config host : %s", config->host);
|
||||
plog_info(plugin, "config port : %" PRIu16, config->port);
|
||||
plog_notice(plugin, "config client-id : %s", config->client_id);
|
||||
plog_notice(plugin, "config event-topic-prefix: %s",
|
||||
config->event_topic_prefix);
|
||||
plog_notice(plugin, "config heartbeat-interval: %" PRIu64,
|
||||
config->heartbeat_interval);
|
||||
plog_notice(plugin, "config heartbeat-topic : %s",
|
||||
config->heartbeat_topic);
|
||||
plog_notice(plugin, "config host : %s", config->host);
|
||||
plog_notice(plugin, "config port : %" PRIu16, config->port);
|
||||
|
||||
if (config->username) {
|
||||
plog_info(plugin, "config username : %s", config->username);
|
||||
plog_notice(plugin, "config username : %s", config->username);
|
||||
}
|
||||
if (config->password) {
|
||||
plog_info(plugin, "config password : %s",
|
||||
0 == strlen(config->password) ? "" : placeholder);
|
||||
plog_notice(plugin, "config password : %s",
|
||||
0 == strlen(config->password) ? "" : placeholder);
|
||||
}
|
||||
if (config->ca) {
|
||||
plog_info(plugin, "config ca : %s", placeholder);
|
||||
plog_notice(plugin, "config ca : %s", placeholder);
|
||||
}
|
||||
if (config->cert) {
|
||||
plog_info(plugin, "config cert : %s", placeholder);
|
||||
plog_notice(plugin, "config cert : %s", placeholder);
|
||||
}
|
||||
if (config->key) {
|
||||
plog_info(plugin, "config key : %s", placeholder);
|
||||
plog_notice(plugin, "config key : %s", placeholder);
|
||||
}
|
||||
if (config->keypass) {
|
||||
plog_info(plugin, "config keypass : %s", placeholder);
|
||||
plog_notice(plugin, "config keypass : %s", placeholder);
|
||||
}
|
||||
|
||||
plog_info(plugin, "node add event topic : %s", config->node_add_topic);
|
||||
plog_info(plugin, "node del event topic : %s", config->node_del_topic);
|
||||
plog_info(plugin, "node ctl event topic : %s", config->node_ctl_topic);
|
||||
plog_info(plugin, "node setting event topic : %s",
|
||||
config->node_setting_topic);
|
||||
plog_info(plugin, "group add topic : %s", config->group_add_topic);
|
||||
plog_info(plugin, "group del topic : %s", config->group_del_topic);
|
||||
plog_info(plugin, "group update topic : %s",
|
||||
config->group_update_topic);
|
||||
plog_info(plugin, "tag add topic : %s", config->tag_add_topic);
|
||||
plog_info(plugin, "tag del topic : %s", config->tag_del_topic);
|
||||
plog_info(plugin, "tag update topic : %s",
|
||||
config->tag_update_topic);
|
||||
plog_notice(plugin, "node add event topic : %s",
|
||||
config->node_add_topic);
|
||||
plog_notice(plugin, "node del event topic : %s",
|
||||
config->node_del_topic);
|
||||
plog_notice(plugin, "node ctl event topic : %s",
|
||||
config->node_ctl_topic);
|
||||
plog_notice(plugin, "node setting event topic : %s",
|
||||
config->node_setting_topic);
|
||||
plog_notice(plugin, "group add topic : %s",
|
||||
config->group_add_topic);
|
||||
plog_notice(plugin, "group del topic : %s",
|
||||
config->group_del_topic);
|
||||
plog_notice(plugin, "group update topic : %s",
|
||||
config->group_update_topic);
|
||||
plog_notice(plugin, "tag add topic : %s", config->tag_add_topic);
|
||||
plog_notice(plugin, "tag del topic : %s", config->tag_del_topic);
|
||||
plog_notice(plugin, "tag update topic : %s",
|
||||
config->tag_update_topic);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
+27
-25
@@ -72,12 +72,12 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// ssl, optional
|
||||
int ret = neu_parse_param(setting, NULL, 1, ssl);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no ssl");
|
||||
plog_notice(plugin, "setting no ssl");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (false == ssl->v.val_bool) {
|
||||
plog_info(plugin, "setting ssl disabled");
|
||||
plog_notice(plugin, "setting ssl disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// cert, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, cert);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no cert");
|
||||
plog_notice(plugin, "setting no cert");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ static inline int parse_ssl_params(neu_plugin_t *plugin, const char *setting,
|
||||
// keypass, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, keypass);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no keypass");
|
||||
plog_notice(plugin, "setting no keypass");
|
||||
} else if (0 == strlen(keypass->v.val_str)) {
|
||||
plog_error(plugin, "setting invalid keypass");
|
||||
return -1;
|
||||
@@ -128,7 +128,7 @@ static int parse_cache_params(neu_plugin_t *plugin, const char *setting,
|
||||
// offline-cache flag, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, offline_cache);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no offline cache flag");
|
||||
plog_notice(plugin, "setting no offline cache flag");
|
||||
flag_present = false; // `offline-cache` not present in setting
|
||||
}
|
||||
|
||||
@@ -302,13 +302,13 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
// username, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, &username);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no username");
|
||||
plog_notice(plugin, "setting no username");
|
||||
}
|
||||
|
||||
// password, optional
|
||||
ret = neu_parse_param(setting, NULL, 1, &password);
|
||||
if (0 != ret) {
|
||||
plog_info(plugin, "setting no password");
|
||||
plog_notice(plugin, "setting no password");
|
||||
}
|
||||
|
||||
ret = parse_ssl_params(plugin, setting, &ssl, &ca, &cert, &key, &keypass);
|
||||
@@ -333,36 +333,38 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
config->key = key.v.val_str;
|
||||
config->keypass = keypass.v.val_str;
|
||||
|
||||
plog_info(plugin, "config client-id : %s", config->client_id);
|
||||
plog_info(plugin, "config qos : %d", config->qos);
|
||||
plog_info(plugin, "config format : %s",
|
||||
mqtt_upload_format_str(config->format));
|
||||
plog_info(plugin, "config write-req-topic : %s", config->write_req_topic);
|
||||
plog_info(plugin, "config write-resp-topic: %s", config->write_resp_topic);
|
||||
plog_info(plugin, "config cache : %zu", config->cache);
|
||||
plog_info(plugin, "config cache-mem-size : %zu", config->cache_mem_size);
|
||||
plog_info(plugin, "config cache-disk-size : %zu", config->cache_disk_size);
|
||||
plog_info(plugin, "config host : %s", config->host);
|
||||
plog_info(plugin, "config port : %" PRIu16, config->port);
|
||||
plog_notice(plugin, "config client-id : %s", config->client_id);
|
||||
plog_notice(plugin, "config qos : %d", config->qos);
|
||||
plog_notice(plugin, "config format : %s",
|
||||
mqtt_upload_format_str(config->format));
|
||||
plog_notice(plugin, "config write-req-topic : %s", config->write_req_topic);
|
||||
plog_notice(plugin, "config write-resp-topic: %s",
|
||||
config->write_resp_topic);
|
||||
plog_notice(plugin, "config cache : %zu", config->cache);
|
||||
plog_notice(plugin, "config cache-mem-size : %zu", config->cache_mem_size);
|
||||
plog_notice(plugin, "config cache-disk-size : %zu",
|
||||
config->cache_disk_size);
|
||||
plog_notice(plugin, "config host : %s", config->host);
|
||||
plog_notice(plugin, "config port : %" PRIu16, config->port);
|
||||
|
||||
if (config->username) {
|
||||
plog_info(plugin, "config username : %s", config->username);
|
||||
plog_notice(plugin, "config username : %s", config->username);
|
||||
}
|
||||
if (config->password) {
|
||||
plog_info(plugin, "config password : %s",
|
||||
0 == strlen(config->password) ? "" : placeholder);
|
||||
plog_notice(plugin, "config password : %s",
|
||||
0 == strlen(config->password) ? "" : placeholder);
|
||||
}
|
||||
if (config->ca) {
|
||||
plog_info(plugin, "config ca : %s", placeholder);
|
||||
plog_notice(plugin, "config ca : %s", placeholder);
|
||||
}
|
||||
if (config->cert) {
|
||||
plog_info(plugin, "config cert : %s", placeholder);
|
||||
plog_notice(plugin, "config cert : %s", placeholder);
|
||||
}
|
||||
if (config->key) {
|
||||
plog_info(plugin, "config key : %s", placeholder);
|
||||
plog_notice(plugin, "config key : %s", placeholder);
|
||||
}
|
||||
if (config->keypass) {
|
||||
plog_info(plugin, "config keypass : %s", placeholder);
|
||||
plog_notice(plugin, "config keypass : %s", placeholder);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -194,8 +194,8 @@ static char *generate_write_resp_json(neu_plugin_t * plugin,
|
||||
static inline int send_read_req(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
|
||||
neu_json_read_req_t *req)
|
||||
{
|
||||
plog_info(plugin, "read uuid:%s, group:%s, node:%s", mqtt->uuid, req->group,
|
||||
req->node);
|
||||
plog_notice(plugin, "read uuid:%s, group:%s, node:%s", mqtt->uuid,
|
||||
req->group, req->node);
|
||||
|
||||
neu_reqresp_head_t header = { 0 };
|
||||
header.ctx = mqtt;
|
||||
@@ -214,8 +214,8 @@ static inline int send_read_req(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
|
||||
static int send_write_req(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
|
||||
neu_json_write_req_t *req)
|
||||
{
|
||||
plog_info(plugin, "write uuid:%s, group:%s, node:%s", mqtt->uuid,
|
||||
req->group, req->node);
|
||||
plog_notice(plugin, "write uuid:%s, group:%s, node:%s", mqtt->uuid,
|
||||
req->group, req->node);
|
||||
|
||||
neu_reqresp_head_t header = { 0 };
|
||||
neu_req_write_tag_t cmd = { 0 };
|
||||
@@ -538,8 +538,8 @@ int handle_subscribe_group(neu_plugin_t *plugin, neu_req_subscribe_t *sub_info)
|
||||
goto end;
|
||||
}
|
||||
|
||||
plog_info(plugin, "route driver:%s group:%s to topic:%s", sub_info->driver,
|
||||
sub_info->group, topic.v.val_str);
|
||||
plog_notice(plugin, "route driver:%s group:%s to topic:%s",
|
||||
sub_info->driver, sub_info->group, topic.v.val_str);
|
||||
|
||||
end:
|
||||
free(sub_info->params);
|
||||
@@ -550,7 +550,7 @@ int handle_unsubscribe_group(neu_plugin_t * plugin,
|
||||
neu_req_unsubscribe_t *unsub_info)
|
||||
{
|
||||
route_tbl_del(&plugin->route_tbl, unsub_info->driver, unsub_info->group);
|
||||
plog_info(plugin, "del route driver:%s group:%s", unsub_info->driver,
|
||||
unsub_info->group);
|
||||
plog_notice(plugin, "del route driver:%s group:%s", unsub_info->driver,
|
||||
unsub_info->group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
-14
@@ -30,15 +30,15 @@ static void connect_cb(void *data)
|
||||
{
|
||||
neu_plugin_t *plugin = data;
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_CONNECTED;
|
||||
plog_info(plugin, "plugin `%s` connected", neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "plugin `%s` connected", neu_plugin_module.module_name);
|
||||
}
|
||||
|
||||
static void disconnect_cb(void *data)
|
||||
{
|
||||
neu_plugin_t *plugin = data;
|
||||
plugin->common.link_state = NEU_NODE_LINK_STATE_DISCONNECTED;
|
||||
plog_info(plugin, "plugin `%s` disconnected",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "plugin `%s` disconnected",
|
||||
neu_plugin_module.module_name);
|
||||
}
|
||||
|
||||
static neu_plugin_t *mqtt_plugin_open(void)
|
||||
@@ -51,7 +51,7 @@ static neu_plugin_t *mqtt_plugin_open(void)
|
||||
static int mqtt_plugin_close(neu_plugin_t *plugin)
|
||||
{
|
||||
const char *name = neu_plugin_module.module_name;
|
||||
plog_info(plugin, "success to free plugin:%s", name);
|
||||
plog_notice(plugin, "success to free plugin:%s", name);
|
||||
|
||||
free(plugin);
|
||||
return NEU_ERR_SUCCESS;
|
||||
@@ -59,8 +59,8 @@ static int mqtt_plugin_close(neu_plugin_t *plugin)
|
||||
|
||||
static int mqtt_plugin_init(neu_plugin_t *plugin)
|
||||
{
|
||||
plog_info(plugin, "initialize plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "initialize plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
neu_adapter_register_metric_cb_t register_metric =
|
||||
plugin->common.adapter_callbacks->register_metric;
|
||||
register_metric(plugin->common.adapter, NEU_METRIC_CACHED_MSGS_NUM,
|
||||
@@ -85,8 +85,8 @@ static int mqtt_plugin_uninit(neu_plugin_t *plugin)
|
||||
|
||||
route_tbl_free(plugin->route_tbl);
|
||||
|
||||
plog_info(plugin, "uninitialize plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "uninitialize plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
return NEU_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -269,11 +269,11 @@ static int mqtt_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
}
|
||||
memmove(&plugin->config, &config, sizeof(config));
|
||||
|
||||
plog_info(plugin, "config plugin `%s` success", plugin_name);
|
||||
plog_notice(plugin, "config plugin `%s` success", plugin_name);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
plog_info(plugin, "config plugin `%s` fail", plugin_name);
|
||||
plog_error(plugin, "config plugin `%s` fail", plugin_name);
|
||||
mqtt_config_fini(&config);
|
||||
return rv;
|
||||
}
|
||||
@@ -299,7 +299,7 @@ static int mqtt_plugin_start(neu_plugin_t *plugin)
|
||||
|
||||
end:
|
||||
if (0 == rv) {
|
||||
plog_info(plugin, "start plugin `%s` success", plugin_name);
|
||||
plog_notice(plugin, "start plugin `%s` success", plugin_name);
|
||||
} else {
|
||||
plog_error(plugin, "start plugin `%s` failed, error %d", plugin_name,
|
||||
rv);
|
||||
@@ -313,11 +313,11 @@ static int mqtt_plugin_stop(neu_plugin_t *plugin)
|
||||
if (plugin->client) {
|
||||
unsubscribe(plugin, &plugin->config);
|
||||
neu_mqtt_client_close(plugin->client);
|
||||
plog_info(plugin, "mqtt client closed");
|
||||
plog_notice(plugin, "mqtt client closed");
|
||||
}
|
||||
|
||||
plog_info(plugin, "stop plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
plog_notice(plugin, "stop plugin `%s` success",
|
||||
neu_plugin_module.module_name);
|
||||
return NEU_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ void handle_logs_files(nng_aio *aio)
|
||||
rv = system("rm -rf /tmp/neuron_debug.tar.gz");
|
||||
nlog_warn("remove old neuron_debug.tar.gz, rv: %d", rv);
|
||||
/* tar the neuron directory */
|
||||
rv = system("tar -zcvf /tmp/neuron_debug.tar.gz ../neuron");
|
||||
rv = system("tar -zcvf /tmp/neuron_debug.tar.gz "
|
||||
"--exclude='persistence/neuron.lic' ../neuron");
|
||||
if (rv == -1) {
|
||||
nlog_error("failed to create neuron_debug.tar.gz, rv: %d", rv);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, {
|
||||
|
||||
@@ -54,12 +54,20 @@ void handle_login(nng_aio *aio)
|
||||
aio, neu_json_login_req_t, neu_json_decode_login_req, {
|
||||
neu_json_login_resp_t login_resp = { 0 };
|
||||
neu_user_t * user = neu_load_user(req->name);
|
||||
int pass_len = strlen(req->pass);
|
||||
|
||||
if (NULL == user) {
|
||||
nlog_warn("could not find user `%s`", req->name);
|
||||
nlog_error("could not find user `%s`", req->name);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_PASSWORD, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
} else if (pass_len < NEU_USER_PASSWORD_MIN_LEN ||
|
||||
pass_len > NEU_USER_PASSWORD_MAX_LEN) {
|
||||
nlog_error("user `%s` password too short or too long",
|
||||
req->name);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_PASSWORD_LEN, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
} else if (neu_user_check_password(user, req->pass)) {
|
||||
|
||||
char *token = NULL;
|
||||
@@ -81,7 +89,7 @@ void handle_login(nng_aio *aio)
|
||||
jwt_free_str(token);
|
||||
free(result);
|
||||
} else {
|
||||
nlog_warn("user `%s` password check fail", req->name);
|
||||
nlog_error("user `%s` password check fail", req->name);
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_PASSWORD, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ static nng_http_server *server_init()
|
||||
nng_http_server *server;
|
||||
|
||||
snprintf(host_port, sizeof(host_port), "http://0.0.0.0:7000");
|
||||
nlog_info("bind url: %s", host_port);
|
||||
nlog_notice("bind url: %s", host_port);
|
||||
|
||||
int ret = nng_url_parse(&url, host_port);
|
||||
if (ret != 0) {
|
||||
@@ -105,7 +105,7 @@ static neu_plugin_t *dashb_plugin_open(void)
|
||||
goto server_init_fail;
|
||||
}
|
||||
|
||||
nlog_info("Success to create plugin: %s", neu_plugin_module.module_name);
|
||||
nlog_notice("Success to create plugin: %s", neu_plugin_module.module_name);
|
||||
return plugin;
|
||||
|
||||
server_init_fail:
|
||||
@@ -121,13 +121,11 @@ static int dashb_plugin_close(neu_plugin_t *plugin)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
nlog_info("Success to before free plugin: %s",
|
||||
neu_plugin_module.module_name);
|
||||
nng_http_server_stop(plugin->server);
|
||||
nng_http_server_release(plugin->server);
|
||||
|
||||
free(plugin);
|
||||
nlog_info("Success to free plugin: %s", neu_plugin_module.module_name);
|
||||
nlog_notice("Success to free plugin: %s", neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -139,7 +137,7 @@ static int dashb_plugin_init(neu_plugin_t *plugin)
|
||||
|
||||
rv = neu_jwt_init(g_config_dir);
|
||||
|
||||
nlog_info("Initialize plugin: %s", neu_plugin_module.module_name);
|
||||
nlog_notice("Initialize plugin: %s", neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -149,7 +147,7 @@ static int dashb_plugin_uninit(neu_plugin_t *plugin)
|
||||
|
||||
(void) plugin;
|
||||
|
||||
nlog_info("Uninitialize plugin: %s", neu_plugin_module.module_name);
|
||||
nlog_notice("Uninitialize plugin: %s", neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -160,7 +158,7 @@ static int dashb_plugin_config(neu_plugin_t *plugin, const char *configs)
|
||||
(void) plugin;
|
||||
(void) configs;
|
||||
|
||||
nlog_info("config plugin: %s", neu_plugin_module.module_name);
|
||||
nlog_notice("config plugin: %s", neu_plugin_module.module_name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ void handle_write(nng_aio *aio)
|
||||
|
||||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_write_req_t, neu_json_decode_write_req, {
|
||||
int ret = 0;
|
||||
neu_reqresp_head_t header = { 0 };
|
||||
neu_req_write_tag_t cmd = { 0 };
|
||||
|
||||
@@ -75,8 +74,13 @@ void handle_write(nng_aio *aio)
|
||||
cmd.value.value.u64 = req->value.val_int;
|
||||
break;
|
||||
case NEU_JSON_STR:
|
||||
cmd.value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd.value.value.str, req->value.val_str);
|
||||
if (strlen(req->value.val_str) >= NEU_VALUE_SIZE) {
|
||||
cmd.value.type = NEU_TYPE_ERROR;
|
||||
cmd.value.value.i32 = NEU_ERR_STRING_TOO_LONG;
|
||||
} else {
|
||||
cmd.value.type = NEU_TYPE_STRING;
|
||||
strcpy(cmd.value.value.str, req->value.val_str);
|
||||
}
|
||||
break;
|
||||
case NEU_JSON_DOUBLE:
|
||||
cmd.value.type = NEU_TYPE_DOUBLE;
|
||||
@@ -91,11 +95,18 @@ void handle_write(nng_aio *aio)
|
||||
break;
|
||||
}
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
|
||||
if (cmd.value.type == NEU_TYPE_ERROR) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_STRING_TOO_LONG, {
|
||||
neu_http_response(aio, NEU_ERR_STRING_TOO_LONG,
|
||||
result_error);
|
||||
});
|
||||
} else {
|
||||
int ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -181,13 +181,13 @@ neu_adapter_t *neu_adapter_create(neu_adapter_info_t *info)
|
||||
timer_level.usr_data = (void *) adapter;
|
||||
adapter->timer_lev = neu_event_add_timer(adapter->events, timer_level);
|
||||
|
||||
nlog_info("Success to create adapter: %s", adapter->name);
|
||||
nlog_notice("Success to create adapter: %s", adapter->name);
|
||||
|
||||
adapter_storage_state(adapter->name, adapter->state);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
void neu_adapter_init(neu_adapter_t *adapter, bool auto_start)
|
||||
void neu_adapter_init(neu_adapter_t *adapter, neu_node_running_state_e state)
|
||||
{
|
||||
neu_reqresp_head_t header = { .type = NEU_REQ_NODE_INIT };
|
||||
neu_req_node_init_t init = { 0 };
|
||||
@@ -197,8 +197,8 @@ void neu_adapter_init(neu_adapter_t *adapter, bool auto_start)
|
||||
strcpy(header.receiver, "manager");
|
||||
|
||||
strcpy(init.node, adapter->name);
|
||||
init.auto_start = auto_start;
|
||||
init_msg = neu_msg_gen(&header, &init);
|
||||
init.state = state;
|
||||
init_msg = neu_msg_gen(&header, &init);
|
||||
|
||||
nng_sendmsg(adapter->sock, init_msg, 0);
|
||||
}
|
||||
@@ -371,8 +371,8 @@ static int adapter_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
|
||||
nng_recvmsg(adapter->sock, &msg, 0);
|
||||
header = (neu_reqresp_head_t *) nng_msg_body(msg);
|
||||
nlog_debug("adapter(%s) recv msg from: %s, type: %s", adapter->name,
|
||||
header->sender, neu_reqresp_type_string(header->type));
|
||||
nlog_info("adapter(%s) recv msg from: %s, type: %s", adapter->name,
|
||||
header->sender, neu_reqresp_type_string(header->type));
|
||||
|
||||
switch (header->type) {
|
||||
case NEU_RESP_GET_DRIVER_GROUP:
|
||||
@@ -755,9 +755,10 @@ static int adapter_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
strcpy(name, adapter->name);
|
||||
strcpy(receiver, header->receiver);
|
||||
if (nng_sendmsg(adapter->sock, uninit_msg, 0) == 0) {
|
||||
nlog_warn("%s send uninit msg to %s", name, receiver);
|
||||
nlog_notice("%s send uninit msg to %s", name, receiver);
|
||||
} else {
|
||||
nng_msg_free(uninit_msg);
|
||||
nlog_error("%s send uninit msg to %s failed", name, receiver);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -822,7 +823,7 @@ int neu_adapter_uninit(neu_adapter_t *adapter)
|
||||
|
||||
neu_event_del_timer(adapter->events, adapter->timer_lev);
|
||||
|
||||
nlog_info("Stop the adapter(%s)", adapter->name);
|
||||
nlog_notice("Stop the adapter(%s)", adapter->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ typedef struct adapter_msg_handler {
|
||||
} adapter_msg_handler_t;
|
||||
|
||||
neu_adapter_t *neu_adapter_create(neu_adapter_info_t *info);
|
||||
void neu_adapter_init(neu_adapter_t *adapter, bool auto_start);
|
||||
void neu_adapter_init(neu_adapter_t *adapter, neu_node_running_state_e state);
|
||||
|
||||
int neu_adapter_start(neu_adapter_t *adapter);
|
||||
int neu_adapter_start_single(neu_adapter_t *adapter);
|
||||
|
||||
@@ -55,6 +55,7 @@ typedef struct group {
|
||||
|
||||
neu_event_timer_t *report;
|
||||
neu_event_timer_t *read;
|
||||
neu_event_timer_t *write;
|
||||
|
||||
neu_plugin_group_t grp;
|
||||
neu_adapter_driver_t *driver;
|
||||
@@ -73,6 +74,7 @@ struct neu_adapter_driver {
|
||||
|
||||
static int report_callback(void *usr_data);
|
||||
static int read_callback(void *usr_data);
|
||||
static int write_callback(void *usr_data);
|
||||
static void read_group(int64_t timestamp, int64_t timeout,
|
||||
neu_driver_cache_t *cache, const char *group,
|
||||
UT_array *tags, neu_resp_tag_value_t *datas);
|
||||
@@ -132,7 +134,7 @@ static void update(neu_adapter_t *adapter, const char *group, const char *tag,
|
||||
&driver->adapter, NEU_METRIC_TAG_READ_ERRORS_TOTAL,
|
||||
NEU_TYPE_ERROR == value.type, NULL);
|
||||
}
|
||||
nlog_debug(
|
||||
nlog_info(
|
||||
"update driver: %s, group: %s, tag: %s, type: %s, timestamp: %" PRId64,
|
||||
driver->adapter.name, group, tag, neu_type_string(value.type),
|
||||
global_timestamp);
|
||||
@@ -185,6 +187,7 @@ int neu_adapter_driver_uninit(neu_adapter_driver_t *driver)
|
||||
|
||||
neu_adapter_del_timer((neu_adapter_t *) driver, el->report);
|
||||
neu_event_del_timer(driver->driver_events, el->read);
|
||||
neu_event_del_timer(driver->driver_events, el->write);
|
||||
if (el->grp.group_free != NULL) {
|
||||
el->grp.group_free(&el->grp);
|
||||
}
|
||||
@@ -481,6 +484,11 @@ int neu_adapter_driver_add_group(neu_adapter_driver_t *driver, const char *name,
|
||||
param.cb = read_callback;
|
||||
find->read = neu_event_add_timer(driver->driver_events, param);
|
||||
|
||||
param.second = 0;
|
||||
param.millisecond = 100;
|
||||
param.cb = write_callback;
|
||||
find->write = neu_event_add_timer(driver->driver_events, param);
|
||||
|
||||
REGISTER_GROUP_METRIC(&driver->adapter, find->name,
|
||||
NEU_METRIC_GROUP_TAGS_TOTAL,
|
||||
neu_group_tag_size(find->group));
|
||||
@@ -539,6 +547,7 @@ int neu_adapter_driver_del_group(neu_adapter_driver_t *driver, const char *name)
|
||||
|
||||
neu_adapter_del_timer((neu_adapter_t *) driver, find->report);
|
||||
neu_event_del_timer(driver->driver_events, find->read);
|
||||
neu_event_del_timer(driver->driver_events, find->write);
|
||||
if (find->grp.group_free != NULL) {
|
||||
find->grp.group_free(&find->grp);
|
||||
}
|
||||
@@ -913,10 +922,11 @@ static void group_change(void *arg, int64_t timestamp, UT_array *static_tags,
|
||||
|
||||
group->static_tags = static_tags;
|
||||
group->grp = grp;
|
||||
nlog_notice("group: %s changed", group->name);
|
||||
nlog_notice("group: %s changed, timestamp: %" PRIi64, group->name,
|
||||
timestamp);
|
||||
}
|
||||
|
||||
static int read_callback(void *usr_data)
|
||||
static int write_callback(void *usr_data)
|
||||
{
|
||||
group_t * group = (group_t *) usr_data;
|
||||
neu_node_running_state_e state = group->driver->adapter.state;
|
||||
@@ -935,6 +945,17 @@ static int read_callback(void *usr_data)
|
||||
utarray_clear(group->wt_tags);
|
||||
pthread_mutex_unlock(&group->wt_mtx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_callback(void *usr_data)
|
||||
{
|
||||
group_t * group = (group_t *) usr_data;
|
||||
neu_node_running_state_e state = group->driver->adapter.state;
|
||||
if (state != NEU_NODE_RUNNING_STATE_RUNNING) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (neu_group_is_change(group->group, group->timestamp)) {
|
||||
neu_group_change_test(group->group, group->timestamp, (void *) group,
|
||||
group_change);
|
||||
@@ -970,7 +991,7 @@ static int read_report_group(int64_t timestamp, int64_t timeout,
|
||||
if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE)) {
|
||||
if (neu_driver_cache_get_changed(cache, group, tag->name, &value) !=
|
||||
0) {
|
||||
nlog_debug("tag: %s not changed", tag->name);
|
||||
nlog_info("tag: %s not changed", tag->name);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -125,7 +125,7 @@ int adapter_load_setting(const char *node, char **setting)
|
||||
{
|
||||
int rv = neu_persister_load_node_setting(node, (const char **) setting);
|
||||
if (0 != rv) {
|
||||
nlog_info("load %s setting fail", node);
|
||||
nlog_error("load %s setting fail", node);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -286,7 +286,8 @@ static void split_static_array(tag_elem_t *tags, UT_array **static_tags,
|
||||
{
|
||||
if (neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
utarray_push_back(*static_tags, el->tag);
|
||||
} else {
|
||||
} else if (neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_SUBSCRIBE) ||
|
||||
neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_READ)) {
|
||||
utarray_push_back(*other_tags, el->tag);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -189,7 +189,7 @@ static inline void metrics_unregister_entry(const char *name)
|
||||
HASH_FIND_STR(g_metrics_.registered_metrics, name, e);
|
||||
if (0 == --e->value) {
|
||||
HASH_DEL(g_metrics_.registered_metrics, e);
|
||||
nlog_info("del entry:%s", e->name);
|
||||
nlog_notice("del entry:%s", e->name);
|
||||
neu_metric_entry_free(e);
|
||||
}
|
||||
}
|
||||
|
||||
+95
-47
@@ -47,6 +47,7 @@ struct neu_conn {
|
||||
void * data;
|
||||
bool is_connected;
|
||||
bool stop;
|
||||
bool connection_ok;
|
||||
|
||||
neu_conn_callback connected;
|
||||
neu_conn_callback disconnected;
|
||||
@@ -217,10 +218,10 @@ int neu_conn_tcp_server_accept(neu_conn_t *conn)
|
||||
conn->connected(conn->data, fd);
|
||||
conn->callback_trigger = true;
|
||||
|
||||
zlog_info(conn->param.log, "%s:%d accpet new client: %s:%d, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, inet_ntoa(client.sin_addr),
|
||||
ntohs(client.sin_port), fd);
|
||||
zlog_notice(conn->param.log, "%s:%d accpet new client: %s:%d, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, inet_ntoa(client.sin_addr),
|
||||
ntohs(client.sin_port), fd);
|
||||
|
||||
pthread_mutex_unlock(&conn->mtx);
|
||||
|
||||
@@ -237,6 +238,8 @@ int neu_conn_tcp_server_close_client(neu_conn_t *conn, int fd)
|
||||
|
||||
conn->disconnected(conn->data, fd);
|
||||
conn_tcp_server_del_client(conn, fd);
|
||||
conn->offset = 0;
|
||||
memset(conn->buf, 0, conn->buf_size);
|
||||
|
||||
pthread_mutex_unlock(&conn->mtx);
|
||||
return 0;
|
||||
@@ -338,8 +341,14 @@ ssize_t neu_conn_send(neu_conn_t *conn, uint8_t *buf, ssize_t len)
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
}
|
||||
|
||||
if (ret == -1 && errno != EAGAIN) {
|
||||
conn_disconnect(conn);
|
||||
if (ret == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
conn_disconnect(conn);
|
||||
} else {
|
||||
if (conn->connection_ok == true) {
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret > 0 && conn->callback_trigger == false) {
|
||||
@@ -350,6 +359,7 @@ ssize_t neu_conn_send(neu_conn_t *conn, uint8_t *buf, ssize_t len)
|
||||
|
||||
if (ret > 0) {
|
||||
conn->state.send_bytes += ret;
|
||||
conn->connection_ok = true;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&conn->mtx);
|
||||
@@ -395,19 +405,23 @@ ssize_t neu_conn_recv(neu_conn_t *conn, uint8_t *buf, ssize_t len)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (ret <= 0) {
|
||||
zlog_error(conn->param.log,
|
||||
"conn fd: %d, recv buf len %zd, ret: %zd, errno: %s(%d)",
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
}
|
||||
|
||||
if (errno == EPIPE || ret == -1 || (ret == 0 && errno != 0)) {
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
|
||||
if (ret > 0 && conn->callback_trigger == false) {
|
||||
conn->connected(conn->data, conn->fd);
|
||||
conn->callback_trigger = true;
|
||||
if (conn->param.type == NEU_CONN_TTY_CLIENT) {
|
||||
if (ret == -1) {
|
||||
zlog_error(
|
||||
conn->param.log,
|
||||
"tty conn fd: %d, recv buf len %zd, ret: %zd, errno: %s(%d)",
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
} else {
|
||||
if (ret <= 0) {
|
||||
zlog_error(conn->param.log,
|
||||
"conn fd: %d, recv buf len %zd, ret: %zd, errno: %s(%d)",
|
||||
conn->fd, len, ret, strerror(errno), errno);
|
||||
if (ret == 0 || (ret == -1 && errno != EAGAIN)) {
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&conn->mtx);
|
||||
@@ -487,6 +501,10 @@ static void conn_init_param(neu_conn_t *conn, neu_conn_param_t *param)
|
||||
} else {
|
||||
conn->block = false;
|
||||
}
|
||||
zlog_notice(conn->param.log, "tcp server %s:%d, timeout: %d, block: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port,
|
||||
conn->param.params.tcp_server.timeout, conn->block);
|
||||
break;
|
||||
case NEU_CONN_TCP_CLIENT:
|
||||
conn->param.params.tcp_client.ip = strdup(param->params.tcp_client.ip);
|
||||
@@ -494,6 +512,10 @@ static void conn_init_param(neu_conn_t *conn, neu_conn_param_t *param)
|
||||
conn->param.params.tcp_client.timeout =
|
||||
param->params.tcp_client.timeout;
|
||||
conn->block = conn->param.params.tcp_client.timeout > 0;
|
||||
zlog_notice(conn->param.log, "tcp client %s:%d, timeout: %d, block: %d",
|
||||
conn->param.params.tcp_client.ip,
|
||||
conn->param.params.tcp_client.port,
|
||||
conn->param.params.tcp_client.timeout, conn->block);
|
||||
break;
|
||||
case NEU_CONN_UDP:
|
||||
conn->param.params.udp.src_ip = strdup(param->params.udp.src_ip);
|
||||
@@ -502,6 +524,11 @@ static void conn_init_param(neu_conn_t *conn, neu_conn_param_t *param)
|
||||
conn->param.params.udp.dst_port = param->params.udp.dst_port;
|
||||
conn->param.params.udp.timeout = param->params.udp.timeout;
|
||||
conn->block = conn->param.params.udp.timeout > 0;
|
||||
zlog_notice(
|
||||
conn->param.log, "udp %s:%d -> %s:%d, timeout: %d, block: %d",
|
||||
conn->param.params.udp.src_ip, conn->param.params.udp.src_port,
|
||||
conn->param.params.udp.dst_ip, conn->param.params.udp.dst_port,
|
||||
conn->param.params.udp.timeout, conn->block);
|
||||
break;
|
||||
case NEU_CONN_TTY_CLIENT:
|
||||
conn->param.params.tty_client.device =
|
||||
@@ -552,9 +579,9 @@ static void conn_tcp_server_listen(neu_conn_t *conn)
|
||||
conn->tcp_server.is_listen = true;
|
||||
|
||||
conn->param.params.tcp_server.start_listen(conn->data, fd);
|
||||
zlog_info(conn->param.log, "tcp server listen %s:%d success, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, fd);
|
||||
zlog_notice(conn->param.log, "tcp server listen %s:%d success, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, fd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,9 +589,9 @@ static void conn_tcp_server_stop(neu_conn_t *conn)
|
||||
{
|
||||
if (conn->param.type == NEU_CONN_TCP_SERVER &&
|
||||
conn->tcp_server.is_listen == true) {
|
||||
zlog_info(conn->param.log, "tcp server close %s:%d, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, conn->fd);
|
||||
zlog_notice(conn->param.log, "tcp server close %s:%d, fd: %d",
|
||||
conn->param.params.tcp_server.ip,
|
||||
conn->param.params.tcp_server.port, conn->fd);
|
||||
|
||||
conn->param.params.tcp_server.stop_listen(conn->data, conn->fd);
|
||||
|
||||
@@ -624,9 +651,9 @@ static void conn_connect(neu_conn_t *conn)
|
||||
conn->is_connected = false;
|
||||
return;
|
||||
} else {
|
||||
zlog_info(conn->param.log, "connect %s:%d success",
|
||||
conn->param.params.tcp_client.ip,
|
||||
conn->param.params.tcp_client.port);
|
||||
zlog_notice(conn->param.log, "connect %s:%d, block: %d success",
|
||||
conn->param.params.tcp_client.ip,
|
||||
conn->param.params.tcp_client.port, conn->block);
|
||||
conn->is_connected = true;
|
||||
conn->fd = fd;
|
||||
}
|
||||
@@ -679,9 +706,9 @@ static void conn_connect(neu_conn_t *conn)
|
||||
conn->is_connected = false;
|
||||
return;
|
||||
} else {
|
||||
zlog_info(conn->param.log, "connect %s:%d success",
|
||||
conn->param.params.udp.dst_ip,
|
||||
conn->param.params.udp.dst_port);
|
||||
zlog_notice(conn->param.log, "connect %s:%d success",
|
||||
conn->param.params.udp.dst_ip,
|
||||
conn->param.params.udp.dst_port);
|
||||
conn->is_connected = true;
|
||||
conn->fd = fd;
|
||||
}
|
||||
@@ -846,6 +873,15 @@ static void conn_connect(neu_conn_t *conn)
|
||||
|
||||
static void conn_disconnect(neu_conn_t *conn)
|
||||
{
|
||||
conn->is_connected = false;
|
||||
conn->connection_ok = false;
|
||||
if (conn->callback_trigger == true) {
|
||||
conn->disconnected(conn->data, conn->fd);
|
||||
conn->callback_trigger = false;
|
||||
}
|
||||
conn->offset = 0;
|
||||
memset(conn->buf, 0, conn->buf_size);
|
||||
|
||||
switch (conn->param.type) {
|
||||
case NEU_CONN_TCP_SERVER:
|
||||
for (int i = 0; i < conn->param.params.tcp_server.max_link; i++) {
|
||||
@@ -865,14 +901,6 @@ static void conn_disconnect(neu_conn_t *conn)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
conn->is_connected = false;
|
||||
if (conn->callback_trigger == true) {
|
||||
conn->disconnected(conn->data, conn->fd);
|
||||
conn->callback_trigger = false;
|
||||
}
|
||||
conn->offset = 0;
|
||||
memset(conn->buf, 0, conn->buf_size);
|
||||
}
|
||||
|
||||
static void conn_tcp_server_add_client(neu_conn_t *conn, int fd,
|
||||
@@ -940,8 +968,7 @@ int neu_conn_stream_consume(neu_conn_t *conn, void *context,
|
||||
if (used == 0) {
|
||||
break;
|
||||
} else if (used == -1) {
|
||||
memset(conn->buf, 0, conn->buf_size);
|
||||
conn->offset = 0;
|
||||
neu_conn_disconnect(conn);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -972,8 +999,7 @@ int neu_conn_stream_tcp_server_consume(neu_conn_t *conn, int fd, void *context,
|
||||
if (used == 0) {
|
||||
break;
|
||||
} else if (used == -1) {
|
||||
memset(conn->buf, 0, conn->buf_size);
|
||||
conn->offset = 0;
|
||||
neu_conn_tcp_server_close_client(conn, fd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1001,9 +1027,20 @@ int neu_conn_wait_msg(neu_conn_t *conn, void *context, uint16_t n_byte,
|
||||
neu_protocol_unpack_buf_init(&pbuf, conn->buf, conn->offset);
|
||||
neu_buf_result_t result = fn(context, &pbuf);
|
||||
if (result.need > 0) {
|
||||
assert(result.need <= conn->buf_size - conn->offset);
|
||||
ret = neu_conn_recv(conn, conn->buf + conn->offset, result.need);
|
||||
if (result.need <= conn->buf_size - conn->offset) {
|
||||
ret =
|
||||
neu_conn_recv(conn, conn->buf + conn->offset, result.need);
|
||||
} else {
|
||||
zlog_error(conn->param.log,
|
||||
"no enough recv buf, need: %" PRIu16
|
||||
" , buf size: %" PRIu16 " offset: %" PRIu16,
|
||||
result.need, conn->buf_size, conn->offset);
|
||||
return -1;
|
||||
}
|
||||
} else if (result.need == 0) {
|
||||
return result.used;
|
||||
} else {
|
||||
neu_conn_disconnect(conn);
|
||||
return result.used;
|
||||
}
|
||||
}
|
||||
@@ -1025,9 +1062,20 @@ int neu_conn_tcp_server_wait_msg(neu_conn_t *conn, int fd, void *context,
|
||||
neu_buf_result_t result = fn(context, &pbuf);
|
||||
if (result.need > 0) {
|
||||
assert(result.need <= conn->buf_size - conn->offset);
|
||||
ret = neu_conn_tcp_server_recv(conn, fd, conn->buf + conn->offset,
|
||||
result.need);
|
||||
if (result.need <= conn->buf_size - conn->offset) {
|
||||
ret = neu_conn_tcp_server_recv(
|
||||
conn, fd, conn->buf + conn->offset, result.need);
|
||||
} else {
|
||||
zlog_error(conn->param.log,
|
||||
"no enough recv buf, need: %" PRIu16
|
||||
" , buf size: %" PRIu16 " offset: %" PRIu16,
|
||||
result.need, conn->buf_size, conn->offset);
|
||||
return -1;
|
||||
}
|
||||
} else if (result.need == 0) {
|
||||
return result.used;
|
||||
} else {
|
||||
neu_conn_tcp_server_close_client(conn, fd);
|
||||
return result.used;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,14 +287,14 @@ static void task_handle_sub(task_t *task, neu_mqtt_client_t *client)
|
||||
}
|
||||
|
||||
rc = nng_mqtt_msg_get_suback_return_codes(msg, &n);
|
||||
log(info, "recv SUBACK return_code:%d", *rc);
|
||||
log(debug, "recv SUBACK return_code:%d", *rc);
|
||||
rv = 0x80 == *rc ? -1 : 0;
|
||||
task->sub->ack = true;
|
||||
client->suback_count += 1;
|
||||
|
||||
end:
|
||||
// TODO: handle retry subscribe on failure
|
||||
log(info, "sub [%s, QoS%d], %s", task->sub->topic, task->sub->qos,
|
||||
log(notice, "sub [%s, QoS%d], %s", task->sub->topic, task->sub->qos,
|
||||
(0 == rv) ? "OK" : "FAIL");
|
||||
nng_msg_free(msg);
|
||||
return;
|
||||
@@ -326,10 +326,10 @@ static void task_handle_unsub(task_t *task, neu_mqtt_client_t *client)
|
||||
|
||||
end:
|
||||
if (task->sub) {
|
||||
log(info, "unsub [%s, QoS%d], %s", task->sub->topic, task->sub->qos,
|
||||
log(notice, "unsub [%s, QoS%d], %s", task->sub->topic, task->sub->qos,
|
||||
(0 == rv) ? "OK" : "FAIL");
|
||||
} else {
|
||||
log(info, "unsub %s", (0 == rv) ? "OK" : "FAIL");
|
||||
log(notice, "unsub %s", (0 == rv) ? "OK" : "FAIL");
|
||||
}
|
||||
nng_msg_free(msg);
|
||||
return;
|
||||
@@ -431,7 +431,7 @@ static void connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
|
||||
neu_mqtt_client_connection_cb_t cb = NULL;
|
||||
void * data = NULL;
|
||||
|
||||
log(info, "mqtt client connected");
|
||||
log(notice, "mqtt client connected");
|
||||
|
||||
nng_mtx_lock(client->mtx);
|
||||
// start receiving
|
||||
@@ -457,7 +457,7 @@ static void disconnect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
|
||||
neu_mqtt_client_connection_cb_t cb = NULL;
|
||||
void * data = NULL;
|
||||
|
||||
log(info, "mqtt client disconnected");
|
||||
log(notice, "mqtt client disconnected");
|
||||
nng_mtx_lock(client->mtx);
|
||||
client->connected = false;
|
||||
cb = client->disconnect_cb;
|
||||
@@ -511,7 +511,7 @@ static void recv_cb(void *arg)
|
||||
uint8_t qos = nng_mqtt_msg_get_publish_qos(msg);
|
||||
|
||||
(void) payload;
|
||||
log(info, "recv [%.*s, QoS%d] %" PRIu32 " bytes", (unsigned) topic_len,
|
||||
log(debug, "recv [%.*s, QoS%d] %" PRIu32 " bytes", (unsigned) topic_len,
|
||||
topic, (int) qos, payload_len);
|
||||
|
||||
// find matching subscription
|
||||
@@ -565,7 +565,7 @@ static inline task_t *client_alloc_task(neu_mqtt_client_t *client)
|
||||
// the task queue length should be a small number due to reuse
|
||||
// log info every time the task queue length increments by 32
|
||||
if (0 == (client->task_count & (32 - 1))) {
|
||||
log(info, "task queue length: %zu", client->task_count);
|
||||
log(debug, "task queue length: %zu", client->task_count);
|
||||
}
|
||||
|
||||
return task;
|
||||
@@ -1017,7 +1017,7 @@ int neu_mqtt_client_set_tls(neu_mqtt_client_t *client, const char *ca,
|
||||
|
||||
if (NULL == ca) {
|
||||
// disable tls
|
||||
log(info, "tls disabled");
|
||||
log(debug, "tls disabled");
|
||||
if (client->tls_cfg) {
|
||||
nng_tls_config_free(client->tls_cfg);
|
||||
client->tls_cfg = NULL;
|
||||
@@ -1077,7 +1077,7 @@ int neu_mqtt_client_set_cache_size(neu_mqtt_client_t *client,
|
||||
|
||||
if (0 == mem_size_bytes && 0 == db_size_bytes) {
|
||||
// disable cache
|
||||
log(info, "cache disabled");
|
||||
log(debug, "cache disabled");
|
||||
if (client->sqlite_cfg) {
|
||||
nng_mqtt_free_sqlite_opt(client->sqlite_cfg);
|
||||
client->sqlite_cfg = NULL;
|
||||
|
||||
+12
-7
@@ -136,6 +136,7 @@ neu_manager_t *neu_manager_create()
|
||||
manager->timer_timestamp =
|
||||
neu_event_add_timer(manager->events, timestamp_timer_param);
|
||||
|
||||
nlog_notice("manager start");
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -178,7 +179,7 @@ void neu_manager_destroy(neu_manager_t *manager)
|
||||
neu_event_close(manager->events);
|
||||
|
||||
free(manager);
|
||||
nlog_warn("manager exit");
|
||||
nlog_notice("manager exit");
|
||||
}
|
||||
|
||||
const char *neu_manager_get_url()
|
||||
@@ -229,8 +230,8 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
|
||||
header = (neu_reqresp_head_t *) nng_msg_body(msg);
|
||||
|
||||
nlog_debug("manager recv msg from: %s to %s, type: %s", header->sender,
|
||||
header->receiver, neu_reqresp_type_string(header->type));
|
||||
nlog_info("manager recv msg from: %s to %s, type: %s", header->sender,
|
||||
header->receiver, neu_reqresp_type_string(header->type));
|
||||
switch (header->type) {
|
||||
case NEU_REQRESP_TRANS_DATA: {
|
||||
neu_reqresp_trans_data_t *cmd = (neu_reqresp_trans_data_t *) &header[1];
|
||||
@@ -254,7 +255,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
utarray_foreach(pipes, nng_pipe *, pipe)
|
||||
{
|
||||
forward_msg_dup(manager, msg, *pipe);
|
||||
nlog_info("forward license update to pipe: %d", pipe->id);
|
||||
nlog_notice("forward license update to pipe: %d", pipe->id);
|
||||
}
|
||||
utarray_free(pipes);
|
||||
|
||||
@@ -266,10 +267,14 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
|
||||
neu_node_manager_update(manager->node_manager, init->node, pipe);
|
||||
|
||||
if (init->auto_start) {
|
||||
if (init->state == NEU_NODE_RUNNING_STATE_STOPPED ||
|
||||
init->state == NEU_NODE_RUNNING_STATE_RUNNING) {
|
||||
neu_adapter_t *adapter =
|
||||
neu_node_manager_find(manager->node_manager, init->node);
|
||||
neu_adapter_start(adapter);
|
||||
if (init->state == NEU_NODE_RUNNING_STATE_STOPPED) {
|
||||
neu_adapter_stop(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
nlog_notice("bind node %s to pipe(%d)", init->node, pipe.id);
|
||||
@@ -730,7 +735,7 @@ inline static void forward_msg_dup(neu_manager_t *manager, nng_msg *msg,
|
||||
nng_msg_dup(&out_msg, msg);
|
||||
nng_msg_set_pipe(out_msg, pipe);
|
||||
if (nng_sendmsg(manager->socket, out_msg, 0) == 0) {
|
||||
nlog_debug("forward msg to pipe %d", pipe.id);
|
||||
nlog_info("forward msg to pipe %d", pipe.id);
|
||||
} else {
|
||||
nlog_warn("forward msg to pipe %d fail", pipe.id);
|
||||
nng_msg_free(out_msg);
|
||||
@@ -746,7 +751,7 @@ inline static void forward_msg(neu_manager_t *manager, nng_msg *msg,
|
||||
nng_msg_dup(&out_msg, msg);
|
||||
nng_msg_set_pipe(out_msg, pipe);
|
||||
if (nng_sendmsg(manager->socket, out_msg, 0) == 0) {
|
||||
nlog_debug("forward msg to %s", node);
|
||||
nlog_info("forward msg to %s", node);
|
||||
} else {
|
||||
nlog_warn("forward msg to pipe (%s)%d fail", node, pipe.id);
|
||||
nng_msg_free(out_msg);
|
||||
|
||||
@@ -43,7 +43,8 @@ UT_array *neu_manager_get_plugins(neu_manager_t *manager)
|
||||
}
|
||||
|
||||
int neu_manager_add_node(neu_manager_t *manager, const char *node_name,
|
||||
const char *plugin_name, bool start)
|
||||
const char * plugin_name,
|
||||
neu_node_running_state_e state)
|
||||
{
|
||||
neu_adapter_t * adapter = NULL;
|
||||
neu_plugin_instance_t instance = { 0 };
|
||||
@@ -77,7 +78,7 @@ int neu_manager_add_node(neu_manager_t *manager, const char *node_name,
|
||||
|
||||
adapter = neu_adapter_create(&adapter_info);
|
||||
neu_node_manager_add(manager->node_manager, adapter);
|
||||
neu_adapter_init(adapter, start);
|
||||
neu_adapter_init(adapter, state);
|
||||
|
||||
return NEU_ERR_SUCCESS;
|
||||
}
|
||||
@@ -324,8 +325,10 @@ int neu_manager_send_subscribe(neu_manager_t *manager, const char *app,
|
||||
nng_msg_set_pipe(out_msg, pipe);
|
||||
|
||||
if (nng_sendmsg(manager->socket, out_msg, 0) == 0) {
|
||||
nlog_info("send %s to %s", neu_reqresp_type_string(header.type), app);
|
||||
nlog_notice("send %s to %s", neu_reqresp_type_string(header.type), app);
|
||||
} else {
|
||||
nlog_warn("send %s to %s failed", neu_reqresp_type_string(header.type),
|
||||
app);
|
||||
free(cmd.params);
|
||||
nng_msg_free(out_msg);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ int neu_manager_del_plugin(neu_manager_t *manager, const char *plugin);
|
||||
UT_array *neu_manager_get_plugins(neu_manager_t *manager);
|
||||
|
||||
int neu_manager_add_node(neu_manager_t *manager, const char *node_name,
|
||||
const char *plugin_name, bool start);
|
||||
const char * plugin_name,
|
||||
neu_node_running_state_e state);
|
||||
int neu_manager_del_node(neu_manager_t *manager, const char *node_name);
|
||||
UT_array *neu_manager_get_nodes(neu_manager_t *manager, neu_node_type_e type,
|
||||
const char *plugin, const char *node);
|
||||
|
||||
+9
-10
@@ -96,7 +96,7 @@ int manager_load_plugin(neu_manager_t *manager)
|
||||
{
|
||||
rv = neu_manager_add_plugin(manager, *name);
|
||||
const char *ok_or_err = (0 == rv) ? "success" : "fail";
|
||||
nlog_info("load plugin %s, lib:%s", ok_or_err, *name);
|
||||
nlog_notice("load plugin %s, lib:%s", ok_or_err, *name);
|
||||
}
|
||||
|
||||
utarray_foreach(plugin_infos, char **, name) { free(*name); }
|
||||
@@ -118,13 +118,12 @@ int manager_load_node(neu_manager_t *manager)
|
||||
|
||||
utarray_foreach(node_infos, neu_persist_node_info_t *, node_info)
|
||||
{
|
||||
rv = neu_manager_add_node(
|
||||
manager, node_info->name, node_info->plugin_name,
|
||||
node_info->state == NEU_NODE_RUNNING_STATE_RUNNING);
|
||||
rv = neu_manager_add_node(manager, node_info->name,
|
||||
node_info->plugin_name, node_info->state);
|
||||
const char *ok_or_err = (0 == rv) ? "success" : "fail";
|
||||
nlog_info("load adapter %s type:%d, name:%s plugin:%s state:%d",
|
||||
ok_or_err, node_info->type, node_info->name,
|
||||
node_info->plugin_name, node_info->state);
|
||||
nlog_notice("load adapter %s type:%d, name:%s plugin:%s state:%d",
|
||||
ok_or_err, node_info->type, node_info->name,
|
||||
node_info->plugin_name, node_info->state);
|
||||
}
|
||||
|
||||
utarray_free(node_infos);
|
||||
@@ -151,9 +150,9 @@ int manager_load_subscribe(neu_manager_t *manager)
|
||||
info->driver_name, info->group_name,
|
||||
info->params);
|
||||
const char *ok_or_err = (0 == rv) ? "success" : "fail";
|
||||
nlog_info("%s load subscription app:%s driver:%s grp:%s",
|
||||
ok_or_err, node->node, info->driver_name,
|
||||
info->group_name);
|
||||
nlog_notice("%s load subscription app:%s driver:%s grp:%s",
|
||||
ok_or_err, node->node, info->driver_name,
|
||||
info->group_name);
|
||||
if (0 == rv) {
|
||||
neu_manager_send_subscribe(manager, node->node,
|
||||
info->driver_name,
|
||||
|
||||
@@ -129,6 +129,8 @@ int neuron_already_running()
|
||||
|
||||
snprintf(buf, sizeof(buf), "%ld", (long) getpid());
|
||||
size = write(fd, buf, strlen(buf) + 1);
|
||||
nlog_warn("write %s, error %s(%d)", NEURON_DAEMON_LOCK_FNAME,
|
||||
strerror(errno), errno);
|
||||
assert(size != -1);
|
||||
|
||||
return 0;
|
||||
|
||||
+11
-10
@@ -205,19 +205,20 @@ neu_event_timer_t *neu_event_add_timer(neu_events_t * events,
|
||||
|
||||
ret = epoll_ctl(events->epoll_fd, EPOLL_CTL_ADD, timer_fd, &event);
|
||||
|
||||
zlog_info(neuron,
|
||||
"add timer, second: %" PRId64 ", millisecond: %" PRId64
|
||||
", timer: %d in epoll %d, "
|
||||
"ret: %d",
|
||||
timer.second, timer.millisecond, timer_fd, events->epoll_fd, ret);
|
||||
zlog_notice(neuron,
|
||||
"add timer, second: %" PRId64 ", millisecond: %" PRId64
|
||||
", timer: %d in epoll %d, "
|
||||
"ret: %d",
|
||||
timer.second, timer.millisecond, timer_fd, events->epoll_fd,
|
||||
ret);
|
||||
|
||||
return timer_ctx;
|
||||
}
|
||||
|
||||
int neu_event_del_timer(neu_events_t *events, neu_event_timer_t *timer)
|
||||
{
|
||||
zlog_info(neuron, "del timer: %d from epoll: %d", timer->fd,
|
||||
events->epoll_fd);
|
||||
zlog_notice(neuron, "del timer: %d from epoll: %d", timer->fd,
|
||||
events->epoll_fd);
|
||||
|
||||
timer->stop = true;
|
||||
nng_mtx_lock(timer->mtx);
|
||||
@@ -251,8 +252,8 @@ neu_event_io_t *neu_event_add_io(neu_events_t *events, neu_event_io_param_t io)
|
||||
|
||||
ret = epoll_ctl(events->epoll_fd, EPOLL_CTL_ADD, io.fd, &event);
|
||||
|
||||
nlog_info("add io, fd: %d, epoll: %d, ret: %d", io.fd, events->epoll_fd,
|
||||
ret);
|
||||
nlog_notice("add io, fd: %d, epoll: %d, ret: %d", io.fd, events->epoll_fd,
|
||||
ret);
|
||||
|
||||
return io_ctx;
|
||||
}
|
||||
@@ -260,7 +261,7 @@ neu_event_io_t *neu_event_add_io(neu_events_t *events, neu_event_io_param_t io)
|
||||
int neu_event_del_io(neu_events_t *events, neu_event_io_t *io)
|
||||
{
|
||||
struct event_data *data = (struct event_data *) io->event_data;
|
||||
zlog_info(neuron, "del io: %d from epoll: %d", io->fd, events->epoll_fd);
|
||||
zlog_notice(neuron, "del io: %d from epoll: %d", io->fd, events->epoll_fd);
|
||||
|
||||
epoll_ctl(events->epoll_fd, EPOLL_CTL_DEL, io->fd, NULL);
|
||||
switch (data->type) {
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ static bool exit_flag = false;
|
||||
static neu_manager_t *g_manager = NULL;
|
||||
zlog_category_t * neuron = NULL;
|
||||
bool disable_jwt = false;
|
||||
int default_log_level = ZLOG_LEVEL_INFO;
|
||||
int default_log_level = ZLOG_LEVEL_NOTICE;
|
||||
|
||||
int64_t global_timestamp = 0;
|
||||
|
||||
|
||||
@@ -199,7 +199,8 @@ int neu_json_tag_check_type(neu_json_tag_t *tag)
|
||||
return NEU_JSON_BOOL == tag->t;
|
||||
case NEU_TYPE_BYTES:
|
||||
case NEU_TYPE_STRING:
|
||||
return NEU_JSON_STR == tag->t;
|
||||
return NEU_JSON_STR == tag->t &&
|
||||
strlen(tag->value.val_str) <= NEU_VALUE_SIZE;
|
||||
}
|
||||
} else {
|
||||
// non-static tag should have no initial value
|
||||
|
||||
+117
-17
@@ -25,6 +25,7 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -49,9 +50,12 @@
|
||||
|
||||
#define PATH_MAX_SIZE 128
|
||||
|
||||
static const char *plugin_file = "persistence/plugins.json";
|
||||
static const char *db_file = "persistence/sqlite.db";
|
||||
static sqlite3 * global_db = NULL;
|
||||
static const char *plugin_file = "persistence/plugins.json";
|
||||
static const char *db_file = "persistence/sqlite.db";
|
||||
static sqlite3 * global_db = NULL;
|
||||
pthread_rwlock_t global_rwlock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
static int global_node_count = 0;
|
||||
static int global_tag_count = 0;
|
||||
|
||||
static inline bool ends_with(const char *str, const char *suffix)
|
||||
{
|
||||
@@ -383,8 +387,8 @@ static int apply_schema_file(sqlite3 *db, const char *dir, const char *file)
|
||||
|
||||
end:
|
||||
if (0 == rv) {
|
||||
nlog_info("success apply schema `%s`, version=`%s` description=`%s`",
|
||||
path, version, description);
|
||||
nlog_notice("success apply schema `%s`, version=`%s` description=`%s`",
|
||||
path, version, description);
|
||||
} else {
|
||||
nlog_error("fail apply schema `%s`, version=`%s` description=`%s`",
|
||||
path, version, description);
|
||||
@@ -441,7 +445,7 @@ static int apply_schemas(sqlite3 *db, const char *dir)
|
||||
return NEU_ERR_EINTERNAL;
|
||||
}
|
||||
|
||||
nlog_info("schema head version=%s", version ? version : "none");
|
||||
nlog_notice("schema head version=%s", version ? version : "none");
|
||||
|
||||
if (dirty) {
|
||||
nlog_error("database is dirty, need manual intervention");
|
||||
@@ -474,6 +478,44 @@ static int apply_schemas(sqlite3 *db, const char *dir)
|
||||
return rv;
|
||||
}
|
||||
|
||||
static inline int node_count_load()
|
||||
{
|
||||
int rv = 0;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char * query = "select count(*) from nodes";
|
||||
|
||||
if (SQLITE_OK == sqlite3_prepare_v2(global_db, query, -1, &stmt, NULL) &&
|
||||
SQLITE_ROW == sqlite3_step(stmt)) {
|
||||
pthread_rwlock_wrlock(&global_rwlock);
|
||||
global_node_count = sqlite3_column_int(stmt, 0);
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static inline int tag_count_load()
|
||||
{
|
||||
int rv = 0;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char * query = "select count(*) from tags";
|
||||
|
||||
if (SQLITE_OK == sqlite3_prepare_v2(global_db, query, -1, &stmt, NULL) &&
|
||||
SQLITE_ROW == sqlite3_step(stmt)) {
|
||||
pthread_rwlock_wrlock(&global_rwlock);
|
||||
global_tag_count = sqlite3_column_int(stmt, 0);
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int neu_persister_create(const char *schema_dir)
|
||||
{
|
||||
int rv = sqlite3_open(db_file, &global_db);
|
||||
@@ -506,6 +548,12 @@ int neu_persister_create(const char *schema_dir)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != node_count_load() || 0 != tag_count_load()) {
|
||||
nlog_fatal("load node/tag count fail");
|
||||
sqlite3_close(global_db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -514,6 +562,36 @@ sqlite3 *neu_persister_get_db()
|
||||
return global_db;
|
||||
}
|
||||
|
||||
static inline void node_count_add(int n)
|
||||
{
|
||||
pthread_rwlock_wrlock(&global_rwlock);
|
||||
global_node_count += n;
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
}
|
||||
|
||||
int neu_persister_node_count()
|
||||
{
|
||||
pthread_rwlock_rdlock(&global_rwlock);
|
||||
int cnt = global_node_count;
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static inline void tag_count_add(int n)
|
||||
{
|
||||
pthread_rwlock_wrlock(&global_rwlock);
|
||||
global_tag_count += n;
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
}
|
||||
|
||||
int neu_persister_tag_count()
|
||||
{
|
||||
pthread_rwlock_rdlock(&global_rwlock);
|
||||
int cnt = global_tag_count;
|
||||
pthread_rwlock_unlock(&global_rwlock);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void neu_persister_destroy()
|
||||
{
|
||||
sqlite3_close(global_db);
|
||||
@@ -521,10 +599,15 @@ void neu_persister_destroy()
|
||||
|
||||
int neu_persister_store_node(neu_persist_node_info_t *info)
|
||||
{
|
||||
return execute_sql(global_db,
|
||||
"INSERT INTO nodes (name, type, state, plugin_name) "
|
||||
"VALUES (%Q, %i, %i, %Q)",
|
||||
info->name, info->type, info->state, info->plugin_name);
|
||||
int rv =
|
||||
execute_sql(global_db,
|
||||
"INSERT INTO nodes (name, type, state, plugin_name) "
|
||||
"VALUES (%Q, %i, %i, %Q)",
|
||||
info->name, info->type, info->state, info->plugin_name);
|
||||
if (0 == rv) {
|
||||
node_count_add(1);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static UT_icd node_info_icd = {
|
||||
@@ -585,8 +668,13 @@ int neu_persister_delete_node(const char *node_name)
|
||||
{
|
||||
// rely on foreign key constraints to remove settings, groups, tags and
|
||||
// subscriptions
|
||||
return execute_sql(global_db, "DELETE FROM nodes WHERE name=%Q;",
|
||||
node_name);
|
||||
int rv =
|
||||
execute_sql(global_db, "DELETE FROM nodes WHERE name=%Q;", node_name);
|
||||
if (0 == rv) {
|
||||
node_count_add(-1);
|
||||
tag_count_load();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int neu_persister_update_node(const char *node_name, const char *new_name)
|
||||
@@ -716,6 +804,9 @@ int neu_persister_store_tag(const char *driver_name, const char *group_name,
|
||||
tag->attribute, tag->precision, tag->type,
|
||||
tag->decimal, tag->description, val_str);
|
||||
|
||||
if (0 == rv) {
|
||||
tag_count_add(1);
|
||||
}
|
||||
free(val_str);
|
||||
return rv;
|
||||
}
|
||||
@@ -821,11 +912,12 @@ int neu_persister_store_tags(const char *driver_name, const char *group_name,
|
||||
goto error;
|
||||
}
|
||||
|
||||
tag_count_add(n);
|
||||
sqlite3_finalize(stmt);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
nlog_info("rollback transaction");
|
||||
nlog_warn("rollback transaction");
|
||||
sqlite3_exec(global_db, "ROLLBACK", NULL, NULL, NULL);
|
||||
sqlite3_finalize(stmt);
|
||||
free(val_str);
|
||||
@@ -926,10 +1018,14 @@ int neu_persister_update_tag_value(const char * driver_name,
|
||||
int neu_persister_delete_tag(const char *driver_name, const char *group_name,
|
||||
const char *tag_name)
|
||||
{
|
||||
return execute_sql(
|
||||
int rv = execute_sql(
|
||||
global_db,
|
||||
"DELETE FROM tags WHERE driver_name=%Q AND group_name=%Q AND name=%Q",
|
||||
driver_name, group_name, tag_name);
|
||||
if (0 == rv) {
|
||||
tag_count_add(-1);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int neu_persister_store_subscription(const char *app_name,
|
||||
@@ -1101,9 +1197,13 @@ error:
|
||||
int neu_persister_delete_group(const char *driver_name, const char *group_name)
|
||||
{
|
||||
// rely on foreign key constraints to delete tags and subscriptions
|
||||
return execute_sql(global_db,
|
||||
"DELETE FROM groups WHERE driver_name=%Q AND name=%Q",
|
||||
driver_name, group_name);
|
||||
int rv = execute_sql(global_db,
|
||||
"DELETE FROM groups WHERE driver_name=%Q AND name=%Q",
|
||||
driver_name, group_name);
|
||||
if (0 == rv) {
|
||||
tag_count_load();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int neu_persister_store_node_setting(const char *node_name, const char *setting)
|
||||
|
||||
@@ -295,6 +295,8 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_MQTT_CONNECT_FAILURE:
|
||||
case NEU_ERR_MQTT_SUBSCRIBE_FAILURE:
|
||||
case NEU_ERR_MQTT_PUBLISH_FAILURE:
|
||||
case NEU_ERR_STRING_TOO_LONG:
|
||||
case NEU_ERR_FILE_WRITE_FAILURE:
|
||||
status = NNG_HTTP_STATUS_OK;
|
||||
break;
|
||||
case NEU_ERR_EINTERNAL:
|
||||
|
||||
Reference in New Issue
Block a user