Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
20b5b67d
Commit
20b5b67d
authored
Jun 04, 2015
by
Steven Murray
Browse files
Improved the unit tests for Scheduler and SchedulerDatabase.
parent
cf0d75ab
Changes
20
Hide whitespace changes
Inline
Side-by-side
common/Utils.cpp
View file @
20b5b67d
...
...
@@ -102,9 +102,9 @@ void cta::Utils::assertPathDoesContainConsecutiveSlashes(
}
//------------------------------------------------------------------------------
// getEnclosing
Dir
Path
// getEnclosingPath
//------------------------------------------------------------------------------
std
::
string
cta
::
Utils
::
getEnclosing
Dir
Path
(
const
std
::
string
&
path
)
{
std
::
string
cta
::
Utils
::
getEnclosingPath
(
const
std
::
string
&
path
)
{
if
(
path
==
"/"
)
{
throw
Exception
(
"Root directory does not have a parent"
);
}
...
...
common/Utils.hpp
View file @
20b5b67d
...
...
@@ -51,7 +51,7 @@ public:
* @param path The path.
* @return The path of the enclosing directory.
*/
static
std
::
string
getEnclosing
Dir
Path
(
const
std
::
string
&
path
);
static
std
::
string
getEnclosingPath
(
const
std
::
string
&
path
);
/**
* Returns the name of the enclosed file or directory of the specified path.
...
...
common/UtilsTest.cpp
View file @
20b5b67d
...
...
@@ -98,62 +98,62 @@ TEST_F(cta_client_UtilsTest,
ASSERT_EQ
(
std
::
string
(
"VALUE"
),
trimmedString
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosing
Dir
Path_empty_string
)
{
TEST_F
(
cta_client_UtilsTest
,
getEnclosingPath_empty_string
)
{
using
namespace
cta
;
const
std
::
string
dirPath
=
""
;
ASSERT_THROW
(
Utils
::
getEnclosing
Dir
Path
(
dirPath
),
std
::
exception
);
ASSERT_THROW
(
Utils
::
getEnclosingPath
(
dirPath
),
std
::
exception
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosing
Dir
Path_root
)
{
TEST_F
(
cta_client_UtilsTest
,
getEnclosingPath_root
)
{
using
namespace
cta
;
const
std
::
string
dirPath
=
"/"
;
std
::
string
enclosing
Dir
Path
;
ASSERT_THROW
(
enclosing
Dir
Path
=
Utils
::
getEnclosing
Dir
Path
(
dirPath
),
std
::
string
enclosingPath
;
ASSERT_THROW
(
enclosingPath
=
Utils
::
getEnclosingPath
(
dirPath
),
std
::
exception
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosing
Dir
Path_grandparent
)
{
TEST_F
(
cta_client_UtilsTest
,
getEnclosingPath_grandparent
)
{
using
namespace
cta
;
const
std
::
string
dirPath
=
"/grandparent"
;
std
::
string
enclosing
Dir
Path
;
ASSERT_NO_THROW
(
enclosing
Dir
Path
=
Utils
::
getEnclosing
Dir
Path
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/"
),
enclosing
Dir
Path
);
std
::
string
enclosingPath
;
ASSERT_NO_THROW
(
enclosingPath
=
Utils
::
getEnclosingPath
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/"
),
enclosingPath
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosing
Dir
Path_grandparent_parent
)
{
getEnclosingPath_grandparent_parent
)
{
using
namespace
cta
;
const
std
::
string
dirPath
=
"/grandparent/parent"
;
std
::
string
enclosing
Dir
Path
;
ASSERT_NO_THROW
(
enclosing
Dir
Path
=
Utils
::
getEnclosing
Dir
Path
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/grandparent/"
),
enclosing
Dir
Path
);
std
::
string
enclosingPath
;
ASSERT_NO_THROW
(
enclosingPath
=
Utils
::
getEnclosingPath
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/grandparent/"
),
enclosingPath
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosing
Dir
Path_grandparent_parent_child
)
{
getEnclosingPath_grandparent_parent_child
)
{
using
namespace
cta
;
const
std
::
string
dirPath
=
"/grandparent/parent/child"
;
std
::
string
enclosing
Dir
Path
;
ASSERT_NO_THROW
(
enclosing
Dir
Path
=
Utils
::
getEnclosing
Dir
Path
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/grandparent/parent/"
),
enclosing
Dir
Path
);
std
::
string
enclosingPath
;
ASSERT_NO_THROW
(
enclosingPath
=
Utils
::
getEnclosingPath
(
dirPath
));
ASSERT_EQ
(
std
::
string
(
"/grandparent/parent/"
),
enclosingPath
);
}
TEST_F
(
cta_client_UtilsTest
,
getEnclosedName
)
{
using
namespace
cta
;
const
std
::
string
enclosing
Dir
Path
=
"/grandparent/parent/"
;
const
std
::
string
enclosingPath
=
"/grandparent/parent/"
;
const
std
::
string
enclosedName
=
"child"
;
const
std
::
string
absoluteFilePath
=
enclosing
Dir
Path
+
enclosedName
;
const
std
::
string
absoluteFilePath
=
enclosingPath
+
enclosedName
;
std
::
string
result
;
ASSERT_NO_THROW
(
result
=
Utils
::
getEnclosedName
(
absoluteFilePath
));
ASSERT_EQ
(
enclosedName
,
result
);
...
...
@@ -162,16 +162,16 @@ TEST_F(cta_client_UtilsTest, getEnclosedName) {
TEST_F
(
cta_client_UtilsTest
,
getEnclosedNames
)
{
using
namespace
cta
;
const
std
::
string
enclosing
Dir
Path
=
"/grandparent/parent/"
;
const
std
::
string
enclosingPath
=
"/grandparent/parent/"
;
const
std
::
string
enclosedName1
=
"child1"
;
const
std
::
string
enclosedName2
=
"child2"
;
const
std
::
string
enclosedName3
=
"child3"
;
const
std
::
string
enclosedName4
=
"child4"
;
std
::
list
<
std
::
string
>
absoluteFilePaths
;
absoluteFilePaths
.
push_back
(
enclosing
Dir
Path
+
enclosedName1
);
absoluteFilePaths
.
push_back
(
enclosing
Dir
Path
+
enclosedName2
);
absoluteFilePaths
.
push_back
(
enclosing
Dir
Path
+
enclosedName3
);
absoluteFilePaths
.
push_back
(
enclosing
Dir
Path
+
enclosedName4
);
absoluteFilePaths
.
push_back
(
enclosingPath
+
enclosedName1
);
absoluteFilePaths
.
push_back
(
enclosingPath
+
enclosedName2
);
absoluteFilePaths
.
push_back
(
enclosingPath
+
enclosedName3
);
absoluteFilePaths
.
push_back
(
enclosingPath
+
enclosedName4
);
std
::
list
<
std
::
string
>
results
;
ASSERT_NO_THROW
(
results
=
Utils
::
getEnclosedNames
(
absoluteFilePaths
));
ASSERT_EQ
(
4
,
results
.
size
());
...
...
middletier/SQLite/SqliteMiddleTierUser.cpp
View file @
20b5b67d
...
...
@@ -173,7 +173,9 @@ void cta::SqliteMiddleTierUser::archiveToFile(
}
const
std
::
string
&
srcFileName
=
srcUrls
.
front
();
std
::
string
storageClassName
=
m_ns
.
getDirStorageClass
(
requester
,
cta
::
Utils
::
getEnclosingDirPath
(
dstFile
));
const
std
::
string
enclosingPath
=
Utils
::
getEnclosingPath
(
dstFile
);
const
std
::
string
storageClassName
=
m_ns
.
getDirStorageClass
(
requester
,
enclosingPath
);
cta
::
StorageClass
storageClass
=
m_db
.
getStorageClassByName
(
requester
,
storageClassName
);
if
(
storageClass
.
getNbCopies
()
==
0
)
{
std
::
ostringstream
message
;
...
...
nameserver/MockNameServer.cpp
View file @
20b5b67d
...
...
@@ -221,7 +221,7 @@ void cta::MockNameServer::createFile(
const
std
::
string
&
path
,
const
uint16_t
mode
)
{
Utils
::
assertAbsolutePathSyntax
(
path
);
assertFsDirExists
(
m_fsDir
+
Utils
::
getEnclosing
Dir
Path
(
path
));
assertFsDirExists
(
m_fsDir
+
Utils
::
getEnclosingPath
(
path
));
const
std
::
string
fsPath
=
m_fsDir
+
path
;
assertFsPathDoesNotExist
(
fsPath
);
...
...
@@ -246,11 +246,11 @@ void cta::MockNameServer::createFile(
void
cta
::
MockNameServer
::
createDir
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
path
,
const
uint16_t
mode
)
{
Utils
::
assertAbsolutePathSyntax
(
path
);
const
std
::
string
enclosing
Dir
Path
=
Utils
::
getEnclosing
Dir
Path
(
path
);
assertFsDirExists
(
m_fsDir
+
enclosing
Dir
Path
);
const
std
::
string
enclosingPath
=
Utils
::
getEnclosingPath
(
path
);
assertFsDirExists
(
m_fsDir
+
enclosingPath
);
const
std
::
string
inheritedStorageClass
=
getDirStorageClass
(
requester
,
enclosing
Dir
Path
);
enclosingPath
);
const
std
::
string
fsPath
=
m_fsDir
+
path
;
if
(
mkdir
(
fsPath
.
c_str
(),
mode
))
{
...
...
@@ -308,7 +308,7 @@ cta::DirEntry cta::MockNameServer::statDirEntry(
const
std
::
string
&
path
)
const
{
Utils
::
assertAbsolutePathSyntax
(
path
);
const
std
::
string
name
=
Utils
::
getEnclosedName
(
path
);
const
std
::
string
enclosingPath
=
Utils
::
getEnclosing
Dir
Path
(
path
);
const
std
::
string
enclosingPath
=
Utils
::
getEnclosingPath
(
path
);
const
std
::
string
fsPath
=
m_fsDir
+
path
;
struct
stat
stat_result
;
...
...
nameserver/MockNameServerTest.cpp
View file @
20b5b67d
...
...
@@ -174,4 +174,4 @@ TEST_F(cta_MockNameServerTest, storageClass_inheritance) {
}
}
}
}
// namespace unitTests
scheduler/CMakeLists.txt
View file @
20b5b67d
...
...
@@ -58,7 +58,9 @@ add_library (ctaschedulertest SHARED
MockSchedulerDatabase.cpp
MockSchedulerDatabaseFactory.cpp
SchedulerDatabaseFactory.cpp
SchedulerTest.cpp
)
SchedulerDatabaseTest.cpp
SchedulerTest.cpp
UserIdentityTest.cpp
)
target_link_libraries
(
ctaschedulertest
ctascheduler
)
scheduler/MockSchedulerDatabase.cpp
View file @
20b5b67d
...
...
@@ -209,13 +209,13 @@ void cta::MockSchedulerDatabase::queue(const ArchiveToFileRequest &rqst,
// getArchivalJobs
//------------------------------------------------------------------------------
std
::
map
<
cta
::
TapePool
,
std
::
list
<
cta
::
ArchivalJob
>
>
cta
::
MockSchedulerDatabase
::
getArchivalJobs
(
const
SecurityIdentity
&
requester
)
cta
::
MockSchedulerDatabase
::
getArchivalJobs
()
const
{
std
::
ostringstream
query
;
std
::
map
<
cta
::
TapePool
,
std
::
list
<
cta
::
ArchivalJob
>
>
map
;
query
<<
"SELECT STATE, REMOTEFILE, ARCHIVEFILE, TAPEPOOL_NAME, UID, GID,"
" CREATIONTIME FROM ARCHIVALJOB ORDER BY ARCHIVEFILE;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -227,7 +227,7 @@ std::map<cta::TapePool, std::list<cta::ArchivalJob> >
SqliteColumnNameToIndex
idx
(
statement
);
const
std
::
string
tapePoolName
=
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"TAPEPOOL_NAME"
));
const
TapePool
tapePool
=
getTapePool
ByName
(
requester
,
tapePoolName
);
const
TapePool
tapePool
=
getTapePool
(
tapePoolName
);
map
[
tapePool
].
push_back
(
ArchivalJob
(
(
ArchivalJobState
::
Enum
)
sqlite3_column_int
(
statement
,
idx
(
"STATE"
)),
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"REMOTEFILE"
)),
...
...
@@ -242,15 +242,15 @@ std::map<cta::TapePool, std::list<cta::ArchivalJob> >
}
//------------------------------------------------------------------------------
// getTapePool
ByName
// getTapePool
//------------------------------------------------------------------------------
cta
::
TapePool
cta
::
MockSchedulerDatabase
::
getTapePool
ByN
ame
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
name
)
const
{
cta
::
TapePool
cta
::
MockSchedulerDatabase
::
getTapePool
(
const
std
::
string
&
n
ame
)
const
{
std
::
ostringstream
query
;
cta
::
TapePool
pool
;
query
<<
"SELECT NAME, NBPARTIALTAPES, UID, GID, CREATIONTIME, COMMENT"
" FROM TAPEPOOL WHERE NAME='"
<<
name
<<
"';"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -296,7 +296,6 @@ cta::TapePool cta::MockSchedulerDatabase::getTapePoolByName(
// getArchivalJobs
//------------------------------------------------------------------------------
std
::
list
<
cta
::
ArchivalJob
>
cta
::
MockSchedulerDatabase
::
getArchivalJobs
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
tapePoolName
)
const
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" not implemented"
);
}
...
...
@@ -359,12 +358,12 @@ void cta::MockSchedulerDatabase::queue(const RetrieveToFileRequest &rqst,
// getRetrievalJobs
//------------------------------------------------------------------------------
std
::
map
<
cta
::
Tape
,
std
::
list
<
cta
::
RetrievalJob
>
>
cta
::
MockSchedulerDatabase
::
getRetrievalJobs
(
const
SecurityIdentity
&
requester
)
const
{
getRetrievalJobs
()
const
{
std
::
ostringstream
query
;
std
::
map
<
cta
::
Tape
,
std
::
list
<
cta
::
RetrievalJob
>
>
map
;
query
<<
"SELECT STATE, ARCHIVEFILE, REMOTEFILE, VID, UID, GID, CREATIONTIME"
" FROM RETRIEVALJOB ORDER BY REMOTEFILE;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -375,7 +374,7 @@ std::map<cta::Tape, std::list<cta::RetrievalJob> > cta::MockSchedulerDatabase::
while
(
SQLITE_ROW
==
sqlite3_step
(
statement
))
{
SqliteColumnNameToIndex
idx
(
statement
);
const
std
::
string
vid
=
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"VID"
));
const
Tape
tape
=
getTape
ByVid
(
requester
,
vid
);
const
Tape
tape
=
getTape
(
vid
);
map
[
tape
].
push_back
(
RetrievalJob
(
(
RetrievalJobState
::
Enum
)
sqlite3_column_int
(
statement
,
idx
(
"STATE"
)),
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"ARCHIVEFILE"
)),
...
...
@@ -390,16 +389,15 @@ std::map<cta::Tape, std::list<cta::RetrievalJob> > cta::MockSchedulerDatabase::
}
//------------------------------------------------------------------------------
// getTape
ByVid
// getTape
//------------------------------------------------------------------------------
cta
::
Tape
cta
::
MockSchedulerDatabase
::
getTapeByVid
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
vid
)
const
{
cta
::
Tape
cta
::
MockSchedulerDatabase
::
getTape
(
const
std
::
string
&
vid
)
const
{
std
::
ostringstream
query
;
cta
::
Tape
tape
;
query
<<
"SELECT VID, LOGICALLIBRARY_NAME, TAPEPOOL_NAME, CAPACITY_BYTES,"
" DATAONTAPE_BYTES, UID, GID, CREATIONTIME, COMMENT FROM TAPE WHERE VID='"
<<
vid
<<
"';"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -448,7 +446,6 @@ cta::Tape cta::MockSchedulerDatabase::getTapeByVid(
// getRetrievalJobs
//------------------------------------------------------------------------------
std
::
list
<
cta
::
RetrievalJob
>
cta
::
MockSchedulerDatabase
::
getRetrievalJobs
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
vid
)
const
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" not implemented"
);
}
...
...
@@ -539,13 +536,12 @@ void cta::MockSchedulerDatabase::deleteAdminUser(
//------------------------------------------------------------------------------
// getAdminUsers
//------------------------------------------------------------------------------
std
::
list
<
cta
::
AdminUser
>
cta
::
MockSchedulerDatabase
::
getAdminUsers
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
AdminUser
>
cta
::
MockSchedulerDatabase
::
getAdminUsers
()
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
AdminUser
>
list
;
query
<<
"SELECT ADMIN_UID, ADMIN_GID, UID, GID, CREATIONTIME, COMMENT"
" FROM ADMINUSER ORDER BY ADMIN_UID, ADMIN_GID;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -589,7 +585,7 @@ void cta::MockSchedulerDatabase::assertIsAdmin(const UserIdentity &user)
std
::
ostringstream
query
;
query
<<
"SELECT COUNT(*) FROM ADMINUSER WHERE ADMIN_UID="
<<
adminUid
<<
" AND ADMIN_GID="
<<
adminGid
<<
";"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -618,7 +614,7 @@ void cta::MockSchedulerDatabase::assertIsAdminHost(const std::string &host)
const
{
std
::
ostringstream
query
;
query
<<
"SELECT COUNT(*) FROM ADMINHOST WHERE NAME='"
<<
host
<<
"';"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -696,13 +692,12 @@ void cta::MockSchedulerDatabase::deleteAdminHost(
//------------------------------------------------------------------------------
// getAdminHosts
//------------------------------------------------------------------------------
std
::
list
<
cta
::
AdminHost
>
cta
::
MockSchedulerDatabase
::
getAdminHosts
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
AdminHost
>
cta
::
MockSchedulerDatabase
::
getAdminHosts
()
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
AdminHost
>
list
;
query
<<
"SELECT NAME, UID, GID, CREATIONTIME, COMMENT"
" FROM ADMINHOST ORDER BY NAME;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -774,13 +769,13 @@ void cta::MockSchedulerDatabase::deleteStorageClass(
//------------------------------------------------------------------------------
// getStorageClasses
//------------------------------------------------------------------------------
std
::
list
<
cta
::
StorageClass
>
cta
::
MockSchedulerDatabase
::
getStorageClasses
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
StorageClass
>
cta
::
MockSchedulerDatabase
::
getStorageClasses
(
)
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
StorageClass
>
classes
;
query
<<
"SELECT NAME, NBCOPIES, UID, GID, CREATIONTIME, COMMENT FROM"
" STORAGECLASS ORDER BY NAME;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -803,6 +798,58 @@ std::list<cta::StorageClass> cta::MockSchedulerDatabase::getStorageClasses(
return
classes
;
}
//------------------------------------------------------------------------------
// getStorageClass
//------------------------------------------------------------------------------
cta
::
StorageClass
cta
::
MockSchedulerDatabase
::
getStorageClass
(
const
std
::
string
&
name
)
const
{
std
::
ostringstream
query
;
query
<<
"SELECT NAME, NBCOPIES, UID, GID, CREATIONTIME, COMMENT"
" FROM STORAGECLASS WHERE NAME='"
<<
name
<<
"';"
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
message
<<
__FUNCTION__
<<
" - SQLite error"
;
sqlite3_finalize
(
statement
);
throw
(
exception
::
Exception
(
message
.
str
()));
}
StorageClass
storageClass
;
switch
(
sqlite3_step
(
statement
))
{
case
SQLITE_ROW
:
{
SqliteColumnNameToIndex
idx
(
statement
);
storageClass
=
cta
::
StorageClass
(
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"NAME"
)),
sqlite3_column_int
(
statement
,
idx
(
"NBCOPIES"
)),
UserIdentity
(
sqlite3_column_int
(
statement
,
idx
(
"UID"
)),
sqlite3_column_int
(
statement
,
idx
(
"GID"
))),
(
char
*
)
sqlite3_column_text
(
statement
,
idx
(
"COMMENT"
)),
time_t
(
sqlite3_column_int
(
statement
,
idx
(
"CREATIONTIME"
)))
);
}
break
;
case
SQLITE_DONE
:
{
std
::
ostringstream
message
;
message
<<
__FUNCTION__
<<
" - No storage class found with name "
<<
name
;
sqlite3_finalize
(
statement
);
throw
(
exception
::
Exception
(
message
.
str
()));
}
break
;
default:
{
std
::
ostringstream
message
;
message
<<
__FUNCTION__
<<
" - SQLite error"
;
sqlite3_finalize
(
statement
);
throw
(
exception
::
Exception
(
message
.
str
()));
}
}
sqlite3_finalize
(
statement
);
return
storageClass
;
}
//------------------------------------------------------------------------------
// createTapePool
//------------------------------------------------------------------------------
...
...
@@ -854,14 +901,12 @@ void cta::MockSchedulerDatabase::deleteTapePool(
//------------------------------------------------------------------------------
// getTapePools
//------------------------------------------------------------------------------
std
::
list
<
cta
::
TapePool
>
cta
::
MockSchedulerDatabase
::
getTapePools
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
TapePool
>
cta
::
MockSchedulerDatabase
::
getTapePools
()
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
TapePool
>
pools
;
query
<<
"SELECT NAME, NBPARTIALTAPES, UID, GID, CREATIONTIME, COMMENT FROM"
" TAPEPOOL ORDER BY NAME;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -940,14 +985,14 @@ void cta::MockSchedulerDatabase::deleteArchivalRoute(
//------------------------------------------------------------------------------
// getArchivalRoutes
//------------------------------------------------------------------------------
std
::
list
<
cta
::
ArchivalRoute
>
cta
::
MockSchedulerDatabase
::
getArchivalRoutes
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
ArchivalRoute
>
cta
::
MockSchedulerDatabase
::
getArchivalRoutes
(
)
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
ArchivalRoute
>
routes
;
query
<<
"SELECT STORAGECLASS_NAME, COPYNB, TAPEPOOL_NAME, UID, GID,"
" CREATIONTIME, COMMENT FROM ARCHIVALROUTE ORDER BY STORAGECLASS_NAME,"
" COPYNB;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
int
rc
=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
);
if
(
rc
!=
SQLITE_OK
){
std
::
ostringstream
message
;
...
...
@@ -971,6 +1016,14 @@ std::list<cta::ArchivalRoute> cta::MockSchedulerDatabase::getArchivalRoutes(
return
routes
;
}
//------------------------------------------------------------------------------
// getArchivalRoutes
//------------------------------------------------------------------------------
std
::
list
<
cta
::
ArchivalRoute
>
cta
::
MockSchedulerDatabase
::
getArchivalRoutes
(
const
std
::
string
&
storageClassName
)
const
{
return
std
::
list
<
cta
::
ArchivalRoute
>
();
}
//------------------------------------------------------------------------------
// createLogicalLibrary
//------------------------------------------------------------------------------
...
...
@@ -1021,13 +1074,13 @@ void cta::MockSchedulerDatabase::deleteLogicalLibrary(
//------------------------------------------------------------------------------
// getLogicalLibraries
//------------------------------------------------------------------------------
std
::
list
<
cta
::
LogicalLibrary
>
cta
::
MockSchedulerDatabase
::
getLogicalLibraries
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
LogicalLibrary
>
cta
::
MockSchedulerDatabase
::
getLogicalLibraries
(
)
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
LogicalLibrary
>
list
;
query
<<
"SELECT NAME, UID, GID, CREATIONTIME, COMMENT"
" FROM LOGICALLIBRARY ORDER BY NAME;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
@@ -1104,14 +1157,13 @@ void cta::MockSchedulerDatabase::deleteTape(
//------------------------------------------------------------------------------
// getTapes
//------------------------------------------------------------------------------
std
::
list
<
cta
::
Tape
>
cta
::
MockSchedulerDatabase
::
getTapes
(
const
SecurityIdentity
&
requester
)
const
{
std
::
list
<
cta
::
Tape
>
cta
::
MockSchedulerDatabase
::
getTapes
()
const
{
std
::
ostringstream
query
;
std
::
list
<
cta
::
Tape
>
tapes
;
query
<<
"SELECT VID, LOGICALLIBRARY_NAME, TAPEPOOL_NAME, CAPACITY_BYTES,"
" DATAONTAPE_BYTES, UID, GID, CREATIONTIME, COMMENT"
" FROM TAPE ORDER BY VID;"
;
sqlite3_stmt
*
statement
;
sqlite3_stmt
*
statement
=
NULL
;
if
(
SQLITE_OK
!=
sqlite3_prepare
(
m_dbHandle
,
query
.
str
().
c_str
(),
-
1
,
&
statement
,
0
))
{
std
::
ostringstream
message
;
...
...
scheduler/MockSchedulerDatabase.hpp
View file @
20b5b67d
...
...
@@ -62,25 +62,20 @@ public:
* Returns all of the existing archival jobs grouped by tape pool and then
* sorted by creation time in ascending order (oldest first).
*
* @param requester The identity of the requester.
* @return All of the existing archival jobs grouped by tape pool and then
* sorted by creation time in ascending order (oldest first).
*/
std
::
map
<
TapePool
,
std
::
list
<
ArchivalJob
>
>
getArchivalJobs
(
const
SecurityIdentity
&
requester
)
const
;
std
::
map
<
TapePool
,
std
::
list
<
ArchivalJob
>
>
getArchivalJobs
()
const
;
/**
* Returns the list of archival jobs associated with the specified tape pool
* sorted by creation time in ascending order (oldest first).
*
* @param requester The identity of the requester.
* @param tapePoolName The name of the tape pool.
* @return The list of archival jobs associated with the specified tape pool
* sorted by creation time in ascending order (oldest first).
*/
std
::
list
<
ArchivalJob
>
getArchivalJobs
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
tapePoolName
)
const
;
std
::
list
<
ArchivalJob
>
getArchivalJobs
(
const
std
::
string
&
tapePoolName
)
const
;
/**
* Deletes the specified archival job.
...
...
@@ -115,25 +110,20 @@ public:
* Returns all of the existing retrieval jobs grouped by tape and then
* sorted by creation time in ascending order (oldest first).
*
* @param requester The identity of the requester.
* @return All of the existing retrieval jobs grouped by tape and then
* sorted by creation time in ascending order (oldest first).
*/
std
::
map
<
Tape
,
std
::
list
<
RetrievalJob
>
>
getRetrievalJobs
(
const
SecurityIdentity
&
requester
)
const
;
std
::
map
<
Tape
,
std
::
list
<
RetrievalJob
>
>
getRetrievalJobs
()
const
;
/**
* Returns the list of retrieval jobs associated with the specified tape
* sorted by creation time in ascending order (oldest first).
*
* @param requester The identity of the requester.
* @param vid The volume identifier of the tape.
* @return The list of retrieval jobs associated with the specified tape
* sorted by creation time in ascending order (oldest first).
*/
std
::
list
<
RetrievalJob
>
getRetrievalJobs
(
const
SecurityIdentity
&
requester
,
const
std
::
string
&
vid
)
const
;
std
::
list
<
RetrievalJob
>
getRetrievalJobs
(
const
std
::
string
&
vid
)
const
;
/**
* Deletes the specified retrieval job.
...
...
@@ -170,11 +160,9 @@ public:
/**
* Returns the current list of administrators in lexicographical order.
*
* @param requester The identity of the requester.
* @return The current list of administrators in lexicographical order.
*/
std
::
list
<
AdminUser
>
getAdminUsers
(
const
SecurityIdentity
&
requester
)
const
;
std
::
list
<
AdminUser
>
getAdminUsers
()
const
;
/**
* Throws an exception if the specified user is not an administrator or if the
...
...
@@ -209,11 +197,9 @@ public:
/**
* Returns the current list of administration hosts in lexicographical order.
*
* @param requester The identity of the requester.
* @return The current list of administration hosts in lexicographical order.
*/
std
::
list
<
AdminHost
>
getAdminHosts
(
const
SecurityIdentity
&
requester
)
const
;
std
::
list
<
AdminHost
>
getAdminHosts
()
const
;
/**
* Creates the specified storage class.
...
...
@@ -241,13 +227,19 @@ public:
const
std
::
string
&
name
);
/**
*
G
ets the current list of storage classes in lexicographical order.
*
R
et
urn
s the current list of storage classes in lexicographical order.
*
* @param requester The identity of the requester.
* @return The current list of storage classes in lexicographical order.
*/
std
::
list
<
StorageClass
>
getStorageClasses
(
const
SecurityIdentity
&
requester
)
const
;
std
::
list
<
StorageClass
>
getStorageClasses
()
const
;
/**
* Returns the storage class with the specified name.
*
* @param name The name of the storage class.
* @return The storage class with the specified name.
*/
StorageClass
getStorageClass
(
const
std
::
string
&
name
)
const
;