Commit 91f0beed authored by Eric Cano's avatar Eric Cano
Browse files

Moved parts from scheduler directory out into common, in a move to reduce this too long directory.

Also organised common in subdirectories, and added sub directory for mockDB.
parent af157d49
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
#include <string>
#include <time.h>
......
......@@ -24,9 +24,9 @@
#include "objectstore/ArchiveToFileRequest.hpp"
#include "objectstore/RetrieveToFileRequest.hpp"
#include "common/exception/Exception.hpp"
#include "scheduler/AdminHost.hpp"
#include "scheduler/AdminUser.hpp"
#include "scheduler/ArchiveRoute.hpp"
#include "common/admin/AdminHost.hpp"
#include "common/admin/AdminUser.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
#include "scheduler/ArchiveRequest.hpp"
#include "scheduler/ArchiveToFileRequest.hpp"
#include "scheduler/LogicalLibrary.hpp"
......@@ -68,14 +68,12 @@ std::unique_ptr<SchedulerDatabase::TapeMount>
}
void OStoreDB::createAdminHost(const SecurityIdentity& requester,
const std::string& hostName, const std::string& comment) {
void OStoreDB::createAdminHost(const std::string& hostName,
const cta::CreationLog & creationLog) {
RootEntry re(m_objectStore);
objectstore::CreationLog cl(requester.getUser(), requester.getHost(),
time(NULL), comment);
ScopedExclusiveLock rel(re);
re.fetch();
re.addAdminHost(hostName, cl);
re.addAdminHost(hostName, creationLog);
re.commit();
}
......@@ -88,8 +86,7 @@ std::list<AdminHost> OStoreDB::getAdminHosts() const {
rel.release();
for (auto h=hl.begin(); h!=hl.end(); h++) {
ret.push_back(AdminHost(h->hostname,
cta::UserIdentity(h->log.user.uid, h->log.user.gid),
h->log.comment, h->log.time));
h->log));
}
return ret;
}
......@@ -134,9 +131,7 @@ std::list<AdminUser> OStoreDB::getAdminUsers() const {
ret.push_back(
AdminUser(
cta::UserIdentity(au->user.uid, au->user.gid),
cta::UserIdentity(au->log.user.uid, au->log.user.gid),
au->log.comment,
au->log.time
au->log
));
}
rel.release();
......
......@@ -47,8 +47,8 @@ public:
const std::string &driveName);
/* === Admin host handling ================================================ */
virtual void createAdminHost(const SecurityIdentity& requester,
const std::string& hostName, const std::string& comment);
virtual void createAdminHost(const std::string& hostName,
const CreationLog& creationLog);
virtual std::list<AdminHost> getAdminHosts() const;
......
......@@ -78,8 +78,8 @@ public:
m_OStoreDB.assertIsAdminOnAdminHost(id);
}
virtual void createAdminHost(const SecurityIdentity& requester, const std::string& hostName, const std::string& comment) {
m_OStoreDB.createAdminHost(requester, hostName, comment);
virtual void createAdminHost(const std::string& hostName, const cta::CreationLog& creationLog) {
m_OStoreDB.createAdminHost(hostName, creationLog);
}
virtual void createAdminUser(const SecurityIdentity& requester, const UserIdentity& user, const std::string& comment) {
......
/*
* 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 <memory>
namespace cta {
class RetrieveMount;
/**
* The class driving a retrieve mount.
* The class only has private constructors as it is instanciated by
* the Scheduler class.
*/
class RetrieveMount {
private:
public:
/**
* Notifies the scheduler that the session is finished
*/
virtual void finish();
/**
* Generator
*/
std::unique_ptr<RetrieveMount> getNextJob();
virtual ~RetrieveMount();
private:
};
}
\ No newline at end of file
......@@ -17,15 +17,15 @@
*/
#include "common/exception/Exception.hpp"
#include "common/RemotePathAndStatus.hpp"
#include "common/remoteFS/RemotePathAndStatus.hpp"
#include "common/UserIdentity.hpp"
#include "common/Utils.hpp"
#include "nameserver/NameServer.hpp"
#include "remotens/RemoteNS.hpp"
#include "scheduler/AdminHost.hpp"
#include "scheduler/AdminUser.hpp"
#include "common/admin/AdminHost.hpp"
#include "common/admin/AdminUser.hpp"
#include "scheduler/ArchiveMount.hpp"
#include "scheduler/ArchiveRoute.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
#include "scheduler/ArchiveToDirRequest.hpp"
#include "scheduler/ArchiveToFileRequest.hpp"
#include "scheduler/ArchiveToTapeCopyRequest.hpp"
......@@ -183,7 +183,9 @@ void cta::Scheduler::createAdminHost(
const std::string &hostName,
const std::string &comment) {
m_db.assertIsAdminOnAdminHost(requester);
m_db.createAdminHost(requester, hostName, comment);
CreationLog log(requester.getUser(), requester.getHost(), time(NULL),
comment);
m_db.createAdminHost(hostName, log);
}
//------------------------------------------------------------------------------
......@@ -193,7 +195,8 @@ void cta::Scheduler::createAdminHostWithoutAuthorizingRequester(
const SecurityIdentity &requester,
const std::string &hostName,
const std::string &comment) {
m_db.createAdminHost(requester, hostName, comment);
CreationLog log (requester.getUser(), requester.getHost(), time(NULL), comment);
m_db.createAdminHost(hostName, log);
}
//------------------------------------------------------------------------------
......
......@@ -23,8 +23,8 @@
#include <stdint.h>
#include <string>
#include <memory>
#include "common/ArchiveFileStatus.hpp"
#include "common/RemotePathAndStatus.hpp"
#include "common/archiveNS/ArchiveFileStatus.hpp"
#include "common/remoteFS/RemotePathAndStatus.hpp"
namespace cta {
......@@ -281,14 +281,12 @@ public:
/**
* Creates the specified administration host.
*
* @param requester The identity of the requester.
* @param hostName The network name of the administration host.
* @param comment The comment describing the administration host.
*/
virtual void createAdminHost(
const SecurityIdentity &requester,
const std::string &hostName,
const std::string &comment) = 0;
const CreationLog &creationLog) = 0;
/**
* Deletes the specified administration host.
......
......@@ -17,11 +17,11 @@
*/
#include "common/UserIdentity.hpp"
#include "scheduler/AdminHost.hpp"
#include "scheduler/AdminUser.hpp"
#include "scheduler/ArchiveRoute.hpp"
#include "scheduler/MockDB/MockSchedulerDatabase.hpp"
#include "scheduler/MockDB/MockSchedulerDatabaseFactory.hpp"
#include "common/admin/AdminHost.hpp"
#include "common/admin/AdminUser.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include "scheduler/mockDB/MockSchedulerDatabaseFactory.hpp"
#include "scheduler/SchedulerDatabase.hpp"
#include "scheduler/SchedulerDatabaseFactory.hpp"
#include "scheduler/SecurityIdentity.hpp"
......@@ -145,8 +145,8 @@ TEST_P(SchedulerDatabaseTest, create_new_admin) {
ASSERT_EQ((std::list<AdminUser>::size_type)1, adminUsers.size());
const AdminUser &adminUser = adminUsers.front();
ASSERT_EQ(s_system, adminUser.getCreator());
ASSERT_EQ(comment, adminUser.getComment());
ASSERT_EQ(s_system, adminUser.getCreationLog().user);
ASSERT_EQ(comment, adminUser.getCreationLog().comment);
ASSERT_EQ(s_admin, adminUser.getUser());
}
}
......@@ -164,16 +164,18 @@ TEST_P(SchedulerDatabaseTest, create_new_admin_host) {
const std::string comment =
"The initial administration host created by the system";
db.createAdminHost(s_systemOnSystemHost, s_adminHost, comment);
cta::CreationLog log(s_systemOnSystemHost.getUser(), s_systemOnSystemHost.getHost(),
time(NULL), comment);
db.createAdminHost(s_adminHost, log);
{
std::list<AdminHost> adminHosts;
ASSERT_NO_THROW(adminHosts = db.getAdminHosts());
/*ASSERT_NO_THROW*/(adminHosts = db.getAdminHosts());
ASSERT_EQ((std::list<AdminHost>::size_type)1, adminHosts.size());
const AdminHost &adminHost = adminHosts.front();
ASSERT_EQ(s_system, adminHost.getCreator());
ASSERT_EQ(comment, adminHost.getComment());
ASSERT_EQ(s_system, adminHost.creationLog.user);
ASSERT_EQ(comment, adminHost.creationLog.comment);
ASSERT_EQ(s_adminHost, adminHost.name);
}
}
......@@ -204,7 +206,9 @@ TEST_P(SchedulerDatabaseTest, create_assert_admin_on_admin_host) {
const std::string hostComment =
"The initial administration host created by the system";
db.createAdminHost(s_systemOnSystemHost, s_adminHost, hostComment);
cta::CreationLog log(s_systemOnSystemHost.getUser(), s_systemOnSystemHost.getHost(),
time(NULL), hostComment);
db.createAdminHost(s_adminHost, log);
ASSERT_NO_THROW(db.assertIsAdminOnAdminHost(s_adminOnAdminHost));
......@@ -214,8 +218,8 @@ TEST_P(SchedulerDatabaseTest, create_assert_admin_on_admin_host) {
ASSERT_EQ((std::list<AdminUser>::size_type)1, adminUsers.size());
const AdminUser &adminUser = adminUsers.front();
ASSERT_EQ(s_system, adminUser.getCreator());
ASSERT_EQ(userComment, adminUser.getComment());
ASSERT_EQ(s_system, adminUser.getCreationLog().user);
ASSERT_EQ(userComment, adminUser.getCreationLog().comment);
ASSERT_EQ(s_admin, adminUser.getUser());
}
......@@ -225,8 +229,8 @@ TEST_P(SchedulerDatabaseTest, create_assert_admin_on_admin_host) {
ASSERT_EQ((std::list<AdminHost>::size_type)1, adminHosts.size());
const AdminHost &adminHost = adminHosts.front();
ASSERT_EQ(s_system, adminHost.getCreator());
ASSERT_EQ(hostComment, adminHost.getComment());
ASSERT_EQ(s_system, adminHost.creationLog.user);
ASSERT_EQ(hostComment, adminHost.creationLog.comment);
ASSERT_EQ(s_adminHost, adminHost.name);
}
}
......
......@@ -16,16 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nameserver/MockNameServerFactory.hpp"
#include "nameserver/mockNS/MockNameServerFactory.hpp"
#include "nameserver/NameServer.hpp"
#include "remotens/MockRemoteNS.hpp"
#include "scheduler/AdminUser.hpp"
#include "scheduler/AdminHost.hpp"
#include "scheduler/ArchiveRoute.hpp"
#include "common/admin/AdminUser.hpp"
#include "common/admin/AdminHost.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
#include "scheduler/ArchiveToFileRequest.hpp"
#include "scheduler/ArchiveToTapeCopyRequest.hpp"
#include "scheduler/LogicalLibrary.hpp"
#include "scheduler/MockDB/MockSchedulerDatabaseFactory.hpp"
#include "scheduler/mockDB/MockSchedulerDatabaseFactory.hpp"
#include "scheduler/MountRequest.hpp"
#include "scheduler/Scheduler.hpp"
#include "scheduler/SchedulerDatabase.hpp"
......@@ -100,8 +100,9 @@ public:
SchedulerDatabase &db = *m_db.get();
db.createAdminUser(s_systemOnSystemHost, s_admin,
"The initial administrator created by the system");
db.createAdminHost(s_systemOnSystemHost, s_adminHost,
"The initial administration host created by the system");
cta::CreationLog log(s_systemOnSystemHost.getUser(), s_systemOnSystemHost.getHost(),
time(NULL), "The initial administration host created by the system");
db.createAdminHost(s_adminHost, log);
}
virtual void TearDown() {
......
......@@ -17,7 +17,7 @@
*/
#include "scheduler/StorageClass.hpp"
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
//------------------------------------------------------------------------------
// constructor
......
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
#include <stdint.h>
#include <string>
......
......@@ -19,7 +19,7 @@
#pragma once
#include "common/UserIdentity.hpp"
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
#include <stdint.h>
#include <string>
......
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
#include <string>
......
......@@ -39,15 +39,13 @@ cta::UserGroup::UserGroup(
const DriveQuota &retrieveDriveQuota,
const MountCriteria &archiveMountCriteria,
const MountCriteria &retrieveMountCriteria,
const UserIdentity &creator,
const std::string &comment,
const time_t creationTime):
ConfigurationItem(creator, comment, creationTime),
const CreationLog &creationLog):
m_name(name),
m_archiveDriveQuota(archiveDriveQuota),
m_retrieveDriveQuota(retrieveDriveQuota),
m_archiveMountCriteria(archiveMountCriteria),
m_retrieveMountCriteria(retrieveMountCriteria) {
m_retrieveMountCriteria(retrieveMountCriteria),
m_creationLog(creationLog){
}
//------------------------------------------------------------------------------
......
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/ConfigurationItem.hpp"
#include "common/CreationLog.hpp"
#include "scheduler/DriveQuota.hpp"
#include "scheduler/MountCriteria.hpp"
......@@ -31,7 +31,7 @@ namespace cta {
/**
* Class representing a user group.
*/
class UserGroup: public ConfigurationItem {
class UserGroup {
public:
/**
......@@ -69,9 +69,7 @@ public:
const DriveQuota &retrieveDriveQuota,
const MountCriteria &archiveMountCriteria,
const MountCriteria &retrieveMountCriteria,
const UserIdentity &creator,
const std::string &comment,
const time_t creationTime = time(NULL));
const CreationLog & creationLog);
/**
* Returns the name of the user group.
......@@ -140,7 +138,12 @@ private:
* tape for file retrieve.
*/
MountCriteria m_retrieveMountCriteria;
/**
* The when, who, why of the group's creation
*/
CreationLog m_creationLog;
}; // class UserGroup
} // namespace cta
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/CreationLog.hpp"
#include "common/CreationLog.hpp"
#include <stdint.h>
#include <string>
......
......@@ -35,11 +35,8 @@ cta::VO::~VO() throw() {
//------------------------------------------------------------------------------
cta::VO::VO(
const std::string &name,
const UserIdentity &creator,
const std::string &comment,
const time_t creationTime):
ConfigurationItem(creator, comment, creationTime),
m_name(name) {
const CreationLog & creationLog):
m_name(name), m_creationLog(creationLog) {
}
//------------------------------------------------------------------------------
......
......@@ -18,7 +18,7 @@
#pragma once
#include "scheduler/ConfigurationItem.hpp"
#include "common/CreationLog.hpp"
#include <string>
......@@ -27,7 +27,7 @@ namespace cta {
/**
* Class representing a virtual organisation.
*/
class VO: public ConfigurationItem {
class VO {
public:
/**
......@@ -53,9 +53,7 @@ public:
*/
VO(
const std::string &name,
const UserIdentity &creator,
const std::string &comment,
const time_t creationTime = time(NULL));
const CreationLog &creationLog);
/**
* Returns the name of the tape pool.
......@@ -70,6 +68,11 @@ private:
* The name of the tape pool.
*/
std::string m_name;
/**
* The who, why, when, where of the creation of the VO
*/
CreationLog m_creationLog;
}; // class VO
......
......@@ -16,23 +16,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/ArchiveDirIterator.hpp"
#include "common/archiveNS/ArchiveDirIterator.hpp"
#include "common/exception/Exception.hpp"
#include "common/UserIdentity.hpp"
#include "nameserver/NameServer.hpp"
#include "scheduler/AdminHost.hpp"
#include "scheduler/AdminUser.hpp"
#include "common/admin/AdminHost.hpp"
#include "common/admin/AdminUser.hpp"
#include "scheduler/ArchiveToDirRequest.hpp"
#include "scheduler/ArchiveToFileRequest.hpp"
#include "scheduler/ArchiveToTapeCopyRequest.hpp"
#include "scheduler/ArchiveRoute.hpp"
#include "common/archiveRoutes/ArchiveRoute.hpp"
#include "scheduler/LogicalLibrary.hpp"
#include "scheduler/MockDB/MockSchedulerDatabase.hpp"
#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include "scheduler/RetrieveFromTapeCopyRequest.hpp"
#include "scheduler/RetrieveToFileRequest.hpp"
#include "scheduler/SecurityIdentity.hpp"
#include "scheduler/SqliteColumnNameToIndex.hpp"
#include "scheduler/SQLiteStatementDeleter.hpp"
#include "scheduler/mockDB/SqliteColumnNameToIndex.hpp"
#include "scheduler/mockDB/SQLiteStatementDeleter.hpp"
#include "scheduler/StorageClass.hpp"
#include "scheduler/Tape.hpp"
#include "scheduler/TapePool.hpp"
......@@ -803,7 +803,7 @@ void cta::MockSchedulerDatabase::deleteAdminUser(
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"
query << "SELECT ADMIN_UID, ADMIN_GID, UID, GID, HOST, CREATIONTIME, COMMENT"
" FROM ADMINUSER ORDER BY ADMIN_UID, ADMIN_GID;";
sqlite3_stmt *s = NULL;
const int rc = sqlite3_prepare(m_dbHandle, query.str().c_str(), -1, &s, 0 );
......@@ -819,11 +819,13 @@ std::list<cta::AdminUser> cta::MockSchedulerDatabase::getAdminUsers() const {
sqlite3_column_int(statement.get(),idx("ADMIN_GID")));
const UserIdentity requester(sqlite3_column_int(statement.get(),idx("UID")),
sqlite3_column_int(statement.get(),idx("GID")));
CreationLog log(requester,
(char *)sqlite3_column_text(statement.get(),idx("COMMENT")),
time_t(sqlite3_column_int(statement.get(),idx("CREATIONTIME"))),
(char *)sqlite3_column_text(statement.get(),idx("COMMENT")));
list.push_back(AdminUser(
user,
requester,
(char *)sqlite3_column_text(statement.get(),idx("COMMENT")),
time_t(sqlite3_column_int(statement.get(),idx("CREATIONTIME")))
log
));
}
return list;
......@@ -900,14 +902,13 @@ void cta::MockSchedulerDatabase::assertIsAdminHost(const std::string &host)
// createAdminHost
//------------------------------------------------------------------------------
void cta::MockSchedulerDatabase::createAdminHost(
const SecurityIdentity &requester,
const std::string &hostName,
const std::string &comment) {
const CreationLog & log) {
char *zErrMsg = 0;
std::ostringstream query;
query << "INSERT INTO ADMINHOST(NAME, UID, GID, CREATIONTIME, COMMENT)"
" VALUES('" << hostName << "',"<< requester.getUser().uid << "," <<
requester.getUser().gid << "," << (int)time(NULL) << ",'" << comment <<
query << "INSERT INTO ADMINHOST(NAME, UID, GID, HOST, CREATIONTIME, COMMENT)"
" VALUES('" << hostName << "',"<< log.user.uid << "," <<
log.user.gid << ", '" << log.host << "', " << log.time << ",'" << log.comment <<
"');";
if(SQLITE_OK != sqlite3_exec(m_dbHandle, query.str().c_str(), 0, 0,
&zErrMsg)) {
......@@ -956,7 +957,7 @@ void cta::MockSchedulerDatabase::deleteAdminHost(
std::list<cta::AdminHost> cta::MockSchedulerDatabase::getAdminHosts() const {
std::ostringstream query;
std::list<cta::AdminHost> list;
query << "SELECT NAME, UID, GID, CREATIONTIME, COMMENT"
query << "SELECT NAME, UID, GID, HOST, CREATIONTIME, COMMENT"
" FROM ADMINHOST ORDER BY NAME;";
sqlite3_stmt *s = NULL;
const int rc = sqlite3_prepare(m_dbHandle, query.str().c_str(), -1, &s, 0 );
......@@ -970,12 +971,13 @@ std::list<cta::AdminHost> cta::MockSchedulerDatabase::getAdminHosts() const {
SqliteColumnNameToIndex idx(statement.get());
const UserIdentity requester(sqlite3_column_int(statement.get(),idx("UID")),
sqlite3_column_int(statement.get(),idx("GID")));
const CreationLog log(requester,
(char *)sqlite3_column_text(statement.get(),idx("HOST")),
time_t(sqlite3_column_int(statement.get(),idx("CREATIONTIME"))),
(char *)sqlite3_column_text(statement.get(),idx("COMMENT")));
list.push_back(AdminHost(
(char *)sqlite3_column_text(statement.get(),idx("NAME")),
requester,
(char *)sqlite3_column_text(statement.get(),idx("COMMENT")),
time_t(sqlite3_column_int(statement.get(),idx("CREATIONTIME")))
));
log));
}
return list;
}
......
......@@ -250,9 +250,8 @@ public:
* @param comment The comment describing the administration host.
*/
void createAdminHost(
const SecurityIdentity &requester,
const std::string &hostName,
const std::string &comment);
const CreationLog &creationLog);
/**
* Deletes the specified administration host.
......
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