Commit bebb097d authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Added structure RetrieveRequest both to protocol buffers and to the objectstore

parent eded047a
/*
* 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;
}
/*
* 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
......@@ -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
......
......@@ -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();
......
......@@ -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);
......
......@@ -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
......
......@@ -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
......
/*
* 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());