Skip to content

Commit

Permalink
make JobStatus private and replace accesses with setter and getter
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and arogge committed Nov 7, 2022
1 parent d4c36b6 commit c94a9a9
Show file tree
Hide file tree
Showing 31 changed files with 90 additions and 80 deletions.
6 changes: 3 additions & 3 deletions core/src/cats/sql_create.cc
Expand Up @@ -802,7 +802,7 @@ bool BareosDb::CreateFilesetRecord(JobControlRecord* jcr, FileSetDbRecord* fsr)
bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
{
bool retval = false;
int JobStatus = jcr->JobStatus;
int JobStatus = jcr->getJobStatus();

if (!jcr->batch_started) { /* no files to backup ? */
Dmsg0(50, "db_create_file_record : no files\n");
Expand All @@ -811,7 +811,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)

Dmsg1(50, "db_create_file_record changes=%u\n", changes);

jcr->JobStatus = JS_AttrInserting;
jcr->setJobStatus(JS_AttrInserting);

Jmsg(jcr, M_INFO, 0,
"Insert of attributes batch table with %u entries start\n",
Expand Down Expand Up @@ -850,7 +850,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
}
/* clang-format on */

jcr->JobStatus = JobStatus; /* reset entry status */
jcr->setJobStatus(JobStatus); /* reset entry status */
Jmsg(jcr, M_INFO, 0, "Insert of attributes batch table done\n");
retval = true;

Expand Down
2 changes: 1 addition & 1 deletion core/src/cats/sql_update.cc
Expand Up @@ -102,7 +102,7 @@ bool BareosDb::UpdateJobStartRecord(JobControlRecord* jcr, JobDbRecord* jr)
"UPDATE Job SET JobStatus='%c',Level='%c',StartTime='%s',"
"ClientId=%s,JobTDate=%s,PoolId=%s,FileSetId=%s,VolSessionId=%lu,"
"VolSessionTime=%lu WHERE JobId=%s",
(char)(jcr->JobStatus), (char)(jr->JobLevel), dt,
(char)(jcr->getJobStatus()), (char)(jr->JobLevel), dt,
edit_int64(jr->ClientId, ed1), edit_uint64(JobTDate, ed2),
edit_int64(jr->PoolId, ed3), edit_int64(jr->FileSetId, ed4),
jcr->VolSessionId, jcr->VolSessionTime, edit_int64(jr->JobId, ed5));
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/admin.cc
Expand Up @@ -84,7 +84,7 @@ void AdminCleanup(JobControlRecord* jcr, int TermCode)
}

msg_type = M_INFO; /* by default INFO message */
switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Admin OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/archive.cc
Expand Up @@ -83,7 +83,7 @@ void ArchiveCleanup(JobControlRecord* jcr, int TermCode)
}

msg_type = M_INFO; /* by default INFO message */
switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Archive OK");
break;
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/backup.cc
Expand Up @@ -657,7 +657,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
== 7) {
fd_ok = true;
jcr->setJobStatusWithPriorityCheck(jcr->impl->FDJobStatus);
Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
Dmsg1(100, "FDStatus=%c\n", (char)jcr->getJobStatus());
} else {
Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
fd->msg);
Expand Down Expand Up @@ -717,7 +717,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
if (!fd_ok || IsBnetError(fd)) { /* if fd not set, that use !fd_ok */
jcr->impl->FDJobStatus = JS_ErrorTerminated;
}
if (jcr->JobStatus != JS_Terminated) { return jcr->JobStatus; }
if (jcr->getJobStatus() != JS_Terminated) { return jcr->getJobStatus(); }
if (jcr->impl->FDJobStatus != JS_Terminated) {
return jcr->impl->FDJobStatus;
}
Expand Down Expand Up @@ -757,7 +757,7 @@ void NativeBackupCleanup(JobControlRecord* jcr, int TermCode)

UpdateBootstrapFile(jcr);

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/consolidate.cc
Expand Up @@ -347,7 +347,7 @@ void ConsolidateCleanup(JobControlRecord* jcr, int TermCode)
}

msg_type = M_INFO; /* by default INFO message */
switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Consolidate OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/dir_plugins.cc
Expand Up @@ -642,7 +642,7 @@ static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value)
NPRT(*((char**)value)));
break;
case bDirVarJobStatus:
*((int*)value) = jcr->JobStatus;
*((int*)value) = jcr->getJobStatus();
Dmsg1(debuglevel, "dir-plugin: return bDirVarJobStatus=%c\n",
jcr->getJobStatus());
break;
Expand Down
24 changes: 13 additions & 11 deletions core/src/dird/jcr_private.h
Expand Up @@ -45,17 +45,19 @@ namespace storagedaemon {
struct BootStrapRecord;
} // namespace storagedaemon

#define JobWaiting(jcr) \
(jcr->job_started \
&& (jcr->JobStatus == JS_WaitFD || jcr->JobStatus == JS_WaitSD \
|| jcr->JobStatus == JS_WaitMedia || jcr->JobStatus == JS_WaitMount \
|| jcr->JobStatus == JS_WaitStoreRes || jcr->JobStatus == JS_WaitJobRes \
|| jcr->JobStatus == JS_WaitClientRes \
|| jcr->JobStatus == JS_WaitMaxJobs \
|| jcr->JobStatus == JS_WaitPriority \
|| jcr->impl->SDJobStatus == JS_WaitMedia \
|| jcr->impl->SDJobStatus == JS_WaitMount \
|| jcr->impl->SDJobStatus == JS_WaitDevice \
#define JobWaiting(jcr) \
(jcr->job_started \
&& (jcr->getJobStatus() == JS_WaitFD || jcr->getJobStatus() == JS_WaitSD \
|| jcr->getJobStatus() == JS_WaitMedia \
|| jcr->getJobStatus() == JS_WaitMount \
|| jcr->getJobStatus() == JS_WaitStoreRes \
|| jcr->getJobStatus() == JS_WaitJobRes \
|| jcr->getJobStatus() == JS_WaitClientRes \
|| jcr->getJobStatus() == JS_WaitMaxJobs \
|| jcr->getJobStatus() == JS_WaitPriority \
|| jcr->impl->SDJobStatus == JS_WaitMedia \
|| jcr->impl->SDJobStatus == JS_WaitMount \
|| jcr->impl->SDJobStatus == JS_WaitDevice \
|| jcr->impl->SDJobStatus == JS_WaitMaxJobs))

/* clang-format off */
Expand Down
10 changes: 5 additions & 5 deletions core/src/dird/job.cc
Expand Up @@ -675,7 +675,7 @@ void SdMsgThreadSendSignal(JobControlRecord* jcr, int sig)
bool CancelJob(UaContext* ua, JobControlRecord* jcr)
{
char ed1[50];
int32_t old_status = jcr->JobStatus;
int32_t old_status = jcr->getJobStatus();

jcr->setJobStatusWithPriorityCheck(JS_Canceled);

Expand Down Expand Up @@ -957,7 +957,7 @@ bool AllowDuplicateJob(JobControlRecord* jcr)
* If CancelQueuedDuplicates is set do so only if job is queued.
*/
if (job->CancelQueuedDuplicates) {
switch (djcr->JobStatus) {
switch (djcr->getJobStatus()) {
case JS_Created:
case JS_WaitJobRes:
case JS_WaitClientRes:
Expand Down Expand Up @@ -1399,7 +1399,7 @@ void InitJcrJobRecord(JobControlRecord* jcr)
jcr->impl->jr.EndTime = 0; /* perhaps rescheduled, clear it */
jcr->impl->jr.JobType = jcr->getJobType();
jcr->impl->jr.JobLevel = jcr->getJobLevel();
jcr->impl->jr.JobStatus = jcr->JobStatus;
jcr->impl->jr.JobStatus = jcr->getJobStatus();
jcr->impl->jr.JobId = jcr->JobId;
jcr->impl->jr.JobSumTotalBytes = 18446744073709551615LLU;
bstrncpy(jcr->impl->jr.Name, jcr->impl->res.job->resource_name_,
Expand All @@ -1413,7 +1413,7 @@ void UpdateJobEndRecord(JobControlRecord* jcr)
jcr->impl->jr.EndTime = time(NULL);
jcr->end_time = jcr->impl->jr.EndTime;
jcr->impl->jr.JobId = jcr->JobId;
jcr->impl->jr.JobStatus = jcr->JobStatus;
jcr->impl->jr.JobStatus = jcr->getJobStatus();
jcr->impl->jr.JobFiles = jcr->JobFiles;
jcr->impl->jr.JobBytes = jcr->JobBytes;
jcr->impl->jr.ReadBytes = jcr->ReadBytes;
Expand Down Expand Up @@ -1636,7 +1636,7 @@ void SetJcrDefaults(JobControlRecord* jcr, JobResource* job)
jcr->impl->res.job = job;
jcr->setJobType(job->JobType);
jcr->setJobProtocol(job->Protocol);
jcr->JobStatus = JS_Created;
jcr->setJobStatus(JS_Created);

switch (jcr->getJobType()) {
case JT_ADMIN:
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/jobq.cc
Expand Up @@ -625,7 +625,7 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je)
_("Rescheduled Job %s at %s to re-run in %d seconds (%s).\n"),
jcr->Job, dt, (int)jcr->impl->res.job->RescheduleInterval, dt2);
DirdFreeJcrPointers(jcr); /* partial cleanup old stuff */
jcr->JobStatus = -1;
jcr->setJobStatus(-1);
jcr->impl->SDJobStatus = 0;
jcr->JobErrors = 0;
if (!AllowDuplicateJob(jcr)) { return false; }
Expand Down Expand Up @@ -675,8 +675,8 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je)
njcr->impl->res.next_pool = jcr->impl->res.next_pool;
njcr->impl->res.run_next_pool_override
= jcr->impl->res.run_next_pool_override;
njcr->JobStatus = -1;
njcr->setJobStatusWithPriorityCheck(jcr->JobStatus);
njcr->setJobStatus(-1);
njcr->setJobStatusWithPriorityCheck(jcr->getJobStatus());
if (jcr->impl->res.read_storage) {
CopyRstorage(njcr, jcr->impl->res.read_storage_list, _("previous Job"));
} else {
Expand Down
14 changes: 7 additions & 7 deletions core/src/dird/migrate.cc
Expand Up @@ -1243,7 +1243,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
edit_int64(jcr->impl->previous_jr.JobId, ed1),
jcr->get_ActionName(true), jcr->get_OperationName());
jcr->setJobStatusWithPriorityCheck(JS_Terminated);
MigrationCleanup(jcr, jcr->JobStatus);
MigrationCleanup(jcr, jcr->getJobStatus());
return true;
}

Expand All @@ -1253,7 +1253,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
edit_int64(jcr->impl->previous_jr.JobId, ed1),
jcr->get_OperationName());
jcr->setJobStatusWithPriorityCheck(JS_Terminated);
MigrationCleanup(jcr, jcr->JobStatus);
MigrationCleanup(jcr, jcr->getJobStatus());
return true;
}

Expand Down Expand Up @@ -1501,7 +1501,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
FreePairedStorage(jcr);

if (jcr->is_JobStatus(JS_Terminated)) {
MigrationCleanup(jcr, jcr->JobStatus);
MigrationCleanup(jcr, jcr->getJobStatus());
retval = true;
}

Expand All @@ -1516,7 +1516,7 @@ static inline bool DoMigrationSelection(JobControlRecord* jcr)
retval = getJobs_to_migrate(jcr);
if (retval) {
jcr->setJobStatusWithPriorityCheck(JS_Terminated);
MigrationCleanup(jcr, jcr->JobStatus);
MigrationCleanup(jcr, jcr->getJobStatus());
} else {
jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
Expand Down Expand Up @@ -1852,7 +1852,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
}
}

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("%s OK");
break;
Expand All @@ -1868,7 +1868,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
* can be different so that is why we do a second switch inside the
* switch on the JobStatus.
*/
switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Canceled:
TermMsg = _("%s Canceled");
break;
Expand Down Expand Up @@ -1902,7 +1902,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
Mmsg(query, "DELETE FROM job WHERE JobId=%d", jcr->JobId);
jcr->db->SqlQuery(query.c_str());

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("%s OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ndmp_dma_backup_common.cc
Expand Up @@ -293,7 +293,7 @@ void NdmpBackupCleanup(JobControlRecord* jcr, int TermCode)

UpdateBootstrapFile(jcr);

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc
Expand Up @@ -344,7 +344,7 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr)
WaitForStorageDaemonTermination(jcr);

jcr->impl->FDJobStatus = JS_Terminated;
if (jcr->JobStatus != JS_Terminated) { return jcr->JobStatus; }
if (jcr->getJobStatus() != JS_Terminated) { return jcr->getJobStatus(); }
if (jcr->impl->FDJobStatus != JS_Terminated) {
return jcr->impl->FDJobStatus;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/ua_cmds.cc
Expand Up @@ -623,7 +623,7 @@ bool Do_a_command(UaContext* ua)
* ua->jcr->setJobStatus(JS_Running)
* isn't enough, as it does not overwrite error states.
*/
ua->jcr->JobStatus = JS_Running;
ua->jcr->setJobStatus(JS_Running);

if (ua->api) { user->signal(BNET_CMD_BEGIN); }
ua->send->SetMode(ua->api);
Expand Down Expand Up @@ -2741,8 +2741,8 @@ static bool wait_cmd(UaContext* ua, const char*)
for (bool waiting = false; !waiting;) {
foreach_jcr (jcr) {
if (jcr->JobId != 0
&& (jcr->JobStatus == JS_WaitMedia
|| jcr->JobStatus == JS_WaitMount)) {
&& (jcr->getJobStatus() == JS_WaitMedia
|| jcr->getJobStatus() == JS_WaitMount)) {
waiting = true;
break;
}
Expand Down
10 changes: 7 additions & 3 deletions core/src/dird/ua_select.cc
Expand Up @@ -1691,16 +1691,20 @@ alist<JobId_t*>* select_jobs(UaContext* ua, const char* reason)
case all_jobs:
break;
case created_jobs:
if (jcr->JobStatus != JS_Created) { continue; }
if (jcr->getJobStatus() != JS_Created) { continue; }
break;
case blocked_jobs:
if (!jcr->job_started || jcr->JobStatus != JS_Blocked) { continue; }
if (!jcr->job_started || jcr->getJobStatus() != JS_Blocked) {
continue;
}
break;
case waiting_jobs:
if (!JobWaiting(jcr)) { continue; }
break;
case running_jobs:
if (!jcr->job_started || jcr->JobStatus != JS_Running) { continue; }
if (!jcr->job_started || jcr->getJobStatus() != JS_Running) {
continue;
}
break;
default:
break;
Expand Down
10 changes: 5 additions & 5 deletions core/src/dird/ua_status.cc
Expand Up @@ -291,12 +291,12 @@ static void DoAllStatus(UaContext* ua)
}
UnlockRes(my_config);

previous_JobStatus = ua->jcr->JobStatus;
previous_JobStatus = ua->jcr->getJobStatus();

/* Call each unique Storage daemon */
for (j = 0; j < i; j++) {
StorageStatus(ua, unique_store[j], NULL);
ua->jcr->JobStatus = previous_JobStatus;
ua->jcr->setJobStatus(previous_JobStatus);
}
free(unique_store);

Expand Down Expand Up @@ -326,12 +326,12 @@ static void DoAllStatus(UaContext* ua)
}
UnlockRes(my_config);

previous_JobStatus = ua->jcr->JobStatus;
previous_JobStatus = ua->jcr->getJobStatus();

/* Call each unique File daemon */
for (j = 0; j < i; j++) {
ClientStatus(ua, unique_client[j], NULL);
ua->jcr->JobStatus = previous_JobStatus;
ua->jcr->setJobStatus(previous_JobStatus);
}
free(unique_client);
}
Expand Down Expand Up @@ -970,7 +970,7 @@ static void ListRunningJobs(UaContext* ua)
continue;
}
njobs++;
switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Created:
msg = _("is waiting execution");
break;
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/vbackup.cc
Expand Up @@ -380,7 +380,7 @@ bool DoNativeVbackup(JobControlRecord* jcr)
jcr); /* used by bulk batch file insert */
if (!jcr->is_JobStatus(JS_Terminated)) { return false; }

NativeVbackupCleanup(jcr, jcr->JobStatus, JobLevel_of_first_job);
NativeVbackupCleanup(jcr, jcr->getJobStatus(), JobLevel_of_first_job);

// Remove the successfully consolidated jobids from the database
if (jcr->impl->res.job->AlwaysIncremental
Expand All @@ -407,7 +407,7 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)

Dmsg2(100, "Enter backup_cleanup %d %c\n", TermCode, TermCode);

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
case JS_Warnings:
jcr->impl->jr.JobLevel = JobLevel; /* We want this to appear as what the
Expand Down Expand Up @@ -456,7 +456,7 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)

UpdateBootstrapFile(jcr);

switch (jcr->JobStatus) {
switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
Expand Down
2 changes: 1 addition & 1 deletion core/src/filed/fd_plugins.cc
Expand Up @@ -2054,7 +2054,7 @@ static bRC bareosGetValue(PluginContext* ctx, bVariable var, void* value)
NPRT(*((char**)value)));
break;
case bVarJobStatus:
*((int*)value) = jcr->JobStatus;
*((int*)value) = jcr->getJobStatus();
Dmsg1(debuglevel, "fd-plugin: return bVarJobStatus=%d\n",
jcr->getJobStatus());
break;
Expand Down

0 comments on commit c94a9a9

Please sign in to comment.