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
b7fd6293
Commit
b7fd6293
authored
Jun 20, 2018
by
Steven Murray
Browse files
cta/CTA#289 Remove the concept of admin host
Done
parent
920f57f3
Changes
36
Hide whitespace changes
Inline
Side-by-side
catalogue/CMakeLists.txt
View file @
b7fd6293
...
...
@@ -168,22 +168,7 @@ set_property (TARGET cta-catalogue-admin-user-create APPEND PROPERTY INSTALL_RPA
install
(
TARGETS cta-catalogue-admin-user-create DESTINATION /usr/bin
)
install
(
FILES
${
CMAKE_CURRENT_SOURCE_DIR
}
/cta-catalogue-admin-user-create.1cta DESTINATION /usr/share/man/man1
)
add_executable
(
cta-catalogue-admin-host-create
CreateAdminHostCmd.cpp
CreateAdminHostCmdLineArgs.cpp
CreateAdminHostCmdMain.cpp
)
target_link_libraries
(
cta-catalogue-admin-host-create
ctacatalogue
)
set_property
(
TARGET cta-catalogue-admin-host-create APPEND PROPERTY INSTALL_RPATH
${
ORACLE-INSTANTCLIENT_RPATH
}
)
install
(
TARGETS cta-catalogue-admin-host-create DESTINATION /usr/bin
)
install
(
FILES
${
CMAKE_CURRENT_SOURCE_DIR
}
/cta-catalogue-admin-host-create.1cta DESTINATION /usr/share/man/man1
)
set
(
CATALOGUE_CMD_LINE_UNIT_TESTS_LIB_SRC_FILES
CreateAdminHostCmdLineArgs.cpp
CreateAdminHostCmdLineArgsTest.cpp
CreateAdminUserCmdLineArgs.cpp
CreateAdminUserCmdLineArgsTest.cpp
CreateSchemaCmdLineArgs.cpp
...
...
catalogue/Catalogue.hpp
View file @
b7fd6293
...
...
@@ -24,7 +24,6 @@
#include
"catalogue/TapeForWriting.hpp"
#include
"catalogue/TapePool.hpp"
#include
"catalogue/TapeSearchCriteria.hpp"
#include
"common/dataStructures/AdminHost.hpp"
#include
"common/dataStructures/AdminUser.hpp"
#include
"common/dataStructures/ArchiveFile.hpp"
#include
"common/dataStructures/ArchiveFileQueueCriteria.hpp"
...
...
@@ -240,11 +239,6 @@ public:
virtual
std
::
list
<
common
::
dataStructures
::
AdminUser
>
getAdminUsers
()
const
=
0
;
virtual
void
modifyAdminUserComment
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
std
::
string
&
username
,
const
std
::
string
&
comment
)
=
0
;
virtual
void
createAdminHost
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
std
::
string
&
hostName
,
const
std
::
string
&
comment
)
=
0
;
virtual
void
deleteAdminHost
(
const
std
::
string
&
hostName
)
=
0
;
virtual
std
::
list
<
common
::
dataStructures
::
AdminHost
>
getAdminHosts
()
const
=
0
;
virtual
void
modifyAdminHostComment
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
std
::
string
&
hostName
,
const
std
::
string
&
comment
)
=
0
;
/**
* Creates the specified storage class.
*
...
...
catalogue/CatalogueFactoryTest.cpp
View file @
b7fd6293
...
...
@@ -61,14 +61,10 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) {
ASSERT_TRUE
(
nullptr
!=
catalogue
.
get
());
ASSERT_TRUE
(
catalogue
->
getAdminUsers
().
empty
());
ASSERT_TRUE
(
catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminUserComment
=
"Create admin user"
;
catalogue
->
createAdminUser
(
m_localAdmin
,
m_admin
.
username
,
createAdminUserComment
);
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminUser
>
admins
;
admins
=
catalogue
->
getAdminUsers
();
...
...
@@ -84,22 +80,6 @@ TEST_F(cta_catalogue_CatalogueFactoryTest, instance_in_memory) {
const
common
::
dataStructures
::
EntryLog
lastModificationLog
=
admin
.
lastModificationLog
;
ASSERT_EQ
(
creationLog
,
lastModificationLog
);
}
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
host
=
hosts
.
front
();
ASSERT_EQ
(
createAdminHostComment
,
host
.
comment
);
const
common
::
dataStructures
::
EntryLog
creationLog
=
host
.
creationLog
;
ASSERT_EQ
(
m_localAdmin
.
username
,
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
creationLog
.
host
);
const
common
::
dataStructures
::
EntryLog
lastModificationLog
=
host
.
lastModificationLog
;
ASSERT_EQ
(
creationLog
,
lastModificationLog
);
}
}
}
// namespace unitTests
catalogue/CatalogueRetryWrapper.hpp
View file @
b7fd6293
...
...
@@ -121,22 +121,6 @@ public:
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
modifyAdminUserComment
(
admin
,
username
,
comment
);},
m_maxTriesToConnect
);
}
void
createAdminHost
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
std
::
string
&
hostName
,
const
std
::
string
&
comment
)
override
{
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
createAdminHost
(
admin
,
hostName
,
comment
);},
m_maxTriesToConnect
);
}
void
deleteAdminHost
(
const
std
::
string
&
hostName
)
override
{
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
deleteAdminHost
(
hostName
);},
m_maxTriesToConnect
);
}
std
::
list
<
common
::
dataStructures
::
AdminHost
>
getAdminHosts
()
const
override
{
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
getAdminHosts
();},
m_maxTriesToConnect
);
}
void
modifyAdminHostComment
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
std
::
string
&
hostName
,
const
std
::
string
&
comment
)
override
{
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
modifyAdminHostComment
(
admin
,
hostName
,
comment
);},
m_maxTriesToConnect
);
}
void
createStorageClass
(
const
common
::
dataStructures
::
SecurityIdentity
&
admin
,
const
common
::
dataStructures
::
StorageClass
&
storageClass
)
override
{
return
retryOnLostConnection
(
m_log
,
[
&
]{
return
m_catalogue
->
createStorageClass
(
admin
,
storageClass
);},
m_maxTriesToConnect
);
}
...
...
catalogue/CatalogueTest.cpp
View file @
b7fd6293
...
...
@@ -70,12 +70,6 @@ void cta_catalogue_CatalogueTest::SetUp() {
m_catalogue->deleteAdminUser(adminUser.name);
}
}
{
const
std
::
list
<
common
::
dataStructures
::
AdminHost
>
adminHosts
=
m_catalogue
->
getAdminHosts
();
for
(
auto
&
adminHost
:
adminHosts
)
{
m_catalogue
->
deleteAdminHost
(
adminHost
.
name
);
}
}
{
const std::list<common::dataStructures::ArchiveRoute> archiveRoutes = m_catalogue->getArchiveRoutes();
for(auto &archiveRoute: archiveRoutes) {
...
...
@@ -224,30 +218,6 @@ std::map<std::string, cta::common::dataStructures::AdminUser> cta_catalogue_Cata
}
}
//------------------------------------------------------------------------------
// adminHostListToMap
//------------------------------------------------------------------------------
std
::
map
<
std
::
string
,
cta
::
common
::
dataStructures
::
AdminHost
>
cta_catalogue_CatalogueTest
::
adminHostListToMap
(
const
std
::
list
<
cta
::
common
::
dataStructures
::
AdminHost
>
&
listOfAdminHosts
)
{
using
namespace
cta
;
try
{
std
::
map
<
std
::
string
,
common
::
dataStructures
::
AdminHost
>
m
;
for
(
auto
&
adminHost
:
listOfAdminHosts
)
{
if
(
m
.
end
()
!=
m
.
find
(
adminHost
.
name
))
{
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Admin host "
<<
adminHost
.
name
<<
" is a duplicate"
;
throw
ex
;
}
m
[
adminHost
.
name
]
=
adminHost
;
}
return
m
;
}
catch
(
exception
::
Exception
&
ex
)
{
throw
exception
::
Exception
(
std
::
string
(
__FUNCTION__
)
+
" failed: "
+
ex
.
getMessage
().
str
());
}
}
//------------------------------------------------------------------------------
// tapePoolListToMap
//------------------------------------------------------------------------------
...
...
@@ -395,133 +365,6 @@ TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment_nonExtistentAdminUser
exception::UserError);
}
TEST_P
(
cta_catalogue_CatalogueTest
,
createAdminHost
)
{
using
namespace
cta
;
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
createAdminHostComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
}
TEST_P
(
cta_catalogue_CatalogueTest
,
createAdminHost_same_twice
)
{
using
namespace
cta
;
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
createAdminHostComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
ASSERT_THROW
(
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
"comment 2"
),
exception
::
UserError
);
}
TEST_P
(
cta_catalogue_CatalogueTest
,
deleteAdminHost
)
{
using
namespace
cta
;
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
createAdminHostComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
m_catalogue
->
deleteAdminHost
(
m_admin
.
host
);
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
}
TEST_P
(
cta_catalogue_CatalogueTest
,
deleteAdminHost_non_existant
)
{
using
namespace
cta
;
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
ASSERT_THROW
(
m_catalogue
->
deleteAdminHost
(
"non_exstant_admin_host"
),
exception
::
UserError
);
}
TEST_P
(
cta_catalogue_CatalogueTest
,
modifyAdminHostComment
)
{
using
namespace
cta
;
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
createAdminHostComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
const
std
::
string
modifiedComment
=
"Modified comment"
;
m_catalogue
->
modifyAdminHostComment
(
m_localAdmin
,
m_admin
.
host
,
modifiedComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
modifiedComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
}
TEST_P(cta_catalogue_CatalogueTest, isAdmin_false) {
using namespace cta;
...
...
@@ -551,26 +394,6 @@ TEST_P(cta_catalogue_CatalogueTest, isAdmin_true) {
ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
}
ASSERT_TRUE
(
m_catalogue
->
getAdminHosts
().
empty
());
const
std
::
string
createAdminHostComment
=
"Create admin host"
;
m_catalogue
->
createAdminHost
(
m_localAdmin
,
m_admin
.
host
,
createAdminHostComment
);
{
std
::
list
<
common
::
dataStructures
::
AdminHost
>
hosts
;
hosts
=
m_catalogue
->
getAdminHosts
();
ASSERT_EQ
(
1
,
hosts
.
size
());
const
common
::
dataStructures
::
AdminHost
h
=
hosts
.
front
();
ASSERT_EQ
(
m_admin
.
host
,
h
.
name
);
ASSERT_EQ
(
createAdminHostComment
,
h
.
comment
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
creationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
creationLog
.
host
);
ASSERT_EQ
(
m_localAdmin
.
username
,
h
.
lastModificationLog
.
username
);
ASSERT_EQ
(
m_localAdmin
.
host
,
h
.
lastModificationLog
.
host
);
}
ASSERT_TRUE(m_catalogue->isAdmin(m_admin));
}
...
...
@@ -9168,7 +8991,6 @@ TEST_P(cta_catalogue_CatalogueTest, schemaTables) {
tableNameToListPos[tableName] = listPos++;
}
ASSERT_NE
(
tableNameToListPos
.
end
(),
tableNameToListPos
.
find
(
"ADMIN_HOST"
));
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("ADMIN_USER"));
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("ARCHIVE_FILE"));
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("ARCHIVE_ROUTE"));
...
...
@@ -9181,19 +9003,6 @@ TEST_P(cta_catalogue_CatalogueTest, schemaTables) {
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("TAPE"));
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("TAPE_FILE"));
ASSERT_NE(tableNameToListPos.end(), tableNameToListPos.find("TAPE_POOL"));
ASSERT_LT
(
tableNameToListPos
.
at
(
"ADMIN_HOST"
)
,
tableNameToListPos
.
at
(
"ADMIN_USER"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"ADMIN_USER"
)
,
tableNameToListPos
.
at
(
"ARCHIVE_FILE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"ARCHIVE_FILE"
)
,
tableNameToListPos
.
at
(
"ARCHIVE_ROUTE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"ARCHIVE_ROUTE"
)
,
tableNameToListPos
.
at
(
"CTA_CATALOGUE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"CTA_CATALOGUE"
)
,
tableNameToListPos
.
at
(
"LOGICAL_LIBRARY"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"LOGICAL_LIBRARY"
)
,
tableNameToListPos
.
at
(
"MOUNT_POLICY"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"MOUNT_POLICY"
)
,
tableNameToListPos
.
at
(
"REQUESTER_GROUP_MOUNT_RULE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"REQUESTER_GROUP_MOUNT_RULE"
),
tableNameToListPos
.
at
(
"REQUESTER_MOUNT_RULE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"REQUESTER_MOUNT_RULE"
)
,
tableNameToListPos
.
at
(
"STORAGE_CLASS"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"STORAGE_CLASS"
)
,
tableNameToListPos
.
at
(
"TAPE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"TAPE"
)
,
tableNameToListPos
.
at
(
"TAPE_FILE"
));
ASSERT_LT
(
tableNameToListPos
.
at
(
"TAPE_FILE"
)
,
tableNameToListPos
.
at
(
"TAPE_POOL"
));
}
} // namespace unitTests
catalogue/CatalogueTest.hpp
View file @
b7fd6293
...
...
@@ -83,16 +83,6 @@ protected:
std
::
map
<
std
::
string
,
cta
::
common
::
dataStructures
::
AdminUser
>
adminUserListToMap
(
const
std
::
list
<
cta
::
common
::
dataStructures
::
AdminUser
>
&
listOfAdminUsers
);
/**
* Creates a map from admin host name to admin user from the specified list of
* admin users.
*
* @param listOfAdminHosts The list of admin hosts.
* @return Map from host name to admin host.
*/
std
::
map
<
std
::
string
,
cta
::
common
::
dataStructures
::
AdminHost
>
adminHostListToMap
(
const
std
::
list
<
cta
::
common
::
dataStructures
::
AdminHost
>
&
listOfAdminHosts
);
/**
* Creates a map from tape pool name to tape pool from the specified list of
* tape pools.
...
...
catalogue/CreateAdminHostCmd.cpp
deleted
100644 → 0
View file @
920f57f3
/*
* 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/>.
*/
#include
"catalogue/CatalogueFactory.hpp"
#include
"catalogue/CreateAdminHostCmd.hpp"
#include
"catalogue/CreateAdminHostCmdLineArgs.hpp"
#include
"common/exception/Exception.hpp"
#include
"common/log/DummyLogger.hpp"
#include
"rdbms/wrapper/ConnFactoryFactory.hpp"
#include
"common/utils/utils.hpp"
namespace
cta
{
namespace
catalogue
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminHostCmd
::
CreateAdminHostCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
)
:
CmdLineTool
(
inStream
,
outStream
,
errStream
)
{
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
CreateAdminHostCmd
::~
CreateAdminHostCmd
()
noexcept
{
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int
CreateAdminHostCmd
::
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
)
{
const
CreateAdminHostCmdLineArgs
cmdLineArgs
(
argc
,
argv
);
if
(
cmdLineArgs
.
help
)
{
printUsage
(
m_out
);
return
0
;
}
const
rdbms
::
Login
dbLogin
=
rdbms
::
Login
::
parseFile
(
cmdLineArgs
.
dbConfigPath
);
const
uint64_t
nbDbConns
=
1
;
const
uint64_t
nbArchiveFileListingDbConns
=
0
;
log
::
DummyLogger
dummyLog
(
"dummy"
,
"dummy"
);
auto
catalogue
=
CatalogueFactory
::
create
(
dummyLog
,
dbLogin
,
nbDbConns
,
nbArchiveFileListingDbConns
);
const
common
::
dataStructures
::
SecurityIdentity
adminRunningCommand
(
getUsername
(),
getHostname
());
// Validate that the hostname is a valid IPv4 or IPv6 address, or a Fully-Qualified Domain Name
if
(
!
utils
::
isValidIPAddress
(
cmdLineArgs
.
adminHostname
))
{
utils
::
assertIsFQDN
(
cmdLineArgs
.
adminHostname
);
}
catalogue
->
createAdminHost
(
adminRunningCommand
,
cmdLineArgs
.
adminHostname
,
cmdLineArgs
.
comment
);
return
0
;
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void
CreateAdminHostCmd
::
printUsage
(
std
::
ostream
&
os
)
{
CreateAdminHostCmdLineArgs
::
printUsage
(
os
);
}
}
// namespace catalogue
}
// namespace cta
catalogue/CreateAdminHostCmd.hpp
deleted
100644 → 0
View file @
920f57f3
/*
* 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
"catalogue/Catalogue.hpp"
#include
"catalogue/CmdLineTool.hpp"
namespace
cta
{
namespace
catalogue
{
/**
* Command-line tool that creates an admin host.
*/
class
CreateAdminHostCmd
:
public
CmdLineTool
{
public:
/**
* Constructor.
*
* @param inStream Standard input stream.
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
CreateAdminHostCmd
(
std
::
istream
&
inStream
,
std
::
ostream
&
outStream
,
std
::
ostream
&
errStream
);
/**
* Destructor.
*/
~
CreateAdminHostCmd
()
noexcept
;
private:
/**
* An exception throwing version of main().
*
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
* @return The exit value of the program.
*/
int
exceptionThrowingMain
(
const
int
argc
,
char
*
const
*
const
argv
)
override
;
/**
* Prints the usage message of the command-line tool.
*
* @param os The output stream to which the usage message is to be printed.
*/
void
printUsage
(
std
::
ostream
&
os
)
override
;
};
// class CreateAdminHostCmd
}
// namespace catalogue
}
// namespace cta
catalogue/CreateAdminHostCmdLineArgs.cpp
deleted
100644 → 0
View file @
920f57f3
/*
* 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/>.
*/
#include
"catalogue/CreateAdminHostCmdLineArgs.hpp"
#include
"common/exception/CommandLineNotParsed.hpp"
#include
<getopt.h>
#include
<ostream>
namespace
cta
{
namespace
catalogue
{
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminHostCmdLineArgs
::
CreateAdminHostCmdLineArgs
(
const
int
argc
,
char
*
const
*
const
argv
)
:
help
(
false
)
{
static
struct
option
longopts
[]
=
{
{
"comment"
,
required_argument
,
NULL
,
'm'
},
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"hostname"
,
required_argument
,
NULL
,
'n'
},
{
NULL
,
0
,
NULL
,
0
}
};
// Prevent getopt() from printing an error message if it does not recognize
// an option character
opterr
=
0
;
int
opt
=
0
;
while
((
opt
=
getopt_long
(
argc
,
argv
,
":m:hn:"
,
longopts
,
NULL
))
!=
-
1
)
{
switch
(
opt
)
{
case
'm'
:
comment
=
optarg
?
optarg
:
""
;
break
;
case
'h'
:
help
=
true
;
break
;
case
'n'
:
adminHostname
=
optarg
?
optarg
:
""
;
break
;
case
':'
:
// Missing parameter
{
exception
::
CommandLineNotParsed
ex
;
ex
.
getMessage
()
<<
"The -"
<<
(
char
)
opt
<<
" option requires a parameter"
;
throw
ex
;
}
case
'?'
:
// Unknown option
{
exception
::
CommandLineNotParsed
ex
;
if
(
0
==
optopt
)
{
ex
.
getMessage
()
<<
"Unknown command-line option"
;
}
else
{
ex
.
getMessage
()
<<
"Unknown command-line option: -"
<<
(
char
)
optopt
;
}
throw
ex
;
}
default:
{
exception
::
CommandLineNotParsed
ex
;
ex
.
getMessage
()
<<
"getopt_long returned the following unknown value: 0x"
<<
std
::
hex
<<
(
int
)
opt
;
throw
ex
;
}
}
// switch(opt)
}
// while getopt_long()
// There is no need to continue parsing when the help option is set
if
(
help
)
{
return
;
}
if
(
adminHostname
.
empty
())
{
throw
exception
::
CommandLineNotParsed
(
"The hostname option must be specified with a non-empty string"
);
}
if
(
comment
.
empty
())
{
throw
exception
::
CommandLineNotParsed
(
"The comment option must be specified with a non-empty string"
);
}