8 #include <kea_version.h>
37 const uint32_t MAX_LEASE_ERRORS = 100;
48 const char* LFCController::lfc_app_name_ =
"DhcpLFC";
51 const char* LFCController::lfc_bin_name_ =
"kea-lfc";
53 LFCController::LFCController()
54 : protocol_version_(0), verbose_(false), config_file_(
""), previous_file_(
""),
55 copy_file_(
""), output_file_(
""), finish_file_(
""), pid_file_(
"") {
63 bool do_rotate =
true;
81 startLogger(test_mode);
89 if (pid_file.
check()) {
106 if (!lf_finish.
exists()) {
113 processLeases<Lease4, CSVLeaseFile4, Lease4Storage>();
115 processLeases<Lease6, CSVLeaseFile6, Lease6Storage>();
117 }
catch (
const std::exception& proc_ex) {
154 while ((ch = getopt(argc, argv,
":46dhvVWp:x:i:o:c:f:")) != -1) {
158 protocol_version_ = 4;
163 protocol_version_ = 6;
168 std::cout << getVersion(
false) << std::endl;
173 std::cout << getVersion(
true) << std::endl;
188 if (optarg == NULL) {
196 if (optarg == NULL) {
199 previous_file_ = optarg;
204 if (optarg == NULL) {
212 if (optarg == NULL) {
215 output_file_ = optarg;
220 if (optarg == NULL) {
223 finish_file_ = optarg;
228 if (optarg == NULL) {
231 config_file_ = optarg;
259 if (protocol_version_ == 0) {
263 if (pid_file_.empty()) {
267 if (previous_file_.empty()) {
271 if (copy_file_.empty()) {
275 if (output_file_.empty()) {
279 if (finish_file_.empty()) {
283 if (config_file_.empty()) {
289 std::cout <<
"Protocol version: DHCPv" << protocol_version_ << std::endl
290 <<
"Previous or ex lease file: " << previous_file_ << std::endl
291 <<
"Copy lease file: " << copy_file_ << std::endl
292 <<
"Output lease file: " << output_file_ << std::endl
293 <<
"Finish file: " << finish_file_ << std::endl
294 <<
"Config file: " << config_file_ << std::endl
295 <<
"PID file: " << pid_file_ << std::endl
301 LFCController::usage(
const std::string& text) {
303 std::cerr <<
"Usage error: " << text << std::endl;
307 <<
" [-4|-6] -p file -x file -i file -o file -f file -c file" << std::endl
308 <<
" -4 or -6 clean a set of v4 or v6 lease files" << std::endl
309 <<
" -p <file>: PID file" << std::endl
310 <<
" -x <file>: previous or ex lease file" << std::endl
311 <<
" -i <file>: copy of lease file" << std::endl
312 <<
" -o <file>: output lease file" << std::endl
313 <<
" -f <file>: finish file" << std::endl
314 <<
" -c <file>: configuration file" << std::endl
315 <<
" -v: print version number and exit" << std::endl
316 <<
" -V: print extended version information and exit" << std::endl
317 <<
" -d: optional, verbose output " << std::endl
318 <<
" -h: print this message " << std::endl
323 LFCController::getVersion(
const bool extended)
const{
324 std::stringstream version_stream;
326 version_stream << VERSION;
328 version_stream << std::endl << EXTENDED_VERSION << std::endl
332 return (version_stream.str());
335 template<
typename LeaseObjectType,
typename LeaseFileType,
typename StorageType>
337 LFCController::processLeases()
const {
342 if (lf_prev.exists()) {
343 LeaseFileLoader::load<LeaseObjectType>(lf_prev, storage,
349 if (lf_copy.exists()) {
350 LeaseFileLoader::load<LeaseObjectType>(lf_copy, storage,
356 LeaseFileLoader::write<LeaseObjectType>(lf_output, storage);
360 .arg(lf_prev.getReadLeases() + lf_copy.getReadLeases())
361 .arg(lf_prev.getReads() + lf_copy.getReads())
362 .arg(lf_prev.getReadErrs() + lf_copy.getReadErrs());
365 .arg(lf_output.getWriteLeases())
366 .arg(lf_output.getWrites())
367 .arg(lf_output.getWriteErrs());
371 isc_throw(RunTimeFail,
"Unable to move output (" << output_file_
372 <<
") to complete (" << finish_file_
373 <<
") error: " << strerror(errno));
383 << previous_file_ <<
"' error: " << strerror(errno));
390 << copy_file_ <<
"' error: " << strerror(errno));
394 if (rename(finish_file_.c_str(), previous_file_.c_str()) != 0) {
396 <<
") to previous (" << previous_file_
397 <<
") error: " << strerror(errno));
402 LFCController::startLogger(
const bool test_mode)
const {
429 spec.addOutputOption(option);
const isc::log::MessageID LFC_FAIL_PID_DEL
void deleteFile() const
Delete the PID file.
const std::string & getRootLoggerName()
Get root logger name.
int check() const
Read the PID in from the file and check it.
isc::log::Logger lfc_logger("DhcpLFC")
Defines the logger used within LFC.
Exception thrown when an error occurs during PID file processing.
~LFCController()
Destructor.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity)
Obtains logging severity from KEA_LOGGER_SEVERITY.
void process(T start, T finish)
Process Specifications.
const isc::log::MessageID LFC_RUNNING
An abstract API for lease database.
int getProtocolVersion() const
Gets the protocol version of the leases files.
int keaLoggerDbglevel(int defdbglevel)
Obtains logging debug level from KEA_LOGGER_DBGLEVEL.
const isc::log::MessageID LFC_FAIL_PID_CREATE
Class to help with processing PID files.
Exceptions thrown when a method is unable to manipulate (remove or rename) a file.
static std::string getDBVersion()
Local version of getDBVersion() class method.
const isc::log::MessageID LFC_FAIL_PROCESS
void launch(int argc, char *argv[], const bool test_mode)
Acts as the primary entry point to start execution of the process.
const isc::log::MessageID LFC_START
const isc::log::MessageID LFC_READ_STATS
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string getCopyFile() const
Gets the copy file name.
void parseArgs(int argc, char *argv[])
Process the command line arguments.
const char *const config_report[]
const isc::log::MessageID LFC_PROCESSING
static const char * lfc_bin_name_
Defines the executable name, by convention this should match the executable name. ...
Destination destination
Members.
std::string getPreviousFile() const
Gets the previous file name.
const isc::log::MessageID LFC_FAIL_ROTATE
void fileRotate() const
Rotate files.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::string getOutputFile() const
Gets the output file name.
static const char * lfc_app_name_
Defines the application name, it may be used to locate configuration data and appears in log statemen...
Exception thrown when the command line is invalid.
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::log::MessageID LFC_TERMINATE
const isc::log::MessageID LFC_ROTATING
bool exists() const
Checks if the CSV file exists and can be opened for reading.
Provides input/output access to CSV files.
const char *const * lfc_config_report
std::string getConfigReport()
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
void write(int) const
Write the PID to the file.
void initLogger(const string &root, isc::log::Severity severity, int dbglevel, const char *file, bool buffer)
Run-time initialization.
std::string getFinishFile() const
Gets the finish file name.
const isc::log::MessageID LFC_WRITE_STATS