diff --git a/nameserver/mockNS/MockNameServer.cpp b/nameserver/mockNS/MockNameServer.cpp index 26c1e29fc5ad9103deacaf3b36eb12b3e870177e..fa6f3ec1e2d8419bd538198c60a0420bb17bd67a 100644 --- a/nameserver/mockNS/MockNameServer.cpp +++ b/nameserver/mockNS/MockNameServer.cpp @@ -168,23 +168,81 @@ void cta::MockNameServer::assertStorageClassIsNotInUse( closedir(dp); } +//------------------------------------------------------------------------------ +// fromNameServerTapeFileToString +//------------------------------------------------------------------------------ +std::string cta::MockNameServer::fromNameServerTapeFileToString(const cta::NameServerTapeFile &tapeFile) const { + std::stringstream ss; + ss << tapeFile.checksum.checksumTypeToStr(tapeFile.checksum.getType()) + << " " << tapeFile.checksum.str() + << " " << tapeFile.compressedSize + << " " << tapeFile.copyNb + << " " << tapeFile.size + << " " << tapeFile.tapeFileLocation.blockId + << " " << tapeFile.tapeFileLocation.copyNb + << " " << tapeFile.tapeFileLocation.fSeq + << " " << tapeFile.tapeFileLocation.vid; + return ss.str(); +} + +//------------------------------------------------------------------------------ +// fromStringToNameServerTapeFile +//------------------------------------------------------------------------------ +cta::NameServerTapeFile cta::MockNameServer::fromStringToNameServerTapeFile(const std::string &xAttributeString) const { + NameServerTapeFile tapeFile; + std::stringstream ss(xAttributeString); + std::string checksumTypeString; + std::string checksumString; + ss >> checksumTypeString + >> checksumString + >> tapeFile.compressedSize + >> tapeFile.copyNb + >> tapeFile.size + >> tapeFile.tapeFileLocation.blockId + >> tapeFile.tapeFileLocation.copyNb + >> tapeFile.tapeFileLocation.fSeq + >> tapeFile.tapeFileLocation.vid; + cta::ByteArray byteArray(checksumString); + cta::Checksum::ChecksumType checksumType=checksumString=="ADLER32"?cta::Checksum::ChecksumType::CHECKSUMTYPE_ADLER32:cta::Checksum::ChecksumType::CHECKSUMTYPE_NONE; + cta::Checksum checksum(checksumType, byteArray); + tapeFile.checksum=checksum; + return tapeFile; +} + //------------------------------------------------------------------------------ // addTapeFile //------------------------------------------------------------------------------ -void cta::MockNameServer::addTapeFile( - const SecurityIdentity &requester, - const std::string &path, - const NameServerTapeFile &tapeFile) { - throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +void cta::MockNameServer::addTapeFile(const SecurityIdentity &requester, const std::string &path, const NameServerTapeFile &tapeFile) { + Utils::assertAbsolutePathSyntax(path); + const std::string fsPath = m_fsDir + path; + assertFsDirExists(fsPath); + if(tapeFile.tapeFileLocation.copyNb==1) { + Utils::setXattr(fsPath.c_str(), "user.CTATapeFileCopyOne", fromNameServerTapeFileToString(tapeFile)); + } + else if(tapeFile.tapeFileLocation.copyNb==2) { + Utils::setXattr(fsPath.c_str(), "user.CTATapeFileCopyTwo", fromNameServerTapeFileToString(tapeFile)); + } else { + throw exception::Exception(std::string(__FUNCTION__) + ": Invalid copyNb (only supporting 1 and 2 in the MockNameServer)"); + } } //------------------------------------------------------------------------------ // getTapeFiles //------------------------------------------------------------------------------ -std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles( - const SecurityIdentity &requester, - const std::string &path) { - throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +std::list<cta::NameServerTapeFile> cta::MockNameServer::getTapeFiles(const SecurityIdentity &requester, const std::string &path) { + Utils::assertAbsolutePathSyntax(path); + const std::string fsPath = m_fsDir + path; + assertFsDirExists(fsPath); + std::list<cta::NameServerTapeFile> tapeFileList; + std::string copyOne = Utils::getXattr(fsPath, "user.CTATapeFileCopyOne"); + std::string copyTwo = Utils::getXattr(fsPath, "user.CTATapeFileCopyTwo"); + if(copyOne!="") { + tapeFileList.push_back(fromStringToNameServerTapeFile(copyOne)); + } + if(copyTwo!="") { + tapeFileList.push_back(fromStringToNameServerTapeFile(copyTwo)); + } + return tapeFileList; } //------------------------------------------------------------------------------ @@ -286,6 +344,8 @@ void cta::MockNameServer::createFile( << Utils::errnoToString(savedErrno); throw(exception::Exception(msg.str())); } + Utils::setXattr(fsPath.c_str(), "user.CTATapeFileCopyOne", ""); + Utils::setXattr(fsPath.c_str(), "user.CTATapeFileCopyTwo", ""); } //------------------------------------------------------------------------------ diff --git a/nameserver/mockNS/MockNameServer.hpp b/nameserver/mockNS/MockNameServer.hpp index f2d02dca3c9cfd5ab8faa66c1a9828f31c4d3d37..ece07f7daff0f100c7016debc84e0cccbe9d6351 100644 --- a/nameserver/mockNS/MockNameServer.hpp +++ b/nameserver/mockNS/MockNameServer.hpp @@ -105,6 +105,22 @@ public: const std::string &path); private: + + /** + * Converts a NameServerTapeFile to a string to be used as an extended attribute + * + * @param tapeFile The NameServerTapeFile object + * @return the converted string + */ + std::string fromNameServerTapeFileToString(const cta::NameServerTapeFile &tapeFile) const; + + /** + * Converts a string (the value of an extended attribute) to a NameServerTapeFile + * + * @param xAttributeString The value of an extended attribute + * @return the NameServerTapeFile object resulting from the conversion + */ + cta::NameServerTapeFile fromStringToNameServerTapeFile(const std::string &xAttributeString) const; std::string m_fsDir; @@ -116,7 +132,7 @@ private: /** * Throws an exception if the specified user is not the owner of the - * specified namepsace entry. + * specified namespace entry. * * @param requester The identity of the requester. * @param user The user. @@ -148,7 +164,7 @@ private: const struct stat statResult) const; /** - * The string name and numeric idenitifer of a storage class. + * The string name and numeric identifier of a storage class. */ struct StorageClassNameAndId { std::string name; @@ -178,7 +194,7 @@ private: * Throws an exception if the specified storage class numeric identifier * already exists. * - * @param id The numeric idenitifer of the storage class. + * @param id The numeric identifier of the storage class. */ void assertStorageClassIdDoesNotExist(const uint32_t id) const;