Commit 8ab4d00c authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Plugged in the optional in the frontend and the catalogue

parent 251b9751
......@@ -20,6 +20,8 @@
#include <string>
#include "common/optional.hpp"
namespace cta {
namespace catalogue {
......@@ -37,12 +39,12 @@ struct ArchiveFileSearchCriteria {
/**
* The unique identifier of an archive file.
*/
std::string archiveFileId;
optional<uint64_t> archiveFileId;
/**
* The name of a disk instance.
*/
std::string diskInstance;
optional<std::string> diskInstance;
/**
* The unique identifier of a disk file within its disk instance.
......@@ -50,42 +52,42 @@ struct ArchiveFileSearchCriteria {
* The combination of diskInstance and diskFileId is unique across all disk
* instances.
*/
std::string diskFileId;
optional<std::string> diskFileId;
/**
* The absolute path of a file within its disk instance.
*/
std::string diskFilePath;
optional<std::string> diskFilePath;
/**
* The owner of a file within its disk instance.
*/
std::string diskFileUser;
optional<std::string> diskFileUser;
/**
* The group of a file within its disk instance.
*/
std::string diskFileGroup;
optional<std::string> diskFileGroup;
/**
* The storage class name of the file.
*/
std::string storageClass;
optional<std::string> storageClass;
/**
* The volume identifier of a tape.
*/
std::string vid;
optional<std::string> vid;
/**
* The copy number of a tape file.
*/
std::string tapeFileCopyNb;
optional<uint64_t> tapeFileCopyNb;
/**
* The name of a tape pool.
*/
std::string tapePool;
optional<std::string> tapePool;
}; // struct ArchiveFileSearchCriteria
......
......@@ -2174,7 +2174,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
{
catalogue::ArchiveFileSearchCriteria searchCriteria;
searchCriteria.archiveFileId = "10";
searchCriteria.archiveFileId = 10;
archiveFileItor = m_catalogue->getArchiveFileItor(searchCriteria, prefetch);
m = archiveFileItorToMap(*archiveFileItor);
ASSERT_EQ(1, m.size());
......@@ -2242,7 +2242,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
{
catalogue::ArchiveFileSearchCriteria searchCriteria;
searchCriteria.tapeFileCopyNb = "1";
searchCriteria.tapeFileCopyNb = 1;
archiveFileItor = m_catalogue->getArchiveFileItor(searchCriteria, prefetch);
m = archiveFileItorToMap(*archiveFileItor);
ASSERT_EQ(nbArchiveFiles, m.size());
......@@ -2258,9 +2258,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) {
{
catalogue::ArchiveFileSearchCriteria searchCriteria;
std::ostringstream nonExistantArchiveFileId;
nonExistantArchiveFileId << (nbArchiveFiles + 1234);
searchCriteria.archiveFileId = nonExistantArchiveFileId.str();
searchCriteria.archiveFileId = nbArchiveFiles + 1234;
archiveFileItor = m_catalogue->getArchiveFileItor(searchCriteria, prefetch);
m = archiveFileItorToMap(*archiveFileItor);
ASSERT_EQ(0, m.size());
......
......@@ -2415,77 +2415,69 @@ std::list<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveFilesFo
"TAPE_FILE.VID = TAPE.VID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID >= :STARTING_ARCHIVE_FILE_ID";
if(!searchCriteria.archiveFileId.empty()) {
if(!utils::isValidUInt(searchCriteria.archiveFileId)) {
throw UserError(std::string("Archive file ID ") + searchCriteria.archiveFileId +
" is not a valid unsigned integer");
}
if(searchCriteria.archiveFileId) {
sql += " AND ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID";
}
if(!searchCriteria.diskInstance.empty()) {
if(searchCriteria.diskInstance) {
sql += " AND ARCHIVE_FILE.DISK_INSTANCE = :DISK_INSTANCE";
}
if(!searchCriteria.diskFileId.empty()) {
if(searchCriteria.diskFileId) {
sql += " AND ARCHIVE_FILE.DISK_FILE_ID = :DISK_FILE_ID";
}
if(!searchCriteria.diskFilePath.empty()) {
if(searchCriteria.diskFilePath) {
sql += " AND ARCHIVE_FILE.DISK_FILE_PATH = :DISK_FILE_PATH";
}
if(!searchCriteria.diskFileUser.empty()) {
if(searchCriteria.diskFileUser) {
sql += " AND ARCHIVE_FILE.DISK_FILE_USER = :DISK_FILE_USER";
}
if(!searchCriteria.diskFileGroup.empty()) {
if(searchCriteria.diskFileGroup) {
sql += " AND ARCHIVE_FILE.DISK_FILE_GROUP = :DISK_FILE_GROUP";
}
if(!searchCriteria.storageClass.empty()) {
if(searchCriteria.storageClass) {
sql += " AND ARCHIVE_FILE.STORAGE_CLASS_NAME = :STORAGE_CLASS_NAME";
}
if(!searchCriteria.vid.empty()) {
if(searchCriteria.vid) {
sql += " AND TAPE_FILE.VID = :VID";
}
if(!searchCriteria.tapeFileCopyNb.empty()) {
if(!utils::isValidUInt(searchCriteria.tapeFileCopyNb)) {
throw UserError(std::string("Tape-file copy-number ") + searchCriteria.tapeFileCopyNb +
" is not a valid unsigned integer");
}
if(searchCriteria.tapeFileCopyNb) {
sql += " AND TAPE_FILE.COPY_NB = :TAPE_FILE_COPY_NB";
}
if(!searchCriteria.tapePool.empty()) {
if(searchCriteria.tapePool) {
sql += " AND TAPE.TAPE_POOL_NAME = :TAPE_POOL_NAME";
}
sql += " ORDER BY ARCHIVE_FILE.ARCHIVE_FILE_ID, TAPE_FILE.COPY_NB";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindUint64(":STARTING_ARCHIVE_FILE_ID", startingArchiveFileId);
if(!searchCriteria.archiveFileId.empty()) {
stmt->bindUint64(":ARCHIVE_FILE_ID", utils::toUint64(searchCriteria.archiveFileId));
if(searchCriteria.archiveFileId) {
stmt->bindUint64(":ARCHIVE_FILE_ID", searchCriteria.archiveFileId.value());
}
if(!searchCriteria.diskInstance.empty()) {
stmt->bindString(":DISK_INSTANCE", searchCriteria.diskInstance);
if(searchCriteria.diskInstance) {
stmt->bindString(":DISK_INSTANCE", searchCriteria.diskInstance.value());
}
if(!searchCriteria.diskFileId.empty()) {
stmt->bindString(":DISK_FILE_ID", searchCriteria.diskFileId);
if(searchCriteria.diskFileId) {
stmt->bindString(":DISK_FILE_ID", searchCriteria.diskFileId.value());
}
if(!searchCriteria.diskFilePath.empty()) {
stmt->bindString(":DISK_FILE_PATH", searchCriteria.diskFilePath);
if(searchCriteria.diskFilePath) {
stmt->bindString(":DISK_FILE_PATH", searchCriteria.diskFilePath.value());
}
if(!searchCriteria.diskFileUser.empty()) {
stmt->bindString(":DISK_FILE_USER", searchCriteria.diskFileUser);
if(searchCriteria.diskFileUser) {
stmt->bindString(":DISK_FILE_USER", searchCriteria.diskFileUser.value());
}
if(!searchCriteria.diskFileGroup.empty()) {
stmt->bindString(":DISK_FILE_GROUP", searchCriteria.diskFileGroup);
if(searchCriteria.diskFileGroup) {
stmt->bindString(":DISK_FILE_GROUP", searchCriteria.diskFileGroup.value());
}
if(!searchCriteria.storageClass.empty()) {
stmt->bindString(":STORAGE_CLASS_NAME", searchCriteria.storageClass);
if(searchCriteria.storageClass) {
stmt->bindString(":STORAGE_CLASS_NAME", searchCriteria.storageClass.value());
}
if(!searchCriteria.vid.empty()) {
stmt->bindString(":VID", searchCriteria.vid);
if(searchCriteria.vid) {
stmt->bindString(":VID", searchCriteria.vid.value());
}
if(!searchCriteria.tapeFileCopyNb.empty()) {
stmt->bindUint64(":TAPE_FILE_COPY_NB", utils::toUint64(searchCriteria.tapeFileCopyNb));
if(searchCriteria.tapeFileCopyNb) {
stmt->bindUint64(":TAPE_FILE_COPY_NB", searchCriteria.tapeFileCopyNb.value());
}
if(!searchCriteria.tapePool.empty()) {
stmt->bindString(":TAPE_POOL_NAME", searchCriteria.tapePool);
if(searchCriteria.tapePool) {
stmt->bindString(":TAPE_POOL_NAME", searchCriteria.tapePool.value());
}
std::unique_ptr<DbRset> rset(stmt->executeQuery());
std::list<common::dataStructures::ArchiveFile> archiveFiles;
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "optional.hpp"
nullopt_t nullopt{};
......@@ -28,7 +28,7 @@ struct nullopt_t {
nullopt_t() {}
};
nullopt_t nullopt{};
extern nullopt_t nullopt;
template <class T> class optional
{
......
This diff is collapsed.
......@@ -21,6 +21,7 @@
#include "catalogue/Catalogue.hpp"
#include "common/dataStructures/FrontendReturnCode.hpp"
#include "common/log/SyslogLogger.hpp"
#include "common/optional.hpp"
#include "scheduler/Scheduler.hpp"
#include "XrdSfs/XrdSfsInterface.hh"
......@@ -123,27 +124,37 @@ protected:
/**
* Parses the command line and dispatches it to the relevant function
*
* @param tokens The command line tokens
* @param requester The requester identity
* @return SFS_OK in case command succeeded, SFS_ERROR otherwise
*/
int dispatchCommand();
/**
* Given the command line string vector it returns the value of the specified option or an empty string if absent
* Set of functions that, given the command line string vector, return the string/numerical/boolean/time value of the specified option
*
* @param tokens The command line tokens
* @param optionShortName The short name of the required option
* @param optionLongName The long name of the required option
* @param encoded True if the argument is encoded, false otherwise
* @return the value of the option or an empty string if absent
* @return the option value (empty if absent)
*/
std::string getOptionValue(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
optional<std::string> getOptionStringValue(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
optional<uint64_t> getOptionUint64Value(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
optional<bool> getOptionBoolValue(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
optional<time_t> getOptionTimeValue(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
/**
* Returns the string/numerical/boolean value of the specified option
*
* @param optionShortName The short name of the required option
* @param optionLongName The long name of the required option
* @param encoded True if the argument is encoded, false otherwise
* @return the option value (empty if absent)
*/
std::string getOption(const std::string& optionShortName, const std::string& optionLongName, const bool encoded);
/**
* Given the command line string vector it returns true if the specified option is present, false otherwise
*
* @param tokens The command line tokens
* @param optionShortName The short name of the required option
* @param optionLongName The long name of the required option
* @return true if the specified option is present, false otherwise
......@@ -222,6 +233,24 @@ protected:
*/
uint64_t stringParameterToUint64(const std::string &parameterName, const std::string &parameterValue) const;
/**
* Converts a parameter string into a bool (throws a cta::exception if it fails)
*
* @param parameterName The name of the parameter
* @param parameterValue The value of the parameter
* @return the conversion result
*/
bool stringParameterToBool(const std::string &parameterName, const std::string &parameterValue) const;
/**
* Converts a parameter string into a time_t (throws a cta::exception if it fails)
*
* @param parameterName The name of the parameter
* @param parameterValue The value of the parameter
* @return the conversion result
*/
time_t stringParameterToTime(const std::string &parameterName, const std::string &parameterValue) const;
/**
* Sets the return code of the cmdline client and its output. Always returns SFS_OK, which is the only xroot return
* code that allows the copy process to happen successfully. Logs the original request and any error in processing it.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment