Commit c08adc26 authored by Eric Cano's avatar Eric Cano
Browse files

Added support for URL based backend location makeMinimalVFS, tapeserverd and CTAAddAdminUser.

New URLs are rados://user@pool and file:///tmp/XXXXX. Otherwise, we fall back to interpreting
the URL as a bare path.
parent 5bd22fff
......@@ -10,7 +10,7 @@ set(CMAKE_C_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter")
# following:
#
# ClientSimulator.hpp:65: error: ISO C++ prohibits anonymous structs
set(CMAKE_CXX_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter -Wno-long-long -std=c++0x -fms-extensions")
set(CMAKE_CXX_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter -Wno-long-long -std=c++0x -fms-extensions -fstack-protector-all")
# Explicitly setting the C and C++ compiler flags for the RelWithDebInfo build
......
......@@ -17,6 +17,7 @@
*/
#include <exception>
#include "objectstore/BackendFactory.hpp"
#include "objectstore/BackendVFS.hpp"
#include "tapeserver/castor/common/CastorConfiguration.hpp"
#include "tapeserver/castor/log/DummyLogger.hpp"
......@@ -34,9 +35,15 @@ int main(int argc, char ** argv) {
castor::common::CastorConfiguration::getConfig();
castor::log::DummyLogger log("ctaAddAdminUser");
cta::objectstore::BackendVFS be(castorConf.getConfEntString("TapeServer", "ObjectStoreBackendPath", &log));
be.noDeleteOnExit();
cta::OStoreDB db(be);
std::unique_ptr<cta::objectstore::Backend> be(
cta::objectstore::BackendFactory::createBackend(
castorConf.getConfEntString("TapeServer", "ObjectStoreBackendPath", &log)).release());
// If the backend is a VFS, make sure we don't delete it on exit.
// If not, nevermind.
try {
dynamic_cast<cta::objectstore::BackendVFS &>(*be).noDeleteOnExit();
} catch (std::bad_cast &){}
cta::OStoreDB db(*be);
db.createAdminUser(cta::SecurityIdentity(cta::UserIdentity(getuid(), getgid()),
castor::utils::getHostName()),
cta::UserIdentity(uid, gid), "");
......
......@@ -104,6 +104,12 @@ public:
*/
virtual std::string toStr() = 0;
/**
* Turns parameter class into URL representation
* @return the URL
*/
virtual std::string toURL() = 0;
/**
* Virtual destructor
*/
......
/*
* 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 "BackendFactory.hpp"
#include "BackendRados.hpp"
#include "BackendVFS.hpp"
#include "common/Utils.hpp"
#include "tapeserver/castor/tape/tapeserver/utils/Regex.hpp"
auto cta::objectstore::BackendFactory::createBackend(const std::string& URL)
-> std::unique_ptr<Backend> {
castor::tape::utils::Regex fileRe("^file://(.*)$"),
radosRe("^rados://([^@]+)@(.*)$");
std::vector<std::string> regexResult;
// Is it a file:// URL?
regexResult = fileRe.exec(URL);
if (regexResult.size()) {
return std::unique_ptr<Backend>(new BackendVFS(regexResult[1]));
}
// Is it a rados:// URL?
regexResult = radosRe.exec(URL);
if (regexResult.size()) {
return std::unique_ptr<Backend>(new BackendRados(regexResult[1], regexResult[2]));
}
// Fall back to a file URL if all failed
return std::unique_ptr<Backend>(new BackendVFS(URL));
}
\ No newline at end of file
/*
* 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 "Backend.hpp"
#include <memory>
namespace cta { namespace objectstore {
class BackendFactory {
public:
static std::unique_ptr<Backend> createBackend(const std::string & URL);
};
}}
\ No newline at end of file
......@@ -25,7 +25,7 @@
namespace cta { namespace objectstore {
BackendRados::BackendRados(std::string userId, std::string pool) :
BackendRados::BackendRados(const std::string & userId, const std::string & pool) :
m_user(userId), m_pool(pool), m_cluster(), m_radosCtx() {
cta::exception::Errnum::throwOnNonZero(m_cluster.init(userId.c_str()),
"In ObjectStoreRados::ObjectStoreRados, failed to m_cluster.init");
......@@ -171,6 +171,13 @@ std::string BackendRados::Parameters::toStr() {
return ret.str();
}
std::string BackendRados::Parameters::toURL() {
std::stringstream ret;
ret << "rados://" << m_userId << "@" << m_pool;
return ret.str();
}
BackendRados::Parameters* BackendRados::getParams() {
std::unique_ptr<Parameters> ret(new Parameters);
ret->m_pool = m_pool;
......
......@@ -34,7 +34,7 @@ public:
* @param userId
* @param pool
*/
BackendRados(std::string userId, std::string pool);
BackendRados(const std::string & userId, const std::string & pool);
virtual ~BackendRados();
virtual std::string user() {
return m_user;
......@@ -85,6 +85,7 @@ public:
* @return a string representation of the parameters for logging
*/
virtual std::string toStr();
virtual std::string toURL();
private:
std::string m_userId;
std::string m_pool;
......
......@@ -241,4 +241,10 @@ std::string BackendVFS::Parameters::toStr() {
return ret.str();
}
std::string BackendVFS::Parameters::toURL() {
std::stringstream ret;
ret << "file://" << m_path;
return ret.str();
}
}} // end of cta::objectstore
......@@ -95,6 +95,12 @@ public:
* @return a string representation of the parameters for logging
*/
virtual std::string toStr();
/**
* The standard-issue params to URL
* @return a string representation of the parameters for logging
*/
virtual std::string toURL();
/**
* A more specific member, giving access to the path itself
......
......@@ -24,11 +24,13 @@ add_library (CTAObjectStore
DriveRegister.cpp
BackendVFS.cpp
BackendRados.cpp
BackendFactory.cpp
ObjectOps.cpp
ProtocolBuffersAlgorithms.cpp
GenericObject.cpp
GarbageCollector.cpp
SchedulerGlobalLock.cpp)
target_link_libraries(CTAObjectStore Utils rados)
set(ObjectStoreUnitTests
BackendTest.cpp
......
......@@ -23,20 +23,34 @@
*/
#include "BackendVFS.hpp"
#include "BackendFactory.hpp"
#include "RootEntry.hpp"
#include "Agent.hpp"
#include <iostream>
#include <stdexcept>
int main(void) {
int main(int argc, char ** argv) {
try {
cta::objectstore::BackendVFS be;
be.noDeleteOnExit();
cta::objectstore::RootEntry re(be);
std::unique_ptr<cta::objectstore::Backend> be;
if (1 == argc) {
be.reset(new cta::objectstore::BackendVFS);
} else if (2 == argc) {
be.reset(cta::objectstore::BackendFactory::createBackend(argv[1]).release());
} else {
throw std::runtime_error("Wrong number of arguments: expected 0 or 1");
}
// If the backend is a VFS, make sure we don't delete it on exit.
// If not, nevermind.
try {
dynamic_cast<cta::objectstore::BackendVFS &>(*be).noDeleteOnExit();
} catch (std::bad_cast &){}
cta::objectstore::RootEntry re(*be);
re.initialize();
re.insert();
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
cta::objectstore::Agent ag(be);
cta::objectstore::Agent ag(*be);
ag.generateName("makeMinimalVFS");
ag.initialize();
cta::objectstore::CreationLog cl(cta::UserIdentity(1111, 1111), "systemhost",
......@@ -48,7 +62,7 @@ int main(void) {
re.addOrGetDriveRegisterPointerAndCommit(ag, cl);
re.addOrGetSchedulerGlobalLockAndCommit(ag,cl);
rel.release();
std::cout << "New object store path: " << be.getParams()->getPath() << std::endl;
std::cout << "New object store path: " << be->getParams()->toURL() << std::endl;
} catch (std::exception & e) {
std::cerr << "Failed to initialise the root entry in a new VFS backend store"
<< std::endl << e.what() << std::endl;
......
......@@ -49,6 +49,7 @@
#include "castor/utils/utils.hpp"
#include "nameserver/CastorNameServer.hpp"
#include "objectstore/BackendVFS.hpp"
#include "objectstore/BackendFactory.hpp"
#include "objectstore/RootEntry.hpp"
#include "remotens/EosNS.hpp"
#include "scheduler/OStoreDB/OStoreDB.hpp"
......@@ -558,9 +559,17 @@ castor::tape::tapeserver::daemon::Session::EndOfSessionAction
cta::EosNS eosNs(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "EOSRemoteHostAndPort"));
cta::MockNameServer mockNs(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "MockNameServerPath"));
cta::objectstore::BackendVFS backend(castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "ObjectStoreBackendPath"));
BackendPopulator backendPopulator(backend);
OStoreDBWithAgent osdb(backend, backendPopulator.getAgent());
std::unique_ptr<cta::objectstore::Backend> backend(
cta::objectstore::BackendFactory::createBackend(
castor::common::CastorConfiguration::getConfig().getConfEntString("TapeServer", "ObjectStoreBackendPath"))
.release());
// If the backend is a VFS, make sure we don't delete it on exit.
// If not, nevermind.
try {
dynamic_cast<cta::objectstore::BackendVFS &>(*backend).noDeleteOnExit();
} catch (std::bad_cast &){}
BackendPopulator backendPopulator(*backend);
OStoreDBWithAgent osdb(*backend, backendPopulator.getAgent());
cta::Scheduler scheduler(mockNs, osdb, eosNs);
......
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