Skip to content
Snippets Groups Projects
Commit 9582b4f9 authored by Michael Davis's avatar Michael Davis
Browse files

[migration] Tool to extract list of files not on tape

As requested by ATLAS
parent 6bb80c0d
No related branches found
No related tags found
No related merge requests found
# The CERN Tape Archive (CTA) project
# Copyright 2019 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/>.
cmake_minimum_required (VERSION 2.6)
include_directories(${XRD_SSI_PB_DIR}/include ${XROOTD_INCLUDE_DIR} ${XROOTD_INCLUDE_DIR}/private)
# Extract CASTOR metadata
add_executable(not-on-tape NotOnTape.cpp)
target_link_libraries(not-on-tape ctacatalogue)
/*!
* @project The CERN Tape Archive (CTA)
* @brief Inject directory metadata into EOS using gRPC
* @copyright Copyright 2019 CERN
* @license 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 <iostream>
#include <sstream>
#include <map>
#include <memory>
#include <XrdSsiPbConfig.hpp>
#include <migration/CastorDB.hpp>
namespace cta {
namespace migration {
//! DB Connection Pool
std::unique_ptr<rdbms::ConnPool> CastorDbConn::m_connPool;
class NotOnTape
{
public:
NotOnTape(const std::string &configfile);
private:
CastorDbConn m_castordb; //!< Oracle database for CASTOR namespace
};
NotOnTape::NotOnTape(const std::string &configfile)
{
// Parse configuration file
XrdSsiPb::Config config(configfile);
auto dbconn = config.getOptionValueStr("castor.db_login");
auto max_num_conns = config.getOptionValueInt("castor.max_num_connections");
// Connect to Oracle
if(!dbconn.first) {
throw std::runtime_error("castor.db_login must be specified in the config file in the form oracle:user/password@TNS");
}
m_castordb.connect(dbconn.second, max_num_conns.first ? max_num_conns.second : 1);
m_castordb.query("select * from mdavis_cns_not_on_tape_files where (dirname like '/castor/cern.ch/atlas%' or dirname like '/castor/cern.ch/grid/atlas%' or fileclass like '%atlas%')");
std::ofstream ofs("no_tape_copy.csv", std::ofstream::out);
ofs << "\"Path\",\"Size\",\"Gid\",\"File class\"" << std::endl;
int interval = 10000;
int count = 0;
while(m_castordb.nextRow()) {
if(++count % interval == 0) {
std::cerr << count << "...";
}
ofs << "\"" << m_castordb.getResultColumnString("DIRNAME") << "/"
<< m_castordb.getResultColumnString("FILENAME") << "\","
<< m_castordb.getResultColumnString("FILESIZE") << ","
<< m_castordb.getResultColumnString("GID") << ","
<< "\"" << m_castordb.getResultColumnString("FILECLASS") << "\"" << std::endl;
}
}
}} // namespace cta::migration
void throwUsage(const std::string &program, const std::string &error_txt)
{
std::stringstream help;
help << program << ": " << error_txt << std::endl
<< "Usage: " << program << " [--config <config_file>]";
throw std::runtime_error(help.str());
}
int main(int argc, const char* argv[])
{
std::string configfile = "/home/ctadev/CTA/migration/castor-migration.conf";
try {
for(auto i = 1; i < argc; ++i) {
std::string option(argv[i]);
if(option == "--config" && argc > ++i) {
configfile = argv[i];
continue;
}
throwUsage(argv[0], "invalid option " + option);
}
cta::migration::NotOnTape graphdb(configfile);
} catch(std::runtime_error &ex) {
std::cerr << ex.what() << std::endl;
return -1;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment