Commit feeda5c6 authored by Steven Murray's avatar Steven Murray Committed by Victor Kotlyar
Browse files

Simply replaced CASTOR's Exception class with that of CTA

parent 879c4268
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
#include "castor/Constants.hpp" #include "castor/Constants.hpp"
#include "castor/Services.hpp" #include "castor/Services.hpp"
#include "castor/BaseObject.hpp" #include "castor/BaseObject.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/server/Mutex.hpp" #include "castor/server/Mutex.hpp"
#include "castor/server/MutexLocker.hpp" #include "castor/server/MutexLocker.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// static values initialization // static values initialization
...@@ -82,7 +82,7 @@ castor::Services* castor::BaseObject::services() ...@@ -82,7 +82,7 @@ castor::Services* castor::BaseObject::services()
const int rc = pthread_setspecific(s_servicesKey, services); const int rc = pthread_setspecific(s_servicesKey, services);
if(0 != rc) { if(0 != rc) {
delete services; delete services;
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Error caught in call to pthread_setspecific"; e.getMessage() << "Error caught in call to pthread_setspecific";
throw e; throw e;
} }
...@@ -102,7 +102,7 @@ void castor::BaseObject::resetServices() ...@@ -102,7 +102,7 @@ void castor::BaseObject::resetServices()
delete services(); delete services();
const int rc = pthread_setspecific(s_servicesKey, NULL); const int rc = pthread_setspecific(s_servicesKey, NULL);
if(0 != rc) { if(0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to reset the thread's servicesKey to NULL after delete"; e.getMessage() << "Failed to reset the thread's servicesKey to NULL after delete";
throw e; throw e;
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma once #pragma once
// Include Files // Include Files
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
#include <pthread.h> #include <pthread.h>
namespace castor { namespace castor {
...@@ -89,7 +89,7 @@ namespace castor { ...@@ -89,7 +89,7 @@ namespace castor {
pthreadKey() { pthreadKey() {
int rc = pthread_key_create(&m_key, NULL); int rc = pthread_key_create(&m_key, NULL);
if (rc != 0) { if (rc != 0) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Error caught in call to pthread_key_create (from castor::BaseObject::pthreadKey::pthreadKey"; e.getMessage() << "Error caught in call to pthread_key_create (from castor::BaseObject::pthreadKey::pthreadKey";
throw e; throw e;
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
// Include Files // Include Files
#include "castor/IService.hpp" #include "castor/IService.hpp"
#include "castor/Constants.hpp" #include "castor/Constants.hpp"
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
#include <vector> #include <vector>
namespace castor { namespace castor {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "IAddress.hpp" #include "IAddress.hpp"
#include "IObject.hpp" #include "IObject.hpp"
#include "ICnvSvc.hpp" #include "ICnvSvc.hpp"
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Constructor // Constructor
...@@ -65,7 +65,7 @@ castor::IService* castor::Services::service(const std::string name, ...@@ -65,7 +65,7 @@ castor::IService* castor::Services::service(const std::string name,
const ISvcFactory* fac = castor::Factories::instance()->factory(id); const ISvcFactory* fac = castor::Factories::instance()->factory(id);
// if no factory is available, complain // if no factory is available, complain
if (0 == fac) { if (0 == fac) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "No factory found for object type " << id; e.getMessage() << "No factory found for object type " << id;
throw e; throw e;
} }
...@@ -73,7 +73,7 @@ castor::IService* castor::Services::service(const std::string name, ...@@ -73,7 +73,7 @@ castor::IService* castor::Services::service(const std::string name,
IService* svc = fac->instantiate(name); IService* svc = fac->instantiate(name);
// if the service was not instantiated, complain // if the service was not instantiated, complain
if (0 == svc) { if (0 == svc) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "No service found for service " << name; e.getMessage() << "No service found for service " << name;
throw e; throw e;
} else { } else {
...@@ -160,7 +160,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address) ...@@ -160,7 +160,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address)
{ {
// check address // check address
if (0 == address) { if (0 == address) {
castor::exception::Exception ex; cta::exception::Exception ex;
ex.getMessage() << "No appropriate converter for a null address !"; ex.getMessage() << "No appropriate converter for a null address !";
throw ex; throw ex;
} }
...@@ -168,7 +168,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address) ...@@ -168,7 +168,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address)
castor::ICnvSvc *cnvSvc = castor::ICnvSvc *cnvSvc =
cnvService(address->cnvSvcName(), address->cnvSvcType()); cnvService(address->cnvSvcName(), address->cnvSvcType());
if (0 == cnvSvc) { if (0 == cnvSvc) {
castor::exception::Exception ex; cta::exception::Exception ex;
ex.getMessage() << "No conversion service with name " ex.getMessage() << "No conversion service with name "
<< address->cnvSvcName() << " and type " << address->cnvSvcName() << " and type "
<< address->cnvSvcType(); << address->cnvSvcType();
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
//Include Files //Include Files
#include <vector> #include <vector>
#include <map> #include <map>
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
namespace castor { namespace castor {
......
...@@ -60,7 +60,7 @@ std::string castor::System::getHostName() ...@@ -60,7 +60,7 @@ std::string castor::System::getHostName()
if (EINVAL != errno && if (EINVAL != errno &&
ENAMETOOLONG != errno) { ENAMETOOLONG != errno) {
free(hostname); free(hostname);
castor::exception::Exception e(errno); cta::exception::Exception e;
e.getMessage() << "gethostname error"; e.getMessage() << "gethostname error";
throw e; throw e;
} }
...@@ -70,7 +70,7 @@ std::string castor::System::getHostName() ...@@ -70,7 +70,7 @@ std::string castor::System::getHostName()
char *hostnameLonger = (char*) realloc(hostname, len); char *hostnameLonger = (char*) realloc(hostname, len);
if (0 == hostnameLonger) { if (0 == hostnameLonger) {
free(hostname); free(hostname);
castor::exception::Exception e(ENOMEM); cta::exception::Exception e;
e.getMessage() << "Could not allocate memory for hostname"; e.getMessage() << "Could not allocate memory for hostname";
throw e; throw e;
...@@ -83,7 +83,7 @@ std::string castor::System::getHostName() ...@@ -83,7 +83,7 @@ std::string castor::System::getHostName()
if (EINVAL != errno && if (EINVAL != errno &&
ENAMETOOLONG != errno) { ENAMETOOLONG != errno) {
free(hostname); free(hostname);
castor::exception::Exception e(errno); cta::exception::Exception e;
e.getMessage() << "Could not get hostname" e.getMessage() << "Could not get hostname"
<< strerror(errno); << strerror(errno);
throw e; throw e;
...@@ -105,12 +105,12 @@ int castor::System::porttoi(char* str) ...@@ -105,12 +105,12 @@ int castor::System::porttoi(char* str)
errno = 0; errno = 0;
int iport = strtoul(str, &dp, 0); int iport = strtoul(str, &dp, 0);
if (*dp != 0) { if (*dp != 0) {
castor::exception::Exception e(errno); cta::exception::Exception e;
e.getMessage() << "Bad port value." << std::endl; e.getMessage() << "Bad port value." << std::endl;
throw e; throw e;
} }
if ((iport > 65535) || (iport < 0)) { if ((iport > 65535) || (iport < 0)) {
castor::exception::Exception e(errno); cta::exception::Exception e;
e.getMessage() e.getMessage()
<< "Invalid port value : " << iport << "Invalid port value : " << iport
<< ". Must be < 65535 and > 0." << std::endl; << ". Must be < 65535 and > 0." << std::endl;
...@@ -138,27 +138,27 @@ void castor::System::switchToCastorSuperuser() ...@@ -138,27 +138,27 @@ void castor::System::switchToCastorSuperuser()
// Get information on generic stage account from password file // Get information on generic stage account from password file
if ((stage_passwd = getpwnam(STAGERSUPERUSER)) == NULL) { if ((stage_passwd = getpwnam(STAGERSUPERUSER)) == NULL) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Castor super user " << STAGERSUPERUSER e.getMessage() << "Castor super user " << STAGERSUPERUSER
<< " not found in password file"; << " not found in password file";
throw e; throw e;
} }
// verify existence of its primary group id // verify existence of its primary group id
if (getgrgid(stage_passwd->pw_gid) == NULL) { if (getgrgid(stage_passwd->pw_gid) == NULL) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Castor super user group does not exist"; e.getMessage() << "Castor super user group does not exist";
throw e; throw e;
} }
// Get information on generic stage account from group file // Get information on generic stage account from group file
if ((stage_group = getgrnam(STAGERSUPERGROUP)) == NULL) { if ((stage_group = getgrnam(STAGERSUPERGROUP)) == NULL) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Castor super user group " << STAGERSUPERGROUP e.getMessage() << "Castor super user group " << STAGERSUPERGROUP
<< " not found in group file"; << " not found in group file";
throw e; throw e;
} }
// Verify consistency // Verify consistency
if (stage_group->gr_gid != stage_passwd->pw_gid) { if (stage_group->gr_gid != stage_passwd->pw_gid) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Inconsistent password file. The group of the " e.getMessage() << "Inconsistent password file. The group of the "
<< "castor superuser " << STAGERSUPERUSER << "castor superuser " << STAGERSUPERUSER
<< " should be " << stage_group->gr_gid << " should be " << stage_group->gr_gid
...@@ -168,25 +168,25 @@ void castor::System::switchToCastorSuperuser() ...@@ -168,25 +168,25 @@ void castor::System::switchToCastorSuperuser()
} }
// Undo group privilege // Undo group privilege
if (setregid (egid, rgid) < 0) { if (setregid (egid, rgid) < 0) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Unable to undo group privilege"; e.getMessage() << "Unable to undo group privilege";
throw e; throw e;
} }
// Undo user privilege // Undo user privilege
if (setreuid (euid, ruid) < 0) { if (setreuid (euid, ruid) < 0) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Unable to undo user privilege"; e.getMessage() << "Unable to undo user privilege";
throw e; throw e;
} }
// set the effective privileges to superuser // set the effective privileges to superuser
if (setegid(stage_passwd->pw_gid) < 0) { if (setegid(stage_passwd->pw_gid) < 0) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Unable to set group privileges of Castor Superuser. " e.getMessage() << "Unable to set group privileges of Castor Superuser. "
<< "You may want to check that the suid bit is set properly"; << "You may want to check that the suid bit is set properly";
throw e; throw e;
} }
if (seteuid(stage_passwd->pw_uid) < 0) { if (seteuid(stage_passwd->pw_uid) < 0) {
castor::exception::Exception e; cta::exception::Exception e;
e.getMessage() << "Unable to set privileges of Castor Superuser."; e.getMessage() << "Unable to set privileges of Castor Superuser.";
throw e; throw e;
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// Include Files // Include Files
#include <string> #include <string>
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
namespace castor { namespace castor {
......
...@@ -44,7 +44,7 @@ castor::common::CastorConfiguration::getConfig(std::string fileName) ...@@ -44,7 +44,7 @@ castor::common::CastorConfiguration::getConfig(std::string fileName)
// lock // lock
int rc = pthread_mutex_lock(&s_globalConfigLock); int rc = pthread_mutex_lock(&s_globalConfigLock);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to get CASTOR configuration:" e.getMessage() << "Failed to get CASTOR configuration:"
" Failed to take a lock on s_globalConfigLock"; " Failed to take a lock on s_globalConfigLock";
throw e; throw e;
...@@ -77,7 +77,7 @@ castor::common::CastorConfiguration::CastorConfiguration(std::string fileName) ...@@ -77,7 +77,7 @@ castor::common::CastorConfiguration::CastorConfiguration(std::string fileName)
// create internal r/w lock // create internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL); int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "CastorConfiguration constructor Failed" e.getMessage() << "CastorConfiguration constructor Failed"
": Failed to create internal r/w lock"; ": Failed to create internal r/w lock";
throw e; throw e;
...@@ -94,7 +94,7 @@ castor::common::CastorConfiguration::CastorConfiguration( ...@@ -94,7 +94,7 @@ castor::common::CastorConfiguration::CastorConfiguration(
// create a new internal r/w lock // create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL); int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "CastorConfiguration copy constructor failed" e.getMessage() << "CastorConfiguration copy constructor failed"
": Failed to create a new internal r/w lock"; ": Failed to create a new internal r/w lock";
throw e; throw e;
...@@ -122,7 +122,7 @@ castor::common::CastorConfiguration & ...@@ -122,7 +122,7 @@ castor::common::CastorConfiguration &
// create a new internal r/w lock // create a new internal r/w lock
int rc = pthread_rwlock_init(&m_lock, NULL); int rc = pthread_rwlock_init(&m_lock, NULL);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Assignment operator of CastorConfiguration object failed" e.getMessage() << "Assignment operator of CastorConfiguration object failed"
": Failed to create a new internal r/w lock"; ": Failed to create a new internal r/w lock";
throw e; throw e;
...@@ -143,7 +143,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString( ...@@ -143,7 +143,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
// get read lock // get read lock
int rc = pthread_rwlock_rdlock(&m_lock); int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to get configuration entry " << category << ":" e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to get read lock"; << key << ": Failed to get read lock";
throw e; throw e;
...@@ -178,7 +178,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString( ...@@ -178,7 +178,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
} }
// Unlock and return default // Unlock and return default
pthread_rwlock_unlock(&m_lock); pthread_rwlock_unlock(&m_lock);
} catch (castor::exception::Exception ex) { } catch (cta::exception::Exception ex) {
// exception caught : Unlock and return default // exception caught : Unlock and return default
pthread_rwlock_unlock(&m_lock); pthread_rwlock_unlock(&m_lock);
// log the exception // log the exception
...@@ -210,7 +210,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString( ...@@ -210,7 +210,7 @@ const std::string& castor::common::CastorConfiguration::getConfEntString(
// get read lock // get read lock
int rc = pthread_rwlock_rdlock(&m_lock); int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to get configuration entry " << category << ":" e.getMessage() << "Failed to get configuration entry " << category << ":"
<< key << ": Failed to get read lock"; << key << ": Failed to get read lock";
throw e; throw e;
...@@ -261,7 +261,7 @@ bool castor::common::CastorConfiguration::isStale() ...@@ -261,7 +261,7 @@ bool castor::common::CastorConfiguration::isStale()
// get read lock // get read lock
int rc = pthread_rwlock_rdlock(&m_lock); int rc = pthread_rwlock_rdlock(&m_lock);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to determine if CASTOR configuration is stale" e.getMessage() << "Failed to determine if CASTOR configuration is stale"
": Failed to get read lock"; ": Failed to get read lock";
throw e; throw e;
...@@ -288,7 +288,7 @@ void castor::common::CastorConfiguration::tryToRenewConfig() ...@@ -288,7 +288,7 @@ void castor::common::CastorConfiguration::tryToRenewConfig()
// we should probably renew. First take the write lock. // we should probably renew. First take the write lock.
int rc = pthread_rwlock_wrlock(&m_lock); int rc = pthread_rwlock_wrlock(&m_lock);
if (0 != rc) { if (0 != rc) {
castor::exception::Exception e(rc); cta::exception::Exception e;
e.getMessage() << "Failed to renew configuration cache" e.getMessage() << "Failed to renew configuration cache"
": Failed to take write lock"; ": Failed to take write lock";
throw e; throw e;
...@@ -343,7 +343,7 @@ void castor::common::CastorConfiguration::renewConfigNolock() ...@@ -343,7 +343,7 @@ void castor::common::CastorConfiguration::renewConfigNolock()
// failure // failure
std::ifstream file(m_fileName.c_str()); std::ifstream file(m_fileName.c_str());
if(file.fail()) { if(file.fail()) {
castor::exception::Exception ex(EIO); cta::exception::Exception ex;
ex.getMessage() << __FUNCTION__ << " failed" ex.getMessage() << __FUNCTION__ << " failed"
": Failed to open file" ": Failed to open file"
": m_fileName=" << m_fileName; ": m_fileName=" << m_fileName;
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
#pragma once #pragma once
#include "castor/exception/Exception.hpp"
#include "castor/exception/NoEntry.hpp" #include "castor/exception/NoEntry.hpp"
#include "castor/log/Logger.hpp" #include "castor/log/Logger.hpp"
#include "castor/utils/utils.hpp" #include "castor/utils/utils.hpp"
#include "common/exception/Exception.hpp"
#include <string> #include <string>
#include <map> #include <map>
...@@ -141,7 +141,7 @@ namespace castor { ...@@ -141,7 +141,7 @@ namespace castor {
std::string strValue; std::string strValue;
try { try {
strValue = getConfEntString(category, key); strValue = getConfEntString(category, key);
} catch(castor::exception::Exception &ex) { } catch(cta::exception::Exception &ex) {
if(NULL != log) { if(NULL != log) {
std::list<log::Param> params = { std::list<log::Param> params = {
log::Param("category", category), log::Param("category", category),
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
castor::exception::AcceptConnectionInterrupted::AcceptConnectionInterrupted( castor::exception::AcceptConnectionInterrupted::AcceptConnectionInterrupted(
const time_t remainingTime) throw() : const time_t remainingTime) throw() :
castor::exception::Exception(666), cta::exception::Exception(),
m_remainingTime(remainingTime) { m_remainingTime(remainingTime) {
// Do nothing // Do nothing
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#pragma once #pragma once
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
#include <sys/types.h> #include <sys/types.h>
...@@ -33,7 +33,7 @@ namespace exception { ...@@ -33,7 +33,7 @@ namespace exception {
/** /**
* castor::io::acceptConnection() was interrupted. * castor::io::acceptConnection() was interrupted.
*/ */
class AcceptConnectionInterrupted : public castor::exception::Exception { class AcceptConnectionInterrupted : public cta::exception::Exception {
public: public:
......
...@@ -28,5 +28,5 @@ ...@@ -28,5 +28,5 @@
// Constructor // Constructor
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
castor::exception::BadAlloc::BadAlloc(): castor::exception::BadAlloc::BadAlloc():
castor::exception::Exception(666) { cta::exception::Exception() {
} }
...@@ -23,14 +23,14 @@ ...@@ -23,14 +23,14 @@
#pragma once #pragma once
#include "castor/exception/Exception.hpp" #include "common/exception/Exception.hpp"
namespace castor { namespace exception { namespace castor { namespace exception {
/** /**
* BadAlloc. * BadAlloc.
*/ */
class BadAlloc : public castor::exception::Exception { class BadAlloc : public cta::exception::Exception {
public: public:
......
...@@ -28,5 +28,5 @@ ...@@ -28,5 +28,5 @@
// Constructor // Constructor
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
castor::exception::CommandLineNotParsed::CommandLineNotParsed(): castor::exception::CommandLineNotParsed::CommandLineNotParsed():
castor::exception::Exception(666) { cta::exception::Exception() {
} }