mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 23:19:18 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a7016dc92 | ||
|
|
2d0c0a120a | ||
|
|
3bd8fddc03 | ||
|
|
770f797272 | ||
|
|
eb5c7462e1 | ||
|
|
34f0b19b81 | ||
|
|
105f1e64a7 | ||
|
|
f35e459a1c | ||
|
|
3ad96be5a3 | ||
|
|
8ef1b843ca | ||
|
|
87ba865774 | ||
|
|
582bf17b28 | ||
|
|
6d93894c15 | ||
|
|
5dfa8484b1 | ||
|
|
fe2b827655 | ||
|
|
3dfdc2a18b | ||
|
|
7025f71f7d | ||
|
|
8e0d796357 | ||
|
|
05a9ce7c5d | ||
|
|
0295ea0b8f | ||
|
|
b51a2ff374 | ||
|
|
b09b99864d | ||
|
|
719beafadc | ||
|
|
f888f1ec1c | ||
|
|
b567c91bc8 | ||
|
|
9128189f65 | ||
|
|
1443d0f546 | ||
|
|
7980eb4b71 | ||
|
|
98c522fde2 | ||
|
|
2c02652cd6 | ||
|
|
fec1b06df2 | ||
|
|
8a96a51abd | ||
|
|
597932ba8b | ||
|
|
d1f05991d4 | ||
|
|
b6a5ae2a12 | ||
|
|
7ed0abe9f6 | ||
|
|
6ba9d26027 | ||
|
|
f90ffbc5bd | ||
|
|
ede4f02369 | ||
|
|
b66b54943b | ||
|
|
2a043d4bbb | ||
|
|
33cc987da0 |
@@ -8,9 +8,9 @@ on:
|
||||
- published
|
||||
|
||||
env:
|
||||
VERSION: 2.3.0
|
||||
UI_VERSION: 2.3
|
||||
BRANCH: main
|
||||
VERSION: 2.3.3
|
||||
UI_VERSION: 2.3.2
|
||||
BRANCH: v2.3
|
||||
|
||||
jobs:
|
||||
cross-build:
|
||||
@@ -58,54 +58,6 @@ jobs:
|
||||
path: |
|
||||
neuron-sdk-*.tar.gz
|
||||
|
||||
cross-build-old:
|
||||
runs-on: ubuntu-18.04
|
||||
strategy:
|
||||
matrix:
|
||||
arch:
|
||||
- [aarch64-linux-gnu, aarch64, arm64]
|
||||
- [arm-linux-gnueabihf, armv4, armhf]
|
||||
- [x86_64-linux-gnu, x86_64, amd64]
|
||||
container: neugates/build_old:${{ matrix.arch[1] }}-2.3
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: troydhanson/uthash
|
||||
path: extern/uthash
|
||||
|
||||
- name: compile
|
||||
run: |
|
||||
git config --global --add safe.directory $(pwd)
|
||||
mkdir -p build && cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/${{ matrix.arch[0] }}.cmake \
|
||||
-DCMAKE_BUILD_TYPE=Release -DDISABLE_UT=ON
|
||||
make -j4
|
||||
|
||||
- name: fetch dashboard
|
||||
uses: dsaltares/fetch-gh-release-asset@master
|
||||
with:
|
||||
repo: "emqx/neuron-dashboard-src"
|
||||
version: "tags/${{ env.UI_VERSION }}"
|
||||
file: "neuron-dashboard.zip"
|
||||
target: "neuron-dashboard.zip"
|
||||
|
||||
- name: unpack dashboard
|
||||
run: |
|
||||
unzip neuron-dashboard.zip -d ./build
|
||||
|
||||
- name: Create neuron sdk package
|
||||
run: |
|
||||
./package-sdk.sh -p ${{ matrix.arch[2] }} -n neuron-sdk-old-$VERSION
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: neuron-sdk-old-${{ matrix.arch[2] }}
|
||||
path: |
|
||||
neuron-sdk-old-*.tar.gz
|
||||
|
||||
build-debug-sdk:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
@@ -178,7 +130,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [arm64, armhf, amd64]
|
||||
type: [neuron-sdk, neuron-sdk-old]
|
||||
type: [neuron-sdk]
|
||||
package: [tar.gz]
|
||||
|
||||
steps:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX aarch64-linux-gnu)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
set(LIBRARY_DIR /opt/externs/libs)
|
||||
set(LIBRARY_DIR /home/neuron/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
@@ -20,3 +20,5 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
link_directories(${CMAKE_STAGING_PREFIX})
|
||||
|
||||
file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX arm-linux-gnueabi)
|
||||
set(CMAKE_SYSTEM_PROCESSOR armv5tejl)
|
||||
set(LIBRARY_DIR /opt/externs/libs)
|
||||
set(LIBRARY_DIR /home/neuron/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
@@ -20,3 +20,5 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
link_directories(${CMAKE_STAGING_PREFIX})
|
||||
|
||||
file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX arm-linux-gnueabihf)
|
||||
set(CMAKE_SYSTEM_PROCESSOR armv7l)
|
||||
set(LIBRARY_DIR /opt/externs/libs)
|
||||
set(LIBRARY_DIR /home/neuron/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
@@ -20,3 +20,5 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
link_directories(${CMAKE_STAGING_PREFIX})
|
||||
|
||||
file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
|
||||
@@ -1,7 +1,24 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(COMPILER_PREFIX x86_64-linux-gnu)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
set(LIBRARY_DIR /usr/local)
|
||||
set(LIBRARY_DIR /home/neuron/libs)
|
||||
|
||||
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
|
||||
set(CMAKE_AR ${COMPILER_PREFIX}-ar)
|
||||
set(CMAKE_LINKER ${COMPILER_PREFIX}-ld)
|
||||
set(CMAKE_NM ${COMPILER_PREFIX}-nm)
|
||||
set(CMAKE_OBJDUMP ${COMPILER_PREFIX}-objdump)
|
||||
set(CMAKE_RANLIB ${COMPILER_PREFIX}-ranlib)
|
||||
set(CMAKE_STAGING_PREFIX ${LIBRARY_DIR}/${COMPILER_PREFIX})
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
|
||||
set(CMAKE_PREFIX_PATH ${CMAKE_STAGING_PREFIX})
|
||||
|
||||
include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/include)
|
||||
include_directories(SYSTEM ${CMAKE_STAGING_PREFIX}/openssl/include)
|
||||
set(CMAKE_FIND_ROOT_PATH ${CMAKE_STAGING_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
link_directories(${CMAKE_STAGING_PREFIX})
|
||||
|
||||
file(COPY ${CMAKE_STAGING_PREFIX}/lib/libzlog.so.1.2 DESTINATION /usr/local/lib)
|
||||
|
||||
@@ -414,6 +414,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
char driver[NEU_NODE_NAME_LEN];
|
||||
char group[NEU_GROUP_NAME_LEN];
|
||||
int64_t timestamp;
|
||||
uint16_t n_tag;
|
||||
neu_resp_tag_value_t tags[];
|
||||
} neu_reqresp_trans_data_t;
|
||||
|
||||
@@ -27,6 +27,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "errcodes.h"
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ cp -r build/dist ${package_name}/
|
||||
|
||||
cp build/neuron ${package_name}
|
||||
cp build/libneuron-base.so ${package_name}/lib
|
||||
cp /library/zlog/src/libzlog.so.1.2 ${package_name}/lib
|
||||
cp /usr/local/lib/libzlog.so.1.2 ${package_name}/lib
|
||||
|
||||
cp persistence/*.sql ${package_name}/config/
|
||||
|
||||
|
||||
@@ -32,15 +32,36 @@ VALUES
|
||||
"$5$PwFeXpBBIBZuZdZl$fP8fFPWCLoaWcnVXVSR.3Xi8TEqCvX92gjhowNNn6S4"
|
||||
);
|
||||
|
||||
--- Modify tags table ---
|
||||
BEGIN TRANSACTION;
|
||||
|
||||
ALTER TABLE nodes RENAME TO old_nodes;
|
||||
CREATE TABLE
|
||||
nodes (
|
||||
name TEXT PRIMARY KEY check(length(name) <= 128),
|
||||
type integer(1) NOT NULL check(type IN (1, 2)),
|
||||
state integer(1) NOT NULL check(state BETWEEN 1 AND 4),
|
||||
plugin_name TEXT NOT NULL check(length(plugin_name) <= 32)
|
||||
);
|
||||
INSERT INTO nodes SELECT * FROM old_nodes;
|
||||
|
||||
ALTER TABLE groups RENAME TO old_groups;
|
||||
CREATE TABLE IF NOT EXISTS
|
||||
groups (
|
||||
driver_name TEXT NOT NULL,
|
||||
name TEXT NULL check(length(name) <= 128),
|
||||
interval INTEGER NOT NULL check(interval >= 100),
|
||||
UNIQUE (driver_name, name),
|
||||
FOREIGN KEY (driver_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO groups SELECT * FROM old_groups;
|
||||
|
||||
ALTER TABLE tags RENAME TO old_tags;
|
||||
CREATE TABLE IF NOT EXISTS
|
||||
tags (
|
||||
driver_name TEXT NOT NULL,
|
||||
group_name TEXT NOT NULL,
|
||||
name TEXT NULL check(length(name) <= 32),
|
||||
address TEXT NULL check(length(address) <= 64),
|
||||
name TEXT NULL check(length(name) <= 64),
|
||||
address TEXT NULL check(length(address) <= 128),
|
||||
attribute INTEGER NOT NULL check(attribute BETWEEN 0 AND 7),
|
||||
precision INTEGER NOT NULL check(precision BETWEEN 0 AND 17),
|
||||
decimal REAL NOT NULL,
|
||||
@@ -50,5 +71,33 @@ CREATE TABLE IF NOT EXISTS
|
||||
FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO tags SELECT * FROM old_tags;
|
||||
DROP TABLE old_tags;
|
||||
|
||||
ALTER TABLE subscriptions RENAME TO old_subscriptions;
|
||||
CREATE TABLE IF NOT EXISTS
|
||||
subscriptions (
|
||||
app_name TEXT NOT NULL,
|
||||
driver_name TEXT NOT NULL,
|
||||
group_name TEXT NOT NULL,
|
||||
CHECK (app_name != driver_name),
|
||||
UNIQUE (app_name, driver_name, group_name),
|
||||
FOREIGN KEY (app_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO subscriptions SELECT * FROM old_subscriptions;
|
||||
|
||||
ALTER TABLE settings RENAME TO old_settings;
|
||||
CREATE TABLE IF NOT EXISTS
|
||||
settings (
|
||||
node_name TEXT NOT NULL,
|
||||
setting TEXT NOT NULL,
|
||||
UNIQUE (node_name),
|
||||
FOREIGN KEY (node_name) REFERENCES nodes (name) ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO settings SELECT * FROM old_settings;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS
|
||||
node_cache (
|
||||
node_name TEXT NOT NULL,
|
||||
cache TEXT NOT NULL
|
||||
);
|
||||
COMMIT;
|
||||
@@ -201,7 +201,7 @@ int json_encode_read_resp(void *json_object, void *param)
|
||||
|
||||
json_read_resp_header_t header = { .group_name = trans_data->group,
|
||||
.node_name = trans_data->driver,
|
||||
.timestamp = global_timestamp };
|
||||
.timestamp = trans_data->timestamp };
|
||||
|
||||
ret = json_encode_read_resp_header(json_object, &header);
|
||||
if (0 != ret) {
|
||||
|
||||
@@ -242,7 +242,6 @@ void handle_get_metric(nng_aio *aio)
|
||||
FILE * stream = NULL;
|
||||
neu_plugin_t *plugin = neu_monitor_get_plugin();
|
||||
|
||||
VALIDATE_JWT(aio);
|
||||
neu_metrics_category_e cat = NEU_METRICS_CATEGORY_ALL;
|
||||
size_t cat_param_len = 0;
|
||||
const char *cat_param = http_get_param(aio, "category", &cat_param_len);
|
||||
|
||||
@@ -19,16 +19,6 @@
|
||||
"length": 255
|
||||
}
|
||||
},
|
||||
"heartbeat-topic": {
|
||||
"name": "heartbeat topic",
|
||||
"description": "Topic to which publish heartbeat messages.",
|
||||
"type": "string",
|
||||
"attribute": "required",
|
||||
"default": "/neuron/${node-name}/heartbeat",
|
||||
"valid": {
|
||||
"length": 255
|
||||
}
|
||||
},
|
||||
"format": {
|
||||
"name": "upload format",
|
||||
"description": "JSON format of the data reported in the upload topic. In values mode, data are split into `values` and `errors` sub objects. In tags mode, tag data are put in a single array.",
|
||||
|
||||
+10
-22
@@ -122,13 +122,11 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
char * err_param = NULL;
|
||||
const char *placeholder = "********";
|
||||
|
||||
neu_json_elem_t client_id = { .name = "client-id", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t upload_topic = { .name = "upload-topic",
|
||||
neu_json_elem_t client_id = { .name = "client-id", .t = NEU_JSON_STR };
|
||||
neu_json_elem_t upload_topic = { .name = "upload-topic",
|
||||
.t = NEU_JSON_STR };
|
||||
neu_json_elem_t heartbeat_topic = { .name = "heartbeat-topic",
|
||||
.t = NEU_JSON_STR };
|
||||
neu_json_elem_t format = { .name = "format", .t = NEU_JSON_INT };
|
||||
neu_json_elem_t cache_mem_size = { .name = "cache-mem-size",
|
||||
neu_json_elem_t format = { .name = "format", .t = NEU_JSON_INT };
|
||||
neu_json_elem_t cache_mem_size = { .name = "cache-mem-size",
|
||||
.t = NEU_JSON_INT };
|
||||
neu_json_elem_t cache_disk_size = { .name = "cache-disk-size",
|
||||
.t = NEU_JSON_INT };
|
||||
@@ -147,9 +145,9 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = neu_parse_param(setting, &err_param, 8, &client_id, &upload_topic,
|
||||
&heartbeat_topic, &format, &cache_mem_size,
|
||||
&cache_disk_size, &host, &port);
|
||||
ret = neu_parse_param(setting, &err_param, 7, &client_id, &upload_topic,
|
||||
&format, &cache_mem_size, &cache_disk_size, &host,
|
||||
&port);
|
||||
if (0 != ret) {
|
||||
plog_error(plugin, "parsing setting fail, key: `%s`", err_param);
|
||||
goto error;
|
||||
@@ -167,12 +165,6 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
goto error;
|
||||
}
|
||||
|
||||
// heartbeat-topic, required
|
||||
if (0 == strlen(heartbeat_topic.v.val_str)) {
|
||||
plog_error(plugin, "setting empty heartbeat-topic");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// format, required
|
||||
if (MQTT_UPLOAD_FORMAT_VALUES != format.v.val_int &&
|
||||
MQTT_UPLOAD_FORMAT_TAGS != format.v.val_int) {
|
||||
@@ -239,10 +231,9 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
goto error;
|
||||
}
|
||||
|
||||
config->client_id = client_id.v.val_str;
|
||||
config->upload_topic = upload_topic.v.val_str;
|
||||
config->heartbeat_topic = heartbeat_topic.v.val_str;
|
||||
config->format = format.v.val_int;
|
||||
config->client_id = client_id.v.val_str;
|
||||
config->upload_topic = upload_topic.v.val_str;
|
||||
config->format = format.v.val_int;
|
||||
config->cache =
|
||||
0 != cache_mem_size.v.val_int || 0 != cache_disk_size.v.val_int;
|
||||
config->cache_mem_size = cache_mem_size.v.val_int * MB;
|
||||
@@ -258,7 +249,6 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
|
||||
plog_info(plugin, "config client-id : %s", config->client_id);
|
||||
plog_info(plugin, "config upload-topic : %s", config->upload_topic);
|
||||
plog_info(plugin, "config heartbeat-topic: %s", config->heartbeat_topic);
|
||||
plog_info(plugin, "config format : %s",
|
||||
mqtt_upload_format_str(config->format));
|
||||
plog_info(plugin, "config cache : %zu", config->cache);
|
||||
@@ -292,7 +282,6 @@ int mqtt_config_parse(neu_plugin_t *plugin, const char *setting,
|
||||
error:
|
||||
free(err_param);
|
||||
free(upload_topic.v.val_str);
|
||||
free(heartbeat_topic.v.val_str);
|
||||
free(host.v.val_str);
|
||||
free(username.v.val_str);
|
||||
free(password.v.val_str);
|
||||
@@ -307,7 +296,6 @@ void mqtt_config_fini(mqtt_config_t *config)
|
||||
{
|
||||
free(config->client_id);
|
||||
free(config->upload_topic);
|
||||
free(config->heartbeat_topic);
|
||||
free(config->host);
|
||||
free(config->username);
|
||||
free(config->password);
|
||||
|
||||
@@ -49,7 +49,6 @@ static inline const char *mqtt_upload_format_str(mqtt_upload_format_e f)
|
||||
typedef struct {
|
||||
char * client_id; // client id
|
||||
char * upload_topic; // upload topic
|
||||
char * heartbeat_topic; // heartbeat topic
|
||||
mqtt_upload_format_e format; // upload format
|
||||
size_t cache; // cache enable flag
|
||||
size_t cache_mem_size; // cache memory size in bytes
|
||||
|
||||
@@ -26,36 +26,6 @@
|
||||
#include "mqtt_handle.h"
|
||||
#include "mqtt_plugin.h"
|
||||
|
||||
static char *generate_heartbeat_json(neu_plugin_t *plugin, UT_array *states)
|
||||
{
|
||||
(void) plugin;
|
||||
char * version = NEURON_VERSION;
|
||||
neu_json_states_head_t header = { .version = version,
|
||||
.timpstamp = global_timestamp };
|
||||
neu_json_states_t json = { 0 };
|
||||
char * json_str = NULL;
|
||||
|
||||
json.n_state = utarray_len(states);
|
||||
json.states = calloc(json.n_state, sizeof(neu_json_node_state_t));
|
||||
if (NULL == json.states) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
utarray_foreach(states, neu_nodes_state_t *, state)
|
||||
{
|
||||
int index = utarray_eltidx(states, state);
|
||||
json.states[index].node = state->node;
|
||||
json.states[index].link = state->state.link;
|
||||
json.states[index].running = state->state.running;
|
||||
}
|
||||
|
||||
neu_json_encode_with_mqtt(&json, neu_json_encode_states_resp, &header,
|
||||
neu_json_encode_state_header_resp, &json_str);
|
||||
|
||||
free(json.states);
|
||||
return json_str;
|
||||
}
|
||||
|
||||
static int tag_values_to_json(neu_resp_tag_value_t *tags, uint16_t len,
|
||||
neu_json_read_resp_t *json)
|
||||
{
|
||||
@@ -524,38 +494,3 @@ int handle_trans_data(neu_plugin_t * plugin,
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int handle_nodes_state(neu_plugin_t *plugin, neu_reqresp_nodes_state_t *states)
|
||||
{
|
||||
int rv = 0;
|
||||
char *json_str = NULL;
|
||||
|
||||
if (NULL == plugin->client) {
|
||||
rv = NEU_ERR_MQTT_IS_NULL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (0 == plugin->config.cache &&
|
||||
!neu_mqtt_client_is_connected(plugin->client)) {
|
||||
// cache disable and we are disconnected
|
||||
rv = NEU_ERR_MQTT_FAILURE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
json_str = generate_heartbeat_json(plugin, states->states);
|
||||
if (NULL == json_str) {
|
||||
plog_error(plugin, "generate heartbeat json fail");
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
char * topic = plugin->config.heartbeat_topic;
|
||||
neu_mqtt_qos_e qos = NEU_MQTT_QOS0;
|
||||
rv = publish(plugin, qos, topic, json_str, strlen(json_str));
|
||||
json_str = NULL;
|
||||
|
||||
end:
|
||||
utarray_free(states->states);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ int handle_read_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json,
|
||||
int handle_trans_data(neu_plugin_t * plugin,
|
||||
neu_reqresp_trans_data_t *trans_data);
|
||||
|
||||
int handle_nodes_state(neu_plugin_t *plugin, neu_reqresp_nodes_state_t *states);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -170,7 +170,14 @@ static int mqtt_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
return NEU_ERR_NODE_SETTING_INVALID;
|
||||
}
|
||||
|
||||
if (plugin->client && neu_mqtt_client_is_open(plugin->client)) {
|
||||
if (NULL == plugin->client) {
|
||||
plugin->client = neu_mqtt_client_new(NEU_MQTT_VERSION_V311);
|
||||
if (NULL == plugin->client) {
|
||||
plog_error(plugin, "neu_mqtt_client_new fail");
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto error;
|
||||
}
|
||||
} else if (neu_mqtt_client_is_open(plugin->client)) {
|
||||
started = true;
|
||||
rv = neu_mqtt_client_close(plugin->client);
|
||||
if (0 != rv) {
|
||||
@@ -178,13 +185,6 @@ static int mqtt_plugin_config(neu_plugin_t *plugin, const char *setting)
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
plugin->client = neu_mqtt_client_new(NEU_MQTT_VERSION_V311);
|
||||
if (NULL == plugin->client) {
|
||||
plog_error(plugin, "neu_mqtt_client_new fail");
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
rv = config_mqtt_client(plugin, plugin->client, &config);
|
||||
@@ -349,10 +349,6 @@ static int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
case NEU_REQRESP_TRANS_DATA:
|
||||
error = handle_trans_data(plugin, data);
|
||||
break;
|
||||
case NEU_REQRESP_NODES_STATE: {
|
||||
error = handle_nodes_state(plugin, data);
|
||||
break;
|
||||
}
|
||||
case NEU_REQRESP_NODE_DELETED:
|
||||
break;
|
||||
default:
|
||||
@@ -385,7 +381,7 @@ const neu_plugin_module_t neu_plugin_module = {
|
||||
.intf_funs = &plugin_intf_funs,
|
||||
.kind = NEU_PLUGIN_KIND_SYSTEM,
|
||||
.type = NEU_NA_TYPE_APP,
|
||||
.sub_msg[0] = NEU_SUBSCRIBE_NODES_STATE,
|
||||
.sub_msg = { 0 },
|
||||
.display = true,
|
||||
.single = false,
|
||||
};
|
||||
|
||||
@@ -422,7 +422,7 @@ int neu_adapter_driver_add_group(neu_adapter_driver_t *driver, const char *name,
|
||||
.second = interval / 1000,
|
||||
.millisecond = interval % 1000,
|
||||
.usr_data = (void *) find,
|
||||
.type = NEU_EVENT_TIMER_BLOCK,
|
||||
.type = NEU_EVENT_TIMER_NOBLOCK,
|
||||
};
|
||||
|
||||
find->driver = driver;
|
||||
@@ -467,13 +467,14 @@ int neu_adapter_driver_update_group(neu_adapter_driver_t *driver,
|
||||
.second = interval / 1000,
|
||||
.millisecond = interval % 1000,
|
||||
.usr_data = (void *) find,
|
||||
.type = NEU_EVENT_TIMER_BLOCK,
|
||||
.type = NEU_EVENT_TIMER_NOBLOCK,
|
||||
};
|
||||
|
||||
neu_group_set_interval(find->group, interval);
|
||||
|
||||
param.cb = report_callback;
|
||||
find->report = neu_adapter_add_timer((neu_adapter_t *) driver, param);
|
||||
param.type = driver->adapter.module->timer_type;
|
||||
param.cb = read_callback;
|
||||
find->read = neu_event_add_timer(driver->driver_events, param);
|
||||
|
||||
@@ -769,6 +770,7 @@ static int report_callback(void *usr_data)
|
||||
sizeof(neu_reqresp_trans_data_t) +
|
||||
utarray_len(tags) * sizeof(neu_resp_tag_value_t));
|
||||
|
||||
data->timestamp = global_timestamp;
|
||||
strcpy(data->driver, group->driver->adapter.name);
|
||||
strcpy(data->group, group->name);
|
||||
data->n_tag = read_report_group(global_timestamp,
|
||||
|
||||
@@ -589,7 +589,7 @@ static void conn_connect(neu_conn_t *conn)
|
||||
sizeof(struct sockaddr_in));
|
||||
if (ret != 0 && errno != EINPROGRESS) {
|
||||
close(fd);
|
||||
zlog_error(neuron, "connect %s:%d error: %s(%d)",
|
||||
zlog_error(conn->param.log, "connect %s:%d error: %s(%d)",
|
||||
conn->param.params.tcp_client.ip,
|
||||
conn->param.params.tcp_client.port, strerror(errno),
|
||||
errno);
|
||||
|
||||
+1
-52
@@ -58,7 +58,6 @@ inline static void forward_msg(neu_manager_t *manager, nng_msg *msg,
|
||||
const char *ndoe);
|
||||
static void start_static_adapter(neu_manager_t *manager, const char *name);
|
||||
static int update_timestamp(void *usr_data);
|
||||
static int report_nodes_state(void *usr_data);
|
||||
static void start_single_adapter(neu_manager_t *manager, const char *name,
|
||||
const char *plugin_name, bool display);
|
||||
|
||||
@@ -75,13 +74,7 @@ neu_manager_t *neu_manager_create()
|
||||
.second = 0,
|
||||
.millisecond = 10,
|
||||
.cb = update_timestamp,
|
||||
.type = NEU_EVENT_TIMER_BLOCK,
|
||||
};
|
||||
neu_event_timer_param_t timer_param = {
|
||||
.second = 1,
|
||||
.millisecond = 0,
|
||||
.cb = report_nodes_state,
|
||||
.type = NEU_EVENT_TIMER_BLOCK,
|
||||
.type = NEU_EVENT_TIMER_NOBLOCK,
|
||||
};
|
||||
|
||||
neu_event_timer_param_t timer_level = {
|
||||
@@ -138,9 +131,6 @@ neu_manager_t *neu_manager_create()
|
||||
timer_level.usr_data = (void *) manager;
|
||||
manager->timer_lev = neu_event_add_timer(manager->events, timer_level);
|
||||
|
||||
timer_param.usr_data = (void *) manager;
|
||||
manager->timer = neu_event_add_timer(manager->events, timer_param);
|
||||
|
||||
timestamp_timer_param.usr_data = (void *) manager;
|
||||
manager->timer_timestamp =
|
||||
neu_event_add_timer(manager->events, timestamp_timer_param);
|
||||
@@ -155,7 +145,6 @@ void neu_manager_destroy(neu_manager_t *manager)
|
||||
nng_msg * uninit_msg = NULL;
|
||||
UT_array *pipes = neu_node_manager_get_pipes_all(manager->node_manager);
|
||||
|
||||
neu_event_del_timer(manager->events, manager->timer);
|
||||
neu_event_del_timer(manager->events, manager->timer_lev);
|
||||
neu_event_del_timer(manager->events, manager->timer_timestamp);
|
||||
strcpy(header.sender, "manager");
|
||||
@@ -733,46 +722,6 @@ inline static void reply(neu_manager_t *manager, neu_reqresp_head_t *header,
|
||||
}
|
||||
}
|
||||
|
||||
static int report_nodes_state(void *usr_data)
|
||||
{
|
||||
neu_manager_t *manager = (neu_manager_t *) usr_data;
|
||||
UT_array * apps = neu_sub_msg_manager_get(manager->sub_msg_manager,
|
||||
NEU_SUBSCRIBE_NODES_STATE);
|
||||
|
||||
neu_manager_count_tag(manager);
|
||||
if (apps == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
UT_array *states = neu_node_manager_get_state(manager->node_manager);
|
||||
|
||||
utarray_foreach(apps, char *, app)
|
||||
{
|
||||
nng_msg * msg = NULL;
|
||||
neu_reqresp_head_t header = { 0 };
|
||||
neu_resp_get_nodes_state_t node_states = { 0 };
|
||||
nng_pipe pipe = neu_node_manager_get_pipe(manager->node_manager, app);
|
||||
|
||||
header.type = NEU_REQRESP_NODES_STATE;
|
||||
strcpy(header.sender, "manager");
|
||||
strcpy(header.receiver, app);
|
||||
node_states.states = utarray_clone(states);
|
||||
|
||||
msg = neu_msg_gen(&header, (void *) &node_states);
|
||||
nng_msg_set_pipe(msg, pipe);
|
||||
|
||||
if (nng_sendmsg(manager->socket, msg, 0) != 0) {
|
||||
nng_msg_free(msg);
|
||||
nlog_warn("manager -> %s nodes state fail", app);
|
||||
}
|
||||
}
|
||||
|
||||
utarray_free(apps);
|
||||
utarray_free(states);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update_timestamp(void *usr_data)
|
||||
{
|
||||
(void) usr_data;
|
||||
|
||||
@@ -41,7 +41,6 @@ typedef struct neu_manager {
|
||||
neu_subscribe_mgr_t * subscribe_manager;
|
||||
neu_sub_msg_mgr_t * sub_msg_manager;
|
||||
|
||||
neu_event_timer_t *timer;
|
||||
neu_event_timer_t *timer_timestamp;
|
||||
|
||||
neu_event_timer_t *timer_lev;
|
||||
|
||||
@@ -333,7 +333,7 @@ static int apply_schema_file(sqlite3 *db, const char *dir, const char *file)
|
||||
char *err_msg = NULL;
|
||||
rv = sqlite3_exec(db, sql, NULL, NULL, &err_msg);
|
||||
if (SQLITE_OK != rv) {
|
||||
nlog_error("execute %s fail: %s", path, err_msg);
|
||||
nlog_error("execute %s fail: (%d)%s", path, rv, err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
rv = NEU_ERR_EINTERNAL;
|
||||
goto end;
|
||||
@@ -772,7 +772,8 @@ int neu_persister_load_tags(const char *driver_name, const char *group_name,
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
const char * query = "SELECT name, address, attribute, precision, type, "
|
||||
"decimal, description "
|
||||
"FROM tags WHERE driver_name=? AND group_name=?";
|
||||
"FROM tags WHERE driver_name=? AND group_name=? "
|
||||
"ORDER BY rowid ASC";
|
||||
|
||||
utarray_new(*tags, neu_tag_get_icd());
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ target_include_directories(jwt_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/src/utils)
|
||||
target_link_libraries(jwt_test neuron-base gtest_main gtest jansson ssl crypto jwt)
|
||||
target_link_libraries(jwt_test neuron-base gtest_main gtest jansson ssl crypto jwt libzlog.so)
|
||||
|
||||
add_executable(base64_test base64_test.cc ${CMAKE_SOURCE_DIR}/src/utils/base64.c)
|
||||
target_include_directories(base64_test PRIVATE
|
||||
|
||||
Reference in New Issue
Block a user