Commit 35a4622b authored by Steven Murray's avatar Steven Murray
Browse files

Reduced MockNameServer class to the single method addTapeFile()

parent 936779f2
......@@ -1757,6 +1757,9 @@ void SqliteCatalogue::setDriveStatus(const common::dataStructures::SecurityIdent
void SqliteCatalogue::fileWrittenToTape(
const cta::common::dataStructures::ArchiveRequest &archiveRequest,
const cta::common::dataStructures::TapeFile &tapeFileLocation) {
const uint64_t archiveFileId = 0;
std::list<common::dataStructures::ArchiveFile> files = getArchiveFile(archiveFileId);
}
//------------------------------------------------------------------------------
......
......@@ -64,8 +64,6 @@ set (COMMON_LIB_SRC_FILES
admin/AdminHost.cpp
admin/AdminUser.cpp
archiveRoutes/ArchiveRoute.cpp
archiveNS/ArchiveDirEntry.cpp
archiveNS/ArchiveDirIterator.cpp
archiveNS/ArchiveFile.cpp
archiveNS/ArchiveFileStatus.cpp
archiveNS/StorageClass.cpp
......
/*
* 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/archiveNS/ArchiveDirEntry.hpp"
//------------------------------------------------------------------------------
// entryTypeToStr
//------------------------------------------------------------------------------
const char *cta::common::archiveNS::ArchiveDirEntry::entryTypeToStr(const EntryType enumValue)
throw() {
switch(enumValue) {
case ENTRYTYPE_NONE : return "NONE";
case ENTRYTYPE_FILE : return "FILE";
case ENTRYTYPE_DIRECTORY: return "DIRECTORY";
default : return "UNKNOWN";
}
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::archiveNS::ArchiveDirEntry::ArchiveDirEntry() {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::archiveNS::ArchiveDirEntry::ArchiveDirEntry(
const EntryType type,
const std::string &name,
const common::archiveNS::ArchiveFileStatus &status,
const std::list<NameServerTapeFile> &tapeCopies):
type(type),
name(name),
status(status),
tapeCopies(tapeCopies) {
}
/*
* 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 "common/archiveNS/ArchiveFileStatus.hpp"
#include "nameserver/NameServerTapeFile.hpp"
#include <string>
#include <list>
namespace cta { namespace common { namespace archiveNS {
/**
* A directory entry within the archive namespace.
*/
struct ArchiveDirEntry {
/**
* Enumeration of the different types of directory entry.
*/
enum EntryType {
ENTRYTYPE_NONE,
ENTRYTYPE_FILE,
ENTRYTYPE_DIRECTORY};
/**
* Thread safe method that returns the string representation of the specified
* enumeration value.
*
* @param enumValue The integer value of the type.
* @return The string representation.
*/
static const char *entryTypeToStr(const EntryType enumValue) throw();
/**
* Constructor.
*
* Initialises all integer member-variables to 0.
*/
ArchiveDirEntry();
/**
* Constructor.
*
* Initialises all integer member-variables to 0.
*
* @param type The type of the entry.
* @param name The name of the directory entry.
* @param status The status of the entry.
*/
ArchiveDirEntry(const EntryType type, const std::string &name,
const common::archiveNS::ArchiveFileStatus &status, const std::list<NameServerTapeFile> &tapeCopies);
/**
* The type of the directory entry.
*/
EntryType type;
/**
* The name of the directory entry.
*/
std::string name;
/**
* The status of the entry.
*/
common::archiveNS::ArchiveFileStatus status;
/**
* The tape copies associated to this file.
*/
std::list<NameServerTapeFile> tapeCopies;
}; // class ArchiveDirEntry
}}} // namespace cta::common::archiveNS
/*
* 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/archiveNS/ArchiveDirIterator.hpp"
#include "common/exception/Exception.hpp"
using cta::exception::Exception;
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::archiveNS::ArchiveDirIterator::ArchiveDirIterator() {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::common::archiveNS::ArchiveDirIterator::ArchiveDirIterator(
const std::list<common::archiveNS::ArchiveDirEntry> &entries): m_entries(entries) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::common::archiveNS::ArchiveDirIterator::~ArchiveDirIterator() throw() {
}
//------------------------------------------------------------------------------
// hasMore
//------------------------------------------------------------------------------
bool cta::common::archiveNS::ArchiveDirIterator::hasMore() {
return !m_entries.empty();
}
//------------------------------------------------------------------------------
// next
//------------------------------------------------------------------------------
const cta::common::archiveNS::ArchiveDirEntry cta::common::archiveNS::ArchiveDirIterator::next() {
if(m_entries.empty()) {
throw Exception("Out of bounds: There are no more directory entries");
}
common::archiveNS::ArchiveDirEntry entry = m_entries.front();
m_entries.pop_front();
return entry;
}
/*
* 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 "common/archiveNS/ArchiveDirEntry.hpp"
#include <list>
namespace cta { namespace common { namespace archiveNS {
/**
* Instances of ths class should be used in the following way to iterate
* through the contents of a directory.
*
* \code
* ArchiveDirIterator &itor = ...
*
* while(itor.hasMore())) {
* const ArchiveDirEntry &entry = itor.next();
*
* // Do something with entry
* }
* \endcode
*/
class ArchiveDirIterator {
public:
/**
* Constructor.
*/
ArchiveDirIterator();
/**
* Constructor.
*
* @param entries The directory entries.
*/
ArchiveDirIterator(const std::list<common::archiveNS::ArchiveDirEntry> &entries);
/**
* Destructor.
*/
~ArchiveDirIterator() throw();
/**
* Returns true if there are more directory entries.
*
* @return True if there are more directory entries.
*/
bool hasMore();
/**
* Returns a reference to the next directory entry or throws an exception if
* out of bounds.
*
* @return The next directory entry.
*/
const common::archiveNS::ArchiveDirEntry next();
private:
/**
* The directory entries.
*/
std::list<common::archiveNS::ArchiveDirEntry> m_entries;
}; // ArchiveDirIterator
}}} // namespace cta
......@@ -158,7 +158,6 @@ Unit tests and system tests with virtual tape drives
%attr(0755,root,root) %{_libdir}/libctaiounittests.so
%attr(0755,root,root) %{_libdir}/libctalegacymsgunittests.so
%attr(0755,root,root) %{_libdir}/libctamessagesunittests.so
%attr(0755,root,root) %{_libdir}/libctanameserverunittests.so
%attr(0755,root,root) %{_libdir}/libctaobjectstoreunittests.so
%attr(0755,root,root) %{_libdir}/libctaremotensunittests.so
%attr(0755,root,root) %{_libdir}/libctaschedulerunittests.so
......
......@@ -12,16 +12,5 @@ target_link_libraries(ctanameserver ctacommon)
install (TARGETS ctanameserver DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
add_library (ctanameserverunittests SHARED
mockNS/MockNameServerFactory.cpp
mockNS/MockNameServerTest.cpp
mockNS/SmartFdTest.cpp
NameServerFactory.cpp)
target_link_libraries(ctanameserverunittests
ctanameserver)
install(TARGETS ctanameserverunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
add_executable(makeMockNameServerBasePath mockNS/makeMockNameServerBasePath.cpp)
target_link_libraries(makeMockNameServerBasePath ctacommon)
\ No newline at end of file
target_link_libraries(makeMockNameServerBasePath ctacommon)
......@@ -18,11 +18,11 @@
#pragma once
#include "common/archiveNS/ArchiveDirIterator.hpp"
#include "common/archiveNS/ArchiveFileStatus.hpp"
#include "common/SecurityIdentity.hpp"
#include "nameserver/NameServerTapeFile.hpp"
#include <list>
#include <memory>
#include <string>
......@@ -40,217 +40,6 @@ public:
*/
virtual ~NameServer() throw() = 0;
/**
* Creates the specified directory.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
* @param mode The mode bits of the directory entry.
*/
virtual void createDir(
const SecurityIdentity &cliIdentity,
const std::string &path,
const mode_t mode) = 0;
/**
* Deletes the specified directory.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
*/
virtual void deleteDir(
const SecurityIdentity &cliIdentity,
const std::string &path) = 0;
/**
* Returns the volume identifier of the tape on which the specified tape copy
* has been archived.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file.
* @param copyNb The copy number of the file.
*/
virtual std::string getVidOfFile(
const SecurityIdentity &cliIdentity,
const std::string &path,
const uint16_t copyNb) const = 0;
/**
* Gets the contents of the specified directory.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
* @return An iterator over the contents of the directory.
*/
virtual common::archiveNS::ArchiveDirIterator getDirContents(
const SecurityIdentity &cliIdentity,
const std::string &path) const = 0;
/**
* Returns the status of the specified file or directory within the archive
* namespace or NULL if the file or directory does not exist.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file or directory within the archive
* namespace.
* @return The status of the file or directory or NULL if the file or
* directory does not exist.
*/
virtual std::unique_ptr<common::archiveNS::ArchiveFileStatus> statFile(
const SecurityIdentity &cliIdentity,
const std::string &path) const = 0;
/**
* Creates the specified storage class.
*
* @param requester The identity of the user requesting the creation of the
* storage class.
* @param name The name of the storage class.
* @param nbCopies The number of copies a file associated with this storage
* class should have on tape.
*/
virtual void createStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &name,
const uint16_t nbCopies) = 0;
/**
* Creates the specified storage class with the specified numeric indentifier.
*
* @param requester The identity of the user requesting the creation of the
* storage class.
* @param name The name of the storage class.
* @param nbCopies The number of copies a file associated with this storage
* class should have on tape.
* @param id The numeric indentifier of the storage class.
*/
virtual void createStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &name,
const uint16_t nbCopies,
const uint32_t id) = 0;
/**
* Deletes the specified storage class.
*
* @param requester The identity of the user requesting the deletion of the
* storage class.
* @param name The name of the storage class.
*/
virtual void deleteStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &name) = 0;
/**
* Updates the specified storage class with the specified number of tape
* copies.
*
* @param requester The identity of the user requesting the deletion of the
* storage class.
* @param name The name of the storage class.
* @param nbCopies The number of copies a file associated with this storage
* class should have on tape.
*/
virtual void updateStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &name,
const uint16_t nbCopies) = 0;
/**
* Sets the storage class of the specified directory to the specified value.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
* @param storageClassName The name of the storage class.
*/
virtual void setDirStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &path,
const std::string &storageClassName) = 0;
/**
* Clears the storage class of the specified directory.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
*/
virtual void clearDirStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &path) = 0;
/**
* Returns the name of the storage class of the specified directory.
*
* @param requester The identity of the requester.
* @param path The absolute path of the directory.
* @return The name of the storage class of the specified directory.
*/
virtual std::string getDirStorageClass(
const SecurityIdentity &cliIdentity,
const std::string &path) const = 0;
/**
* Throws an exception if the specified storage class is in use within the
* specified file or directory. This is a nice to have but probably impractical,
* due to the fact that to manage large name spaces one would need a running counter
* of storage class usages, which could be a major area of contention.
*
* @param requester The identity of the requester.
* @param storageClassName The name of the storage class.
* @param path The absolute path of the file or directory.
*/
virtual void assertStorageClassIsNotInUse(
const SecurityIdentity &cliIdentity,
const std::string &storageClass,
const std::string &path) const = 0;
/**
* Creates the specified file entry.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file.
* @param mode The mode bits of the file entry.
*/
virtual void createFile(
const SecurityIdentity &cliIdentity,
const std::string &path,
const mode_t mode,
const Checksum & checksum,
const uint64_t size) = 0;
/**
* Sets the owner of the specified file or directory entry.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file or directory.
* @param owner The owner.
*/
virtual void setOwner(
const SecurityIdentity &cliIdentity,
const std::string &path,
const UserIdentity &owner) = 0;
/**
* Returns the owner of the specified file or directory entry.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file or directory.
* @return The owner of the specified file or directory entry.
*/
virtual UserIdentity getOwner(
const SecurityIdentity &cliIdentity,
const std::string &path) const = 0;
/**
* Deletes the specified file entry.
*
* @param requester The identity of the requester.
* @param path The absolute path of the file.
*/
virtual void deleteFile(
const SecurityIdentity &cliIdentity,
const std::string &path) = 0;
/**
* Add the specified tape file entry to the archive namespace.
*
......@@ -263,30 +52,6 @@ public:
const std::string &path,
const NameServerTapeFile &tapeFile) = 0;
/**
* Delete the specified tape file entry from the archive namespace.
*
* @param requester The identity of the requester.
* @param path The absolute path of the archive file.
* @param copyNb The tape copy to delete.
*/
virtual void deleteTapeFile(
const SecurityIdentity &cliIdentity,
const std::string &path,
const uint16_t copyNb) = 0;
/**
* Gets the tape entries from the archive namespace corresponding the archive
* with the specified path.
*
* @param requester The identity of the requester.
* @param path The absolute path of the archive file.
* @return The tape file entries.
*/
virtual std::list<NameServerTapeFile> getTapeFiles(
const SecurityIdentity &cliIdentity,
const std::string &path) const = 0;
}; // class NameServer
} // namespace
/*
* 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 "nameserver/NameServerFactory.hpp"