bbfdm: utility functions and micro-service handler

This commit is contained in:
Vivek Kumar Dutta 2024-03-12 16:14:14 +05:30
parent e9d0a81e8e
commit 4535954699
3 changed files with 156 additions and 30 deletions

92
bbfdm/README.md Normal file
View file

@ -0,0 +1,92 @@
# BBFDM configuration options and utilities
bbfdm provides few compile time configuration options and compile time help utility called [bbfdm.mk](./bbfdm.mk), this document aimed to explain the available usages and best practices.
## Compilation options
| Configuration option | Default Value | Description |
| ----------------------- | ------------- | ----------- |
| CONFIG_BBF_VENDOR_LIST | iopsys | List of vendor extension directories |
| CONFIG_BBF_VENDOR_PREFIX | X_IOPSYS_EU_ | Prefix for Vendor extension datamodel objects/parameters |
| CONFIG_BBF_TR143 | y | Enable/Add TR-143 Data Model Support |
| CONFIG_BBF_TR471 | y | Enable/Add TR-471 Data Model Support |
| CONFIG_BBF_MAX_OBJECT_INSTANCES | 255 | Maximum number of instances per object |
## Helper utility (bbfdm.mk)
bbfdm provides a helper utility [bbfdm.mk](./bbfdm.mk) to install datamodel plugins in bbfdm core or in microservice directory.
### Install datamodel DotSO/JSON plugin in bbfdm core
Utility to install the DotSO/JSON plugin in bbfdm core plugin path
```bash
# inputs:
# $1 => package install directory
# $2 => Plugin artifact
```
Example:
```make
define Package/$(PKG_NAME)/install
$(call BbfdmInstallPlugin,$(1),./files/etc/bbfdm/json/CWMPManagementServer.json)
endef
```
### Install datamodel DotSO/JSON plugin in bbfdm core with priority
Its now possible to overwrite/remove core datamodel with plugin, so, if some datamodel objects/parameters are present in more than one plugin, order in which they loaded into memory becomes crucial, this Utility help to configure a priority order in which they gets loaded in memory.
```bash
# inputs:
# $1 => package install directory
# $2 => Priority of the installed plugin
# $3 => Plugin artifact
```
Example:
```make
define Package/$(PKG_NAME)/install
$(call BbfdmInstallPluginWithPriority,$(1),01,$(PKG_BUILD_DIR)/bbf_plugin/bulkdata.json)
endef
```
> Note: Last loaded plugin gets the highest priority
### Install plugin into micro-service directory
Utility to install the plugin in datamodel microservice directory, ex. user wants to run a datamodel micro-service, it required to install the DotSO/JSON plugin into a non bbf core directory, this utility helps in installing the DotSO/JSON plugin in mentioned directory.
```bash
# inputs:
# $1 => package install directory with micro-service directory
# $2 => Plugin artifact
```
Example:
```make
define Package/$(PKG_NAME)/install
$(call BbfdmInstallPluginInMicroservice,$(1)/etc/bulkdata,$(PKG_BUILD_DIR)/bbf_plugin/bulkdata.json)
endef
```
### Install datamodel micro-service input file
Utility to install the datamodel plugin input file into the bbfdm micro-service directory, so that bbfdm auto start the datamodel micro-service before main bbfdm process.
```bash
# inputs:
# $1 => package install directory
# $2 => Microservice input.json path
```
Example:
```make
define Package/$(PKG_NAME)/install
$(call BbfdmInstallMicroServiceInputFile,$(1),./files/etc/bulkdata/input.json)
endef
```

View file

@ -2,8 +2,56 @@
# Copyright (C) 2023 IOPSYS # Copyright (C) 2023 IOPSYS
# #
# Utility to install the plugin in bbfdm core path
# inputs:
# $1 => package install directory
# $2 => Plugin artifact
#
# Example:
# $(call BbfdmInstallPlugin,$(1),./files/etc/bbfdm/json/CWMPManagementServer.json)
#
define BbfdmInstallPlugin define BbfdmInstallPlugin
$(INSTALL_DIR) $(1)/etc/bbfdm/plugins $(INSTALL_DIR) $(1)/etc/bbfdm/plugins
$(INSTALL_DATA) $(2) $(1)/etc/bbfdm/plugins/ $(INSTALL_DATA) $(2) $(1)/etc/bbfdm/plugins/
endef endef
# Utility to install the plugin in bbfdm core path with priority
# inputs:
# $1 => package install directory
# $2 => Priority of the installed plugin
# $3 => Plugin artifact
#
# Example:
# $(call BbfdmInstallPluginWithPriority,$(1),01,$(PKG_BUILD_DIR)/bbf_plugin/bulkdata.json)
#
define BbfdmInstallPluginWithPriority
$(INSTALL_DIR) $(1)/etc/bbfdm/plugins
$(INSTALL_DATA) $(3) $(1)/etc/bbfdm/plugins/$(2)_$(shell basename ${3})
endef
# Utility to install the plugin in datamodel microservice directory
# inputs:
# $1 => package install directory with micro-service directory
# $2 => Plugin artifact
#
# Example:
# $(call BbfdmInstallPluginInMicroservice,$(1)/etc/bulkdata,$(PKG_BUILD_DIR)/bbf_plugin/bulkdata.json)
#
define BbfdmInstallPluginInMicroservice
$(INSTALL_DIR) $(1)
$(INSTALL_DATA) $(2) $(1)/
endef
# Utility to install the datamodel plugin input file
# inputs:
# $1 => package install directory
# $2 => Microservice input.json path
#
# Example:
# $(call BbfdmInstallMicroServiceInputFile,$(1),./files/etc/bulkdata/input.json)
#
define BbfdmInstallMicroServiceInputFile
$(INSTALL_DIR) $(1)/etc/bbfdm/micro_services
$(INSTALL_DATA) $(2) $(1)/etc/bbfdm/micro_services/$(PKG_NAME).json
endef

View file

@ -7,6 +7,7 @@ USE_PROCD=1
PROG=/usr/sbin/bbfdmd PROG=/usr/sbin/bbfdmd
BBFDM_JSON_INPUT="/etc/bbfdm/input.json" BBFDM_JSON_INPUT="/etc/bbfdm/input.json"
BBFDM_MICROSERVICE_DIR="/etc/bbfdm/micro_services"
BBFDM_TEMP_DIR="/tmp/bbfdm" BBFDM_TEMP_DIR="/tmp/bbfdm"
log() { log() {
@ -25,30 +26,13 @@ validate_bbfdm_bbfdmd_section()
'subprocess_level:uinteger' 'subprocess_level:uinteger'
} }
validate_bbfdm_micro_service_section()
{
uci_validate_section bbfdm micro_service "${1}" \
'enable:bool:true' \
'loglevel:uinteger:1' \
'input_json:string'
}
bbfdm_add_micro_service() bbfdm_add_micro_service()
{ {
local name path local name path
name="${1}" path="${1}"
path="${BBFDM_TEMP_DIR}/${name}.json" name="$(basename ${path})"
name="${name//.json}"
if [ -z "${name}" ]; then
log "micro-service name not defined"
return 0;
fi
if [ ! -f "$path" ]; then
log "micro-service input file not present"
return 0;
fi
ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['${PROG}','-m','$path']}}}" ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['${PROG}','-m','$path']}}}"
} }
@ -57,26 +41,28 @@ _add_microservice()
{ {
local enable loglevel input_json name local enable loglevel input_json name
validate_bbfdm_micro_service_section "${1}" || {
log "validation of bbfdm micro_service $1 failed"
return 1;
}
name="${1}" name="${1}"
[ "${enable}" -eq 0 ] && return 0 input_json="$(jq -r '.daemon.input.name' ${name})"
if [ -f "${input_json}" ]; then if [ -f "${input_json}" ]; then
echo "$(jq --arg log ${loglevel} '.daemon.config += {"loglevel": $log }' ${input_json})" > "${BBFDM_TEMP_DIR}/${name}.json"
bbfdm_add_micro_service "${name}" bbfdm_add_micro_service "${name}"
else
log "Input json [${input_json}] does not defined/present"
fi fi
} }
configure_bbfdm_micro_services() configure_bbfdm_micro_services()
{ {
config_load bbfdm if [ -d "${BBFDM_MICROSERVICE_DIR}" ]; then
config_foreach _add_microservice "micro_service" FILES="$(ls -1 ${BBFDM_MICROSERVICE_DIR}/*.json)"
for service in $FILES;
do
[ -e "$service" ] || continue
_add_microservice $service
done
fi
ubus call service state '{"name":"bbfdm.services", "spawn":true}' ubus call service state '{"name":"bbfdm.services", "spawn":true}'
} }