diff --git a/nameserver/CMakeLists.txt b/nameserver/CMakeLists.txt index f045d0955b3d67d6f1d0c6363ead482444f43058..abcc71e30cf7cd8b4d5805a8035f566147244bce 100644 --- a/nameserver/CMakeLists.txt +++ b/nameserver/CMakeLists.txt @@ -6,7 +6,8 @@ add_library (ctanameserver SHARED mockNS/MockNameServer.cpp mockNS/SmartFd.cpp CastorNameServer.cpp - NameServer.cpp) + NameServer.cpp + NameServerTapeFile.cpp) target_link_libraries(ctanameserver castorns castorcommon) diff --git a/nameserver/CastorNameServer.cpp b/nameserver/CastorNameServer.cpp index 50df4b382a60f27647055c7285d3cb6d40a1983b..41b450087b288fb613c2323be89550ae66dd916a 100644 --- a/nameserver/CastorNameServer.cpp +++ b/nameserver/CastorNameServer.cpp @@ -100,6 +100,26 @@ void cta::CastorNameServer::assertStorageClassIsNotInUse( const std::string &path) const { } + +//------------------------------------------------------------------------------ +// addTapeFile +//------------------------------------------------------------------------------ +void cta::CastorNameServer::addTapeFile( + const SecurityIdentity &requester, + const std::string &path, + const NameServerTapeFile &tapeFile) { + throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +} + +//------------------------------------------------------------------------------ +// getTapeFiles +//------------------------------------------------------------------------------ +std::list<cta::NameServerTapeFile> cta::CastorNameServer::getTapeFiles( + const SecurityIdentity &requester, + const std::string &path) { + throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +} + //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ @@ -312,7 +332,8 @@ cta::ArchiveDirEntry cta::CastorNameServer::getArchiveDirEntry(const SecurityIde //------------------------------------------------------------------------------ // getDirContents //------------------------------------------------------------------------------ -cta::ArchiveDirIterator cta::CastorNameServer::getDirContents(const SecurityIdentity &requester, const std::string &path) const { +cta::ArchiveDirIterator cta::CastorNameServer::getDirContents( + const SecurityIdentity &requester, const std::string &path) const { Utils::assertAbsolutePathSyntax(path); return getDirEntries(requester, path); } @@ -320,7 +341,8 @@ cta::ArchiveDirIterator cta::CastorNameServer::getDirContents(const SecurityIden //------------------------------------------------------------------------------ // getVidOfFile //------------------------------------------------------------------------------ -std::string cta::CastorNameServer::getVidOfFile(const SecurityIdentity &requester, const std::string &path, const uint16_t copyNb) const { +std::string cta::CastorNameServer::getVidOfFile(const SecurityIdentity &requester, + const std::string &path, const uint16_t copyNb) const { Utils::assertAbsolutePathSyntax(path); struct Cns_fileid file_uniqueid; memset(&file_uniqueid, 0, sizeof(struct Cns_fileid)); diff --git a/nameserver/CastorNameServer.hpp b/nameserver/CastorNameServer.hpp index c0e5ba26e556498a78483d6836fb53714a63608e..307cfb7febf64cc0cf3ee1248c187dd274747cc0 100644 --- a/nameserver/CastorNameServer.hpp +++ b/nameserver/CastorNameServer.hpp @@ -79,6 +79,30 @@ public: void updateStorageClass(const SecurityIdentity &requester, const std::string &name, const uint16_t nbCopies); + /** + * Add the specified tape file entry to the archive namespace. + * + * @param requester The identity of the requester. + * @param path The absolute path of the archive file. + * @param nameServerTapeFile The tape file entry. + */ + void addTapeFile( + const SecurityIdentity &requester, + const std::string &path, + const NameServerTapeFile &tapeFile); + + /** + * 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. + */ + std::list<NameServerTapeFile> getTapeFiles( + const SecurityIdentity &requester, + const std::string &path); + private: /** diff --git a/nameserver/CastorNameServerTest.cpp b/nameserver/CastorNameServerTest.cpp index 094191458c2e3491bb256b126acb4cede2039553..e548240590c5e894d90072c665e4f091230efb83 100644 --- a/nameserver/CastorNameServerTest.cpp +++ b/nameserver/CastorNameServerTest.cpp @@ -1,3 +1,21 @@ +/* + * 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/CastorNameServer.hpp" #include "common/exception/Exception.hpp" #include <iostream> diff --git a/nameserver/NameServer.hpp b/nameserver/NameServer.hpp index 4144b59f877a63457db5bfc2a6738319da127b4f..4ffe2c1c40bacdf2bc5db8f2cc6ef5ae3374394f 100644 --- a/nameserver/NameServer.hpp +++ b/nameserver/NameServer.hpp @@ -21,6 +21,7 @@ #include "common/archiveNS/ArchiveDirIterator.hpp" #include "common/archiveNS/ArchiveFileStatus.hpp" #include "common/SecurityIdentity.hpp" +#include "nameserver/NameServerTapeFile.hpp" #include <memory> #include <string> @@ -207,7 +208,7 @@ public: * Creates the specified file entry. * * @param requester The identity of the requester. - * @param path The absolute path of the directory. + * @param path The absolute path of the file. * @param mode The mode bits of the file entry. */ virtual void createFile( @@ -249,6 +250,30 @@ public: const SecurityIdentity &requester, const std::string &path) = 0; + /** + * Add the specified tape file entry to the archive namespace. + * + * @param requester The identity of the requester. + * @param path The absolute path of the archive file. + * @param nameServerTapeFile The tape file entry. + */ + virtual void addTapeFile( + const SecurityIdentity &requester, + const std::string &path, + const NameServerTapeFile &tapeFile) = 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 &requester, + const std::string &path) = 0; + }; // class NameServer } // namespace diff --git a/nameserver/NameServerTapeFile.cpp b/nameserver/NameServerTapeFile.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5906dae115c0ef0b3d7602aedc84c2a64799d96 --- /dev/null +++ b/nameserver/NameServerTapeFile.cpp @@ -0,0 +1,28 @@ +/* + * 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/NameServerTapeFile.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::NameServerTapeFile::NameServerTapeFile(): + copyNb(0), + size(0), + compressedSize(0) { +} diff --git a/nameserver/NameServerTapeFile.hpp b/nameserver/NameServerTapeFile.hpp new file mode 100644 index 0000000000000000000000000000000000000000..413a929910e1ec224c9a2555690724a557f24227 --- /dev/null +++ b/nameserver/NameServerTapeFile.hpp @@ -0,0 +1,67 @@ +/* + * 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/TapeFileLocation.hpp" +#include "common/checksum/Checksum.hpp" + +#include <stdint.h> + +namespace cta { + +/** + * A tape file entry within the archive namespace. + */ +struct NameServerTapeFile { + + /** + * Default constructor. + */ + NameServerTapeFile(); + + /** + * The copy number of the tape file where copy numbers start from 1. + * Please note that copy number 0 is an ivalid copy number. + */ + uint16_t copyNb; + + /** + * The location of the file on tape. + */ + TapeFileLocation tapeFileLocation; + + /** + * The uncompressed size of the tape file in bytes. + */ + uint64_t size; + + /** + * The compressed size of the tape file in bytes. In other words the actual + * number of bytes it occupies on tape. + */ + uint64_t compressedSize; + + /** + * The checksum of the tape file. + */ + Checksum checksum; + +}; // class NameServer + +} // namespace cta diff --git a/nameserver/mockNS/MockNameServer.cpp b/nameserver/mockNS/MockNameServer.cpp index d8bdcf5949ddf6c8cbaf99d5da847bf4e52afb13..26c1e29fc5ad9103deacaf3b36eb12b3e870177e 100644 --- a/nameserver/mockNS/MockNameServer.cpp +++ b/nameserver/mockNS/MockNameServer.cpp @@ -168,6 +168,25 @@ void cta::MockNameServer::assertStorageClassIsNotInUse( closedir(dp); } +//------------------------------------------------------------------------------ +// addTapeFile +//------------------------------------------------------------------------------ +void cta::MockNameServer::addTapeFile( + const SecurityIdentity &requester, + const std::string &path, + const NameServerTapeFile &tapeFile) { + throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +} + +//------------------------------------------------------------------------------ +// getTapeFiles +//------------------------------------------------------------------------------ +std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles( + const SecurityIdentity &requester, + const std::string &path) { + throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +} + //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ diff --git a/nameserver/mockNS/MockNameServer.hpp b/nameserver/mockNS/MockNameServer.hpp index 0f5a4908626df7d496f893994b028e2c6670ee1a..f2d02dca3c9cfd5ab8faa66c1a9828f31c4d3d37 100644 --- a/nameserver/mockNS/MockNameServer.hpp +++ b/nameserver/mockNS/MockNameServer.hpp @@ -80,6 +80,30 @@ public: void assertStorageClassIsNotInUse(const SecurityIdentity &requester, const std::string &storageClass, const std::string &path) const; + /** + * Add the specified tape file entry to the archive namespace. + * + * @param requester The identity of the requester. + * @param path The absolute path of the archive file. + * @param nameServerTapeFile The tape file entry. + */ + void addTapeFile( + const SecurityIdentity &requester, + const std::string &path, + const NameServerTapeFile &tapeFile); + + /** + * 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. + */ + std::list<NameServerTapeFile> getTapeFiles( + const SecurityIdentity &requester, + const std::string &path); + private: std::string m_fsDir;