summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorTimotej S <6674623+underhood@users.noreply.github.com>2021-07-07 16:32:37 +0200
committerGitHub <noreply@github.com>2021-07-07 16:32:37 +0200
commitd005dee55800818b26f6308c433e6aed8079f7fe (patch)
tree2e884e10d333dfa947b1b20d360dcad805a492ed /database
parent59394b5f9d8891cb59c42ac87fd8f0d41b28db94 (diff)
ACLK-NG New Cloud NodeInstance related msgs (#11234)
Adds new cloud arch NodeInstance messages as per design. Co-authored-by: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com>
Diffstat (limited to 'database')
-rw-r--r--database/sqlite/sqlite_functions.c36
-rw-r--r--database/sqlite/sqlite_functions.h1
2 files changed, 37 insertions, 0 deletions
diff --git a/database/sqlite/sqlite_functions.c b/database/sqlite/sqlite_functions.c
index b7c997ae9a..7fa340bdb8 100644
--- a/database/sqlite/sqlite_functions.c
+++ b/database/sqlite/sqlite_functions.c
@@ -1430,6 +1430,42 @@ failed:
return rc - 1;
}
+#define SQL_SELECT_HOST_BY_NODE_ID "select host_id from node_instance where node_id = @node_id;"
+
+int get_host_id(uuid_t *node_id, uuid_t *host_id)
+{
+ sqlite3_stmt *res = NULL;
+ int rc;
+
+ if (unlikely(!db_meta)) {
+ if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE)
+ error_report("Database has not been initialized");
+ return 1;
+ }
+
+ rc = sqlite3_prepare_v2(db_meta, SQL_SELECT_HOST_BY_NODE_ID, -1, &res, 0);
+ if (unlikely(rc != SQLITE_OK)) {
+ error_report("Failed to prepare statement to select node instance information for a node");
+ return 1;
+ }
+
+ rc = sqlite3_bind_blob(res, 1, node_id, sizeof(*node_id), SQLITE_STATIC);
+ if (unlikely(rc != SQLITE_OK)) {
+ error_report("Failed to bind host_id parameter to select node instance information");
+ goto failed;
+ }
+
+ rc = sqlite3_step(res);
+ if (likely(rc == SQLITE_ROW && host_id))
+ uuid_copy(*host_id, *((uuid_t *) sqlite3_column_blob(res, 0)));
+
+failed:
+ if (unlikely(sqlite3_finalize(res) != SQLITE_OK))
+ error_report("Failed to finalize the prepared statement when selecting node instance information");
+
+ return (rc == SQLITE_ROW) ? 0 : -1;
+}
+
#define SQL_SELECT_NODE_ID "select node_id from node_instance where host_id = @host_id and node_id not null;"
int get_node_id(uuid_t *host_id, uuid_t *node_id)
diff --git a/database/sqlite/sqlite_functions.h b/database/sqlite/sqlite_functions.h
index fe1b2acb69..4fb43c2640 100644
--- a/database/sqlite/sqlite_functions.h
+++ b/database/sqlite/sqlite_functions.h
@@ -74,6 +74,7 @@ extern void sql_build_context_param_list(struct context_param **param_list, RRDH
extern void store_claim_id(uuid_t *host_id, uuid_t *claim_id);
extern int update_node_id(uuid_t *host_id, uuid_t *node_id);
extern int get_node_id(uuid_t *host_id, uuid_t *node_id);
+extern int get_host_id(uuid_t *node_id, uuid_t *host_id);
extern void invalidate_node_instances(uuid_t *host_id, uuid_t *claim_id);
extern struct node_instance_list *get_node_list(void);
extern void sql_load_node_id(RRDHOST *host);