Skip to content
Snippets Groups Projects
Commit e3b92ab6 authored by Marco De Marco's avatar Marco De Marco
Browse files

Code refactoring almost complete

parent bad4b1c5
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ void Client::start() ...@@ -53,7 +53,7 @@ void Client::start()
{ {
DEBUG_STREAM << "Client::start()" << endl; DEBUG_STREAM << "Client::start()" << endl;
m_dBManager_sp->connect(); m_dBManager_sp->connectAll();
m_protocolManager_sp = ProtocolManager::create(m_deviceImpl_p, m_protocolManager_sp = ProtocolManager::create(m_deviceImpl_p,
m_configuration_sp, m_dBManager_sp); m_configuration_sp, m_dBManager_sp);
...@@ -91,7 +91,10 @@ void Client::stop() ...@@ -91,7 +91,10 @@ void Client::stop()
m_protocolManager_sp.reset(); m_protocolManager_sp.reset();
m_dBManager_sp->disconnect(); m_dBManager_sp->disconnectAll();
writeState(Tango::OFF);
writeStatus("Database loop paused");
} }
//============================================================================== //==============================================================================
...@@ -188,7 +191,7 @@ void Client::startUpdateLists() ...@@ -188,7 +191,7 @@ void Client::startUpdateLists()
m_protocolManager_sp->updateFileLists(); m_protocolManager_sp->updateFileLists();
writeState(Tango::ON); writeState(Tango::ON);
writeStatus("Looking for new files"); writeStatus("Database loop active");
} }
catch(std::exception& ec) catch(std::exception& ec)
{ {
...@@ -341,8 +344,7 @@ void Client::handleReadResponseBody(const boost::system::error_code& errorCode) ...@@ -341,8 +344,7 @@ void Client::handleReadResponseBody(const boost::system::error_code& errorCode)
{ {
WARN_STREAM << "Client::handleReadResponseBody() " << ec.what() << endl; WARN_STREAM << "Client::handleReadResponseBody() " << ec.what() << endl;
writeState(Tango::ALARM); onTransferFailed();
writeStatus(ec.what());
} }
catch(std::runtime_error& ec) catch(std::runtime_error& ec)
{ {
...@@ -387,9 +389,36 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte ...@@ -387,9 +389,36 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte
} }
else else
{ {
INFO_STREAM << "Client::handleReadData() transfer complete " << endl; onTransferCompleted(fileWrapper_sp);
}
}
else
{
WARN_STREAM << "Client::handleReadData() bad I/O" << endl;
onTransferFailed();
}
}
else
{
ERROR_STREAM << "Client::handleReadData() "
<< errorCode.message() << " from " << m_remoteEndpoint << endl;
writeState(Tango::ALARM);
writeStatus(errorCode.message());
}
}
//==============================================================================
// Client::onTransferCompleted()
//==============================================================================
void Client::onTransferCompleted(FileWrapper::SP fileWrapper_sp)
{
DEBUG_STREAM << "Client::onTransferCompleted()" << endl;
m_protocolManager_sp->markAsCompleted(); try
{
m_protocolManager_sp->setFileTransfered(fileWrapper_sp);
m_protocolManager_sp->nextFile(); m_protocolManager_sp->nextFile();
...@@ -404,22 +433,59 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte ...@@ -404,22 +433,59 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte
startUpdateLists(); startUpdateLists();
} }
} }
catch(std::exception& ec)
{
ERROR_STREAM << "Client::onTransferCompleted() " << ec.what() << endl;
writeState(Tango::ALARM);
writeStatus(ec.what());
} }
else catch(...)
{ {
ERROR_STREAM << "Client::handleReadData() bad I/O" << endl; ERROR_STREAM << "Client::onTransferCompleted() Unknown error" << endl;
writeState(Tango::ALARM); writeState(Tango::ALARM);
writeStatus("Bad I/O"); writeStatus("Unknown error");
}
} }
//==============================================================================
// Client::onTransferFailed()
//==============================================================================
void Client::onTransferFailed()
{
DEBUG_STREAM << "Client::onTransferFailed()" << endl;
try
{
m_protocolManager_sp->setFileFailed();
m_protocolManager_sp->nextFile();
if(m_protocolManager_sp->hasNextFile())
{
startWriteRequest();
} }
else else
{ {
ERROR_STREAM << "Client::handleReadData() " closeConnection();
<< errorCode.message() << " from " << m_remoteEndpoint << endl;
startUpdateLists();
}
}
catch(std::exception& ec)
{
ERROR_STREAM << "Client::onTransferFailed() " << ec.what() << endl;
writeState(Tango::ALARM); writeState(Tango::ALARM);
writeStatus(errorCode.message()); writeStatus(ec.what());
}
catch(...)
{
ERROR_STREAM << "Client::onTransferFailed() Unknown error" << endl;
writeState(Tango::ALARM);
writeStatus("Unknown error");
} }
} }
......
...@@ -116,6 +116,13 @@ protected: ...@@ -116,6 +116,13 @@ protected:
virtual void handleReadData(FileWrapper::SP, std::size_t, virtual void handleReadData(FileWrapper::SP, std::size_t,
const boost::system::error_code&); const boost::system::error_code&);
//------------------------------------------------------------------------------
// [Protected] Transfer result methods
//------------------------------------------------------------------------------
void onTransferCompleted(FileWrapper::SP);
void onTransferFailed();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Connection reset and timeout handler methods // [Protected] Connection reset and timeout handler methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -52,7 +52,7 @@ DBManager::SP DBManager::create(Tango::DeviceImpl* deviceImpl_p, ...@@ -52,7 +52,7 @@ DBManager::SP DBManager::create(Tango::DeviceImpl* deviceImpl_p,
//============================================================================== //==============================================================================
// DBManager::connect() // DBManager::connect()
//============================================================================== //==============================================================================
void DBManager::connect() throw(soci::soci_error) void DBManager::connectAll() throw(soci::soci_error)
{ {
DEBUG_STREAM << "DBManager::connect()" << endl; DEBUG_STREAM << "DBManager::connect()" << endl;
...@@ -88,7 +88,7 @@ void DBManager::connect() throw(soci::soci_error) ...@@ -88,7 +88,7 @@ void DBManager::connect() throw(soci::soci_error)
//============================================================================== //==============================================================================
// DBManager::disconnect() // DBManager::disconnect()
//============================================================================== //==============================================================================
void DBManager::disconnect() void DBManager::disconnectAll()
{ {
DEBUG_STREAM << "DBManager::disconnect()" << endl; DEBUG_STREAM << "DBManager::disconnect()" << endl;
...@@ -99,6 +99,34 @@ void DBManager::disconnect() ...@@ -99,6 +99,34 @@ void DBManager::disconnect()
m_auxSession_sp->close(); m_auxSession_sp->close();
} }
//==============================================================================
// DBManager::getMainTransaction()
//==============================================================================
DBManager::TransactionSP DBManager::getMainTransaction()
{
DEBUG_STREAM << "DBManager::getMainTransaction()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
TransactionSP transaction_sp(new soci::transaction(*m_mainSession_sp));
return transaction_sp;
}
//==============================================================================
// DBManager::getAuxTransaction()
//==============================================================================
DBManager::TransactionSP DBManager::getAuxTransaction()
{
DEBUG_STREAM << "DBManager::getAuxTransaction()" << endl;
boost::mutex::scoped_lock lock(m_sessionMutex);
TransactionSP transaction_sp(new soci::transaction(*m_auxSession_sp));
return transaction_sp;
}
//============================================================================== //==============================================================================
// DBManager::retrieveNewFiles() // DBManager::retrieveNewFiles()
//============================================================================== //==============================================================================
...@@ -134,10 +162,10 @@ void DBManager::updateNewFilePath(std::string storagePath, std::string filePath, ...@@ -134,10 +162,10 @@ void DBManager::updateNewFilePath(std::string storagePath, std::string filePath,
if(m_mainSession_sp->get_backend() == NULL) if(m_mainSession_sp->get_backend() == NULL)
m_mainSession_sp->reconnect(); m_mainSession_sp->reconnect();
*m_mainSession_sp << "insert into " << m_configuration_sp->getDatabaseSchema() *m_mainSession_sp << "update " << m_configuration_sp->getDatabaseSchema()
<< "." << m_configuration_sp->getDatabaseTable() << " (storage_path, " << "." << m_configuration_sp->getDatabaseTable()
<< "file_path) values (:storagePath, :filePath) where file_version = " << " set storage_path = :storagePath, file_path = :filePath "
<< ":fileVersion and file_name like :FileName", << " where file_version = :fileVersion and file_name like :fileName",
soci::use(storagePath, "storagePath"), soci::use(filePath, "filePath"), soci::use(storagePath, "storagePath"), soci::use(filePath, "filePath"),
soci::use(fileVersion, "fileVersion"), soci::use(fileName, "fileName"); soci::use(fileVersion, "fileVersion"), soci::use(fileName, "fileName");
} }
......
...@@ -61,11 +61,20 @@ public: ...@@ -61,11 +61,20 @@ public:
static DBManager::SP create(Tango::DeviceImpl*, Configuration::SP); static DBManager::SP create(Tango::DeviceImpl*, Configuration::SP);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] Connection handling methods // [Public] Connections handling methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
virtual void connect() throw(soci::soci_error); virtual void connectAll() throw(soci::soci_error);
virtual void disconnect(); virtual void disconnectAll();
//------------------------------------------------------------------------------
// [Public] Transaction retriever methods
//------------------------------------------------------------------------------
typedef boost::shared_ptr<soci::transaction> TransactionSP;
TransactionSP getMainTransaction();
TransactionSP getAuxTransaction();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] New file method // [Public] New file method
......
...@@ -7,13 +7,34 @@ namespace DataImporter_ns ...@@ -7,13 +7,34 @@ namespace DataImporter_ns
// FileWrapper::FileWrapper() // FileWrapper::FileWrapper()
//============================================================================== //==============================================================================
FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p, FileWrapper::FileWrapper(Tango::DeviceImpl* deviceImpl_p,
boost::filesystem::path filePath, boost::uint64_t totalFileSize) : std::string storagePath, std::string filePath, int fileVersion,
Tango::LogAdapter(deviceImpl_p), m_totalFileSize(totalFileSize) std::string fileName, boost::uint64_t totalFileSize) throw(std::logic_error)
: Tango::LogAdapter(deviceImpl_p), m_storagePath(storagePath),
m_filePath(filePath), m_fileVersion(fileVersion), m_fileName(fileName),
m_totalFileSize(totalFileSize)
{ {
DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl; DEBUG_STREAM << "FileWrapper::FileWrapper()" << endl;
m_outputFileStream.open(filePath.string(), std::ios::binary); boost::filesystem::path destPath(storagePath);
destPath /= filePath;
std::stringstream fileStream;
fileStream << "/" << fileVersion;
destPath /= fileStream.str();
if(!boost::filesystem::exists(destPath))
boost::filesystem::create_directories(destPath);
if(!boost::filesystem::is_directory(destPath))
throw std::logic_error("Destination path \'"
+ destPath.string() + "\' is not a directory" );
destPath /= fileName;
m_outputFileStream.open(destPath.string(), std::ios::binary);
} }
//============================================================================== //==============================================================================
...@@ -30,14 +51,56 @@ FileWrapper::~FileWrapper() ...@@ -30,14 +51,56 @@ FileWrapper::~FileWrapper()
// FileWrapper::create() // FileWrapper::create()
//============================================================================== //==============================================================================
FileWrapper::SP FileWrapper::create(Tango::DeviceImpl* deviceImpl_p, FileWrapper::SP FileWrapper::create(Tango::DeviceImpl* deviceImpl_p,
boost::filesystem::path filePath, boost::uint64_t totalFileSize) std::string storagePath, std::string filePath, int fileVersion,
std::string fileName, boost::uint64_t fileSize)
throw(std::logic_error)
{ {
FileWrapper::SP d_sp(new FileWrapper(deviceImpl_p, filePath, totalFileSize), FileWrapper::SP d_sp(new FileWrapper(deviceImpl_p, storagePath, filePath,
FileWrapper::Deleter()); fileVersion, fileName, fileSize), FileWrapper::Deleter());
return d_sp; return d_sp;
} }
//==============================================================================
// FileWrapper::getStoragePath()
//==============================================================================
std::string FileWrapper::getStoragePath()
{
DEBUG_STREAM << "FileWrapper::getStoragePath()" << endl;
return m_storagePath;
}
//==============================================================================
// FileWrapper::getFilePath()
//==============================================================================
std::string FileWrapper::getFilePath()
{
DEBUG_STREAM << "FileWrapper::getFilePath()" << endl;
return m_filePath;
}
//==============================================================================
// FileWrapper::getFileVersion()
//==============================================================================
int FileWrapper::getFileVersion()
{
DEBUG_STREAM << "FileWrapper::getFileVersion()" << endl;
return m_fileVersion;
}
//==============================================================================
// FileWrapper::getFileName()
//==============================================================================
std::string FileWrapper::getFileName()
{
DEBUG_STREAM << "FileWrapper::getFileName()" << endl;
return m_fileName;
}
//============================================================================== //==============================================================================
// FileWrapper::isOpen() // FileWrapper::isOpen()
//============================================================================== //==============================================================================
......
...@@ -20,7 +20,8 @@ protected: ...@@ -20,7 +20,8 @@ protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Constructor destructor deleter // [Protected] Constructor destructor deleter
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
FileWrapper(Tango::DeviceImpl*, boost::filesystem::path, boost::uint64_t); FileWrapper(Tango::DeviceImpl*, std::string, std::string, int, std::string,
boost::uint64_t) throw(std::logic_error);
virtual ~FileWrapper(); virtual ~FileWrapper();
...@@ -36,8 +37,19 @@ public: ...@@ -36,8 +37,19 @@ public:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] Class creation method // [Public] Class creation method
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static FileWrapper::SP create(Tango::DeviceImpl*, static FileWrapper::SP create(Tango::DeviceImpl*, std::string, std::string,
boost::filesystem::path, boost::uint64_t); int, std::string, boost::uint64_t) throw(std::logic_error);
//------------------------------------------------------------------------------
// [Public] Properties getter methods
//------------------------------------------------------------------------------
virtual std::string getStoragePath();
virtual std::string getFilePath();
virtual int getFileVersion();
virtual std::string getFileName();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] Input stream methods // [Public] Input stream methods
...@@ -56,6 +68,18 @@ protected: ...@@ -56,6 +68,18 @@ protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Class variables // [Protected] Class variables
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//Storage path property
const std::string m_storagePath;
//File path property
const std::string m_filePath;
//File version property
const int m_fileVersion;
//File name property
const std::string m_fileName;
//Input file size //Input file size
boost::uint64_t m_totalFileSize; boost::uint64_t m_totalFileSize;
......
...@@ -57,6 +57,7 @@ void PlainClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPoint ...@@ -57,6 +57,7 @@ void PlainClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPoint
DEBUG_STREAM << "PlainClient::startConnect() " << infoStream.str() << endl; DEBUG_STREAM << "PlainClient::startConnect() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str()); writeStatus(infoStream.str());
m_plainSocket.async_connect(endPointIterator->endpoint(), m_plainSocket.async_connect(endPointIterator->endpoint(),
...@@ -147,8 +148,7 @@ void PlainClient::startWriteRequest() ...@@ -147,8 +148,7 @@ void PlainClient::startWriteRequest()
{ {
WARN_STREAM << "PlainClient::startWriteRequest() " << ec.what() << endl; WARN_STREAM << "PlainClient::startWriteRequest() " << ec.what() << endl;
writeState(Tango::ALARM); onTransferFailed();
writeStatus(ec.what());
} }
catch(std::runtime_error& ec) catch(std::runtime_error& ec)
{ {
......
...@@ -49,7 +49,7 @@ void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint) ...@@ -49,7 +49,7 @@ void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint)
//============================================================================== //==============================================================================
// ProtocolManager::updateFileLists() // ProtocolManager::updateFileLists()
//============================================================================== //==============================================================================
void ProtocolManager::updateFileLists() throw(soci::soci_error) void ProtocolManager::updateFileLists() throw(std::runtime_error)
{ {
DEBUG_STREAM << "ProtocolManager::updateFileLists()" << endl; DEBUG_STREAM << "ProtocolManager::updateFileLists()" << endl;
...@@ -60,11 +60,9 @@ void ProtocolManager::updateFileLists() throw(soci::soci_error) ...@@ -60,11 +60,9 @@ void ProtocolManager::updateFileLists() throw(soci::soci_error)
<< boost::posix_time::to_simple_string(m_lastTimestamp) << endl; << boost::posix_time::to_simple_string(m_lastTimestamp) << endl;
m_newFileRowset_sp = m_dBManager_sp->retrieveNewFiles(m_lastTimestamp); m_newFileRowset_sp = m_dBManager_sp->retrieveNewFiles(m_lastTimestamp);
m_newFileRowsetIt = m_newFileRowset_sp->begin(); m_newFileRowsetIt = m_newFileRowset_sp->begin();
m_failedFileRowset_sp = m_dBManager_sp->retrieveFailedFiles(); m_failedFileRowset_sp = m_dBManager_sp->retrieveFailedFiles();
m_failedFileRowsetIt = m_failedFileRowset_sp->begin(); m_failedFileRowsetIt = m_failedFileRowset_sp->begin();
} }
...@@ -100,58 +98,6 @@ bool ProtocolManager::hasNextFile() ...@@ -100,58 +98,6 @@ bool ProtocolManager::hasNextFile()
} }
} }
//==============================================================================
// ProtocolManager::markAsCompleted()
//==============================================================================
void ProtocolManager::markAsCompleted()
{
DEBUG_STREAM << "ProtocolManager::markAsCompleted()" << endl;
if(!m_recoveryMode)
{
if(!m_newFileRowset_sp ||
m_newFileRowsetIt == m_newFileRowset_sp->end())
throw std::runtime_error("New list not initialized or empty");
if(!m_newFileRowsetIt->get<0>())
throw std::invalid_argument("Empty file version found on new list");
int fileVersion = m_newFileRowsetIt->get<0>().get();
if(!m_newFileRowsetIt->get<1>())
throw std::invalid_argument("Empty file name found on new list");
std::string fileName = m_newFileRowsetIt->get<1>().get();
if(!m_newFileRowsetIt->get<2>())
throw std::invalid_argument("Empty update time found on new list");
std::tm update_time = m_newFileRowsetIt->get<2>().get();
INFO_STREAM << "ProtocolManager::createRequest() mark completed "
<< fileName << " version " << fileVersion << endl;
boost::posix_time::ptime current_time =
boost::posix_time::ptime_from_tm(update_time);
INFO_STREAM << "ProtocolManager::createRequest() "
<< boost::posix_time::to_simple_string(current_time) << endl;
m_dBManager_sp->persistLastTimestamp(current_time);
}
else
{
ERROR_STREAM << "ProtocolManager::createRequest() mark failed list" << endl;
}
}
//==============================================================================
// ProtocolManager::markAsFailed()
//==============================================================================
void ProtocolManager::markAsFailed()
{
DEBUG_STREAM << "ProtocolManager::markAsFailed()" << endl;
}
//============================================================================== //==============================================================================
// ProtocolManager::nextFile() // ProtocolManager::nextFile()
//============================================================================== //==============================================================================
...@@ -269,26 +215,14 @@ FileWrapper::SP ProtocolManager::processResponse(ResponseSP response_sp) ...@@ -269,26 +215,14 @@ FileWrapper::SP ProtocolManager::processResponse(ResponseSP response_sp)
boost::uint64_t fileSize = response_sp->file_size(); boost::uint64_t fileSize = response_sp->file_size();
boost::filesystem::path destPath = composePath(
m_configuration_sp->getStoragePath(), filePath, fileVersion);
if(!boost::filesystem::exists(destPath))
boost::filesystem::create_directories(destPath);
if(!boost::filesystem::is_directory(destPath))
throw std::invalid_argument("Destination path \'"
+ destPath.string() + "\' is not a directory" );
FileWrapper::SP fileWrapper_sp;
if(response_sp->state() == Response::REQUEST_ACCEPTED) if(response_sp->state() == Response::REQUEST_ACCEPTED)
{ {
INFO_STREAM << "ProtocolManager::processResponse() transfer file " INFO_STREAM << "ProtocolManager::processResponse() transfer file "
<< fileName << " version " << fileVersion << " size " << fileSize << endl; << fileName << " version " << fileVersion << " size " << fileSize << endl;
destPath /= fileName; return FileWrapper::create(m_deviceImpl_p,
m_configuration_sp->getStoragePath(), filePath,
fileWrapper_sp = FileWrapper::create(m_deviceImpl_p, destPath, fileSize); fileVersion, fileName, fileSize);
} }
else if(response_sp->state() == Response::METADATA_NOT_FOUND || else if(response_sp->state() == Response::METADATA_NOT_FOUND ||
response_sp->state() == Response::FILE_NOT_DOWNLOADED || response_sp->state() == Response::FILE_NOT_DOWNLOADED ||
...@@ -297,33 +231,110 @@ FileWrapper::SP ProtocolManager::processResponse(ResponseSP response_sp) ...@@ -297,33 +231,110 @@ FileWrapper::SP ProtocolManager::processResponse(ResponseSP response_sp)
throw std::logic_error(response_sp->status()); throw std::logic_error(response_sp->status());
} }
else else
{
throw std::runtime_error(response_sp->status()); throw std::runtime_error(response_sp->status());
} }
return fileWrapper_sp;
}
//============================================================================== //==============================================================================
// ProtocolManager::composePath() // ProtocolManager::setFileTransfered()
//============================================================================== //==============================================================================
boost::filesystem::path ProtocolManager::composePath(std::string storagePath, void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp)
std::string filePath, int fileVersion) throw(std::logic_error, std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::setFileTransfered()" << endl;
std::string storagePath = fileWrapper_sp->getStoragePath();
std::string filePath = fileWrapper_sp->getFilePath();
if(!m_recoveryMode)
{
if(!m_newFileRowset_sp ||
m_newFileRowsetIt == m_newFileRowset_sp->end())
throw std::runtime_error("New list not initialized or empty");
if(!m_newFileRowsetIt->get<0>())
throw std::invalid_argument("Empty file version found on new list");
int fileVersion = m_newFileRowsetIt->get<0>().get();
if(!m_newFileRowsetIt->get<1>())
throw std::invalid_argument("Empty file name found on new list");
std::string fileName = m_newFileRowsetIt->get<1>().get();
if(!m_newFileRowsetIt->get<2>())
throw std::invalid_argument("Empty update time found on new list");
std::tm update_time = m_newFileRowsetIt->get<2>().get();
INFO_STREAM << "ProtocolManager::setFileTransfered() file "
<< fileName << " version " << fileVersion << " transfered" << endl;
boost::posix_time::ptime newPtime = boost::posix_time::ptime_from_tm(update_time);
if(m_currentPtime.is_not_a_date_time())
m_currentPtime = newPtime;
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
if(newPtime > m_currentPtime)
m_dBManager_sp->persistLastTimestamp(newPtime);
m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
}
else
{ {
DEBUG_STREAM << "ProtocolManager::composePath()" << endl; if(!m_failedFileRowset_sp ||
m_failedFileRowsetIt == m_failedFileRowset_sp->end())
throw std::runtime_error("Failed list not initialized or empty");
boost::filesystem::path path(storagePath); if(!m_failedFileRowsetIt->get<0>())
throw std::invalid_argument("Empty file version found on failed list");
int fileVersion = m_failedFileRowsetIt->get<0>().get();
path /= filePath; if(!m_failedFileRowsetIt->get<1>())
throw std::invalid_argument("Empty file name found on failed list");
string fileName = m_failedFileRowsetIt->get<1>().get();
DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction();
DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction();
m_dBManager_sp->removeFailedFile(fileVersion, fileName);
m_dBManager_sp->updateNewFilePath(storagePath, filePath, fileVersion, fileName);
auxTransaction_sp->commit();
mainTransaction_sp->commit();
}
}
//==============================================================================
// ProtocolManager::markAsFailed()
//==============================================================================
void ProtocolManager::setFileFailed() throw(std::logic_error, std::runtime_error)
{
DEBUG_STREAM << "ProtocolManager::markAsFailed()" << endl;
std::stringstream fileStream; if(!m_recoveryMode)
fileStream << "/" << fileVersion; {
if(!m_newFileRowset_sp ||
m_newFileRowsetIt == m_newFileRowset_sp->end())
throw std::runtime_error("New list not initialized or empty");
path /= fileStream.str(); if(!m_newFileRowsetIt->get<0>())
throw std::invalid_argument("Empty file version found on new list");
int fileVersion = m_newFileRowsetIt->get<0>().get();
DEBUG_STREAM << "ProtocolManager::composePath() \'" << path << "\'" << endl; if(!m_newFileRowsetIt->get<1>())
throw std::invalid_argument("Empty file name found on new list");
string fileName = m_newFileRowsetIt->get<1>().get();
return path; m_dBManager_sp->addFailedFile(fileVersion, fileName);
}
else
{
//TODO: file failed again -> what to do?
}
} }
} //namespace } //namespace
...@@ -59,14 +59,10 @@ public: ...@@ -59,14 +59,10 @@ public:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Public] Files list methods // [Public] Files list methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
virtual void updateFileLists() throw(soci::soci_error); virtual void updateFileLists() throw(std::runtime_error);
virtual bool hasNextFile(); virtual bool hasNextFile();
virtual void markAsCompleted();
virtual void markAsFailed();
virtual void nextFile(); virtual void nextFile();
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -78,12 +74,16 @@ public: ...@@ -78,12 +74,16 @@ public:
FileWrapper::SP processResponse(ResponseSP) FileWrapper::SP processResponse(ResponseSP)
throw(std::logic_error, std::runtime_error); throw(std::logic_error, std::runtime_error);
protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] File path method // [Public] Files status methods
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
virtual boost::filesystem::path composePath(std::string, std::string, int); virtual void setFileTransfered(FileWrapper::SP)
throw(std::logic_error, std::runtime_error);
virtual void setFileFailed()
throw(std::logic_error, std::runtime_error);
protected:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// [Protected] Class variables // [Protected] Class variables
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -99,12 +99,12 @@ protected: ...@@ -99,12 +99,12 @@ protected:
//Address and port of remote endpoint //Address and port of remote endpoint
std::string m_remoteEndpoint; std::string m_remoteEndpoint;
//New file list current timestamp index
boost::posix_time::ptime m_currentTimestamp;
//Processing file from recovery list //Processing file from recovery list
bool m_recoveryMode; bool m_recoveryMode;
//New file list current timestamp index
boost::posix_time::ptime m_currentPtime;
//New file list shared pointer //New file list shared pointer
DBManager::NewFileRowsetSP m_newFileRowset_sp; DBManager::NewFileRowsetSP m_newFileRowset_sp;
......
...@@ -75,6 +75,7 @@ void SSLClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPointIt ...@@ -75,6 +75,7 @@ void SSLClient::startConnect(boost::asio::ip::tcp::resolver::iterator endPointIt
INFO_STREAM << "SSLClient::startConnect() " << infoStream.str() << endl; INFO_STREAM << "SSLClient::startConnect() " << infoStream.str() << endl;
writeState(Tango::RUNNING);
writeStatus(infoStream.str()); writeStatus(infoStream.str());
m_sSLSocket.lowest_layer().async_connect(endPointIterator->endpoint(), m_sSLSocket.lowest_layer().async_connect(endPointIterator->endpoint(),
...@@ -198,10 +199,9 @@ void SSLClient::startWriteRequest() ...@@ -198,10 +199,9 @@ void SSLClient::startWriteRequest()
} }
catch(std::logic_error& ec) catch(std::logic_error& ec)
{ {
ERROR_STREAM << "SSLClient::startWriteRequest() " << ec.what() << endl; WARN_STREAM << "SSLClient::startWriteRequest() " << ec.what() << endl;
writeState(Tango::ALARM); onTransferFailed();
writeStatus(ec.what());
} }
catch(std::runtime_error& ec) catch(std::runtime_error& ec)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment