diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2022-05-13 12:22:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 12:22:24 +0200 |
commit | 6d98eb16fc00acf76d19958f0ac82396f5e56d13 (patch) | |
tree | 1027ef4e25a2e0f8fbd715e0cb7a1e9ae885ea91 /aclk | |
parent | 92d48b177862e0b0d1957a0c97db80d4294e7884 (diff) |
Implements new capability fields in aclk_schemas (#12602)
use new capability fields
Diffstat (limited to 'aclk')
m--------- | aclk/aclk-schemas | 0 | ||||
-rw-r--r-- | aclk/aclk_tx_msgs.c | 16 | ||||
-rw-r--r-- | aclk/schema-wrappers/capability.cc | 11 | ||||
-rw-r--r-- | aclk/schema-wrappers/capability.h | 24 | ||||
-rw-r--r-- | aclk/schema-wrappers/connection.cc | 9 | ||||
-rw-r--r-- | aclk/schema-wrappers/connection.h | 4 | ||||
-rw-r--r-- | aclk/schema-wrappers/node_info.cc | 18 | ||||
-rw-r--r-- | aclk/schema-wrappers/node_info.h | 4 | ||||
-rw-r--r-- | aclk/schema-wrappers/schema_wrappers.h | 1 |
9 files changed, 85 insertions, 2 deletions
diff --git a/aclk/aclk-schemas b/aclk/aclk-schemas -Subproject b23f6a671ccf6d2766d6a208fc1e48b0fbf2fda +Subproject d8342ee6d932c152a78c9fe886281fe28170a6c diff --git a/aclk/aclk_tx_msgs.c b/aclk/aclk_tx_msgs.c index 185f5d7968..69cb5856c5 100644 --- a/aclk/aclk_tx_msgs.c +++ b/aclk/aclk_tx_msgs.c @@ -452,10 +452,21 @@ int aclk_send_app_layer_disconnect(mqtt_wss_client client, const char *message) uint16_t aclk_send_agent_connection_update(mqtt_wss_client client, int reachable) { size_t len; uint16_t pid; + + struct capability agent_capabilities[] = { + { .name = "json", .version = 2, .enabled = 0 }, + { .name = "proto", .version = 1, .enabled = 1 }, +#ifdef ENABLE_ML + { .name = "ml", .version = 1, .enabled = ml_enabled(localhost) }, +#endif + { .name = NULL, .version = 0, .enabled = 0 } + }; + update_agent_connection_t conn = { .reachable = (reachable ? 1 : 0), .lwt = 0, - .session_id = aclk_session_newarch + .session_id = aclk_session_newarch, + .capabilities = agent_capabilities }; rrdhost_aclk_state_lock(localhost); @@ -490,7 +501,8 @@ char *aclk_generate_lwt(size_t *size) { update_agent_connection_t conn = { .reachable = 0, .lwt = 1, - .session_id = aclk_session_newarch + .session_id = aclk_session_newarch, + .capabilities = NULL }; rrdhost_aclk_state_lock(localhost); diff --git a/aclk/schema-wrappers/capability.cc b/aclk/schema-wrappers/capability.cc new file mode 100644 index 0000000000..769806f90b --- /dev/null +++ b/aclk/schema-wrappers/capability.cc @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "proto/aclk/v1/lib.pb.h" + +#include "capability.h" + +void capability_set(aclk_lib::v1::Capability *proto_capa, struct capability *c_capa) { + proto_capa->set_name(c_capa->name); + proto_capa->set_enabled(c_capa->enabled); + proto_capa->set_version(c_capa->version); +} diff --git a/aclk/schema-wrappers/capability.h b/aclk/schema-wrappers/capability.h new file mode 100644 index 0000000000..9517a87163 --- /dev/null +++ b/aclk/schema-wrappers/capability.h @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef ACLK_SCHEMA_CAPABILITY_H +#define ACLK_SCHEMA_CAPABILITY_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct capability { + const char *name; + uint32_t version; + int enabled; +}; + +#ifdef __cplusplus +} + +#include "proto/aclk/v1/lib.pb.h" + +void capability_set(aclk_lib::v1::Capability *proto_capa, struct capability *c_capa); +#endif + +#endif /* ACLK_SCHEMA_CAPABILITY_H */ diff --git a/aclk/schema-wrappers/connection.cc b/aclk/schema-wrappers/connection.cc index e3bbfe31f3..7520a46006 100644 --- a/aclk/schema-wrappers/connection.cc +++ b/aclk/schema-wrappers/connection.cc @@ -28,6 +28,15 @@ char *generate_update_agent_connection(size_t *len, const update_agent_connectio timestamp->set_seconds(tv.tv_sec); timestamp->set_nanos(tv.tv_usec * 1000); + if (data->capabilities) { + struct capability *capa = data->capabilities; + while (capa->name) { + aclk_lib::v1::Capability *proto_capa = connupd.add_capabilities(); + capability_set(proto_capa, capa); + capa++; + } + } + *len = PROTO_COMPAT_MSG_SIZE(connupd); char *msg = (char*)malloc(*len); if (msg) diff --git a/aclk/schema-wrappers/connection.h b/aclk/schema-wrappers/connection.h index 8c223869a8..fcbe6bd595 100644 --- a/aclk/schema-wrappers/connection.h +++ b/aclk/schema-wrappers/connection.h @@ -3,6 +3,8 @@ #ifndef ACLK_SCHEMA_WRAPPER_CONNECTION_H #define ACLK_SCHEMA_WRAPPER_CONNECTION_H +#include "capability.h" + #ifdef __cplusplus extern "C" { #endif @@ -15,6 +17,8 @@ typedef struct { unsigned int lwt:1; + struct capability *capabilities; + // TODO in future optional fields // > 15 optional fields: // How long the system was running until connection (only applicable when reachable=true) diff --git a/aclk/schema-wrappers/node_info.cc b/aclk/schema-wrappers/node_info.cc index f6f15ffb26..f669852467 100644 --- a/aclk/schema-wrappers/node_info.cc +++ b/aclk/schema-wrappers/node_info.cc @@ -94,6 +94,24 @@ char *generate_update_node_info_message(size_t *len, struct update_node_info *in ml_info->set_ml_capable(info->ml_info.ml_capable); ml_info->set_ml_enabled(info->ml_info.ml_enabled); + struct capability *capa; + if (info->node_capabilities) { + capa = info->node_capabilities; + while (capa->name) { + aclk_lib::v1::Capability *proto_capa = msg.mutable_node_info()->add_capabilities(); + capability_set(proto_capa, capa); + capa++; + } + } + if (info->node_instance_capabilities) { + capa = info->node_instance_capabilities; + while (capa->name) { + aclk_lib::v1::Capability *proto_capa = msg.mutable_node_instance_info()->add_capabilities(); + capability_set(proto_capa, capa); + capa++; + } + } + *len = PROTO_COMPAT_MSG_SIZE(msg); char *bin = (char*)malloc(*len); if (bin) diff --git a/aclk/schema-wrappers/node_info.h b/aclk/schema-wrappers/node_info.h index 41daf94c8f..e67f3e1daa 100644 --- a/aclk/schema-wrappers/node_info.h +++ b/aclk/schema-wrappers/node_info.h @@ -6,6 +6,7 @@ #include <stdlib.h> #include "database/rrd.h" +#include "capability.h" #ifdef __cplusplus extern "C" { @@ -67,6 +68,9 @@ struct update_node_info { int child; struct machine_learning_info ml_info; + + struct capability *node_capabilities; + struct capability *node_instance_capabilities; }; char *generate_update_node_info_message(size_t *len, struct update_node_info *info); diff --git a/aclk/schema-wrappers/schema_wrappers.h b/aclk/schema-wrappers/schema_wrappers.h index a3975fca3e..a3248a69b6 100644 --- a/aclk/schema-wrappers/schema_wrappers.h +++ b/aclk/schema-wrappers/schema_wrappers.h @@ -13,5 +13,6 @@ #include "alarm_config.h" #include "alarm_stream.h" #include "node_info.h" +#include "capability.h" #endif /* SCHEMA_WRAPPERS_H */ |