diff --git a/common/ArchiveRequest.cpp b/common/ArchiveRequest.cpp deleted file mode 100644 index 510fa710e0b0146a41be59a4f547d0a8cb545a96..0000000000000000000000000000000000000000 --- a/common/ArchiveRequest.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * The CERN Tape Archive (CTA) project - * Copyright (C) 2015 CERN - * - * 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 <http://www.gnu.org/licenses/>. - */ - -#include "common/ArchiveRequest.hpp" -#include "exception/Exception.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::ArchiveRequest::ArchiveRequest() { - m_srcURLSet = false; - m_fileSizeSet = false; - m_checksumTypeSet = false; - m_checksumValueSet = false; - m_storageClassSet = false; - m_drInstanceSet = false; - m_drPathSet = false; - m_drOwnerSet = false; - m_drGroupSet = false; - m_drBlobSet = false; -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::ArchiveRequest::~ArchiveRequest() throw() { -} - -//------------------------------------------------------------------------------ -// allFieldsSet -//------------------------------------------------------------------------------ -bool cta::ArchiveRequest::allFieldsSet() const { - if(m_srcURLSet==true - && m_fileSizeSet==true - && m_checksumTypeSet==true - && m_checksumValueSet==true - && m_storageClassSet==true - && m_drInstanceSet==true - && m_drPathSet==true - && m_drOwnerSet==true - && m_drGroupSet==true - && m_drBlobSet==true) { - return true; - } - return false; -} - -//------------------------------------------------------------------------------ -// setDrBlob -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setDrBlob(std::string drBlob) { - m_drBlob = drBlob; - m_drBlobSet = true; -} - -//------------------------------------------------------------------------------ -// getDrBlob -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getDrBlob() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_drBlob; -} - -//------------------------------------------------------------------------------ -// setDrGroup -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setDrGroup(std::string drGroup) { - m_drGroup = drGroup; - m_drGroupSet = true; -} - -//------------------------------------------------------------------------------ -// getDrGroup -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getDrGroup() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_drGroup; -} - -//------------------------------------------------------------------------------ -// setDrOwner -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setDrOwner(std::string drOwner) { - m_drOwner = drOwner; - m_drOwnerSet = true; -} - -//------------------------------------------------------------------------------ -// getDrOwner -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getDrOwner() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_drOwner; -} - -//------------------------------------------------------------------------------ -// setDrPath -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setDrPath(std::string drPath) { - m_drPath = drPath; - m_drPathSet = true; -} - -//------------------------------------------------------------------------------ -// getDrPath -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getDrPath() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_drPath; -} - -//------------------------------------------------------------------------------ -// setDrInstance -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setDrInstance(std::string drInstance) { - m_drInstance = drInstance; - m_drInstanceSet = true; -} - -//------------------------------------------------------------------------------ -// getDrInstance -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getDrInstance() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_drInstance; -} - -//------------------------------------------------------------------------------ -// setStorageClass -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setStorageClass(std::string storageClass) { - m_storageClass = storageClass; - m_storageClassSet = true; -} - -//------------------------------------------------------------------------------ -// getStorageClass -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getStorageClass() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_storageClass; -} - -//------------------------------------------------------------------------------ -// setChecksumValue -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setChecksumValue(std::string checksumValue) { - m_checksumValue = checksumValue; - m_checksumValueSet = true; -} - -//------------------------------------------------------------------------------ -// getChecksumValue -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getChecksumValue() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_checksumValue; -} - -//------------------------------------------------------------------------------ -// setChecksumType -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setChecksumType(std::string checksumType) { - m_checksumType = checksumType; - m_checksumTypeSet = true; -} - -//------------------------------------------------------------------------------ -// getChecksumType -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getChecksumType() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_checksumType; -} - -//------------------------------------------------------------------------------ -// setFileSize -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setFileSize(uint64_t fileSize) { - m_fileSize = fileSize; - m_fileSizeSet = true; -} - -//------------------------------------------------------------------------------ -// getFileSize -//------------------------------------------------------------------------------ -uint64_t cta::ArchiveRequest::getFileSize() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_fileSize; -} - -//------------------------------------------------------------------------------ -// setSrcURL -//------------------------------------------------------------------------------ -void cta::ArchiveRequest::setSrcURL(std::string srcURL) { - m_srcURL = srcURL; - m_srcURLSet = true; -} - -//------------------------------------------------------------------------------ -// getSrcURL -//------------------------------------------------------------------------------ -std::string cta::ArchiveRequest::getSrcURL() const { - if(!allFieldsSet()) { - throw cta::exception::Exception(std::string(__FUNCTION__)+" Error: not all fields of the ArchiveRequest have been set!"); - } - return m_srcURL; -} diff --git a/common/ArchiveRequest.hpp b/common/ArchiveRequest.hpp deleted file mode 100644 index 31f6b0da81eb2bf256e8a78a2b2cd62f2b78a62c..0000000000000000000000000000000000000000 --- a/common/ArchiveRequest.hpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * The CERN Tape Archive (CTA) project - * Copyright (C) 2015 CERN - * - * 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 <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include <stdint.h> -#include <string> - -namespace cta { - -/** - * Structure to store an archive request. - */ -struct ArchiveRequest { - -public: - - /** - * Constructor - */ - ArchiveRequest(); - - /** - * Destructor - */ - ~ArchiveRequest() throw(); - - void setDrBlob(std::string drBlob); - std::string getDrBlob() const; - void setDrGroup(std::string drGroup); - std::string getDrGroup() const; - void setDrOwner(std::string drOwner); - std::string getDrOwner() const; - void setDrPath(std::string drPath); - std::string getDrPath() const; - void setDrInstance(std::string drInstance); - std::string getDrInstance() const; - void setStorageClass(std::string storageClass); - std::string getStorageClass() const; - void setChecksumValue(std::string checksumValue); - std::string getChecksumValue() const; - void setChecksumType(std::string checksumType); - std::string getChecksumType() const; - void setFileSize(uint64_t fileSize); - uint64_t getFileSize() const; - void setSrcURL(std::string srcURL); - std::string getSrcURL() const; - -private: - - /** - * @return true if all fields have been set, false otherwise - */ - bool allFieldsSet() const; - - /** - * The EOS src URL. - */ - std::string m_srcURL; - bool m_srcURLSet; - - /** - * The size of the file to be archived in bytes. - */ - uint64_t m_fileSize; - bool m_fileSizeSet; - - /** - * The checksum type. - */ - std::string m_checksumType; - bool m_checksumTypeSet; - - /** - * The checksum value. - */ - std::string m_checksumValue; - bool m_checksumValueSet; - - /** - * The storage class name. - */ - std::string m_storageClass; - bool m_storageClassSet; - - /** - * The disaster recovery EOS instance. - */ - std::string m_drInstance; - bool m_drInstanceSet; - - /** - * The disaster recovery EOS path. - */ - std::string m_drPath; - bool m_drPathSet; - - /** - * The disaster recovery EOS owner. - */ - std::string m_drOwner; - bool m_drOwnerSet; - - /** - * The disaster recovery EOS group. - */ - std::string m_drGroup; - bool m_drGroupSet; - - /** - * The disaster recovery EOS key-value string containing everything above and more (no parsing by CTA). - */ - std::string m_drBlob; - bool m_drBlobSet; - -}; // struct ArchiveRequest - -} // namespace cta diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7963b9a73d069388d49e4c9471f79d35a2fe3715..ede3830b2c7dad8c190fce1d4477db0eda5f43de 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -73,7 +73,6 @@ set (COMMON_LIB_SRC_FILES threading/Threading.cpp utils/utils.cpp utils/strerror_r_wrapper.cpp - ArchiveRequest.cpp CreationLog.cpp Configuration.cpp SecurityIdentity.cpp diff --git a/objectstore/ArchiveRequest.cpp b/objectstore/ArchiveRequest.cpp index 1456f7143407ae16d4899559526f3ec2e195814a..e1c2157b3c81df3d320f83fac3cb4bc93e796538 100644 --- a/objectstore/ArchiveRequest.cpp +++ b/objectstore/ArchiveRequest.cpp @@ -19,6 +19,7 @@ #include "ArchiveRequest.hpp" #include "GenericObject.hpp" #include "TapePool.hpp" +#include "common/dataStructures/EntryLog.hpp" #include <json-c/json.h> cta::objectstore::ArchiveRequest::ArchiveRequest(const std::string& address, Backend& os): @@ -322,6 +323,34 @@ std::string cta::objectstore::ArchiveRequest::getStorageClass() { return m_payload.storageclass(); } +//------------------------------------------------------------------------------ +// setCreationLog +//------------------------------------------------------------------------------ +void cta::objectstore::ArchiveRequest::setCreationLog(const cta::common::dataStructures::EntryLog &creationLog) { + checkPayloadWritable(); + auto payloadCreationLog = m_payload.mutable_creationlog(); + payloadCreationLog->set_time(creationLog.getTime()); + payloadCreationLog->set_host(creationLog.getHost()); + payloadCreationLog->set_uid(creationLog.getUser().getUid()); + payloadCreationLog->set_gid(creationLog.getUser().getGid()); +} + +//------------------------------------------------------------------------------ +// getCreationLog +//------------------------------------------------------------------------------ +cta::common::dataStructures::EntryLog cta::objectstore::ArchiveRequest::getCreationLog() { + checkPayloadReadable(); + cta::common::dataStructures::EntryLog creationLog; + cta::common::dataStructures::UserIdentity user; + auto payloadCreationLog = m_payload.creationlog(); + user.setUid(payloadCreationLog.uid()); + user.setGid(payloadCreationLog.gid()); + creationLog.setUser(user); + creationLog.setHost(payloadCreationLog.host()); + creationLog.setTime(payloadCreationLog.time()); + return creationLog; +} + auto cta::objectstore::ArchiveRequest::dumpJobs() -> std::list<ArchiveToFileRequest::JobDump> { checkPayloadReadable(); std::list<ArchiveToFileRequest::JobDump> ret; @@ -474,11 +503,8 @@ std::string cta::objectstore::ArchiveRequest::dump() { json_object * jaf = json_object_new_object(); json_object_object_add(jaf, "host", json_object_new_string(m_payload.creationlog().host().c_str())); json_object_object_add(jaf, "time", json_object_new_int64(m_payload.creationlog().time())); - // Object for user in the creation log - json_object * jaff = json_object_new_object(); - json_object_object_add(jaff, "uid", json_object_new_int64(m_payload.creationlog().user().uid())); - json_object_object_add(jaff, "gid", json_object_new_int64(m_payload.creationlog().user().gid())); - json_object_object_add(jaf, "user", jaff); + json_object_object_add(jaf, "uid", json_object_new_int64(m_payload.creationlog().uid())); + json_object_object_add(jaf, "gid", json_object_new_int64(m_payload.creationlog().gid())); json_object_object_add(jo, "creationlog", jaf); // Array for jobs json_object * jja = json_object_new_array(); diff --git a/objectstore/ArchiveRequest.hpp b/objectstore/ArchiveRequest.hpp index a7378f447c1f6819334164be20a3b1106bbca151..069eae76152c803510f7c8dc11c4bbc613933654 100644 --- a/objectstore/ArchiveRequest.hpp +++ b/objectstore/ArchiveRequest.hpp @@ -21,6 +21,7 @@ #include "ArchiveToFileRequest.hpp" #include "common/dataStructures/DRData.hpp" +#include "common/dataStructures/EntryLog.hpp" #include "common/dataStructures/Requester.hpp" #include "ObjectOps.hpp" #include "objectstore/cta.pb.h" @@ -94,6 +95,9 @@ public: void setStorageClass(const std::string &storageClass); std::string getStorageClass(); + + void setCreationLog(const cta::common::dataStructures::EntryLog &creationLog); + cta::common::dataStructures::EntryLog getCreationLog(); std::list<ArchiveToFileRequest::JobDump> dumpJobs(); void garbageCollect(const std::string &presumedOwner); diff --git a/objectstore/CMakeLists.txt b/objectstore/CMakeLists.txt index df7d44868fcc80345ca4bf0002072c032db24d7d..ff397125dc9e95439f24c67184107fdceca51742 100644 --- a/objectstore/CMakeLists.txt +++ b/objectstore/CMakeLists.txt @@ -18,6 +18,7 @@ set (CTAProtoDependants objectstore/Agent.hpp objectstore/GenericObject.hpp objectstore/ObjectOps.cpp objectstore/ObjectOps.hpp + objectstore/RetrieveRequest.hpp objectstore/RetrieveToFileRequest.cpp objectstore/RetrieveToFileRequest.hpp objectstore/RootEntry.hpp @@ -42,6 +43,7 @@ add_library (ctaobjectstore SHARED ArchiveToFileRequest.cpp ArchiveRequest.cpp RetrieveToFileRequest.cpp + RetrieveRequest.cpp DriveRegister.cpp BackendVFS.cpp BackendRados.cpp diff --git a/objectstore/ObjectOps.cpp b/objectstore/ObjectOps.cpp index b9374315d337a83b989c0ab1bab2e25f172a79b9..852c8782e35abcc264476205a44a4a3fcacfee6f 100644 --- a/objectstore/ObjectOps.cpp +++ b/objectstore/ObjectOps.cpp @@ -34,6 +34,7 @@ namespace cta { namespace objectstore { MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(ArchiveToFileRequest); MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(ArchiveRequest); MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(RetrieveToFileRequest); + MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(RetrieveRequest); MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(SchedulerGlobalLock); #undef MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID diff --git a/objectstore/RetrieveRequest.cpp b/objectstore/RetrieveRequest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9fbff8a1f03717264c6691e8dc8f4fe16a5b5d2 --- /dev/null +++ b/objectstore/RetrieveRequest.cpp @@ -0,0 +1,300 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "RetrieveRequest.hpp" +#include "GenericObject.hpp" +#include "CreationLog.hpp" +#include "objectstore/cta.pb.h" +#include <json-c/json.h> + +cta::objectstore::RetrieveRequest::RetrieveRequest( + const std::string& address, Backend& os): + ObjectOps<serializers::RetrieveRequest>(os, address) { } + +cta::objectstore::RetrieveRequest::RetrieveRequest(GenericObject& go): + ObjectOps<serializers::RetrieveRequest>(go.objectStore()) { + // Here we transplant the generic object into the new object + go.transplantHeader(*this); + // And interpret the header. + getPayloadFromHeader(); +} + +void cta::objectstore::RetrieveRequest::initialize() { + // Setup underlying object + ObjectOps<serializers::RetrieveRequest>::initialize(); + // This object is good to go (to storage) + m_payloadInterpreted = true; +} + +void cta::objectstore::RetrieveRequest::addJob(const cta::TapeFileLocation & tapeFileLocation, + const std::string& tapeaddress) { + checkPayloadWritable(); + auto *j = m_payload.add_jobs(); + j->set_copynb(tapeFileLocation.copyNb); + j->set_status(serializers::RetrieveJobStatus::RJS_LinkingToTape); + j->set_tape(tapeFileLocation.vid); + j->set_tapeaddress(tapeaddress); + j->set_totalretries(0); + j->set_retrieswithinmount(0); + j->set_blockid(tapeFileLocation.blockId); + j->set_fseq(tapeFileLocation.fSeq); +} + +bool cta::objectstore::RetrieveRequest::setJobSuccessful(uint16_t copyNumber) { + checkPayloadWritable(); + auto * jl = m_payload.mutable_jobs(); + for (auto j=jl->begin(); j!=jl->end(); j++) { + if (j->copynb() == copyNumber) { + j->set_status(serializers::RetrieveJobStatus::RJS_Complete); + for (auto j2=jl->begin(); j2!=jl->end(); j2++) { + if (j2->status()!= serializers::RetrieveJobStatus::RJS_Complete && + j2->status()!= serializers::RetrieveJobStatus::RJS_Failed) + return false; + } + return true; + } + } + throw NoSuchJob("In RetrieveRequest::setJobSuccessful(): job not found"); +} + + +//------------------------------------------------------------------------------ +// setArchiveFileID +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setArchiveFileID(const uint64_t archiveFileID) { + checkPayloadWritable(); + m_payload.set_archivefileid(archiveFileID); +} + +//------------------------------------------------------------------------------ +// getArchiveFileID +//------------------------------------------------------------------------------ +uint64_t cta::objectstore::RetrieveRequest::getArchiveFileID() { + checkPayloadReadable(); + return m_payload.archivefileid(); +} + +//------------------------------------------------------------------------------ +// setDiskpoolName +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setDiskpoolName(const std::string &diskpoolName) { + checkPayloadWritable(); + m_payload.set_diskpoolname(diskpoolName); +} + +//------------------------------------------------------------------------------ +// getDiskpoolName +//------------------------------------------------------------------------------ +std::string cta::objectstore::RetrieveRequest::getDiskpoolName() { + checkPayloadReadable(); + return m_payload.diskpoolname(); +} + +//------------------------------------------------------------------------------ +// setDiskpoolThroughput +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setDiskpoolThroughput(const uint64_t diskpoolThroughput) { + checkPayloadWritable(); + m_payload.set_diskpoolthroughput(diskpoolThroughput); +} + +//------------------------------------------------------------------------------ +// getDiskpoolThroughput +//------------------------------------------------------------------------------ +uint64_t cta::objectstore::RetrieveRequest::getDiskpoolThroughput() { + checkPayloadReadable(); + return m_payload.diskpoolthroughput(); +} + +//------------------------------------------------------------------------------ +// setDrData +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setDrData(const cta::common::dataStructures::DRData &drData) { + checkPayloadWritable(); + auto payloadDrData = m_payload.mutable_drdata(); + payloadDrData->set_drblob(drData.getDrBlob()); + payloadDrData->set_drgroup(drData.getDrGroup()); + payloadDrData->set_drinstance(drData.getDrInstance()); + payloadDrData->set_drowner(drData.getDrOwner()); + payloadDrData->set_drpath(drData.getDrPath()); +} + +//------------------------------------------------------------------------------ +// getDrData +//------------------------------------------------------------------------------ +cta::common::dataStructures::DRData cta::objectstore::RetrieveRequest::getDrData() { + checkPayloadReadable(); + cta::common::dataStructures::DRData drData; + auto payloadDrData = m_payload.drdata(); + drData.setDrBlob(payloadDrData.drblob()); + drData.setDrGroup(payloadDrData.drgroup()); + drData.setDrInstance(payloadDrData.drinstance()); + drData.setDrOwner(payloadDrData.drowner()); + drData.setDrPath(payloadDrData.drpath()); + return drData; +} + +//------------------------------------------------------------------------------ +// setDstURL +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setDstURL(const std::string &dstURL) { + checkPayloadWritable(); + m_payload.set_dsturl(dstURL); +} + +//------------------------------------------------------------------------------ +// getDstURL +//------------------------------------------------------------------------------ +std::string cta::objectstore::RetrieveRequest::getDstURL() { + checkPayloadReadable(); + return m_payload.dsturl(); +} + +//------------------------------------------------------------------------------ +// setRequester +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setRequester(const cta::common::dataStructures::Requester &requester) { + checkPayloadWritable(); + auto payloadRequester = m_payload.mutable_requester(); + payloadRequester->set_username(requester.getUserName()); + payloadRequester->set_groupname(requester.getGroupName()); +} + +//------------------------------------------------------------------------------ +// getRequester +//------------------------------------------------------------------------------ +cta::common::dataStructures::Requester cta::objectstore::RetrieveRequest::getRequester() { + checkPayloadReadable(); + cta::common::dataStructures::Requester requester; + auto payloadRequester = m_payload.requester(); + requester.setUserName(payloadRequester.username()); + requester.setGroupName(payloadRequester.groupname()); + return requester; +} + +//------------------------------------------------------------------------------ +// setCreationLog +//------------------------------------------------------------------------------ +void cta::objectstore::RetrieveRequest::setCreationLog(const cta::common::dataStructures::EntryLog &creationLog) { + checkPayloadWritable(); + auto payloadCreationLog = m_payload.mutable_creationlog(); + payloadCreationLog->set_time(creationLog.getTime()); + payloadCreationLog->set_host(creationLog.getHost()); + payloadCreationLog->set_uid(creationLog.getUser().getUid()); + payloadCreationLog->set_gid(creationLog.getUser().getGid()); +} + +//------------------------------------------------------------------------------ +// getCreationLog +//------------------------------------------------------------------------------ +cta::common::dataStructures::EntryLog cta::objectstore::RetrieveRequest::getCreationLog() { + checkPayloadReadable(); + cta::common::dataStructures::EntryLog creationLog; + cta::common::dataStructures::UserIdentity user; + auto payloadCreationLog = m_payload.creationlog(); + user.setUid(payloadCreationLog.uid()); + user.setGid(payloadCreationLog.gid()); + creationLog.setUser(user); + creationLog.setHost(payloadCreationLog.host()); + creationLog.setTime(payloadCreationLog.time()); + return creationLog; +} + +auto cta::objectstore::RetrieveRequest::dumpJobs() -> std::list<JobDump> { + checkPayloadReadable(); + std::list<JobDump> ret; + auto & jl = m_payload.jobs(); + for (auto j=jl.begin(); j!=jl.end(); j++) { + ret.push_back(JobDump()); + ret.back().copyNb = j->copynb(); + ret.back().tape = j->tape(); + ret.back().tapeAddress = j->tapeaddress(); + } + return ret; +} + +auto cta::objectstore::RetrieveRequest::getJob(uint16_t copyNb) -> JobDump { + checkPayloadReadable(); + // find the job + auto & jl = m_payload.jobs(); + for (auto j=jl.begin(); j!=jl.end(); j++) { + if (j->copynb() == copyNb) { + JobDump ret; + ret.blockid = j->blockid(); + ret.copyNb = j->copynb(); + ret.fseq = j->fseq(); + ret.tape = j->tape(); + ret.tapeAddress = j->tapeaddress(); + return ret; + } + } + throw NoSuchJob("In objectstore::RetrieveRequest::getJob(): job not found for this copyNb"); +} + +std::string cta::objectstore::RetrieveRequest::dump() { + checkPayloadReadable(); + std::stringstream ret; + ret << "RetrieveRequest" << std::endl; + struct json_object * jo = json_object_new_object(); + json_object_object_add(jo, "archivefileid", json_object_new_int64(m_payload.archivefileid())); + json_object_object_add(jo, "dsturl", json_object_new_string(m_payload.dsturl().c_str())); + json_object_object_add(jo, "diskpoolname", json_object_new_string(m_payload.diskpoolname().c_str())); + json_object_object_add(jo, "diskpoolthroughput", json_object_new_int64(m_payload.diskpoolthroughput())); + // Object for creation log + json_object * jaf = json_object_new_object(); + json_object_object_add(jaf, "host", json_object_new_string(m_payload.creationlog().host().c_str())); + json_object_object_add(jaf, "time", json_object_new_int64(m_payload.creationlog().time())); + json_object_object_add(jaf, "uid", json_object_new_int64(m_payload.creationlog().uid())); + json_object_object_add(jaf, "gid", json_object_new_int64(m_payload.creationlog().gid())); + json_object_object_add(jo, "creationlog", jaf); + // Array for jobs + json_object * jja = json_object_new_array(); + auto & jl = m_payload.jobs(); + for (auto j=jl.begin(); j!=jl.end(); j++) { + // Object for job + json_object * jj = json_object_new_object(); + + json_object_object_add(jj, "copynb", json_object_new_int(j->copynb())); + json_object_object_add(jj, "retrieswithinmount", json_object_new_int(j->retrieswithinmount())); + json_object_object_add(jj, "totalretries", json_object_new_int(j->totalretries())); + json_object_object_add(jj, "status", json_object_new_int64(j->status())); + json_object_object_add(jj, "fseq", json_object_new_int64(j->fseq())); + json_object_object_add(jj, "blockid", json_object_new_int64(j->blockid())); + json_object_object_add(jj, "tape", json_object_new_string(j->tape().c_str())); + json_object_object_add(jj, "tapeAddress", json_object_new_string(j->tapeaddress().c_str())); + json_object_array_add(jja, jj); + } + json_object_object_add(jo, "jobs", jja); + // Object for drdata + json_object * jlog = json_object_new_object(); + json_object_object_add(jlog, "drblob", json_object_new_string(m_payload.drdata().drblob().c_str())); + json_object_object_add(jlog, "drgroup", json_object_new_string(m_payload.drdata().drgroup().c_str())); + json_object_object_add(jlog, "drinstance", json_object_new_string(m_payload.drdata().drinstance().c_str())); + json_object_object_add(jlog, "drowner", json_object_new_string(m_payload.drdata().drowner().c_str())); + json_object_object_add(jlog, "drpath", json_object_new_string(m_payload.drdata().drpath().c_str())); + json_object_object_add(jo, "drdata", jlog); + // Object for requester + json_object * jrf = json_object_new_object(); + json_object_object_add(jrf, "username", json_object_new_string(m_payload.requester().username().c_str())); + json_object_object_add(jrf, "groupname", json_object_new_string(m_payload.requester().groupname().c_str())); + json_object_object_add(jo, "requester", jrf); + ret << json_object_to_json_string_ext(jo, JSON_C_TO_STRING_PRETTY) << std::endl; + json_object_put(jo); + return ret.str(); +} + diff --git a/objectstore/RetrieveRequest.hpp b/objectstore/RetrieveRequest.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b7f241beb18dc537653ab7e15a14f7e4cf49d7e --- /dev/null +++ b/objectstore/RetrieveRequest.hpp @@ -0,0 +1,103 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "ObjectOps.hpp" +#include "objectstore/cta.pb.h" +#include <list> +#include "common/dataStructures/DRData.hpp" +#include "common/dataStructures/EntryLog.hpp" +#include "common/dataStructures/Requester.hpp" +#include "common/archiveNS/TapeFileLocation.hpp" + +namespace cta { namespace objectstore { + +class Backend; +class Agent; +class GenericObject; +class CreationLog; + +class RetrieveRequest: public ObjectOps<serializers::RetrieveRequest> { +public: + RetrieveRequest(const std::string & address, Backend & os); + RetrieveRequest(GenericObject & go); + void initialize(); + // Job management ============================================================ + void addJob(const cta::TapeFileLocation & tapeFileLocation, + const std::string & tapeaddress); + void setJobFailureLimits(uint16_t copyNumber, + uint16_t maxRetiesWithinMount, uint16_t maxTotalRetries); + void setJobSelected(uint16_t copyNumber, const std::string & owner); + void setJobPending(uint16_t copyNumber); + bool setJobSuccessful(uint16_t copyNumber); //< returns true if this is the last job + class JobDump { + public: + uint16_t copyNb; + std::string tape; + std::string tapeAddress; + uint64_t fseq; + uint64_t blockid; + }; + JobDump getJob(uint16_t copyNb); + struct FailuresCount { + uint16_t failuresWithinMount; + uint16_t totalFailures; + }; + FailuresCount addJobFailure(uint16_t copyNumber, uint64_t sessionId); + serializers::RetrieveJobStatus getJobStatus(uint16_t copyNumber); + // Handling of the consequences of a job status. This is simpler that archival + // as one finish is enough. + void finish(); + // Mark all jobs as pending mount (following their linking to a tape pool) + void setAllJobsLinkingToTapePool(); + // Mark all the jobs as being deleted, in case of a cancellation + void setAllJobsFailed(); + // Mark all the jobs as pending deletion from NS. + void setAllJobsPendingNSdeletion(); + CTA_GENERATE_EXCEPTION_CLASS(NoSuchJob); + // Request management ======================================================== + void setSuccessful(); + void setFailed(); + // =========================================================================== + void setArchiveFileID(const uint64_t archiveFileID); + uint64_t getArchiveFileID(); + + void setDiskpoolName(const std::string &diskpoolName); + std::string getDiskpoolName(); + + void setDiskpoolThroughput(const uint64_t diskpoolThroughput); + uint64_t getDiskpoolThroughput(); + + void setDrData(const cta::common::dataStructures::DRData &drData); + cta::common::dataStructures::DRData getDrData(); + + void setDstURL(const std::string &dstURL); + std::string getDstURL(); + + void setRequester(const cta::common::dataStructures::Requester &requester); + cta::common::dataStructures::Requester getRequester(); + + void setCreationLog(const cta::common::dataStructures::EntryLog &creationLog); + cta::common::dataStructures::EntryLog getCreationLog(); + // =========================================================================== + std::list<JobDump> dumpJobs(); + std::string dump(); +}; + +}} diff --git a/objectstore/cta.proto b/objectstore/cta.proto index ed8a54163e8d2f6476db058b27a95a59697aff6e..f7cf62fe27ea5e0fb005f1aaacf9baaab2289ec3 100644 --- a/objectstore/cta.proto +++ b/objectstore/cta.proto @@ -13,6 +13,7 @@ enum ObjectType { RetrieveToFileRequest_t = 7; SchedulerGlobalLock_t = 8; ArchiveRequest_t = 9; + RetrieveRequest_t = 10; GenericObject_t = 1000; } @@ -421,7 +422,8 @@ message DRData { } message EntryLog { - required UserIdentity user = 8950; + required uint64 uid = 8950; + required uint64 gid = 8955; required string host = 8960; required uint64 time = 8970; }