Skip to content

Commit

Permalink
Merge pull request #492 from arogge/dev/arogge/deprecation-messages
Browse files Browse the repository at this point in the history
add infrastructure for configuration warnings
  • Loading branch information
arogge committed Apr 27, 2020
2 parents b3a7b94 + c4e88eb commit 45aed68
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 192 deletions.
12 changes: 11 additions & 1 deletion core/src/dird/dird.cc
Expand Up @@ -395,7 +395,16 @@ int main(int argc, char* argv[])
goto bail_out;
}

if (test_config) { TerminateDird(0); }
if (test_config) {
if (my_config->HasWarnings()) {
/* messaging not initialized, so Jmsg with M_WARNING doesn't work */
fprintf(stderr, _("There are configuration warnings:\n"));
for (auto& warning : my_config->GetWarnings()) {
fprintf(stderr, " * %s\n", warning.c_str());
}
}
TerminateDird(0);
}

if (!InitializeSqlPooling()) {
Jmsg((JobControlRecord*)NULL, M_ERROR_TERM, 0,
Expand Down Expand Up @@ -578,6 +587,7 @@ bool DoReloadConfig()
Dmsg0(100, "Reloading config file\n");

my_config->err_type_ = M_ERROR;
my_config->ClearWarnings();
bool ok = my_config->ParseConfig();

if (!ok || !CheckResources() || !CheckCatalog(UPDATE_CATALOG) ||
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ua_cmds.cc
Expand Up @@ -470,8 +470,8 @@ static struct ua_cmdstruct commands[] = {
{NT_("status"), StatusCmd, _("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> |\n"
"\tsubscriptions"),
"storage=<storage-name> slots | days=<nr_days> | job=<job-name> |\n"
"subscriptions | configuration"),
true, true},
{NT_("setbandwidth"), SetbwlimitCmd, _("Sets bandwidth"),
NT_("client=<client-name> | storage=<storage-name> | jobid=<jobid> |\n"
Expand Down
24 changes: 24 additions & 0 deletions core/src/dird/ua_status.cc
Expand Up @@ -63,6 +63,7 @@ static void ListConnectedClients(UaContext* ua);
static void DoDirectorStatus(UaContext* ua);
static void DoSchedulerStatus(UaContext* ua);
static bool DoSubscriptionStatus(UaContext* ua);
static void DoConfigurationStatus(UaContext* ua);
static void DoAllStatus(UaContext* ua);
static void StatusSlots(UaContext* ua, StorageResource* store);
static void StatusContentApi(UaContext* ua, StorageResource* store);
Expand Down Expand Up @@ -191,6 +192,9 @@ bool StatusCmd(UaContext* ua, const char* cmd)
} else {
return false;
}
} else if (bstrncasecmp(ua->argk[i], NT_("conf"), 4)) {
DoConfigurationStatus(ua);
return true;
} else {
/*
* limit storages to autochangers if slots is given
Expand Down Expand Up @@ -369,6 +373,14 @@ void ListDirStatusHeader(UaContext* ua)

len = ListDirPlugins(msg);
if (len > 0) { ua->SendMsg("%s\n", msg.c_str()); }

if (my_config->HasWarnings()) {
ua->SendMsg(
_("\n"
"There are WARNINGS for the director configuration!\n"
"See 'status configuration' for details.\n"
"\n"));
}
}

static bool show_scheduled_preview(UaContext* ua,
Expand Down Expand Up @@ -525,6 +537,18 @@ static bool DoSubscriptionStatus(UaContext* ua)
return retval;
}

static void DoConfigurationStatus(UaContext* ua)
{
if(my_config->HasWarnings()) {
ua->SendMsg(_("Deprecated configuration settings detected:\n"));
for(auto& warning : my_config->GetWarnings()) {
ua->SendMsg(" * %s\n", warning.c_str());
}
} else {
ua->SendMsg(_("No deprecated configuration settings detected.\n"));
}
}

static void DoSchedulerStatus(UaContext* ua)
{
int i;
Expand Down
11 changes: 10 additions & 1 deletion core/src/filed/filed.cc
Expand Up @@ -259,7 +259,16 @@ int main(int argc, char* argv[])
}
#endif

if (test_config) { TerminateFiled(0); }
if (test_config) {
if (my_config->HasWarnings()) {
/* messaging not initialized, so Jmsg with M_WARNING doesn't work */
fprintf(stderr, _("There are configuration warnings:\n"));
for (auto& warning : my_config->GetWarnings()) {
fprintf(stderr, " * %s\n", warning.c_str());
}
}
TerminateFiled(0);
}

SetThreadConcurrency(me->MaxConcurrentJobs * 2 + 10);

Expand Down
95 changes: 43 additions & 52 deletions core/src/filed/status.cc
Expand Up @@ -33,9 +33,10 @@
#include "filed/filed.h"
#include "filed/filed_globals.h"
#include "filed/jcr_private.h"
#include "lib/status.h"
#include "lib/status_packet.h"
#include "lib/bsock.h"
#include "lib/edit.h"
#include "lib/parse_conf.h"
#include "lib/recent_job_results_list.h"
#include "findlib/enable_priv.h"
#include "lib/util.h"
Expand All @@ -48,7 +49,6 @@ namespace filedaemon {
static void ListTerminatedJobs(StatusPacket* sp);
static void ListRunningJobs(StatusPacket* sp);
static void ListStatusHeader(StatusPacket* sp);
static void sendit(PoolMem& msg, int len, StatusPacket* sp);
static const char* JobLevelToString(int level);

/* Static variables */
Expand Down Expand Up @@ -93,28 +93,28 @@ static void ListStatusHeader(StatusPacket* sp)
len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s %s\n"), my_name,
kBareosVersionStrings.Full, kBareosVersionStrings.Date, VSS,
HOST_OS, DISTNAME, DISTVER);
sendit(msg, len, sp);
sp->send(msg, len);
bstrftime_nc(dt, sizeof(dt), daemon_start_time);
len = Mmsg(msg, _("Daemon started %s. Jobs: run=%d running=%d, %s binary\n"),
dt, num_jobs_run, JobCount(), kBareosVersionStrings.BinaryInfo);
sendit(msg, len, sp);
sp->send(msg, len);

#if defined(HAVE_WIN32)
if (GetWindowsVersionString(buf, sizeof(buf))) {
len = Mmsg(msg, "%s\n", buf);
sendit(msg, len, sp);
sp->send(msg, len);
}

if (debug_level > 0) {
if (!privs) { privs = EnableBackupPrivileges(NULL, 1); }
len = Mmsg(msg, "Priv 0x%x\n", privs);
sendit(msg, len, sp);
sp->send(msg, len);
len =
Mmsg(msg, "APIs=%sOPT,%sATP,%sLPV,%sCFA,%sCFW,\n",
p_OpenProcessToken ? "" : "!", p_AdjustTokenPrivileges ? "" : "!",
p_LookupPrivilegeValue ? "" : "!", p_CreateFileA ? "" : "!",
p_CreateFileW ? "" : "!");
sendit(msg, len, sp);
sp->send(msg, len);
len = Mmsg(msg,
" %sWUL,%sWMKD,%sGFAA,%sGFAW,%sGFAEA,%sGFAEW,%sSFAA,%sSFAW,%sBR,"
"%sBW,%sSPSP,\n",
Expand All @@ -125,20 +125,20 @@ static void ListStatusHeader(StatusPacket* sp)
p_SetFileAttributesA ? "" : "!", p_SetFileAttributesW ? "" : "!",
p_BackupRead ? "" : "!", p_BackupWrite ? "" : "!",
p_SetProcessShutdownParameters ? "" : "!");
sendit(msg, len, sp);
sp->send(msg, len);
len = Mmsg(
msg, " %sWC2MB,%sMB2WC,%sFFFA,%sFFFW,%sFNFA,%sFNFW,%sSCDA,%sSCDW,\n",
p_WideCharToMultiByte ? "" : "!", p_MultiByteToWideChar ? "" : "!",
p_FindFirstFileA ? "" : "!", p_FindFirstFileW ? "" : "!",
p_FindNextFileA ? "" : "!", p_FindNextFileW ? "" : "!",
p_SetCurrentDirectoryA ? "" : "!", p_SetCurrentDirectoryW ? "" : "!");
sendit(msg, len, sp);
sp->send(msg, len);
len =
Mmsg(msg, " %sGCDA,%sGCDW,%sGVPNW,%sGVNFVMPW\n",
p_GetCurrentDirectoryA ? "" : "!",
p_GetCurrentDirectoryW ? "" : "!", p_GetVolumePathNameW ? "" : "!",
p_GetVolumeNameForVolumeMountPointW ? "" : "!");
sendit(msg, len, sp);
sp->send(msg, len);
}
#endif

Expand All @@ -147,16 +147,23 @@ static void ListStatusHeader(StatusPacket* sp)
"bwlimit=%skB/s\n"),
sizeof(boffset_t), sizeof(size_t), debug_level, GetTrace(),
edit_uint64_with_commas(me->max_bandwidth_per_job / 1024, b1));
sendit(msg, len, sp);
sp->send(msg, len);

if (me->secure_erase_cmdline) {
len =
Mmsg(msg, _(" secure erase command='%s'\n"), me->secure_erase_cmdline);
sendit(msg, len, sp);
sp->send(msg, len);
}

len = ListFdPlugins(msg);
if (len > 0) { sendit(msg, len, sp); }
if (len > 0) { sp->send(msg, len); }

if (my_config->HasWarnings()) {
sp->send(
"\n"
"There are WARNINGS for this filedaemon's configuration!\n"
"See output of 'bareos-fd -t' for details.\n");
}
}

static void ListRunningJobsPlain(StatusPacket* sp)
Expand All @@ -172,14 +179,14 @@ static void ListRunningJobsPlain(StatusPacket* sp)
*/
Dmsg0(1000, "Begin status jcr loop.\n");
len = Mmsg(msg, _("\nRunning Jobs:\n"));
sendit(msg, len, sp);
sp->send(msg, len);

foreach_jcr (njcr) {
bstrftime_nc(dt, sizeof(dt), njcr->start_time);
if (njcr->JobId > 0) {
len =
Mmsg(msg, _("JobId %d Job %s is running.\n"), njcr->JobId, njcr->Job);
sendit(msg, len, sp);
sp->send(msg, len);
#ifdef WIN32_VSS
len = Mmsg(
msg, _(" %s%s %s Job started: %s\n"),
Expand All @@ -203,7 +210,7 @@ static void ListRunningJobsPlain(StatusPacket* sp)
*/
len = Mmsg(msg, _("Unknown connection, started at: %s\n"), dt);
}
sendit(msg, len, sp);
sp->send(msg, len);
if (njcr->JobId == 0) { continue; }
sec = time(NULL) - njcr->start_time;
if (sec <= 0) { sec = 1; }
Expand All @@ -215,36 +222,36 @@ static void ListRunningJobsPlain(StatusPacket* sp)
edit_uint64_with_commas(njcr->JobBytes, b2),
edit_uint64_with_commas(bps, b3), njcr->JobErrors,
edit_uint64_with_commas(njcr->max_bandwidth, b4));
sendit(msg, len, sp);
sp->send(msg, len);
len = Mmsg(msg, _(" Files Examined=%s\n"),
edit_uint64_with_commas(njcr->impl->num_files_examined, b1));
sendit(msg, len, sp);
sp->send(msg, len);
if (njcr->JobFiles > 0) {
njcr->lock();
len = Mmsg(msg, _(" Processing file: %s\n"), njcr->impl->last_fname);
njcr->unlock();
sendit(msg, len, sp);
sp->send(msg, len);
}

found = true;
if (njcr->store_bsock) {
len = Mmsg(msg, " SDReadSeqNo=%" lld " fd=%d\n",
njcr->store_bsock->read_seqno, njcr->store_bsock->fd_);
sendit(msg, len, sp);
sp->send(msg, len);
} else {
len = Mmsg(msg, _(" SDSocket closed.\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}
}
endeach_jcr(njcr);

if (!found) {
len = Mmsg(msg, _("No Jobs running.\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}

len = PmStrcpy(msg, _("====\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}

static void ListRunningJobsApi(StatusPacket* sp)
Expand All @@ -263,7 +270,7 @@ static void ListRunningJobsApi(StatusPacket* sp)
len = Mmsg(msg, "DirectorConnected=%s\n", dt);
} else {
len = Mmsg(msg, "JobId=%d\n Job=%s\n", njcr->JobId, njcr->Job);
sendit(msg, len, sp);
sp->send(msg, len);
#ifdef WIN32_VSS
len = Mmsg(
msg, " VSS=%d\n Level=%c\n JobType=%c\n JobStarted=%s\n",
Expand All @@ -276,7 +283,7 @@ static void ListRunningJobsApi(StatusPacket* sp)
njcr->getJobLevel(), njcr->getJobType(), dt);
#endif
}
sendit(msg, len, sp);
sp->send(msg, len);
if (njcr->JobId == 0) { continue; }
sec = time(NULL) - njcr->start_time;
if (sec <= 0) { sec = 1; }
Expand All @@ -287,24 +294,24 @@ static void ListRunningJobsApi(StatusPacket* sp)
edit_uint64(njcr->JobFiles, b1), edit_uint64(njcr->JobBytes, b2),
edit_uint64(bps, b3), njcr->JobErrors,
edit_int64(njcr->max_bandwidth, b4));
sendit(msg, len, sp);
sp->send(msg, len);
len = Mmsg(msg, " Files Examined=%s\n",
edit_uint64(njcr->impl->num_files_examined, b1));
sendit(msg, len, sp);
sp->send(msg, len);
if (njcr->JobFiles > 0) {
njcr->lock();
len = Mmsg(msg, " Processing file=%s\n", njcr->impl->last_fname);
njcr->unlock();
sendit(msg, len, sp);
sp->send(msg, len);
}

if (njcr->store_bsock) {
len = Mmsg(msg, " SDReadSeqNo=%" lld "\n fd=%d\n",
njcr->store_bsock->read_seqno, njcr->store_bsock->fd_);
sendit(msg, len, sp);
sp->send(msg, len);
} else {
len = Mmsg(msg, _(" SDSocket=closed\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}
}
endeach_jcr(njcr);
Expand All @@ -327,24 +334,24 @@ static void ListTerminatedJobs(StatusPacket* sp)

if (!sp->api) {
len = PmStrcpy(msg, _("\nTerminated Jobs:\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}

if (RecentJobResultsList::Count() == 0) {
if (!sp->api) {
len = PmStrcpy(msg, _("====\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}
return;
}

if (!sp->api) {
len = PmStrcpy(msg, _(" JobId Level Files Bytes Status "
"Finished Name \n"));
sendit(msg, len, sp);
sp->send(msg, len);
len = PmStrcpy(msg, _("===================================================="
"==================\n"));
sendit(msg, len, sp);
sp->send(msg, len);
}

for (const RecentJobResultsList::JobResult& je :
Expand Down Expand Up @@ -407,28 +414,12 @@ static void ListTerminatedJobs(StatusPacket* sp)
edit_uint64_with_commas(je.JobFiles, b1),
edit_uint64_with_suffix(je.JobBytes, b2), termstat, dt, JobName);
}
sendit(msg, len, sp);
sp->send(msg, len);
}

if (!sp->api) {
len = PmStrcpy(msg, _("====\n"));
sendit(msg, len, sp);
}
}

/**
* Send to bsock (Director or Console)
*/
static void sendit(PoolMem& msg, int len, StatusPacket* sp)
{
BareosSocket* bs = sp->bs;

if (bs) {
memcpy(bs->msg, msg.c_str(), len + 1);
bs->message_length = len + 1;
bs->send();
} else {
sp->callback(msg.c_str(), len, sp->context);
sp->send(msg, len);
}
}

Expand Down

0 comments on commit 45aed68

Please sign in to comment.