RecallReportPacker.hpp 5.52 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
/******************************************************************************
 *
 * 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
 *****************************************************************************/

24
#pragma once
25
26
27

#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
#include "castor/log/LogContext.hpp"
28
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
29
30
#include "castor/server/Threading.hpp"
#include "castor/server/BlockingQueue.hpp"
31
32
33
34
35
36

namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
37
class RecallReportPacker : public ReportPackerInterface<detail::Recall> {
38
public:
39
40
41
42
43
44
  /**
   * Constructor
   * @param tg the client to whom we report the success/failures 
   * @param reportFilePeriod how often  do we report to the client
   * @param lc log context, copied du to threads
   */
45
46
  RecallReportPacker(client::ClientInterface & tg,unsigned int reportFilePeriod,
          log::LogContext lc);
47
  
48
  virtual ~RecallReportPacker();
49
  
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 the DWT has computed for the file 
55
   */
56
  virtual void reportCompletedJob(const FileStruct& recalledFile,
57
  u_int32_t checksum, u_int64_t size);
58
59
  
  /**
60
   * Create into the MigrationReportPacker a report for the failed migration
61
   * of migratedFile
62
   * @param migratedFile the file which failed 
63
64
   * @param msg the message error with the failure 
   * @param error_code the error code with the failure 
65
   */
66
  virtual void reportFailedJob(const FileStruct & recalledFile,const std::string& msg,int error_code);
67
68
69
70
       
  /**
   * Create into the MigrationReportPacker a report for the nominal end of session
   */
71
  virtual void reportEndOfSession();
72
73
74
75
76
77
  
  /**
   * 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
   */
78
79
80
81
  virtual void reportEndOfSessionWithErrors(const std::string msg,int error_code); 
  
  void reportStuckOn(FileStruct& file);

82
83
84
  /**
   * Start the inner thread
   */
85
  void startThreads() { m_workerThread.start(); }
86
87
88
89
  
  /**
   * Stop the inner thread
   */
90
  void waitThread() { m_workerThread.wait(); }
91
92
  
private:
93
  //inner classes use to store content while receiving a report 
94
  class Report {
95
    const bool m_endNear;
96
  public:
97
    Report(bool b):m_endNear(b){}
98
99
    virtual ~Report(){}
    virtual void execute(RecallReportPacker& packer)=0;
100
    bool goingToEnd() const {return m_endNear;};
101
102
  };
  class ReportSuccessful :  public Report {
103
    const FileStruct m_recalledFile;
104
105
    u_int32_t m_checksum;
    u_int64_t m_size;
106
  public:
107
108
109
    ReportSuccessful(const FileStruct& file,u_int32_t checksum,
      u_int64_t size): 
    Report(false),m_recalledFile(file),m_checksum(checksum),m_size(size){}
110
111
112
    virtual void execute(RecallReportPacker& _this);
  };
  class ReportError : public Report {
113
    const FileStruct m_recalledFile;
114
115
116
117
    const std::string m_error_msg;
    const int m_error_code;
  public:
    ReportError(const FileStruct& file,std::string msg,int error_code):
118
    Report(false),m_recalledFile(file),m_error_msg(msg),m_error_code(error_code){}
119

120
121
    virtual void execute(RecallReportPacker& _this);
  };
122
123
124
125
126
127
128
129
130
  class ReportStuck : public Report {
    const FileStruct m_recalledFile;
  public:
    ReportStuck(const FileStruct& file):
    Report(false),m_recalledFile(file){}

    virtual void execute(RecallReportPacker& _this);
  };
  
131
132
  class ReportEndofSession : public Report {
  public:
133
    ReportEndofSession():Report(true){}
134
135
136
137
138
139
140
    virtual void execute(RecallReportPacker& _this);
  };
  class ReportEndofSessionWithErrors : public Report {
    std::string m_message;
    int m_error_code;
  public:
    ReportEndofSessionWithErrors(std::string msg,int error_code):
141
    Report(true),m_message(msg),m_error_code(error_code){}
142
  
143
144
145
    virtual void execute(RecallReportPacker& _this);
  };
  
146
  class WorkerThread: public castor::server::Thread {
147
148
149
150
151
152
    RecallReportPacker & m_parent;
  public:
    WorkerThread(RecallReportPacker& parent);
    virtual void run();
  } m_workerThread;
  
153
154
155
  /**
   * Function periodically called to report the results to the client
   */
156
157
  void flush();
  
158
  castor::server::Mutex m_producterProtection;
159
160
161
162
  
  /** 
   * m_fifo is holding all the report waiting to be processed
   */
163
  castor::server::BlockingQueue<Report*> m_fifo;
164
  
165
166
167
  /**
   How often do we report to the client
   */
168
  unsigned int m_reportFilePeriod;
169
170
171
172
173
174
  
  /**
   * Is set as true as soon as we process a reportFailedJob
   * That we can do a sanity check to make sure we always call 
   * the right end of the session  
   */
175
176
177
178
179
180
  bool m_errorHappened;
};

}}}}