Skip to content

Commit

Permalink
Enable/Disable Scheduler
Browse files Browse the repository at this point in the history
Fixes #308: Enable/Disable Scheduler
  • Loading branch information
Marco van Wieringen committed Jun 9, 2014
1 parent 96862fb commit 3bbfe41
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/dird/dird_conf.c
Expand Up @@ -395,6 +395,7 @@ static RES_ITEM sch_items[] = {
{ "name", CFG_TYPE_NAME, ITEM(res_sch.hdr.name), 0, CFG_ITEM_REQUIRED, NULL },
{ "description", CFG_TYPE_STR, ITEM(res_sch.hdr.desc), 0, 0, NULL },
{ "run", CFG_TYPE_RUN, ITEM(res_sch.run), 0, 0, NULL },
{ "enabled", CFG_TYPE_BOOL, ITEM(res_sch.enabled), 0, CFG_ITEM_DEFAULT, "true" },
{ NULL, 0, { 0 }, 0, 0, NULL }
};

Expand Down
2 changes: 2 additions & 0 deletions src/dird/dird_conf.h
Expand Up @@ -548,6 +548,7 @@ inline char *FILESETRES::name() const { return hdr.name; }
class SCHEDRES: public BRSRES {
public:
RUNRES *run;
bool enabled; /* Set if schedule is enabled */
};

/*
Expand Down Expand Up @@ -665,3 +666,4 @@ class RUNRES: public BRSRES {
#define GetJobResWithName(x) ((JOBRES *)GetResWithName(R_JOB, (x)))
#define GetFileSetResWithName(x) ((FILESETRES *)GetResWithName(R_FILESET, (x)))
#define GetCatalogResWithName(x) ((CATRES *)GetResWithName(R_CATALOG, (x)))
#define GetScheduleResWithName(x) ((SCHEDRES *)GetResWithName(R_SCHEDULE, (x)))
1 change: 1 addition & 0 deletions src/dird/protos.h
Expand Up @@ -293,6 +293,7 @@ JOBRES *select_restore_job_resource(UAContext *ua);
CLIENTRES *select_client_resource(UAContext *ua);
CLIENTRES *select_enable_disable_client_resource(UAContext *ua, bool enable);
FILESETRES *select_fileset_resource(UAContext *ua);
SCHEDRES *select_enable_disable_schedule_resource(UAContext *ua, bool enable);
int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
int select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
bool select_pool_dbr(UAContext *ua, POOL_DBR *pr, const char *argk = "pool");
Expand Down
4 changes: 3 additions & 1 deletion src/dird/scheduler.c
Expand Up @@ -349,12 +349,14 @@ static void find_runs()
foreach_res(job, R_JOB) {
sched = job->schedule;
if (sched == NULL ||
!sched->enabled ||
!job->enabled ||
(job->client && !job->client->enabled)) { /* scheduled? or enabled? */
continue; /* no, skip this job */
}

Dmsg1(dbglvl, "Got job: %s\n", job->hdr.name);
for (run=sched->run; run; run=run->next) {
for (run = sched->run; run; run = run->next) {
bool run_now, run_nh;
/*
* Find runs scheduled between now and the next hour.
Expand Down
67 changes: 48 additions & 19 deletions src/dird/ua_cmds.c
Expand Up @@ -111,10 +111,10 @@ static struct cmdstruct commands[] = {
NT_("pool=<pool-name>"), false },
{ NT_("delete"), delete_cmd, _("Delete volume, pool or job"),
NT_("volume=<vol-name> pool=<pool-name> jobid=<jobid>"), true },
{ NT_("disable"), disable_cmd, _("Disable a job/client"),
NT_("job=<job-name> client=<client-name>"), true },
{ NT_("enable"), enable_cmd, _("Enable a job/client"),
NT_("job=<job-name> client=<client-name>"), true },
{ NT_("disable"), disable_cmd, _("Disable a job/client/schedule"),
NT_("job=<job-name> client=<client-name> schedule=<schedule-name>"), true },
{ NT_("enable"), enable_cmd, _("Enable a job/client/schedule"),
NT_("job=<job-name> client=<client-name> schedule=<schedule-name>"), true },
{ NT_("estimate"), estimate_cmd, _("Performs FileSet estimate, listing gives full listing"),
NT_("fileset=<fileset-name> client=<client-name> level=<level> accurate=<yes/no> job=<job-name> listing"), true },
{ NT_("exit"), quit_cmd, _("Terminate Bconsole session"),
Expand Down Expand Up @@ -943,48 +943,77 @@ static int setip_cmd(UAContext *ua, const char *cmd)

static void do_en_disable_cmd(UAContext *ua, bool setting)
{
SCHEDRES *sched = NULL;
CLIENTRES *client = NULL;
JOBRES *job = NULL;
int i;

i = find_arg(ua, NT_("client"));
i = find_arg(ua, NT_("schedule"));
if (i >= 0) {
i = find_arg_with_value(ua, NT_("client"));
i = find_arg_with_value(ua, NT_("schedule"));
if (i >= 0) {
LockRes();
client = GetClientResWithName(ua->argv[i]);
sched = GetScheduleResWithName(ua->argv[i]);
UnlockRes();
} else {
client = select_enable_disable_client_resource(ua, setting);
if (!client) {
sched = select_enable_disable_schedule_resource(ua, setting);
if (!sched) {
return;
}
}

if (!client) {
if (!sched) {
ua->error_msg(_("Client \"%s\" not found.\n"), ua->argv[i]);
return;
}
} else {
i = find_arg_with_value(ua, NT_("job"));
i = find_arg(ua, NT_("client"));
if (i >= 0) {
LockRes();
job = GetJobResWithName(ua->argv[i]);
UnlockRes();
i = find_arg_with_value(ua, NT_("client"));
if (i >= 0) {
LockRes();
client = GetClientResWithName(ua->argv[i]);
UnlockRes();
} else {
client = select_enable_disable_client_resource(ua, setting);
if (!client) {
return;
}
}

if (!client) {
ua->error_msg(_("Client \"%s\" not found.\n"), ua->argv[i]);
return;
}
} else {
job = select_enable_disable_job_resource(ua, setting);
i = find_arg_with_value(ua, NT_("job"));
if (i >= 0) {
LockRes();
job = GetJobResWithName(ua->argv[i]);
UnlockRes();
} else {
job = select_enable_disable_job_resource(ua, setting);
if (!job) {
return;
}
}

if (!job) {
ua->error_msg(_("Job \"%s\" not found.\n"), ua->argv[i]);
return;
}
}
}

if (!job) {
ua->error_msg(_("Job \"%s\" not found.\n"), ua->argv[i]);
if (sched) {
if (!acl_access_ok(ua, Schedule_ACL, sched->name())) {
ua->error_msg(_("Unauthorized command from this console.\n"));
return;
}
}

if (client) {
sched->enabled = setting;
ua->send_msg(_("Schedule \"%s\" %sabled\n"), sched->name(), setting ? "en" : "dis");
} else if (client) {
if (!acl_access_ok(ua, Client_ACL, client->name())) {
ua->error_msg(_("Unauthorized command from this console.\n"));
return;
Expand Down
27 changes: 27 additions & 0 deletions src/dird/ua_select.c
Expand Up @@ -410,6 +410,33 @@ CLIENTRES *get_client_resource(UAContext *ua)
return select_client_resource(ua);
}

/*
* Select a schedule to enable or disable
*/
SCHEDRES *select_enable_disable_schedule_resource(UAContext *ua, bool enable)
{
char name[MAX_NAME_LENGTH];
SCHEDRES *sched;

LockRes();
start_prompt(ua, _("The defined Schedule resources are:\n"));
foreach_res(sched, R_SCHEDULE) {
if (!acl_access_ok(ua, Schedule_ACL, sched->name())) {
continue;
}
if (sched->enabled == enable) { /* Already enabled/disabled? */
continue; /* yes, skip */
}
add_prompt(ua, sched->name());
}
UnlockRes();
if (do_prompt(ua, _("Schedule"), _("Select Schedule resource"), name, sizeof(name)) < 0) {
return NULL;
}
sched = (SCHEDRES *)GetResWithName(R_SCHEDULE, name);
return sched;
}

/* Scan what the user has entered looking for:
*
* client=<client-name>
Expand Down
4 changes: 4 additions & 0 deletions src/dird/ua_status.c
Expand Up @@ -646,6 +646,10 @@ static void do_scheduler_status(UAContext *ua)
foreach_res(sched, R_SCHEDULE) {
int cnt = 0;

if (!schedulegiven && !sched->enabled) {
continue;
}

if (!acl_access_ok(ua, Schedule_ACL, sched->hdr.name)) {
continue;
}
Expand Down

0 comments on commit 3bbfe41

Please sign in to comment.