Skip to content

Commit

Permalink
dird: cats: adding jobtype to list jobs command
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Apr 5, 2022
1 parent dbafa0f commit b082200
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
1 change: 1 addition & 0 deletions core/src/cats/cats.h
Expand Up @@ -791,6 +791,7 @@ class BareosDb : public BareosDbQueryEnum {
const char* clientname,
int jobstatus,
int joblevel,
int jobtype,
const char* volumename,
const char* poolname,
utime_t since_time,
Expand Down
6 changes: 6 additions & 0 deletions core/src/cats/sql_list.cc
Expand Up @@ -508,6 +508,7 @@ void BareosDb::ListJobRecords(JobControlRecord* jcr,
const char* clientname,
int jobstatus,
int joblevel,
int jobtype,
const char* volumename,
const char* poolname,
utime_t since_time,
Expand Down Expand Up @@ -547,6 +548,11 @@ void BareosDb::ListJobRecords(JobControlRecord* jcr,
PmStrcat(selection, temp.c_str());
}

if (jobtype) {
temp.bsprintf("AND Job.Type = '%c' ", jobtype);
PmStrcat(selection, temp.c_str());
}

if (volumename) {
temp.bsprintf("AND Media.Volumename = '%s' ", volumename);
PmStrcat(selection, temp.c_str());
Expand Down
20 changes: 14 additions & 6 deletions core/src/dird/ua_output.cc
Expand Up @@ -690,11 +690,19 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
return false;
}

// jobtype=X
int jobtype = 0;
if (!GetUserJobTypeSelection(ua, jobtype, false)) {
ua->ErrorMsg(_("invalid jobtype parameter\n"));
return false;
}

ListCmdOptions optionslist(ua);

char* volumename = nullptr;
char* poolname = nullptr;
int jobid;

// Select what to do based on the first argument.
if ((Bstrcasecmp(ua->argk[1], NT_("jobs")) && (ua->argv[1] == NULL))
|| ((Bstrcasecmp(ua->argk[1], NT_("job"))
Expand Down Expand Up @@ -748,9 +756,9 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
SetQueryRange(query_range, ua, &jr);

ua->db->ListJobRecords(ua->jcr, &jr, query_range.c_str(), clientname,
jobstatus, joblevel, volumename, poolname, schedtime,
optionslist.last, optionslist.count, ua->send,
llist);
jobstatus, joblevel, jobtype, volumename, poolname,
schedtime, optionslist.last, optionslist.count,
ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("jobtotals"))) {
// List JOBTOTALS
ua->db->ListJobTotals(ua->jcr, &jr, ua->send);
Expand Down Expand Up @@ -799,9 +807,9 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
SetQueryRange(query_range, ua, &jr);

ua->db->ListJobRecords(ua->jcr, &jr, query_range.c_str(), clientname,
jobstatus, joblevel, volumename, poolname,
schedtime, optionslist.last, optionslist.count,
ua->send, llist);
jobstatus, joblevel, jobtype, volumename,
poolname, schedtime, optionslist.last,
optionslist.count, ua->send, llist);
}
}
} else if (Bstrcasecmp(ua->argk[1], NT_("basefiles"))) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_prune.cc
Expand Up @@ -211,7 +211,7 @@ bool PruneCmd(UaContext* ua, const char* cmd)
}

// Ask what jobtype to prune.
if (!GetUserJobTypeSelection(ua, &jobtype)) { return false; }
if (!GetUserJobTypeSelection(ua, jobtype, true)) { return false; }

// Verify that result jobtype is valid (this should always be the case).
if (jobtype < 0) { return false; }
Expand Down
50 changes: 33 additions & 17 deletions core/src/dird/ua_select.cc
Expand Up @@ -994,7 +994,7 @@ PoolResource* get_pool_resource(UaContext* ua)
// List all jobs and ask user to select one
int SelectJobDbr(UaContext* ua, JobDbRecord* jr)
{
ua->db->ListJobRecords(ua->jcr, jr, "", NULL, 0, 0, NULL, NULL, 0, 0, 0,
ua->db->ListJobRecords(ua->jcr, jr, "", NULL, 0, 0, 0, NULL, NULL, 0, 0, 0,
ua->send, HORZ_LIST);
if (!GetPint(ua, _("Enter the JobId to select: "))) { return 0; }

Expand Down Expand Up @@ -1888,40 +1888,56 @@ bool GetUserSlotList(UaContext* ua,
return false;
}

bool GetUserJobTypeSelection(UaContext* ua, int* jobtype)
static int GetParsedJobType(std::string jobtype_argument)
{
int i;
char job_type[MAX_NAME_LENGTH];
int return_jobtype = -1;
if (jobtype_argument.size() == 1) {
for (i = 0; jobtypes[i].job_type; i++) {
if (jobtype_argument[0] == static_cast<char>(jobtypes[i].job_type)) {
break;
}
}
} else {
for (i = 0; jobtypes[i].type_name; i++) {
if (jobtypes[i].type_name == jobtype_argument) { break; }
}
}
if (jobtypes[i].type_name) { return_jobtype = jobtypes[i].job_type; }

return return_jobtype;
}

/* set returning jobtype to invalid */
*jobtype = -1;
bool GetUserJobTypeSelection(UaContext* ua, int& jobtype, bool ask_user)
{
int i;
char jobtype_argument[MAX_NAME_LENGTH];

if ((i = FindArgWithValue(ua, NT_("jobtype"))) >= 0) {
bstrncpy(job_type, ua->argv[i], sizeof(job_type));
} else {
StartPrompt(ua, _("Jobtype to prune:\n"));
bstrncpy(jobtype_argument, ua->argv[i], sizeof(jobtype_argument));
} else if (ask_user) {
StartPrompt(ua, _("Jobtype:\n"));
for (i = 0; jobtypes[i].type_name; i++) {
AddPrompt(ua, jobtypes[i].type_name);
}

if (DoPrompt(ua, _("JobType"), _("Select Job Type"), job_type,
sizeof(job_type))
if (DoPrompt(ua, _("JobType"), _("Select Job Type"), jobtype_argument,
sizeof(jobtype_argument))
< 0) {
return false;
}
} else {
return true;
}

for (i = 0; jobtypes[i].type_name; i++) {
if (Bstrcasecmp(jobtypes[i].type_name, job_type)) { break; }
}
int parsed_jobtype = GetParsedJobType(jobtype_argument);

if (!jobtypes[i].type_name) {
ua->WarningMsg(_("Illegal jobtype %s.\n"), job_type);
if (parsed_jobtype == -1) {
ua->WarningMsg(_("Illegal jobtype %s.\n"), jobtype_argument);
return false;
}

*jobtype = jobtypes[i].job_type;

jobtype = parsed_jobtype;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_select.h
Expand Up @@ -89,7 +89,7 @@ bool GetUserSlotList(UaContext* ua,
char* slot_list,
const char* argument,
int num_slots);
bool GetUserJobTypeSelection(UaContext* ua, int* jobtype);
bool GetUserJobTypeSelection(UaContext* ua, int &jobtype, bool ask_user);
bool GetUserJobStatusSelection(UaContext* ua, int* jobstatus);
bool GetUserJobLevelSelection(UaContext* ua, int* joblevel);

Expand Down

0 comments on commit b082200

Please sign in to comment.