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

Added code for add tape file and get tape file in mock name server

parent e7f20708
......@@ -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", "");
}
//------------------------------------------------------------------------------
......
......@@ -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;
......
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