summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2020-04-23 12:12:14 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-05-19 18:29:46 +0200
commit0ac24a6e626e1fe0b4d5c2e912597dfc24dfa961 (patch)
tree18768cedf2c65a0763a267f1d7b9e2db3cab8b77
parent659542febe9a554a855e843d813a62bec3497560 (diff)
#942 Improve scope break down process
OpenGnsys has a hierarchical scope system to organize clients: +------+ |Center| +------+ | | | | v v +--------------------+ +----------+ +-->+Groups of classrooms+----->+Classrooms| | +-+------------------+ +----------+ | | | | +-----+ | | v v +-----------------+ +-------+ +-->+Groups of clients+--------->+Clients| | +-+---------------+ +-------+ | | +-----+ OpenGnsys can send commands and tasks to several clients simultaneously selecting a scope. For example: send poweroff to center Faculty of Pharmacy. We had a waterfall process to loop through all members of the scope and obtain the clients. This commit simplifies the process with queries that save us to loop through the members. Co-authored-by: Irina Gómez <irinagomez@us.es>
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c101
1 files changed, 31 insertions, 70 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
index 97ee69ae..28009fb0 100644
--- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
+++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.c
@@ -3397,45 +3397,6 @@ static int og_queue_task_group_clients(struct og_dbi *dbi, struct og_task *task,
return 0;
}
-static int og_queue_task_classrooms(struct og_dbi *dbi, struct og_task *task,
- char *query)
-{
-
- const char *msglog;
- dbi_result result;
-
- result = dbi_conn_queryf(dbi->conn, query);
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return -1;
- }
-
- while (dbi_result_next_row(result)) {
- uint32_t classroom_id = dbi_result_get_uint(result, "idaula");
-
- sprintf(query, "SELECT idgrupo FROM gruposordenadores "
- "WHERE idaula=%d AND grupoid=0", classroom_id);
- if (og_queue_task_group_clients(dbi, task, query)) {
- dbi_result_free(result);
- return -1;
- }
-
- sprintf(query,"SELECT ip, mac, idordenador FROM ordenadores "
- "WHERE idaula=%d AND grupoid=0", classroom_id);
- if (og_queue_task_command(dbi, task, query)) {
- dbi_result_free(result);
- return -1;
- }
-
- }
-
- dbi_result_free(result);
-
- return 0;
-}
-
static int og_queue_task_group_classrooms(struct og_dbi *dbi,
struct og_task *task, char *query)
{
@@ -3461,8 +3422,13 @@ static int og_queue_task_group_classrooms(struct og_dbi *dbi,
return -1;
}
- sprintf(query,"SELECT idaula FROM aulas WHERE grupoid=%d", group_id);
- if (og_queue_task_classrooms(dbi, task, query)) {
+ sprintf(query,
+ "SELECT ip,mac,idordenador "
+ "FROM ordenadores INNER JOIN aulas "
+ "WHERE ordenadores.idaula=aulas.idaula "
+ "AND aulas.grupoid=%d",
+ group_id);
+ if (og_queue_task_command(dbi, task, query)) {
dbi_result_free(result);
return -1;
}
@@ -3474,47 +3440,42 @@ static int og_queue_task_group_classrooms(struct og_dbi *dbi,
return 0;
}
-static int og_queue_task_center(struct og_dbi *dbi, struct og_task *task,
- char *query)
-{
-
- sprintf(query,"SELECT idgrupo FROM grupos WHERE idcentro=%i AND grupoid=0 AND tipo=%d",
- task->scope, AMBITO_GRUPOSAULAS);
- if (og_queue_task_group_classrooms(dbi, task, query))
- return -1;
-
- sprintf(query,"SELECT idaula FROM aulas WHERE idcentro=%i AND grupoid=0",
- task->scope);
- if (og_queue_task_classrooms(dbi, task, query))
- return -1;
-
- return 0;
-}
-
static int og_queue_task_clients(struct og_dbi *dbi, struct og_task *task)
{
char query[4096];
switch (task->type_scope) {
case AMBITO_CENTROS:
- return og_queue_task_center(dbi, task, query);
+ sprintf(query,
+ "SELECT ip,mac,idordenador "
+ "FROM ordenadores INNER JOIN aulas "
+ "WHERE ordenadores.idaula=aulas.idaula "
+ "AND idcentro=%d",
+ task->scope);
+ return og_queue_task_command(dbi, task, query);
case AMBITO_GRUPOSAULAS:
- sprintf(query, "SELECT idgrupo FROM grupos "
- "WHERE idgrupo=%i AND tipo=%d",
- task->scope, AMBITO_GRUPOSAULAS);
+ sprintf(query,
+ "SELECT idgrupo FROM grupos "
+ "WHERE idgrupo=%i AND tipo=%d",
+ task->scope, AMBITO_GRUPOSAULAS);
return og_queue_task_group_classrooms(dbi, task, query);
case AMBITO_AULAS:
- sprintf(query, "SELECT idaula FROM aulas "
- "WHERE idaula = %d", task->scope);
- return og_queue_task_classrooms(dbi, task, query);
+ sprintf(query,
+ "SELECT ip,mac,idordenador FROM ordenadores "
+ "WHERE idaula=%d",
+ task->scope);
+ return og_queue_task_command(dbi, task, query);
case AMBITO_GRUPOSORDENADORES:
- sprintf(query, "SELECT idgrupo FROM gruposordenadores "
- "WHERE idgrupo = %d", task->scope);
+ sprintf(query,
+ "SELECT idgrupo FROM gruposordenadores "
+ "WHERE idgrupo = %d",
+ task->scope);
return og_queue_task_group_clients(dbi, task, query);
case AMBITO_ORDENADORES:
- sprintf(query, "SELECT ip, mac, idordenador "
- "FROM ordenadores "
- "WHERE idordenador = %d", task->scope);
+ sprintf(query,
+ "SELECT ip, mac, idordenador FROM ordenadores "
+ "WHERE idordenador = %d",
+ task->scope);
return og_queue_task_command(dbi, task, query);
}
return 0;