Skip to content
Snippets Groups Projects
Commit a1e5e189 authored by Steven Murray's avatar Steven Murray
Browse files

Improved archive file logic - tehre are still 2 unit tests that do not pass

parent 62d18554
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ public:
*
* @param storageClassName The name of the storage class that identifies the
* source disk files.
* @param copyNb The tape copy number.
* @param copyNb The tape copy number. Copy numbers start from 1.
* @param tapePoolName The name of the destination tape pool.
* @param creator The identity of the user that created the storage class.
* @param comment Comment describing the storage class.
......
......@@ -97,6 +97,21 @@ std::list<cta::StorageClass> cta::FileSystemStorageClasses::getStorageClasses()
return storageClasses;
}
//------------------------------------------------------------------------------
// getStorageClass
//------------------------------------------------------------------------------
const cta::StorageClass &cta::FileSystemStorageClasses::getStorageClass(
const std::string &name) const {
std::map<std::string, FileSystemStorageClass>::const_iterator itor =
m_storageClasses.find(name);
if(itor == m_storageClasses.end()) {
std::ostringstream message;
message << "Storage class " << name << " does not exist";
throw Exception(message.str());
}
return itor->second.getStorageClass();
}
//------------------------------------------------------------------------------
// incStorageClassUsageCount
//------------------------------------------------------------------------------
......
......@@ -47,6 +47,14 @@ public:
*/
std::list<StorageClass> getStorageClasses() const;
/**
* Returns the specified storage class.
*
* @param name The name of the storage class.
* @return The specified storage class.
*/
const StorageClass &getStorageClass(const std::string &name) const;
/**
* Throws an exception if the specified storage class does not exist.
*
......
......@@ -13,7 +13,8 @@ void cta::MockArchivalJobTable::createArchivalJob(
const std::string &dstPath) {
checkArchivalJobDoesNotAlreadyExist(dstPath);
ArchivalJob job(ArchivalJobState::NONE, srcUrl, dstPath, requester.user, time(NULL));
ArchivalJob job(ArchivalJobState::PENDING, srcUrl, dstPath, requester.user,
time(NULL));
std::map<std::string, std::map<time_t, ArchivalJob> >::iterator poolItor =
m_jobsTree.find(tapePoolName);
......
......@@ -72,6 +72,24 @@ std::list<cta::ArchiveRoute> cta::MockArchiveRouteTable::
return routes;
}
//------------------------------------------------------------------------------
// getArchiveRoute
//------------------------------------------------------------------------------
const cta::ArchiveRoute &cta::MockArchiveRouteTable::getArchiveRoute(
const std::string &storageClassName,
const uint8_t copyNb) const {
const ArchiveRouteId routeId(storageClassName, copyNb);
std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor =
m_archiveRoutes.find(routeId);
if(itor == m_archiveRoutes.end()) {
std::ostringstream message;
message << "No archive route for storage class " << storageClassName <<
" copy number " << copyNb;
throw Exception(message.str());
}
return itor->second;
}
//------------------------------------------------------------------------------
// checkArchiveRouteExists
//------------------------------------------------------------------------------
......
......@@ -51,6 +51,18 @@ public:
*/
std::list<ArchiveRoute> getArchiveRoutes() const;
/**
* Returns the specified archive route.
*
* @param storageClassName The name of the storage class that identifies the
* source disk files.
* @param copyNb The tape copy number.
* @return The specified archive route.
*/
const ArchiveRoute &getArchiveRoute(
const std::string &storageClassName,
const uint8_t copyNb) const;
/**
* Throws an exception if the specified archive route does not exist.
*
......
......@@ -259,12 +259,41 @@ void cta::MockMiddleTierUser::archiveToDirectory(
const std::string inheritedStorageClassName = dstDirNode.getFileSystemEntry().
getEntry().getStorageClassName();
if(inheritedStorageClassName.empty()) {
std::ostringstream message;
message << "Directory " << inheritedStorageClassName << " does not have a "
"storage class";
throw Exception(message.str());
}
const StorageClass storageClass = m_db.storageClasses.getStorageClass(
inheritedStorageClassName);
if(0 == storageClass.getNbCopies()) {
std::ostringstream message;
message << "Storage class " << inheritedStorageClassName << " of directory "
<< dstDir << " has zero tape copies";
throw Exception(message.str());
}
checkStorageClassIsFullyRouted(storageClass);
const std::list<std::string> dstFileNames = Utils::getEnclosedNames(srcUrls);
checkDirNodeDoesNotContainFiles(dstDir, dstDirNode, dstFileNames);
for(std::list<std::string>::const_iterator itor = dstFileNames.begin();
itor != dstFileNames.end(); itor++) {
const std::string &dstFileName = *itor;
std::list<std::string>::const_iterator srcItor = srcUrls.begin();
for(std::list<std::string>::const_iterator dstItor = dstFileNames.begin();
dstItor != dstFileNames.end(); srcItor++, dstItor++) {
const std::string &srcUrl = *srcItor;
const std::string &dstFileName = *dstItor;
const std::string dstPath = dstDir + dstFileName;
for(uint8_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) {
const ArchiveRoute &route = m_db.archiveRoutes.getArchiveRoute(
inheritedStorageClassName, copyNb);
m_db.archivalJobs.createArchivalJob(requester, route.getTapePoolName(),
srcUrl, dstPath);
}
DirectoryEntry dirEntry(DirectoryEntry::ENTRYTYPE_FILE, dstFileName,
inheritedStorageClassName);
dstDirNode.addChild(new FileSystemNode(m_db.storageClasses, dirEntry));
......@@ -289,6 +318,17 @@ void cta::MockMiddleTierUser::checkDirNodeDoesNotContainFiles(
}
}
//------------------------------------------------------------------------------
// checkStorageClassIsFullyRouted
//------------------------------------------------------------------------------
void cta::MockMiddleTierUser::checkStorageClassIsFullyRouted(
const StorageClass &storageClass) const {
for(uint8_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) {
m_db.archiveRoutes.checkArchiveRouteExists(storageClass.getName(),
copyNb);
}
}
//------------------------------------------------------------------------------
// archiveToFile
//------------------------------------------------------------------------------
......@@ -314,6 +354,33 @@ void cta::MockMiddleTierUser::archiveToFile(
const std::string inheritedStorageClassName =
enclosingNode.getFileSystemEntry().getEntry().getStorageClassName();
if(inheritedStorageClassName.empty()) {
std::ostringstream message;
message << "Directory " << inheritedStorageClassName << " does not have a "
"storage class";
throw Exception(message.str());
}
const StorageClass &storageClass = m_db.storageClasses.getStorageClass(
inheritedStorageClassName);
if(0 == storageClass.getNbCopies()) {
std::ostringstream message;
message << "Storage class " << inheritedStorageClassName << " of directory "
<< enclosingDir << " has zero tape copies";
throw Exception(message.str());
}
checkStorageClassIsFullyRouted(storageClass);
const std::string &srcUrl = srcUrls.front();
for(uint8_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) {
const ArchiveRoute &route = m_db.archiveRoutes.getArchiveRoute(
inheritedStorageClassName, copyNb);
m_db.archivalJobs.createArchivalJob(requester, route.getTapePoolName(),
srcUrl, dstFile);
}
DirectoryEntry dirEntry(DirectoryEntry::ENTRYTYPE_FILE, enclosedName,
inheritedStorageClassName);
enclosingNode.addChild(new FileSystemNode(m_db.storageClasses, dirEntry));
......@@ -334,18 +401,29 @@ void cta::MockMiddleTierUser::checkUserIsAuthorisedToArchive(
std::map<cta::TapePool, std::list<cta::ArchivalJob> >
cta::MockMiddleTierUser::getArchivalJobs(
const SecurityIdentity &requester) const {
const std::map<std::string, std::map<time_t, cta::ArchivalJob> >
const std::map<std::string, std::map<time_t, ArchivalJob> >
jobsByPoolName = m_db.archivalJobs.getArchivalJobs(requester);
std::map<cta::TapePool, std::list<cta::ArchivalJob> > jobs;
for(std::map<std::string, std::map<time_t, cta::ArchivalJob> >::const_iterator
byPoolNameItor = jobsByPoolName.begin();
byPoolNameItor != jobsByPoolName.end();
byPoolNameItor++) {
std::map<TapePool, std::list<ArchivalJob> > allJobs;
for(std::map<std::string, std::map<time_t, ArchivalJob> >::const_iterator
poolItor = jobsByPoolName.begin();
poolItor != jobsByPoolName.end();
poolItor++) {
const std::string &tapePoolName = poolItor->first;
const std::map<time_t, ArchivalJob> &timeToJobMap = poolItor->second;
if(!timeToJobMap.empty()) {
const TapePool tapePool = m_db.tapePools.getTapePool(tapePoolName);
std::list<cta::ArchivalJob> poolJobs;
for(std::map<time_t, ArchivalJob>::const_iterator jobItor =
timeToJobMap.begin(); jobItor != timeToJobMap.end(); jobItor++) {
poolJobs.push_back(jobItor->second);
}
allJobs[tapePool] = poolJobs;
}
}
return jobs;
return allJobs;
}
//------------------------------------------------------------------------------
......
......@@ -276,6 +276,13 @@ private:
const std::list<std::string> &srcUrls,
const std::string &dstDir);
/**
* Throws an exception if the specified storage class is not fully routed.
*
* @param storageClass The storage class;
*/
void checkStorageClassIsFullyRouted(const StorageClass &storageClass) const;
/**
* Archives the specified list of source files to the specified destination
* file within the archive namespace.
......@@ -313,10 +320,10 @@ private:
* @param dirNode The file-system node representing the directory.
* @param fileNames The file names to be searched for.
*/
void checkDirNodeDoesNotContainFiles(
const std::string &dirPath,
const FileSystemNode &dirNode,
const std::list<std::string> &fileNames);
void checkDirNodeDoesNotContainFiles(
const std::string &dirPath,
const FileSystemNode &dirNode,
const std::list<std::string> &fileNames);
}; // class MockMiddleTierUser
......
......@@ -72,3 +72,17 @@ std::list<cta::TapePool> cta::MockTapePoolTable::getTapePools(
}
return tapePools;
}
//------------------------------------------------------------------------------
// getTapePool
//------------------------------------------------------------------------------
const cta::TapePool &cta::MockTapePoolTable::getTapePool(
const std::string &name) const {
std::map<std::string, TapePool>::const_iterator itor = m_tapePools.find(name);
if(itor == m_tapePools.end()) {
std::ostringstream message;
message << "Tape pool " << name << " does not exist";
throw(Exception(message.str()));
}
return itor->second;
}
......@@ -69,6 +69,14 @@ public:
std::list<TapePool> getTapePools(
const SecurityIdentity &requester) const;
/**
* Returns the specified tape pool.
*
* @param name The name of the tape pool.
* @return The specified tape pool.
*/
const TapePool &getTapePool(const std::string &name) const;
private:
/**
......
......@@ -27,6 +27,13 @@ cta::TapePool::TapePool(
m_comment(comment) {
}
//------------------------------------------------------------------------------
// operator<
//------------------------------------------------------------------------------
bool cta::TapePool::operator<(const TapePool &rhs) const throw() {
return m_name < rhs.m_name;
}
//------------------------------------------------------------------------------
// getName
//------------------------------------------------------------------------------
......
......@@ -37,6 +37,13 @@ public:
const time_t creationTime,
const std::string &comment);
/**
* Less than operator.
*
* @param rhs The right-hand side of the operator.
*/
bool operator<(const TapePool &rhs) const throw();
/**
* Returns the name of the tape pool.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment