Skip to content

Commit

Permalink
Number of subscriptions can be checked
Browse files Browse the repository at this point in the history
The number of subscribed clients can be set in
the director ressource, e.g.

Subscriptions = 2

When the number of clients is bigger than the
configured limit, each job gets the following
message:

JobId 7: Warning: Subscriptions exceeded: (used/total) (3/2)

Also, the status of the subscriptions can be checked via
* status subscriptions
Warning! No available subscriptions: -1 (3/2) (used/total)

Nothing else than the warning is issued, no enforcement on
backup, restore or any other operation will happen.

Fixes #152: report if number of subscribed clients is exceeded.

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
pstorz authored and Marco van Wieringen committed Feb 17, 2015
1 parent a30603d commit 5232d00
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/dird/dird.c
Expand Up @@ -920,8 +920,16 @@ static bool check_resources()
/*
* Loop over Clients
*/
me->subscriptions_used = 0;
CLIENTRES *client;
foreach_res(client, R_CLIENT) {
/*
* Count the number of clients
*
* Only used as indication not an enforced limit.
*/
me->subscriptions_used++;

/*
* tls_require implies tls_enable
*/
Expand Down
12 changes: 9 additions & 3 deletions src/dird/dird_conf.c
Expand Up @@ -121,6 +121,7 @@ static RES_ITEM dir_items[] = {
{ "piddirectory", store_dir, ITEM(res_dir.pid_directory), 0, ITEM_DEFAULT, _PATH_BAREOS_PIDDIR },
{ "plugindirectory", store_dir, ITEM(res_dir.plugin_directory), 0, 0, NULL },
{ "scriptsdirectory", store_dir, ITEM(res_dir.scripts_directory), 0, 0, NULL },
{ "subscriptions", store_pint32, ITEM(res_dir.subscriptions), 0, ITEM_DEFAULT, "0" },
{ "subsysdirectory", store_dir, ITEM(res_dir.subsys_directory), 0, 0, NULL },
{ "maximumconcurrentjobs", store_pint32, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, "1" },
{ "maximumconsoleconnections", store_pint32, ITEM(res_dir.MaxConsoleConnect), 0, ITEM_DEFAULT, "20" },
Expand Down Expand Up @@ -707,17 +708,22 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fm
}
switch (type) {
case R_DIRECTOR:
sendit(sock, _("Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n"),
reshdr->name, res->res_dir.MaxConcurrentJobs,
sendit(sock, _("Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s \n"
" subscriptions=%d, subscriptions_used=%d\n"),
reshdr->name,
res->res_dir.MaxConcurrentJobs,
edit_uint64(res->res_dir.FDConnectTimeout, ed1),
edit_uint64(res->res_dir.SDConnectTimeout, ed2));
edit_uint64(res->res_dir.SDConnectTimeout, ed2),
res->res_dir.subscriptions,
res->res_dir.subscriptions_used);
if (res->res_dir.query_file) {
sendit(sock, _(" query_file=%s\n"), res->res_dir.query_file);
}
if (res->res_dir.messages) {
sendit(sock, _(" --> "));
dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
}

break;
case R_CONSOLE:
sendit(sock, _("Console: name=%s SSL=%d\n"),
Expand Down
2 changes: 2 additions & 0 deletions src/dird/dird_conf.h
Expand Up @@ -129,6 +129,8 @@ class DIRRES {
bool optimize_for_speed; /* Optimize daemon for speed which may need more memory */
bool ndmp_snooping; /* NDMP Protocol specific snooping enabled */
uint32_t ndmp_loglevel; /* NDMP Protocol specific loglevel to use */
uint32_t subscriptions; /* Number of subscribtions available */
uint32_t subscriptions_used; /* Number of subscribtions used */
char *verid; /* Custom Id to print in version command */
char *keyencrkey; /* Key Encryption Key */

Expand Down
9 changes: 9 additions & 0 deletions src/dird/job.c
Expand Up @@ -481,6 +481,15 @@ static void *job_thread(void *arg)
break;
}

/*
* Check for subscriptions and issue a warning when exceeded.
*/
if (me->subscriptions &&
me->subscriptions < me->subscriptions_used) {
Jmsg(jcr, M_WARNING, 0, _("Subscriptions exceeded: (used/total) (%d/%d)\n"),
me->subscriptions_used, me->subscriptions);
}

run_scripts(jcr, jcr->res.job->RunScripts, "AfterJob");

/*
Expand Down
3 changes: 2 additions & 1 deletion src/dird/ua_cmds.c
Expand Up @@ -187,7 +187,8 @@ static struct cmdstruct commands[] = {
"\tcomment=<text> yes"), false },
{ NT_("status"), status_cmd, _("Report status"),
NT_("all | dir=<dir-name> | director | scheduler | schedule=<schedule-name> | client=<client-name> |\n"
"\tstorage=<storage-name> slots | days=<nr_days> | job=<job-name> | schedule=<schedule-name>"), true },
"\tstorage=<storage-name> slots | days=<nr_days> | job=<job-name> | schedule=<schedule-name> |\n"
"\tsubscriptions" ), true },
{ NT_("setbandwidth"), setbwlimit_cmd, _("Sets bandwidth"),
NT_("client=<client-name> | storage=<storage-name> | jobid=<jobid> |\n"
"\tjob=<job-name> | ujobid=<unique-jobid> state=<job_state> | all\n"
Expand Down
50 changes: 48 additions & 2 deletions src/dird/ua_status.c
Expand Up @@ -36,6 +36,7 @@ static void list_running_jobs(UAContext *ua);
static void list_terminated_jobs(UAContext *ua);
static void do_director_status(UAContext *ua);
static void do_scheduler_status(UAContext *ua);
static bool do_subscription_status(UAContext *ua);
static void do_all_status(UAContext *ua);
static void status_slots(UAContext *ua, STORERES *store);
static void status_content(UAContext *ua, STORERES *store);
Expand Down Expand Up @@ -176,6 +177,12 @@ int status_cmd(UAContext *ua, const char *cmd)
} else if (bstrncasecmp(ua->argk[i], NT_("sched"), 5)) {
do_scheduler_status(ua);
return 1;
} else if (bstrncasecmp(ua->argk[i], NT_("sub"), 3)) {
if (do_subscription_status(ua)) {
return 1;
} else {
return 0;
}
} else {
store = get_storage_resource(ua, false/*no default*/);
if (store) {
Expand Down Expand Up @@ -527,6 +534,45 @@ static bool show_scheduled_preview(UAContext *ua, SCHEDRES *sched,
return true;
}

/*
* Check the number of clients in the DB against the configured number of subscriptions
*
* Return true if (number of clients < number of subscriptions), else
* return false
*/
static bool do_subscription_status(UAContext *ua)
{
int available;
bool retval = false;

/*
* See if we need to check.
*/
if (me->subscriptions == 0) {
ua->send_msg(_("No subscriptions configured in director.\n"));
retval = true;
goto bail_out;
}

if (me->subscriptions_used <= 0) {
ua->error_msg(_("No clients defined.\n"));
goto bail_out;
} else {
available = me->subscriptions - me->subscriptions_used;
if (available < 0) {
ua->send_msg(_("Warning! No available subscriptions: %d (%d/%d) (used/total)\n"),
available, me->subscriptions_used, me->subscriptions);
} else {
ua->send_msg(_("Ok: available subscriptions: %d (%d/%d) (used/total)\n"),
available, me->subscriptions_used, me->subscriptions);
retval = true;
}
}

bail_out:
return retval;
}

static void do_scheduler_status(UAContext *ua)
{
int i;
Expand Down Expand Up @@ -636,7 +682,7 @@ static void do_scheduler_status(UAContext *ua)
/*
* Build an overview.
*/
if ( days > 0 ) { /* future */
if (days > 0) { /* future */
start = now;
stop = now + (days * seconds_per_day);
} else { /* past */
Expand Down Expand Up @@ -858,7 +904,7 @@ static void list_scheduled_jobs(UAContext *ua)
if (!acl_access_ok(ua, Job_ACL, job->name()) || !job->enabled) {
continue;
}
for (run=NULL; (run = find_next_run(run, job, runtime, days)); ) {
for (run = NULL; (run = find_next_run(run, job, runtime, days)); ) {
USTORERES store;
level = job->JobLevel;
if (run->level) {
Expand Down

0 comments on commit 5232d00

Please sign in to comment.