Commit 1c0ac0a6 authored by David COME's avatar David COME
Browse files

Added a small factorisation for XXXReportPacker and modified consequently MigrationReportPacker

log, client interface and m_listReports are now inherited from the base class
parent 069c88e3
......@@ -34,15 +34,14 @@ namespace tape {
namespace tapeserver {
namespace daemon {
MigrationReportPacker::MigrationReportPacker(ClientInterface & tg,castor::log::LogContext& lc):
m_workerThread(*this),m_client(tg),m_lc(lc),
m_listReports(new tapegateway::FileMigrationReportList),m_errorHappened(false),m_continue(true) {
MigrationReportPacker::MigrationReportPacker(ClientInterface & tg,castor::log::LogContext lc):
ReportPackerInterface<detail::Migration>(tg,lc),
m_workerThread(*this),m_errorHappened(false),m_continue(true) {
}
MigrationReportPacker::~MigrationReportPacker(){
castor::tape::threading::MutexLocker ml(&m_producterProtection);
}
MigrationReportPacker::~MigrationReportPacker(){
castor::tape::threading::MutexLocker ml(&m_producterProtection);
}
void MigrationReportPacker::reportCompletedJob(const tapegateway::FileToMigrateStruct& migratedFile) {
std::auto_ptr<Report> rep(new ReportSuccessful(migratedFile));
......@@ -81,7 +80,6 @@ void MigrationReportPacker::ReportSuccessful::execute(MigrationReportPacker& _th
_this.m_listReports->addSuccessfulMigrations(successMigration.release());
}
void MigrationReportPacker::ReportFlush::execute(MigrationReportPacker& _this){
if(!_this.m_errorHappened){
_this.logReport(_this.m_listReports->successfulMigrations(),"A file was successfully written on the tape");
......@@ -97,7 +95,6 @@ void MigrationReportPacker::ReportFlush::execute(MigrationReportPacker& _this){
//Thus all current reports are deleted otherwise they would have been sent again at the next flush
_this.m_listReports.reset(new tapegateway::FileMigrationReportList);
}
void MigrationReportPacker::ReportEndofSession::execute(MigrationReportPacker& _this){
if(!_this.m_errorHappened){
tapeserver::daemon::ClientInterface::RequestReport chrono;
......@@ -139,6 +136,7 @@ void MigrationReportPacker::ReportError::execute(MigrationReportPacker& _this){
_this.m_errorHappened=true;
}
//------------------------------------------------------------------------------
MigrationReportPacker::WorkerThread::WorkerThread(MigrationReportPacker& parent):
m_parent(parent) {
}
......
......@@ -28,8 +28,8 @@
#include "castor/tape/tapeserver/daemon/MigrationJob.hpp"
#include "castor/tape/tapeserver/daemon/ClientInterface.hpp"
#include "castor/tape/tapegateway/FileToMigrateStruct.hpp"
#include "castor/log/LogContext.hpp"
#include "castor/tape/tapeserver/utils/suppressUnusedVariable.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include <list>
#include <memory>
......@@ -38,13 +38,13 @@ namespace tape {
namespace tapeserver {
namespace daemon {
class MigrationReportPacker {
class MigrationReportPacker : private ReportPackerInterface<detail::Migration> {
public:
/**
* @param tg The client who is asking for a migration of his files
* and to whom we have to report to the status of the operations.
*/
MigrationReportPacker(ClientInterface & tg,log::LogContext& lc);
MigrationReportPacker(ClientInterface & tg,log::LogContext lc);
~MigrationReportPacker();
......@@ -83,38 +83,15 @@ public:
void waitThread() { m_workerThread.wait(); }
private:
/**
* Log a set of files independently of the success/failure
* @param c The set of files to log
* @param msg The message to be append at the end.
*/
template <class C> void logReport(const C& c,const std::string& msg){
using castor::log::LogContext;
using castor::log::Param;
for(typename C::const_iterator it=c.begin();it!=c.end();++it)
{
LogContext::ScopedParam sp[]={
LogContext::ScopedParam(m_lc, Param("ID", (*it)->id())),
LogContext::ScopedParam(m_lc, Param("FILEID",(*it)->fileid())),
LogContext::ScopedParam(m_lc, Param("FSEQ", (*it)->fseq())),
LogContext::ScopedParam(m_lc, Param("NSHOST", (*it)->nshost())),
LogContext::ScopedParam(m_lc, Param("FILETRANSACTIONID", (*it)->fileTransactionId()))
};
tape::utils::suppresUnusedVariable(sp);
m_lc.log(LOG_INFO,msg);
}
}
class Report {
public:
virtual ~Report(){}
virtual void execute(MigrationReportPacker& packer)=0;
};
class ReportSuccessful : public Report {
const tapegateway::FileToMigrateStruct m_migratedFile;
const FileStruct m_migratedFile;
public:
ReportSuccessful(const tapegateway::FileToMigrateStruct& file):
ReportSuccessful(const FileStruct& file):
m_migratedFile(file){}
virtual void execute(MigrationReportPacker& _this);
};
......@@ -123,11 +100,11 @@ private:
void execute(MigrationReportPacker& _this);
};
class ReportError : public Report {
const tapegateway::FileToMigrateStruct m_migratedFile;
const FileStruct m_migratedFile;
const std::string m_error_msg;
const int m_error_code;
public:
ReportError(const tapegateway::FileToMigrateStruct& file,std::string msg,int error_code):
ReportError(const FileStruct& file,std::string msg,int error_code):
m_migratedFile(file),m_error_msg(msg),m_error_code(error_code){}
virtual void execute(MigrationReportPacker& _this);
......@@ -152,20 +129,13 @@ private:
WorkerThread(MigrationReportPacker& parent);
virtual void run();
} m_workerThread;
ClientInterface & m_client;
castor::log::LogContext& m_lc;
/**
* m_fifo is holding all the report waiting to be processed
*/
castor::tape::threading::BlockingQueue<Report*> m_fifo;
/**
* m_listReports is holding all the report waiting to be processed
*/
std::auto_ptr<tapegateway::FileMigrationReportList> m_listReports;
castor::tape::threading::Mutex m_producterProtection;
/**
......
/******************************************************************************
* ReportPackerInterface.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 Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#ifndef REPORTPACKERINTERFACE_HPP
#define REPORTPACKERINTERFACE_HPP
#include "castor/log/LogContext.hpp"
#include "castor/tape/tapeserver/daemon/ClientInterface.hpp"
#include "castor/tape/tapeserver/utils/suppressUnusedVariable.hpp"
#include "castor/tape/tapegateway/FileMigratedNotificationStruct.hpp"
#include "castor/tape/tapegateway/FileRecalledNotificationStruct.hpp"
#include "castor/tape/tapegateway/FileToMigrateStruct.hpp"
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"
#include "castor/tape/tapegateway/FileErrorReportStruct.hpp"
#include "castor/tape/tapegateway/FilesToRecallList.hpp"
#include "castor/tape/tapegateway/FilesToMigrateList.hpp"
#include <memory>
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
namespace detail{
struct Recall{};
struct Migration{};
template <class> struct HelperTrait;
template <> struct HelperTrait<Migration>{
typedef tapegateway::FileMigrationReportList FileReportList;
typedef tapegateway::FileToMigrateStruct FileStruct;
typedef tapegateway::FileMigratedNotificationStruct FileSuccessStruct;
typedef tapegateway::FileErrorReportStruct FileErrorStruct;
};
template <> struct HelperTrait<Recall>{
typedef tapegateway::FileRecallReportList FileReportList;
typedef tapegateway::FileToRecallStruct FileStruct;
typedef tapegateway::FileRecalledNotificationStruct FileSuccessStruct;
typedef tapegateway::FileErrorReportStruct FileErrorStruct;
};
}
template <class PlaceHolder> class ReportPackerInterface{
public:
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(ClientInterface & tg,log::LogContext lc):
m_client(tg),m_lc(lc),m_listReports(new FileReportList)
{}
protected:
/**
* Log a set of files independently of the success/failure
* @param c The set of files to log
* @param msg The message to be append at the end.
*/
template <class C> void logReport(const C& c,const std::string& msg){
using castor::log::LogContext;
using castor::log::Param;
for(typename C::const_iterator it=c.begin();it!=c.end();++it)
{
LogContext::ScopedParam sp[]={
LogContext::ScopedParam(m_lc, Param("ID", (*it)->id())),
LogContext::ScopedParam(m_lc, Param("FILEID",(*it)->fileid())),
LogContext::ScopedParam(m_lc, Param("FSEQ", (*it)->fseq())),
LogContext::ScopedParam(m_lc, Param("NSHOST", (*it)->nshost())),
LogContext::ScopedParam(m_lc, Param("FILETRANSACTIONID", (*it)->fileTransactionId()))
};
tape::utils::suppresUnusedVariable(sp);
m_lc.log(LOG_INFO,msg);
}
}
ClientInterface & m_client;
castor::log::LogContext m_lc;
/**
* m_listReports is holding all the report waiting to be processed
*/
std::auto_ptr<FileReportList> m_listReports;
};
}}}}
#endif /* REPORTPACKERINTERFACE_HPP */
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