comparison OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp @ 5573:823aae1ea72a

removed dependency of HouseKeeper upon Orthanc::Logging
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 26 Apr 2024 16:01:26 +0200
parents e02cdf358905
children 3a6d6d35193c
comparison
equal deleted inserted replaced
5572:f0dc99bc811c 5573:823aae1ea72a
20 **/ 20 **/
21 21
22 22
23 #define HOUSEKEEPER_NAME "housekeeper" 23 #define HOUSEKEEPER_NAME "housekeeper"
24 24
25 #include "../../../../OrthancFramework/Sources/Compatibility.h"
26 #include "../../../../OrthancFramework/Sources/Logging.h"
27 #include "../Common/OrthancPluginCppWrapper.h" 25 #include "../Common/OrthancPluginCppWrapper.h"
28 26
29 #include <boost/thread.hpp> 27 #include <boost/thread.hpp>
30 #include <boost/algorithm/string.hpp> 28 #include <boost/algorithm/string.hpp>
31 #include <boost/date_time/posix_time/posix_time.hpp> 29 #include <boost/date_time/posix_time/posix_time.hpp>
90 { 88 {
91 weekday_ = 0; 89 weekday_ = 0;
92 } 90 }
93 else 91 else
94 { 92 {
95 LOG(WARNING) << "Housekeeper: invalid schedule: unknown 'day': " << weekday; 93 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: invalid schedule: unknown 'day': " + weekday);
96 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 94 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
97 } 95 }
98 96
99 std::vector<std::string> hours; 97 std::vector<std::string> hours;
100 boost::split(hours, period, boost::is_any_of("-")); 98 boost::split(hours, period, boost::is_any_of("-"));
402 400
403 if (!OrthancPlugins::CheckMinimalVersion(lastVersion, 1, 9, 1)) 401 if (!OrthancPlugins::CheckMinimalVersion(lastVersion, 1, 9, 1))
404 { 402 {
405 if (triggerOnUnnecessaryDicomAsJsonFiles_) 403 if (triggerOnUnnecessaryDicomAsJsonFiles_)
406 { 404 {
407 LOG(WARNING) << "Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping"; 405 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping");
408 needsReconstruct = true; // the default reconstruct removes the dicom-as-json 406 needsReconstruct = true; // the default reconstruct removes the dicom-as-json
409 } 407 }
410 else 408 else
411 { 409 {
412 LOG(WARNING) << "Housekeeper: your storage might still contain some dicom-as-json files but the trigger has been disabled"; 410 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: your storage might still contain some dicom-as-json files but the trigger has been disabled");
413 } 411 }
414 } 412 }
415 413
416 if (last.patientsMainDicomTagsSignature != current.patientsMainDicomTagsSignature) 414 if (last.patientsMainDicomTagsSignature != current.patientsMainDicomTagsSignature)
417 { 415 {
418 if (triggerOnMainDicomTagsChange_) 416 if (triggerOnMainDicomTagsChange_)
419 { 417 {
420 LOG(WARNING) << "Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping"; 418 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping");
421 needsReconstruct = true; 419 needsReconstruct = true;
422 } 420 }
423 else 421 else
424 { 422 {
425 LOG(WARNING) << "Housekeeper: Patient main dicom tags have changed but the trigger is disabled"; 423 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Patient main dicom tags have changed but the trigger is disabled");
426 } 424 }
427 } 425 }
428 426
429 if (last.studiesMainDicomTagsSignature != current.studiesMainDicomTagsSignature) 427 if (last.studiesMainDicomTagsSignature != current.studiesMainDicomTagsSignature)
430 { 428 {
431 if (triggerOnMainDicomTagsChange_) 429 if (triggerOnMainDicomTagsChange_)
432 { 430 {
433 LOG(WARNING) << "Housekeeper: Study main dicom tags have changed, -> will perform housekeeping"; 431 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Study main dicom tags have changed, -> will perform housekeeping");
434 needsReconstruct = true; 432 needsReconstruct = true;
435 } 433 }
436 else 434 else
437 { 435 {
438 LOG(WARNING) << "Housekeeper: Study main dicom tags have changed but the trigger is disabled"; 436 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Study main dicom tags have changed but the trigger is disabled");
439 } 437 }
440 } 438 }
441 439
442 if (last.seriesMainDicomTagsSignature != current.seriesMainDicomTagsSignature) 440 if (last.seriesMainDicomTagsSignature != current.seriesMainDicomTagsSignature)
443 { 441 {
444 if (triggerOnMainDicomTagsChange_) 442 if (triggerOnMainDicomTagsChange_)
445 { 443 {
446 LOG(WARNING) << "Housekeeper: Series main dicom tags have changed, -> will perform housekeeping"; 444 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Series main dicom tags have changed, -> will perform housekeeping");
447 needsReconstruct = true; 445 needsReconstruct = true;
448 } 446 }
449 else 447 else
450 { 448 {
451 LOG(WARNING) << "Housekeeper: Series main dicom tags have changed but the trigger is disabled"; 449 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Series main dicom tags have changed but the trigger is disabled");
452 } 450 }
453 } 451 }
454 452
455 if (last.instancesMainDicomTagsSignature != current.instancesMainDicomTagsSignature) 453 if (last.instancesMainDicomTagsSignature != current.instancesMainDicomTagsSignature)
456 { 454 {
457 if (triggerOnMainDicomTagsChange_) 455 if (triggerOnMainDicomTagsChange_)
458 { 456 {
459 LOG(WARNING) << "Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping"; 457 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping");
460 needsReconstruct = true; 458 needsReconstruct = true;
461 } 459 }
462 else 460 else
463 { 461 {
464 LOG(WARNING) << "Housekeeper: Instance main dicom tags have changed but the trigger is disabled"; 462 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: Instance main dicom tags have changed but the trigger is disabled");
465 } 463 }
466 } 464 }
467 465
468 if (current.storageCompressionEnabled != last.storageCompressionEnabled) 466 if (current.storageCompressionEnabled != last.storageCompressionEnabled)
469 { 467 {
470 if (triggerOnStorageCompressionChange_) 468 if (triggerOnStorageCompressionChange_)
471 { 469 {
472 if (current.storageCompressionEnabled) 470 if (current.storageCompressionEnabled)
473 { 471 {
474 LOG(WARNING) << "Housekeeper: storage compression is now enabled -> will perform housekeeping"; 472 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: storage compression is now enabled -> will perform housekeeping");
475 } 473 }
476 else 474 else
477 { 475 {
478 LOG(WARNING) << "Housekeeper: storage compression is now disabled -> will perform housekeeping"; 476 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: storage compression is now disabled -> will perform housekeeping");
479 } 477 }
480 478
481 needsReingest = true; 479 needsReingest = true;
482 } 480 }
483 else 481 else
484 { 482 {
485 LOG(WARNING) << "Housekeeper: storage compression has changed but the trigger is disabled"; 483 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: storage compression has changed but the trigger is disabled");
486 } 484 }
487 } 485 }
488 486
489 if (current.ingestTranscoding != last.ingestTranscoding) 487 if (current.ingestTranscoding != last.ingestTranscoding)
490 { 488 {
491 if (triggerOnIngestTranscodingChange_) 489 if (triggerOnIngestTranscodingChange_)
492 { 490 {
493 LOG(WARNING) << "Housekeeper: ingest transcoding has changed -> will perform housekeeping"; 491 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: ingest transcoding has changed -> will perform housekeeping");
494 492
495 needsReingest = true; 493 needsReingest = true;
496 } 494 }
497 else 495 else
498 { 496 {
499 LOG(WARNING) << "Housekeeper: ingest transcoding has changed but the trigger is disabled"; 497 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: ingest transcoding has changed but the trigger is disabled");
500 } 498 }
501 } 499 }
502 500
503 if (!current.dicomWebVersion.empty()) 501 if (!current.dicomWebVersion.empty())
504 { 502 {
505 if (last.dicomWebVersion.empty()) 503 if (last.dicomWebVersion.empty())
506 { 504 {
507 if (triggerOnDicomWebCacheChange_) 505 if (triggerOnDicomWebCacheChange_)
508 { 506 {
509 LOG(WARNING) << "Housekeeper: DicomWEB plugin is enabled and the housekeeper has never run, you might miss series metadata cache -> will perform housekeeping"; 507 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: DicomWEB plugin is enabled and the housekeeper has never run, you might miss series metadata cache -> will perform housekeeping");
510 } 508 }
511 needsDicomWebCaching = triggerOnDicomWebCacheChange_; 509 needsDicomWebCaching = triggerOnDicomWebCacheChange_;
512 } 510 }
513 else 511 else
514 { 512 {
516 514
517 if (!OrthancPlugins::CheckMinimalVersion(lastDicomWebVersion, 1, 15, 0)) 515 if (!OrthancPlugins::CheckMinimalVersion(lastDicomWebVersion, 1, 15, 0))
518 { 516 {
519 if (triggerOnDicomWebCacheChange_) 517 if (triggerOnDicomWebCacheChange_)
520 { 518 {
521 LOG(WARNING) << "Housekeeper: DicomWEB plugin might miss series metadata cache -> will perform housekeeping"; 519 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: DicomWEB plugin might miss series metadata cache -> will perform housekeeping");
522 needsDicomWebCaching = true; 520 needsDicomWebCaching = true;
523 } 521 }
524 else 522 else
525 { 523 {
526 LOG(WARNING) << "Housekeeper: DicomWEB plugin might miss series metadata cache but the trigger has been disabled"; 524 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: DicomWEB plugin might miss series metadata cache but the trigger has been disabled");
527 } 525 }
528 } 526 }
529 } 527 }
530 } 528 }
531 } 529 }
658 } 656 }
659 } 657 }
660 658
661 if (!needsProcessing) 659 if (!needsProcessing)
662 { 660 {
663 LOG(WARNING) << "Housekeeper: everything has been processed already !"; 661 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: everything has been processed already !");
664 return; 662 return;
665 } 663 }
666 664
667 if (force_ || needsFullProcessing) 665 if (force_ || needsFullProcessing)
668 { 666 {
669 if (force_) 667 if (force_)
670 { 668 {
671 LOG(WARNING) << "Housekeeper: forcing execution -> will perform housekeeping"; 669 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: forcing execution -> will perform housekeeping");
672 } 670 }
673 else 671 else
674 { 672 {
675 LOG(WARNING) << "Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !"; 673 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !");
676 } 674 }
677 675
678 Json::Value changes; 676 Json::Value changes;
679 OrthancPlugins::RestApiGet(changes, "/changes?last", false); 677 OrthancPlugins::RestApiGet(changes, "/changes?last", false);
680 678
686 pluginStatus_.lastTimeStarted = boost::posix_time::microsec_clock::universal_time(); 684 pluginStatus_.lastTimeStarted = boost::posix_time::microsec_clock::universal_time();
687 } 685 }
688 } 686 }
689 else 687 else
690 { 688 {
691 LOG(WARNING) << "Housekeeper: the DB configuration has not changed since last run, will continue processing changes"; 689 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper: the DB configuration has not changed since last run, will continue processing changes");
692 } 690 }
693 691
694 bool completed = false; 692 bool completed = false;
695 { 693 {
696 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); 694 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_);
708 706
709 if (!completed) 707 if (!completed)
710 { 708 {
711 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); 709 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_);
712 710
713 LOG(INFO) << "Housekeeper: processed changes " << pluginStatus_.lastProcessedChange << " / " << pluginStatus_.lastChangeToProcess; 711 ORTHANC_PLUGINS_LOG_INFO("Housekeeper: processed changes " + boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) +
712 " / " + boost::lexical_cast<std::string>(pluginStatus_.lastChangeToProcess));
714 713
715 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 100)); // wait 1/10 of the delay between changes 714 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 100)); // wait 1/10 of the delay between changes
716 } 715 }
717 716
718 loggedNotRightPeriodChangeMessage = false; 717 loggedNotRightPeriodChangeMessage = false;
719 } 718 }
720 else 719 else
721 { 720 {
722 if (!loggedNotRightPeriodChangeMessage) 721 if (!loggedNotRightPeriodChangeMessage)
723 { 722 {
724 LOG(INFO) << "Housekeeper: entering quiet period"; 723 ORTHANC_PLUGINS_LOG_INFO("Housekeeper: entering quiet period");
725 loggedNotRightPeriodChangeMessage = true; 724 loggedNotRightPeriodChangeMessage = true;
726 } 725 }
727 726
728 boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); 727 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
729 } 728 }
794 } 793 }
795 794
796 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) 795 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
797 { 796 {
798 OrthancPlugins::SetGlobalContext(c, HOUSEKEEPER_NAME); 797 OrthancPlugins::SetGlobalContext(c, HOUSEKEEPER_NAME);
799 Orthanc::Logging::InitializePluginContext(c, HOUSEKEEPER_NAME);
800 798
801 /* Check the version of the Orthanc core */ 799 /* Check the version of the Orthanc core */
802 if (OrthancPluginCheckVersion(c) == 0) 800 if (OrthancPluginCheckVersion(c) == 0)
803 { 801 {
804 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, 802 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
805 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 803 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
806 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 804 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
807 return -1; 805 return -1;
808 } 806 }
809 807
810 LOG(WARNING) << "Housekeeper plugin is initializing"; 808 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper plugin is initializing");
811 OrthancPluginSetDescription2(c, HOUSEKEEPER_NAME, "Optimizes your DB and storage."); 809 OrthancPluginSetDescription2(c, HOUSEKEEPER_NAME, "Optimizes your DB and storage.");
812 810
813 OrthancPlugins::OrthancConfiguration orthancConfiguration; 811 OrthancPlugins::OrthancConfiguration orthancConfiguration;
814 812
815 OrthancPlugins::OrthancConfiguration housekeeper; 813 OrthancPlugins::OrthancConfiguration housekeeper;
889 887
890 limitMainDicomTagsReconstructLevel_ = housekeeper.GetStringValue("LimitMainDicomTagsReconstructLevel", ""); 888 limitMainDicomTagsReconstructLevel_ = housekeeper.GetStringValue("LimitMainDicomTagsReconstructLevel", "");
891 if (limitMainDicomTagsReconstructLevel_ != "Patient" && limitMainDicomTagsReconstructLevel_ != "Study" 889 if (limitMainDicomTagsReconstructLevel_ != "Patient" && limitMainDicomTagsReconstructLevel_ != "Study"
892 && limitMainDicomTagsReconstructLevel_ != "Series" && limitMainDicomTagsReconstructLevel_ != "Instance") 890 && limitMainDicomTagsReconstructLevel_ != "Series" && limitMainDicomTagsReconstructLevel_ != "Instance")
893 { 891 {
894 LOG(ERROR) << "Housekeeper invalid value for 'LimitMainDicomTagsReconstructLevel': '" << limitMainDicomTagsReconstructLevel_ << "'"; 892 ORTHANC_PLUGINS_LOG_ERROR("Housekeeper invalid value for 'LimitMainDicomTagsReconstructLevel': '" + limitMainDicomTagsReconstructLevel_ + "'");
895 } 893 }
896 else if (limitMainDicomTagsReconstructLevel_ == "Patient") 894 else if (limitMainDicomTagsReconstructLevel_ == "Patient")
897 { 895 {
898 limitToChange_ = "NewPatient"; 896 limitToChange_ = "NewPatient";
899 limitToUrl_ = "patients"; 897 limitToUrl_ = "patients";
923 OrthancPluginRegisterRestCallback(c, "/housekeeper/status", GetPluginStatus); // for backward compatiblity with version 1.11.0 921 OrthancPluginRegisterRestCallback(c, "/housekeeper/status", GetPluginStatus); // for backward compatiblity with version 1.11.0
924 OrthancPluginRegisterRestCallback(c, "/plugins/housekeeper/status", GetPluginStatus); 922 OrthancPluginRegisterRestCallback(c, "/plugins/housekeeper/status", GetPluginStatus);
925 } 923 }
926 else 924 else
927 { 925 {
928 LOG(WARNING) << "Housekeeper plugin is disabled by the configuration file"; 926 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper plugin is disabled by the configuration file");
929 } 927 }
930 928
931 return 0; 929 return 0;
932 } 930 }
933 931
934 932
935 ORTHANC_PLUGINS_API void OrthancPluginFinalize() 933 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
936 { 934 {
937 LOG(WARNING) << "Housekeeper plugin is finalizing"; 935 ORTHANC_PLUGINS_LOG_WARNING("Housekeeper plugin is finalizing");
938 } 936 }
939 937
940 938
941 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 939 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
942 { 940 {