/** * @project The CERN Tape Archive (CTA) * @copyright Copyright © 2023 CERN * @license This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include "rdbms/ConnPool.hpp" #include "scheduler/PostgresSchedDB/PostgresSchedDB.hpp" #include "scheduler/PostgresSchedDB/sql/Enums.hpp" #include "scheduler/PostgresSchedDB/sql/Transaction.hpp" #include "scheduler/PostgresSchedDB/sql/RetrieveJobQueue.hpp" #include "common/dataStructures/ArchiveFile.hpp" #include "common/dataStructures/EntryLog.hpp" #include "common/dataStructures/MountPolicy.hpp" #include "common/dataStructures/RequesterIdentity.hpp" #include "common/dataStructures/RetrieveRequest.hpp" #include "common/dataStructures/RetrieveFileQueueCriteria.hpp" #include #include #include #include #include namespace cta::postgresscheddb { class RetrieveRequest { friend class cta::PostgresSchedDB; public: RetrieveRequest(rdbms::ConnPool &pool, log::LogContext& lc) : m_connPool(&pool), m_lc(lc) { } RetrieveRequest(log::LogContext& lc, const postgresscheddb::sql::RetrieveJobQueueRow &row) : m_connPool(nullptr), m_lc(lc) { *this = row; } RetrieveRequest& operator=(const postgresscheddb::sql::RetrieveJobQueueRow &row); void insert(); void commit(); void update(); // ============================== Job management ============================= struct RetrieveReqRepackInfo { bool isRepack{false}; std::map archiveRouteMap; std::set copyNbsToRearchive; uint64_t repackRequestId{0}; uint64_t fSeq{0}; std::string fileBufferURL; bool hasUserProvidedFile{false}; }; struct RetrieveReqJobDump { uint32_t copyNb{0}; cta::postgresscheddb::RetrieveJobStatus status{RetrieveJobStatus::RJS_ToTransfer}; }; struct RetrieveRequestJob { uint32_t copyNb{0}; uint32_t maxtotalretries{0}; uint32_t maxretrieswithinmount{0}; uint32_t retrieswithinmount{0}; uint32_t totalretries{0}; postgresscheddb::RetrieveJobStatus status{RetrieveJobStatus::RJS_ToTransfer}; uint64_t lastmountwithfailure{0}; std::vector failurelogs; uint32_t maxreportretries{0}; uint32_t totalreportretries{0}; std::vector reportfailurelogs; bool isfailed{false}; }; void setFailureReason(const std::string & reason); bool addJobFailure(uint32_t copyNumber, uint64_t mountId, const std::string & failureReason, log::LogContext & lc); void setRepackInfo(const cta::postgresscheddb::RetrieveRequest::RetrieveReqRepackInfo & repackInfo); void setJobStatus(uint32_t copyNumber, const cta::postgresscheddb::RetrieveJobStatus &status); void setSchedulerRequest(const cta::common::dataStructures::RetrieveRequest & retrieveRequest); void setRetrieveFileQueueCriteria(const cta::common::dataStructures::RetrieveFileQueueCriteria& criteria); void setActivityIfNeeded(const cta::common::dataStructures::RetrieveRequest & retrieveRequest, const cta::common::dataStructures::RetrieveFileQueueCriteria& criteria); void setDiskSystemName(const std::string & diskSystemName); void setCreationTime(const uint64_t creationTime); void setFirstSelectedTime(const uint64_t firstSelectedTime); void setCompletedTime(const uint64_t completedTime); void setReportedTime(const uint64_t reportedTime); void setActiveCopyNumber(uint32_t activeCopyNb); void setIsVerifyOnly(bool isVerifyOnly); void setFailed(); std::list dumpJobs(); std::string getIdStr() { return "?"; } uint64_t m_requestId = 0; uint64_t m_mountId = 0; postgresscheddb::RetrieveJobStatus m_status; std::string m_vid; uint16_t m_priority = 0; time_t m_retrieveMinReqAge = 0; time_t m_startTime = 0; std::string m_failureReportUrl; std::string m_failureReportLog; bool m_isFailed = false; // the archiveFile element in scheduler retrieve request is not used cta::common::dataStructures::RetrieveRequest m_schedRetrieveReq; cta::common::dataStructures::ArchiveFile m_archiveFile; std::string m_mountPolicyName; std::optional m_activity; std::optional m_diskSystemName; uint32_t m_actCopyNb = 0; RetrieveReqRepackInfo m_repackInfo; std::list m_jobs; std::unique_ptr m_txn; // References to external objects rdbms::ConnPool *m_connPool; log::LogContext &m_lc; }; } // namespace cta::postgresscheddb