Commit 1f6488c0 authored by Steven Murray's avatar Steven Murray
Browse files

Added castor/tape/aggregator directory as a place holder for the future

tape aggregator daemon.
parent 664d7dbf
#
# castor/tape/Imakefile
#
# This file is part of the Castor project.
# See http://castor.web.cern.ch/castor
#
# Copyright (C) 2003 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
#
# @author Sebastien Ponce, sebastien.ponce@cern.ch
#
#include <Project.tmpl>
SUBDIRS = $(AGGREGATORCPPDIR)
DEPENDDIRS = $(AGGREGATORCPPDIR)
MakeSubdirs(all,$(SUBDIRS))
MakeSubdirs(install,$(SUBDIRS))
MakeSubdirs(install.man,$(SUBDIRS))
MakeSubdirs(exportman,$(SUBDIRS))
MakeCondSubdirs(clean,$(SUBDIRS),)
MakeCondSubdirs(clobber,$(SUBDIRS),)
#if defined(_WIN32)
Makefiles:
@for %i in ( $(SUBDIRS) ) \
do @(echo %i - & cd %i & \
..\..\..\imake\imake -I..\..\..\config & \
$(MAKE) $(MFLAGS) $@ & cd .. )
depend:
@echo Not supported on this platform
#else
Makefiles:
@. ../../setosflags ;\
for i in $(SUBDIRS) ;\
do (if [ -d $$i ] ;\
then \
(echo " $$i:" ; cd $$i ;\
../../../imake/imake -I../../../config -DOSMajorVersion="$$OSMAJNO" -DOSMinorVersion="$$OSMINNO" ;\
$(MAKE) $(MFLAGS) $@) ;\
else \
(echo "ERROR : No directory $$i" ;\
exit 1) ;\
fi )\
done ;
depend:
for i in $(DEPENDDIRS) ;\
do (if [ -d $$i ] ;\
then \
(echo " $$i:" ; cd $$i ;\
$(MAKE) $(MFLAGS) $@) ;\
else \
(echo "ERROR : No directory $$i" ;\
exit 1) ;\
fi )\
done ;
#endif
install:
install.man:
exportman:
/* This file was generated by ./AggregatorDlfMessagesCodeGenerator on Fri Aug 15 16:14:34 CEST 2008
*/
/******************************************************************************
* castor/tape/aggregator/AggregatorDlfMessageConstants.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven Murray Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP
#define CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP 1
namespace castor {
namespace tape {
namespace aggregator {
enum AggregatorDlfMessages {
AGGREGATOR_NULL=0, /* " - " */
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE=1, /* "Failed to parse the command line" */
AGGREGATOR_FAILED_TO_INIT_DB_SERVICE=2 /* "Failed to initialise database service" */
}; // enum AggregatorDlfMessages
} // namespace aggregator
} // namespace tape
} // namespace castor
#endif // CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP
/******************************************************************************
* castor/tape/aggregator/AggregatorDlfMessageConstants.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven Murray Steven.Murray@cern.ch
*****************************************************************************/
#ifndef CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP
#define CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP 1
namespace castor {
namespace tape {
namespace aggregator {
enum AggregatorDlfMessages {
}; // enum AggregatorDlfMessages
} // namespace aggregator
} // namespace tape
} // namespace castor
#endif // CASTOR_TAPE_AGGREGATOR_AGGREGATORDLFMESSAGECONSTANTS_HPP
/* This file was generated by ./AggregatorDlfMessagesCodeGenerator on Fri Aug 15 16:14:34 CEST 2008
*/
/******************************************************************************
* castor/tape/aggregator/AggregatorDlfMessageStrings.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven Murray Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/aggregator/AggregatorDlfMessageConstants.hpp"
#include "castor/tape/aggregator/AggregatorServer.hpp"
castor::dlf::Message castor::tape::aggregator::AggregatorServer::s_dlfMessages[] = {
{AGGREGATOR_NULL, " - "},
{AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE, "Failed to parse the command line"},
{AGGREGATOR_FAILED_TO_INIT_DB_SERVICE, "Failed to initialise database service"},
{-1, ""}};
/******************************************************************************
* castor/tape/aggregator/AggregatorDlfMessageStrings.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven Murray Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/tape/aggregator/AggregatorDlfMessageConstants.hpp"
#include "castor/tape/aggregator/AggregatorServer.hpp"
castor::dlf::Message castor::tape::aggregator::AggregatorServer::s_dlfMessages[] = {
AGGREGATOR_NULL,0," - "
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE,1,"Failed to parse the command line"
AGGREGATOR_FAILED_TO_INIT_DB_SERVICE,2,"Failed to initialise database service"
#!/usr/bin/perl -w
use strict;
my $constants_filename="AggregatorDlfMessageConstants.hpp";
my $constants_head_filename="AggregatorDlfMessageConstantsHeader.txt";
my $messages_filename="AggregatorDlfMessages.csv";
my $constants_tail_filename="AggregatorDlfMessageConstantsTrailer.txt";
my $strings_filename="AggregatorDlfMessageStrings.cpp";
my $strings_head_filename="AggregatorDlfMessageStringsHeader.txt";
sub writeConstantsFile {
my $date = $_[0];
# Open the constants file for writing
open(CONSTANTS, ">$constants_filename")
or die("Could not open $constants_filename for writing: $!\n");
print(CONSTANTS "/* This file was generated by $0 on $date */\n\n");
# Write the header text
open(CONSTANTSHEAD, "<$constants_head_filename")
or die("Could not open $constants_head_filename for reading: $!\n");
while(<CONSTANTSHEAD>) {
print(CONSTANTS);
}
close(CONSTANTSHEAD);
# Count the number of messages
open(MESSAGES, "<$messages_filename")
or die("Could not open $messages_filename for reading: $!\n");
my $nbMessages = 0;
while(<MESSAGES>) {
$nbMessages = $nbMessages + 1;
}
close(MESSAGES);
# Write the body text
open(MESSAGES, "<$messages_filename")
or die("Could not open $messages_filename for reading: $!\n");
my $const_name;
my $const_val;
my $msg;
my $currentMessageNb = 0;
while(<MESSAGES>) {
$currentMessageNb = $currentMessageNb + 1;
m/^([A-Z0-9_]*),(\d*),(.*)/;
$const_name = $1;
$const_val = $2;
$msg = $3;
# If this is not the last message
if($currentMessageNb != $nbMessages) {
# Terminate the enumeration item with a comma
print(CONSTANTS "${const_name}=${const_val}, /* ${msg} */\n");
} else {
# Don't terminate the enumeration item with a comma
print(CONSTANTS "${const_name}=${const_val} /* ${msg} */\n");
}
}
close(MESSAGES);
# Write the trailer text
open(CONSTANTSTAIL, "<$constants_tail_filename")
or die("Could not open $constants_tail_filename for reading: $!\n");
while(<CONSTANTSTAIL>) {
print(CONSTANTS);
}
close(CONSTANTSTAIL);
# Close the constants file
close(CONSTANTS);
}
sub writeStringsFile {
my $date = $_[0];
# Open the strings file for writing
open(STRINGS, ">$strings_filename")
or die("Could not open $strings_filename for writing: $!\n");
print(STRINGS "/* This file was generated by $0 on $date */\n\n");
# Write the header text
open(STRINGSHEAD, "<$strings_head_filename")
or die("Could not open $strings_head_filename for reading: $!\n");
while(<STRINGSHEAD>) {
print(STRINGS);
}
close(STRINGSHEAD);
# Write the body text
open(MESSAGES, "<$messages_filename")
or die("Could not open $messages_filename for reading: $!\n");
my $const_name;
my $const_val;
my $msg;
while(<MESSAGES>) {
m/^([A-Z0-9_]*),(\d*),(.*)/;
$const_name = $1;
$const_val = $2;
$msg = $3;
print(STRINGS "{${const_name}, ${msg}},\n");
}
close(MESSAGES);
# Write the trailer text
print(STRINGS "{-1, \"\"}};\n");
# Close the strings file
close(STRINGS);
}
my $date = `date`;
print("\n");
print("Source code generator for DLF messages\n");
print("===========================================\n\n");
print("Generating $constants_filename\n");
&writeConstantsFile($date);
print("Generating $strings_filename\n");
&writeStringsFile($date);
print("Finished\n\n");
/******************************************************************************
* castor/tape/aggregator/AggregatorServer.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Steven Murray Steven.Murray@cern.ch
*****************************************************************************/
#include "castor/Services.hpp"
#include "castor/db/DbParamsSvc.hpp"
#include "castor/exception/Internal.hpp"
#include "castor/tape/aggregator/AggregatorDlfMessageConstants.hpp"
#include "castor/tape/aggregator/AggregatorServer.hpp"
#include "Cgetopt.h"
#include <sstream>
// Hardcoded schema version of the tape database
const std::string TAPESCHEMAVERSION = "2_1_7_12";
//------------------------------------------------------------------------------
// main method
//------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
castor::tape::aggregator::AggregatorServer server(argv[0]);
server.parseCommandLine(argc, argv);
server.initDatabaseService();
try {
server.start();
} catch (castor::exception::Exception &e) {
std::cerr << "Failed to start server : " << e.getMessage().str()
<< std::endl;
return 1;
} catch (...) {
std::cerr << "Failed to start server : Caught an unknown" << std::endl;
return 1;
}
return 0;
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::aggregator::AggregatorServer::AggregatorServer(
const char *const serverName) throw():
castor::server::BaseDaemon(serverName) {
// Initializes the DLF logging including the definition of the predefined
// messages.
dlfInit(s_dlfMessages);
}
//------------------------------------------------------------------------------
// usage
//------------------------------------------------------------------------------
void castor::tape::aggregator::AggregatorServer::usage(const char *const
programName) throw() {
std::cerr << "Usage: " << programName << " [options]\n"
"\n"
"where options can be:\n"
"\n"
"\t-f, --foreground Remain in the Foreground\n"
"\t-c, --config config-file Configuration file\n"
"\t-h, --help Print this help and exit\n"
"\n"
"Comments to: Castor.Support@cern.ch" << std::endl;
}
//------------------------------------------------------------------------------
// parseCommandLine
//------------------------------------------------------------------------------
void castor::tape::aggregator::AggregatorServer::parseCommandLine(int argc,
char *argv[]) throw() {
static struct Coptions longopts[] = {
{"foreground" , NO_ARGUMENT , NULL, 'f'},
{"config" , REQUIRED_ARGUMENT, NULL, 'c'},
{"help" , NO_ARGUMENT , NULL, 'h'},
{NULL , 0 , NULL, 0 }
};
Coptind = 1;
Copterr = 0;
char c;
while ((c = Cgetopt_long (argc, argv, "fc:h", longopts, NULL)) != -1) {
switch (c) {
case 'f':
m_foreground = true;
break;
case 'c':
{
FILE *fp = fopen(Coptarg, "r");
if(fp) {
// The file exists
fclose(fp);
} else {
// The file does not exist
std::stringstream oss;
oss << "Configuration file '" << Coptarg << "' does not exist";
// Log
castor::dlf::Param params[] = {
castor::dlf::Param("reason", oss.str())};
castor::dlf::dlf_writep(nullCuuid, DLF_LVL_ERROR,
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage(argv[0]);
exit(1);
}
}
setenv("PATH_CONFIG", Coptarg, 1);
break;
case 'h':
help(argv[0]);
exit(0);
case '?':
{
std::stringstream oss;
oss << "Unknown command-line option: " << (char)Coptopt;
// Log
castor::dlf::Param params[] = {
castor::dlf::Param("reason", oss.str())};
castor::dlf::dlf_writep(nullCuuid, DLF_LVL_ERROR,
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage(argv[0]);
exit(1);
}
case ':':
{
std::stringstream oss;
oss << "An option is missing a parameter";
// Log
castor::dlf::Param params[] = {
castor::dlf::Param("reason", oss.str())};
castor::dlf::dlf_writep(nullCuuid, DLF_LVL_ERROR,
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage(argv[0]);
exit(1);
}
default:
{
std::stringstream oss;
oss << "Cgetopt_long returned the following unknown value: 0x"
<< std::hex << (int)c;
// Log
castor::dlf::Param params[] = {
castor::dlf::Param("reason", oss.str())};
castor::dlf::dlf_writep(nullCuuid, DLF_LVL_ERROR,
AGGREGATOR_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage(argv[0]);
exit(1);
}
}
}
if(Coptind > argc) {
std::cerr
<< std::endl
<< "Internal error. Invalid value for Coptind: " << Coptind
<< std::endl;
exit(1);
}
// Best to abort if there is some extra text on the command-line which has
// not been parsed as it could indicate that a valid option never got parsed
if(Coptind < argc)
{
std::cerr
<< std::endl
<< "Error: Unexpected command-line argument: "
<< argv[Coptind]
<< std::endl << std::endl;
help(argv[0]);
exit(1);
}
}
//------------------------------------------------------------------------------
// initDatabaseService
//------------------------------------------------------------------------------
void castor::tape::aggregator::AggregatorServer::initDatabaseService() {
// Check the database connection details file exists
FILE *fp = fopen(ORATAPECONFIGFILE, "r");
if(fp) {
// The file exists
fclose(fp);
} else {
// The file does not exist
std::cerr
<< std::endl
<< "Error: Database connection details file \"" << ORATAPECONFIGFILE
<< "\" does not exist"