MigrationReportPacker.hpp 5.09 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/******************************************************************************
 *                      MigrationReportPacker.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
 *****************************************************************************/

#pragma once

27
#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"
28
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
29
#include "castor/tape/tapegateway/FileToMigrateStruct.hpp"
30
31
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"

32
#include <list>
33
#include <memory>
34

35
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
 
40
class MigrationReportPacker : private ReportPackerInterface<detail::Migration> {
41
public:
42
43
44
45
  /**
   * @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.
   */
46
  MigrationReportPacker(client::ClientInterface & tg,log::LogContext lc);
47
  
48
49
  ~MigrationReportPacker();
    
50
51
52
53
  /**
   * Create into the MigrationReportPacker a report for the successful migration
   * of migratedFile
   * @param migratedFile the file successfully migrated
54
   * @param checksum the checksum we computed of the file we have just migrated
55
   */
David COME's avatar
David COME committed
56
57
  void reportCompletedJob(const tapegateway::FileToMigrateStruct& migratedFile,
  unsigned long checksum);
58
59
60
61
62
  
  /**
   * Create into the MigrationReportPacker a report for the failled migration
   * of migratedFile
   * @param migratedFile the file which failled 
63
64
   * @param msg the error message to the failure 
   * @param error_code the error code related to the failure 
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
   */
  void reportFailedJob(const tapegateway::FileToMigrateStruct& migratedFile,const std::string& msg,int error_code);
     
   /**
   * Create into the MigrationReportPacker a report for the signaling a flusing on tape
   */
  void reportFlush();
  
  /**
   * Create into the MigrationReportPacker a report for the nominal end of session
   */
  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);
  
85
86
  void startThreads() { m_workerThread.start(); }
  void waitThread() { m_workerThread.wait(); }
87
  
88
89
90
private:
  class Report {
  public:
91
92
    virtual ~Report(){}
    virtual void execute(MigrationReportPacker& packer)=0;
93
  };
94
  class ReportSuccessful :  public Report {
95
    const FileStruct m_migratedFile;
David COME's avatar
David COME committed
96
    const unsigned long m_checksum;
97
  public:
David COME's avatar
David COME committed
98
99
    ReportSuccessful(const FileStruct& file,unsigned long checksum): 
    m_migratedFile(file),m_checksum(checksum){}
100
101
102
103
104
105
    virtual void execute(MigrationReportPacker& _this);
  };
  class ReportFlush : public Report {
    public:
      void execute(MigrationReportPacker& _this);
  };
106
  class ReportError : public Report {
107
    const FileStruct m_migratedFile;
108
109
110
    const std::string m_error_msg;
    const int m_error_code;
  public:
111
    ReportError(const FileStruct& file,std::string msg,int error_code):
112
113
114
115
    m_migratedFile(file),m_error_msg(msg),m_error_code(error_code){}
    
    virtual void execute(MigrationReportPacker& _this);
  };
116
  class ReportEndofSession : public Report {
117
118
119
120
121
122
  public:
    virtual void execute(MigrationReportPacker& _this);
  };
  class ReportEndofSessionWithErrors : public Report {
    std::string m_message;
    int m_error_code;
123
  public:
124
    ReportEndofSessionWithErrors(std::string msg,int error_code):
125
126
127
128
129
130
    m_message(msg),m_error_code(error_code){}

    virtual void execute(MigrationReportPacker& _this);
  };
  
  class WorkerThread: public castor::tape::threading::Thread {
131
    MigrationReportPacker & m_parent;
132
133
134
  public:
    WorkerThread(MigrationReportPacker& parent);
    virtual void run();
135
  } m_workerThread;
136
  
137
138
139
  /** 
   * m_fifo is holding all the report waiting to be processed
   */
140
  castor::tape::threading::BlockingQueue<Report*> m_fifo;
141

142

143
  castor::tape::threading::Mutex m_producterProtection;
144
145
146
147
148
149
150
  
  /** 
   * Sanity check variable to register if an error has happened 
   * Is set at true as soon as a ReportError has been processed.
   */
  bool m_errorHappened;
  
151
152
153
  /* bool to keep the inner thread running. Is set at false 
   * when a end of session (with error) is called
   */
154
  bool m_continue;
155
};
156
157

}}}}