Commit 734c6e9d authored by David COME's avatar David COME
Browse files

Refactor ReportPackerInterface to make it an utility class

Thus, The real reporters do not inherit publicly from it => Changed all the lines of coded that had to be changed
parent e92123ba
......@@ -43,7 +43,7 @@ namespace daemon {
* Main routine: takes each memory block in the fifo and writes it to disk
* @return true if the file has been successfully written false otherwise.
*/
bool DiskWriteTask::execute(ReportPackerInterface<detail::Recall>& reporter,log::LogContext& lc) {
bool DiskWriteTask::execute(RecallReportPacker& reporter,log::LogContext& lc) {
using log::LogContext;
using log::Param;
try{
......
......@@ -29,7 +29,7 @@
#include "castor/tape/tapeserver/daemon/DataConsumer.hpp"
#include "castor/tape/tapeserver/file/File.hpp"
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
#include <memory>
namespace {
......@@ -63,7 +63,7 @@ public:
* Main routine: takes each memory block in the fifo and writes it to disk
* @return true if the file has been successfully written false otherwise.
*/
virtual bool execute(ReportPackerInterface<detail::Recall>& reporter,log::LogContext& lc) ;
virtual bool execute(RecallReportPacker& reporter,log::LogContext& lc) ;
/**
* Allows client code to return a reusable memory block. Should not been called
......
......@@ -14,13 +14,13 @@
namespace unitTests{
using namespace castor::tape::tapeserver::daemon;
using namespace castor::tape::tapeserver::client;
struct MockRecallReportPacker : public ReportPackerInterface<detail::Recall>{
struct MockRecallReportPacker : public RecallReportPacker {
MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
MockRecallReportPacker(ClientInterface& client,castor::log::LogContext lc):
ReportPackerInterface<detail::Recall>(client,lc){}
RecallReportPacker(client,1,lc){}
};
TEST(castor_tape_tapeserver_daemon, DiskWriteTaskFailledBlock){
......
......@@ -9,7 +9,7 @@ namespace daemon {
DiskWriteThreadPool::DiskWriteThreadPool(int nbThread, int maxFilesReq, int maxBlocksReq,
ReportPackerInterface<detail::Recall>& report,castor::log::LogContext lc):
RecallReportPacker& report,castor::log::LogContext lc):
m_maxFilesReq(maxFilesReq), m_maxBytesReq(maxBlocksReq),
m_reporter(report),m_lc(lc)
{
......
......@@ -44,7 +44,7 @@ namespace daemon {
class DiskWriteThreadPool {
public:
DiskWriteThreadPool(int nbThread, int maxFilesReq, int maxBlocksReq,
ReportPackerInterface<detail::Recall>& report,castor::log::LogContext lc);
RecallReportPacker& report,castor::log::LogContext lc);
~DiskWriteThreadPool();
void startThreads();
......@@ -87,7 +87,7 @@ protected:
private:
uint32_t m_maxFilesReq;
uint64_t m_maxBytesReq;
ReportPackerInterface<detail::Recall>& m_reporter;
RecallReportPacker& m_reporter;
//logging context that will copied by each thread
castor::log::LogContext m_lc;
......
......@@ -14,13 +14,13 @@
namespace unitTests{
using namespace castor::tape::tapeserver::daemon;
using namespace castor::tape::tapeserver::client;
struct MockRecallReportPacker : public ReportPackerInterface<detail::Recall>{
struct MockRecallReportPacker : public RecallReportPacker {
MOCK_METHOD2(reportCompletedJob,void(const FileStruct&,unsigned long));
MOCK_METHOD3(reportFailedJob, void(const FileStruct& ,const std::string&,int));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
MockRecallReportPacker(ClientInterface& client,castor::log::LogContext lc):
ReportPackerInterface<detail::Recall>(client,lc){}
RecallReportPacker(client,1,lc){}
};
struct MockTaskInjector : public TaskInjector{
......
......@@ -50,13 +50,13 @@ ReportPackerInterface<detail::Recall>(tg,lc),
RecallReportPacker::~RecallReportPacker(){
}
void RecallReportPacker::reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile,unsigned long checksum){
void RecallReportPacker::reportCompletedJob(const FileStruct& recalledFile,unsigned long checksum){
std::auto_ptr<Report> rep(new ReportSuccessful(recalledFile,checksum));
castor::tape::threading::MutexLocker ml(&m_producterProtection);
m_fifo.push(rep.release());
}
void RecallReportPacker::reportFailedJob(const tapegateway::FileToRecallStruct & recalledFile
void RecallReportPacker::reportFailedJob(const FileStruct & recalledFile
,const std::string& msg,int error_code){
std::auto_ptr<Report> rep(new ReportError(recalledFile,msg,error_code));
castor::tape::threading::MutexLocker ml(&m_producterProtection);
......
......@@ -35,9 +35,10 @@ namespace tape {
namespace tapeserver {
namespace daemon {
class RecallReportPacker : public ReportPackerInterface<detail::Recall> {
class RecallReportPacker : protected ReportPackerInterface<detail::Recall> {
public:
RecallReportPacker(client::ClientInterface & tg,unsigned int reportFilePeriod,log::LogContext lc);
RecallReportPacker(client::ClientInterface & tg,unsigned int reportFilePeriod,
log::LogContext lc);
~RecallReportPacker();
......@@ -46,27 +47,27 @@ public:
* of migratedFile
* @param migratedFile the file successfully migrated
*/
void reportCompletedJob(const tapegateway::FileToRecallStruct& recalledFile,
virtual void reportCompletedJob(const FileStruct& recalledFile,
unsigned long checksum);
/**
* Create into the MigrationReportPacker a report for the failled migration
* Create into the MigrationReportPacker a report for the failed migration
* of migratedFile
* @param migratedFile the file which failled
* @param migratedFile the file which failed
*/
void reportFailedJob(const tapegateway::FileToRecallStruct & recalledFile,const std::string& msg,int error_code);
virtual void reportFailedJob(const FileStruct & recalledFile,const std::string& msg,int error_code);
/**
* Create into the MigrationReportPacker a report for the nominal end of session
*/
void reportEndOfSession();
virtual void reportEndOfSession();
/**
* Create into the MigrationReportPacker a report for an erroneous end of session
* @param msg The error message
* @param error_code The error code given by the drive
*/
void reportEndOfSessionWithErrors(const std::string msg,int error_code);
virtual void reportEndOfSessionWithErrors(const std::string msg,int error_code);
void startThreads() { m_workerThread.start(); }
void waitThread() { m_workerThread.wait(); }
......@@ -95,7 +96,7 @@ private:
public:
ReportError(const FileStruct& file,std::string msg,int error_code):
Report(false),m_migratedFile(file),m_error_msg(msg),m_error_code(error_code){}
virtual void execute(RecallReportPacker& _this);
};
class ReportEndofSession : public Report {
......@@ -109,7 +110,7 @@ private:
public:
ReportEndofSessionWithErrors(std::string msg,int error_code):
Report(true),m_message(msg),m_error_code(error_code){}
virtual void execute(RecallReportPacker& _this);
};
......
......@@ -15,7 +15,7 @@ class FakeDiskWriteThreadPool: public DiskWriteThreadPool
public:
using DiskWriteThreadPool::m_tasks;
FakeDiskWriteThreadPool(castor::log::LogContext & lc):
DiskWriteThreadPool(1,0,0,*((ReportPackerInterface<detail::Recall>*)NULL), lc){}
DiskWriteThreadPool(1,0,0,*((RecallReportPacker*)NULL), lc){}
virtual ~FakeDiskWriteThreadPool() {};
};
......
......@@ -41,7 +41,7 @@ namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
namespace detail{
struct Recall{};
struct Migration{};
......@@ -64,47 +64,17 @@ namespace detail{
}
template <class PlaceHolder> class ReportPackerInterface{
public:
protected :
typedef typename detail::HelperTrait<PlaceHolder>::FileReportList FileReportList;
typedef typename detail::HelperTrait<PlaceHolder>::FileStruct FileStruct;
typedef typename detail::HelperTrait<PlaceHolder>::FileSuccessStruct FileSuccessStruct;
typedef typename detail::HelperTrait<PlaceHolder>::FileErrorStruct FileErrorStruct;
ReportPackerInterface(client::ClientInterface & tg,log::LogContext lc):
ReportPackerInterface(client::ClientInterface & tg,log::LogContext lc):
m_client(tg),m_lc(lc),m_listReports(new FileReportList)
{}
virtual ~ReportPackerInterface(){}
/**
* Create into the MigrationReportPacker a report for the successful migration
* of migratedFile
* @param migratedFile the file successfully migrated
*/
virtual void reportCompletedJob(const FileStruct&,unsigned long checksum) =0;
/**
* Create into the MigrationReportPacker a report for the failled migration
* of migratedFile
* @param migratedFile the file which failled
*/
virtual void reportFailedJob(const FileStruct& ,const std::string&,int)=0;
/**
* Create into the MigrationReportPacker a report for the nominal end of session
*/
virtual void reportEndOfSession() =0;
/**
* Create into the MigrationReportPacker a report for an erroneous end of session
* @param msg The error message
* @param error_code The error code given by the drive
*/
virtual void reportEndOfSessionWithErrors(const std::string,int) =0;
protected:
/**
* Log a set of files independently of the success/failure
* @param c The set of files to log
......
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