Skip to content

Commit e3e464d

Browse files
committed
feat: move default_plugins.json and sql schemas to config directory
1 parent e298f01 commit e3e464d

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

Diff for: CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ file(COPY ${CMAKE_SOURCE_DIR}/dev.conf DESTINATION ${CMAKE_BINARY_DIR}/config)
131131
file(COPY ${CMAKE_SOURCE_DIR}/.gitkeep DESTINATION ${CMAKE_BINARY_DIR}/logs)
132132
file(COPY ${CMAKE_SOURCE_DIR}/neuron.key DESTINATION ${CMAKE_BINARY_DIR}/config)
133133
file(COPY ${CMAKE_SOURCE_DIR}/neuron.pem DESTINATION ${CMAKE_BINARY_DIR}/config)
134-
file(COPY ${CMAKE_SOURCE_DIR}/persistence DESTINATION ${CMAKE_BINARY_DIR}/)
135-
file(COPY ${CMAKE_SOURCE_DIR}/default_plugins.json DESTINATION ${CMAKE_BINARY_DIR}/persistence)
136-
file(RENAME ${CMAKE_BINARY_DIR}/persistence/default_plugins.json ${CMAKE_BINARY_DIR}/persistence/plugins.json)
134+
file(GLOB SQL_SCHEMAS ${CMAKE_SOURCE_DIR}/persistence/*.sql)
135+
file(COPY ${SQL_SCHEMAS} DESTINATION ${CMAKE_BINARY_DIR}/config)
136+
file(COPY ${CMAKE_SOURCE_DIR}/default_plugins.json DESTINATION ${CMAKE_BINARY_DIR}/config)
137137

138138
add_subdirectory(plugins/modbus)
139139
add_subdirectory(plugins/mqtt)

Diff for: ft/Keyword/Neuron.py

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
def prepare_persistence_dir():
1010
os.system("mkdir -p build/persistence")
11-
os.system("cp -r persistence build/")
12-
os.system("cp default_plugins.json build/persistence/plugins.json")
1311

1412

1513
class Neuron(object):

Diff for: package-sdk.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ cp build/neuron ${package_name}
4646
cp build/libneuron-base.so ${package_name}/lib
4747
cp zlog/src/libzlog.so.1.2 ${package_name}/lib
4848

49-
cp -r persistence ${package_name}/
49+
cp persistence/*.sql ${package_name}/config/
5050
cp migrate.py ${package_name}/
5151

5252
cp sdk-zlog.conf ${package_name}/config/

Diff for: sdk-install.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ cp config/sdk-zlog.conf ${neuron_bin}/config/zlog.conf
2727
cp config/dev.conf ${neuron_bin}/config/
2828
cp config/neuron.key ${neuron_bin}/config/
2929
cp config/neuron.pem ${neuron_bin}/config/
30+
cp config/default_plugins.json ${neuron_bin}/config/
31+
cp config/*.sql ${neuron_bin}/config/
3032

31-
cp config/default_plugins.json ${neuron_bin}/persistence/plugins.json
32-
cp persistence/* ${neuron_bin}/persistence/
3333
cp -r plugins/* ${neuron_bin}/plugins/
3434

3535
cp -r dist ${neuron_bin}/

Diff for: src/persist/persist.c

+23-6
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ neu_persister_t *neu_persister_create(const char *dir_name)
616616
sqlite3_close(persister->db);
617617
goto error;
618618
}
619-
if (0 != apply_schemas(persister->db, persister->persist_dir)) {
619+
if (0 != apply_schemas(persister->db, "config/")) {
620620
goto error;
621621
}
622622

@@ -780,6 +780,10 @@ int neu_persister_store_plugins(neu_persister_t *persister,
780780

781781
utarray_foreach(plugin_infos, neu_resp_plugin_info_t *, plugin)
782782
{
783+
if (NEU_PLUGIN_KIND_SYSTEM == plugin->kind) {
784+
// filter out system plugins
785+
continue;
786+
}
783787
plugin_resp.plugins[index] = plugin->library;
784788
index++;
785789
}
@@ -799,11 +803,10 @@ int neu_persister_store_plugins(neu_persister_t *persister,
799803
return rv;
800804
}
801805

802-
int neu_persister_load_plugins(neu_persister_t *persister,
803-
UT_array ** plugin_infos)
806+
static int load_plugins_file(const char *fname, UT_array *plugin_infos)
804807
{
805808
char *json_str = NULL;
806-
int rv = read_file_string(persister->plugins_fname, &json_str);
809+
int rv = read_file_string(fname, &json_str);
807810
if (rv != 0) {
808811
return rv;
809812
}
@@ -815,10 +818,9 @@ int neu_persister_load_plugins(neu_persister_t *persister,
815818
return rv;
816819
}
817820

818-
utarray_new(*plugin_infos, &ut_ptr_icd);
819821
for (int i = 0; i < plugin_req->n_plugin; i++) {
820822
char *name = plugin_req->plugins[i];
821-
utarray_push_back(*plugin_infos, &name);
823+
utarray_push_back(plugin_infos, &name);
822824
}
823825

824826
free(json_str);
@@ -827,6 +829,21 @@ int neu_persister_load_plugins(neu_persister_t *persister,
827829
return 0;
828830
}
829831

832+
int neu_persister_load_plugins(neu_persister_t *persister,
833+
UT_array ** plugin_infos)
834+
{
835+
utarray_new(*plugin_infos, &ut_ptr_icd);
836+
// default plugins will always present
837+
if (0 != load_plugins_file("config/default_plugins.json", *plugin_infos)) {
838+
nlog_warn("cannot load default plugins");
839+
}
840+
// user plugins
841+
if (0 != load_plugins_file(persister->plugins_fname, *plugin_infos)) {
842+
nlog_warn("cannot load user plugins");
843+
}
844+
return 0;
845+
}
846+
830847
int neu_persister_store_tag(neu_persister_t *persister, const char *driver_name,
831848
const char *group_name, const neu_datatag_t *tag)
832849
{

0 commit comments

Comments
 (0)