Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extend-exclude = [
"src/common/libutil/test/sha1.c",
"src/common/libutil/test/blobref.c",
"src/common/libmissing/*.[ch]",
"src/common/libsqlite3/*.[ch]",
"t/hwloc-data/*",
]

Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CODE_COVERAGE_IGNORE_PATTERN = \
"*/common/libyuarel/*" \
"*/common/libczmqcontainers/*" \
"*/common/libccan/*" \
"*/common/libsqlite3/*" \
"*/common/libmissing/*"

CODE_COVERAGE_LCOV_OPTIONS =
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ if test "$have_libsystemd" = yes -a "$have_sd_bus_h" = yes; then
fi
PKG_CHECK_MODULES([HWLOC], [hwloc >= 1.11.1], [], [])
PKG_CHECK_MODULES([LZ4], [liblz4], [], [])
PKG_CHECK_MODULES([SQLITE], [sqlite3], [], [])
PKG_CHECK_MODULES([LIBUUID], [uuid], [], [])
PKG_CHECK_MODULES([CURSES], [ncursesw], [], [])
PKG_CHECK_MODULES([LIBARCHIVE], [libarchive], [], [])
Expand Down Expand Up @@ -569,6 +568,7 @@ AC_CONFIG_FILES( \
src/common/libtaskmap/Makefile \
src/common/libfilemap/Makefile \
src/common/libsdexec/Makefile \
src/common/libsqlite3/Makefile \
src/common/libmissing/Makefile \
src/bindings/Makefile \
src/bindings/lua/Makefile \
Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Build-Depends:
libjansson-dev,
liblz4-dev,
libhwloc-dev,
libsqlite3-dev,
lua5.1,
liblua5.1-dev,
lua-posix,
Expand Down
1 change: 0 additions & 1 deletion scripts/install-deps-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ apt install \
liblz4-dev \
libarchive-dev \
libhwloc-dev \
libsqlite3-dev \
lua5.1 \
liblua5.1-dev \
lua-posix \
Expand Down
1 change: 0 additions & 1 deletion scripts/install-deps-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ yum install \
lz4-devel \
libarchive-devel \
hwloc-devel \
sqlite-devel \
lua \
lua-devel \
lua-posix \
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ flux_SOURCES = \
builtin/restore.c \
builtin/archive.c \
builtin/pmi.c \
builtin/shutdown.c
builtin/shutdown.c \
builtin/sql.c
nodist_flux_SOURCES = \
builtin-cmds.c

Expand Down
96 changes: 96 additions & 0 deletions src/cmd/builtin/sql.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/************************************************************\
* Copyright 2024 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_ARGZ_ADD
#include <argz.h>
#else
#include "src/common/libmissing/argz.h"
#endif
#include <unistd.h>

#include "builtin.h"

static void query_continuation (flux_future_t *f, void *arg)
{
flux_reactor_t *r = flux_future_get_reactor (f);
const char *row;

if (flux_rpc_get (f, &row) < 0) {
if (errno == ENODATA)
flux_reactor_stop (r);
else {
log_msg ("%s", future_strerror (f, errno));
flux_reactor_stop_error (r);
}
return;
}
printf ("%s\n", row);
flux_future_reset (f);
}

static int cmd_sql (optparse_t *p, int ac, char *av[])
{
int n = optparse_option_index (p);
int e;
char *argz = NULL;
size_t argz_len = 0;
flux_t *h;
flux_future_t *f;
int rc;

log_init ("flux-sql");
if (n == ac) {
optparse_print_usage (p);
exit (1);
}
/* Make one SQL query string from one or more query arguments
*/
if ((e = argz_create (&av[n], &argz, &argz_len)) != 0)
log_errn_exit (e, "error processing arguments");
argz_stringify (argz, argz_len, ' ');

if (!(h = builtin_get_flux_handle (p)))
log_err_exit ("could not contact flux broker");

if (!(f = flux_rpc_pack (h,
"job-sql.query",
0,
FLUX_RPC_STREAMING,
"{s:s}",
"query", argz))
|| flux_future_then (f, -1, query_continuation, p) < 0)
log_err_exit ("error sending query");
rc = flux_reactor_run (flux_get_reactor (h), 0);
flux_future_destroy (f);

flux_close (h);
free (argz);
return rc;
}

int subcommand_sql_register (optparse_t *p)
{
if (optparse_reg_subcommand (p,
"sql",
cmd_sql,
"[OPTIONS...] QUERY",
"Query the SQL job database",
0,
NULL) != OPTPARSE_SUCCESS)
return -1;
return 0;
}

/*
* vi: ts=4 sw=4 expandtab
*/
1 change: 1 addition & 0 deletions src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SUBDIRS = \
libtaskmap \
libfilemap \
libsdexec \
libsqlite3 \
libmissing

AM_CFLAGS = $(WARNING_CFLAGS) $(CODE_COVERAGE_CFLAGS)
Expand Down
15 changes: 15 additions & 0 deletions src/common/libsqlite3/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
AM_CFLAGS = \
$(WARNING_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)

AM_LDFLAGS = \
$(CODE_COVERAGE_LIBS)

AM_CPPFLAGS = \
-I$(top_srcdir)

noinst_LTLIBRARIES = libsqlite3.la

libsqlite3_la_SOURCES = \
sqlite3.h \
sqlite3.c
Loading