Skip to content

Commit

Permalink
Rerun command can rerun multiple failed jobs
Browse files Browse the repository at this point in the history
We can now automatically choose multiple failed jobs
for rerunning.

The selection of the failed jobs to rerun are:

- Timeframe in which the failed jobs were scheduled
  -> specify "days=" or "hours="

- Jobs newer than a certain jobid (the given jobid is included)
  -> specifying "since_jobid"

Fixes #168 : Enhance rerun command to be able to restart all failed jobs from last n days

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 6d99a2b commit 697e6ff
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 87 deletions.
129 changes: 68 additions & 61 deletions src/console/console.c
Expand Up @@ -66,7 +66,6 @@ extern "C" void got_sigcontinue(int sig);
extern "C" void got_sigtout(int sig);
extern "C" void got_sigtin(int sig);


/* Static variables */
static char *configfile = NULL;
static BSOCK *UA_sock = NULL;
Expand All @@ -84,7 +83,6 @@ static char *argk[MAX_CMD_ARGS];
static char *argv[MAX_CMD_ARGS];
static CONFIG *config;


/* Command prototypes */
static int versioncmd(FILE *input, BSOCK *UA_sock);
static int inputcmd(FILE *input, BSOCK *UA_sock);
Expand All @@ -99,14 +97,13 @@ static int execcmd(FILE *input, BSOCK *UA_sock);
#ifdef HAVE_READLINE
static int eolcmd(FILE *input, BSOCK *UA_sock);

# ifndef HAVE_REGEX_H
# include "lib/bregex.h"
# else
# include <regex.h>
# endif

#ifndef HAVE_REGEX_H
#include "lib/bregex.h"
#else
#include <regex.h>
#endif

#endif

#define CONFIG_FILE "bconsole.conf" /* default configuration file */

Expand All @@ -129,7 +126,6 @@ PROG_COPYRIGHT
"\n"), 2000, HOST_OS, DISTNAME, DISTVER);
}


extern "C"
void got_sigstop(int sig)
{
Expand All @@ -154,7 +150,6 @@ void got_sigtin(int sig)
// printf("Got tin\n");
}


static int zed_keyscmd(FILE *input, BSOCK *UA_sock)
{
con_set_zed_keys();
Expand All @@ -164,24 +159,28 @@ static int zed_keyscmd(FILE *input, BSOCK *UA_sock)
/*
* These are the @command
*/
struct cmdstruct { const char *key; int (*func)(FILE *input, BSOCK *UA_sock); const char *help; };
struct cmdstruct {
const char *key;
int (*func)(FILE *input, BSOCK *UA_sock);
const char *help;
};
static struct cmdstruct commands[] = {
{ N_("input"), inputcmd, _("input from file")},
{ N_("output"), outputcmd, _("output to file")},
{ N_("quit"), quitcmd, _("quit")},
{ N_("tee"), teecmd, _("output to file and terminal")},
{ N_("sleep"), sleepcmd, _("sleep specified time")},
{ N_("time"), timecmd, _("print current time")},
{ N_("version"), versioncmd, _("print Console's version")},
{ N_("echo"), echocmd, _("echo command string")},
{ N_("exec"), execcmd, _("execute an external command")},
{ N_("exit"), quitcmd, _("exit = quit")},
{ N_("zed_keys"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")},
{ N_("help"), helpcmd, _("help listing")},
{ N_("input"), inputcmd, _("input from file")},
{ N_("output"), outputcmd, _("output to file")},
{ N_("quit"), quitcmd, _("quit")},
{ N_("tee"), teecmd, _("output to file and terminal")},
{ N_("sleep"), sleepcmd, _("sleep specified time")},
{ N_("time"), timecmd, _("print current time")},
{ N_("version"), versioncmd, _("print Console's version")},
{ N_("echo"), echocmd, _("echo command string")},
{ N_("exec"), execcmd, _("execute an external command")},
{ N_("exit"), quitcmd, _("exit = quit")},
{ N_("zed_keys"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")},
{ N_("help"), helpcmd, _("help listing")},
#ifdef HAVE_READLINE
{ N_("separator"), eolcmd, _("set command separator")},
{ N_("separator"), eolcmd, _("set command separator")},
#endif
};
};
#define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct)))

static int do_a_command(FILE *input, BSOCK *UA_sock)
Expand Down Expand Up @@ -220,7 +219,6 @@ static int do_a_command(FILE *input, BSOCK *UA_sock)
return status;
}


static void read_and_process_input(FILE *input, BSOCK *UA_sock)
{
const char *prompt = "*";
Expand Down Expand Up @@ -331,21 +329,21 @@ static int tls_pem_callback(char *buf, int size, const void *userdata)
{
#ifdef HAVE_TLS
const char *prompt = (const char *)userdata;
# if defined(HAVE_WIN32)
#if defined(HAVE_WIN32)
sendit(prompt);
if (win32_cgets(buf, size) == NULL) {
buf[0] = 0;
return 0;
} else {
return strlen(buf);
}
# else
#else
char *passwd;

passwd = getpass(prompt);
bstrncpy(buf, passwd, size);
return strlen(buf);
# endif
#endif
#else
buf[0] = 0;
return 0;
Expand All @@ -357,9 +355,10 @@ static int tls_pem_callback(char *buf, int size, const void *userdata)
#include "readline/readline.h"
#include "readline/history.h"

/* Get the first keyword of the line */
static char *
get_first_keyword()
/*
* Get the first keyword of the line
*/
static char *get_first_keyword()
{
char *ret=NULL;
int len;
Expand All @@ -377,34 +376,41 @@ get_first_keyword()
* Return the command before the current point.
* Set nb to the number of command to skip
*/
static char *
get_previous_keyword(int current_point, int nb)
static char *get_previous_keyword(int current_point, int nb)
{
int i, end=-1, start, inquotes=0;
char *s=NULL;

while (nb-- >= 0) {
/* first we look for a space before the current word */
/*
* First we look for a space before the current word
*/
for (i = current_point; i >= 0; i--) {
if (rl_line_buffer[i] == ' ' || rl_line_buffer[i] == '=') {
break;
}
}

/* find the end of the command */
/*
* Find the end of the command
*/
for (; i >= 0; i--) {
if (rl_line_buffer[i] != ' ') {
end = i;
break;
}
}

/* no end of string */
/*
* No end of string
*/
if (end == -1) {
return NULL;
}

/* look for the start of the command */
/*
* Look for the start of the command
*/
for (start = end; start > 0; start--) {
if (rl_line_buffer[start] == '"') {
inquotes = !inquotes;
Expand All @@ -425,7 +431,9 @@ get_previous_keyword(int current_point, int nb)
return s;
}

/* Simple structure that will contain the completion list */
/*
* Simple structure that will contain the completion list
*/
struct ItemList {
alist list;
};
Expand Down Expand Up @@ -484,7 +492,7 @@ void get_arguments(const char *what)
int rc;
init_items();

rc = regcomp(&preg, "(([a-z]+=)|([a-z]+)( |$))", REG_EXTENDED);
rc = regcomp(&preg, "(([a-z_]+=)|([a-z]+)( |$))", REG_EXTENDED);
if (rc != 0) {
return;
}
Expand Down Expand Up @@ -620,18 +628,18 @@ static char **readline_completion(const char *text, int start, int end)
matches = (char **)NULL;

/* If this word is at the start of the line, then it is a command
* to complete. Otherwise it is the name of a file in the current
* to complete. Otherwise it is the name of a file in the current
* directory.
*/
s = get_previous_keyword(start, 0);
cmd = get_first_keyword();
if (s) {
for (int i=0; i < key_size; i++) {
for (int i = 0; i < key_size; i++) {
if (bstrcasecmp(s, cpl_keywords[i].key)) {
cpl_item = cpl_keywords[i].cmd;
cpl_type = ITEM_ARG;
matches = rl_completion_matches(text, cpl_generator);
found=true;
found = true;
break;
}
}
Expand All @@ -640,7 +648,7 @@ static char **readline_completion(const char *text, int start, int end)
cpl_item = cmd;
cpl_type = ITEM_HELP;
/* we don't want to append " " at the end */
rl_completion_suppress_append=true;
rl_completion_suppress_append = true;
matches = rl_completion_matches(text, cpl_generator);
}
free(s);
Expand Down Expand Up @@ -673,8 +681,7 @@ static int eolcmd(FILE *input, BSOCK *UA_sock)
* 0 if no input
* -1 error (must stop)
*/
int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
static char *line = NULL;
static char *next = NULL;
Expand Down Expand Up @@ -752,8 +759,7 @@ static bool bisatty(int fd)
* Returns: 1 if got input
* -1 if EOF or error
*/
int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
int len;

Expand Down Expand Up @@ -804,8 +810,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
* 0 if timeout
* -1 if EOF or error
*/
int
get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
{
int len;

Expand Down Expand Up @@ -966,16 +971,22 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
}
UnlockRes();
}

/*
* Look for a console linked to this director
*/
LockRes();
/* Look for a console linked to this director */
for (i=0; i<numcon; i++) {
cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)cons);
if (cons->director && bstrcmp(cons->director, dir->hdr.name)) {
break;
}
cons = NULL;
}
/* Look for the first non-linked console */

/*
* Look for the first non-linked console
*/
if (cons == NULL) {
for (i=0; i<numcon; i++) {
cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)cons);
Expand All @@ -985,7 +996,9 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
}
}

/* If no console, take first one */
/*
* If no console, take first one
*/
if (!cons) {
cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
}
Expand All @@ -997,10 +1010,8 @@ static bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret
return 1;
}

/*********************************************************************
*
* Main Bareos Console -- User Interface Program
*
/*
* Main Bareos Console -- User Interface Program
*/
int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -1438,7 +1449,6 @@ static int outputcmd(FILE *input, BSOCK *UA_sock)
return do_outputcmd(input, UA_sock);
}


static int do_outputcmd(FILE *input, BSOCK *UA_sock)
{
FILE *fd;
Expand Down Expand Up @@ -1507,7 +1517,6 @@ static int execcmd(FILE *input, BSOCK *UA_sock)
return 1;
}


/* @echo xxx yyy */
static int echocmd(FILE *input, BSOCK *UA_sock)
{
Expand All @@ -1534,7 +1543,6 @@ static int helpcmd(FILE *input, BSOCK *UA_sock)
return 1;
}


/* @sleep secs */
static int sleepcmd(FILE *input, BSOCK *UA_sock)
{
Expand Down Expand Up @@ -1599,7 +1607,6 @@ void sendit(const char *buf)
fputs(buf, output);
}
#else

fputs(buf, output);
fflush(output);
if (teeout) {
Expand Down
4 changes: 2 additions & 2 deletions src/dird/ua_cmds.c
Expand Up @@ -178,7 +178,7 @@ static struct cmdstruct commands[] = {
{ NT_("reload"), reload_cmd, _("Reload conf file"),
NT_(""), true },
{ NT_("rerun"), rerun_cmd, _("Rerun a job"),
NT_("jobid=<jobid> yes"), false },
NT_("jobid=<jobid> | since_jobid=<jobid> | days=<nr_days> | hours=<nr_hours> | yes"), false },
{ NT_("run"), run_cmd, _("Run a job"),
NT_("job=<job-name> client=<client-name>\n"
"\tfileset=<fileset-name> level=<level>\n"
Expand All @@ -187,7 +187,7 @@ 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=nnn | job=<job-name> | schedule=<schedule-name>"), true },
"\tstorage=<storage-name> slots | days=<nr_days> | job=<job-name> | schedule=<schedule-name>"), 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

0 comments on commit 697e6ff

Please sign in to comment.