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

Added version of object dumper.

parent f26e1e4f
......@@ -73,3 +73,7 @@ target_link_libraries(makeMinimalVFS
add_executable(listObjectStore listObjectStore.cpp)
target_link_libraries(listObjectStore
protobuf ctaobjectstore ctacommon)
add_executable(dumpObject dumpObject.cpp)
target_link_libraries(dumpObject
protobuf ctaobjectstore ctacommon)
\ No newline at end of file
......@@ -20,6 +20,7 @@
#include "AgentRegister.hpp"
#include "TapePool.hpp"
#include "DriveRegister.hpp"
#include <stdexcept>
namespace cta { namespace objectstore {
......@@ -104,5 +105,29 @@ void GenericObject::garbageCollect(ScopedExclusiveLock& lock,
}
}
namespace {
using cta::objectstore::GenericObject;
using cta::objectstore::ScopedExclusiveLock;
template <class C>
std::string dumpWithType(GenericObject * gop, ScopedSharedLock& lock) {
C typedObject(*gop);
lock.transfer(typedObject);
std::string ret = typedObject.dump();
// Release the lock now as if we let the caller do, it will point
// to the then-removed typedObject.
lock.release();
return ret;
}
}
std::string GenericObject::dump(ScopedSharedLock& lock) {
checkHeaderReadable();
switch(m_header.type()) {
case serializers::AgentRegister_t:
return dumpWithType<AgentRegister>(this, lock);
default:
throw std::runtime_error("Unsupported type");
}
}
}}
......@@ -62,6 +62,13 @@ public:
*/
void garbageCollect(ScopedExclusiveLock & lock, const std::string &presumedOwner);
/** This dispatcher function will call the object's dump.
* It also handles the passed lock.
*
* @param lock reference to the generic object's lock
*/
std::string dump(ScopedSharedLock & lock);
CTA_GENERATE_EXCEPTION_CLASS(UnsupportedType);
/**
* This static function is a helper that will garbage collect the object at
......
/*
* 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/>.
*/
/**
* This program will create a VFS backend for the object store and populate
* it with the minimum elements (the root entry). The program will then print out
* the path the backend store and exit
*/
#include "BackendFactory.hpp"
#include "BackendVFS.hpp"
#include "GenericObject.hpp"
#include <iostream>
#include <stdexcept>
int main(int argc, char ** argv) {
try {
std::unique_ptr<cta::objectstore::Backend> be;
if (3 == argc) {
be.reset(cta::objectstore::BackendFactory::createBackend(argv[1]).release());
} else {
throw std::runtime_error("Wrong number of arguments: expected 2");
}
// 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 &){}
std::cout << "Object store path: " << be->getParams()->toURL()
<< " object name=" << argv[2];
cta::objectstore::GenericObject ge(argv[2], *be);
cta::objectstore::ScopedSharedLock gel(ge);
ge.fetch();
std::cout << ge.dump(gel) << 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;
}
}
\ No newline at end of file
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