RecallReportPacker.hpp 5.48 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
29
#include "castor/server/Threading.hpp"
#include "castor/server/BlockingQueue.hpp"
30
#include "scheduler/RetrieveJob.hpp"
31
#include "scheduler/RetrieveMount.hpp"
32

33
34
#include <memory>

35
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
40
class RecallReportPacker : public ReportPackerInterface<detail::Recall> {
41
public:
42
43
  /**
   * Constructor
44
   * @param tg the client to whom we report the success/failures
45
46
   * @param lc log context, copied du to threads
   */
47
  RecallReportPacker(cta::RetrieveMount *retrieveMount, log::LogContext lc);
48
  
49
  virtual ~RecallReportPacker();
50
  
51
 /**
52
53
54
   * Create into the MigrationReportPacker a report for the successful migration
   * of migratedFile
   * @param migratedFile the file successfully migrated
55
   * @param checksum the checksum the DWT has computed for the file 
56
   */
57
  virtual void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob, 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
   * @param ex the reason for the failure
64
   */
65
  virtual void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob, const castor::exception::Exception& ex);
66
67
68
69
       
  /**
   * Create into the MigrationReportPacker a report for the nominal end of session
   */
70
  virtual void reportEndOfSession();
71
72
73
74
75
76
  
  /**
   * 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
   */
77
78
  virtual void reportEndOfSessionWithErrors(const std::string msg,int error_code); 

79
80
81
  /**
   * Start the inner thread
   */
82
  void startThreads() { m_workerThread.start(); }
83
84
85
86
  
  /**
   * Stop the inner thread
   */
87
  void waitThread() { m_workerThread.wait(); }
88
  
89
90
91
92
93
  /**
   * Was there an error?
   */
  bool errorHappened();
  
94
private:
95
  //inner classes use to store content while receiving a report 
96
  class Report {
97
    const bool m_endNear;
98
  public:
99
    Report(bool b):m_endNear(b){}
100
101
    virtual ~Report(){}
    virtual void execute(RecallReportPacker& packer)=0;
102
    bool goingToEnd() const {return m_endNear;};
103
104
  };
  class ReportSuccessful :  public Report {
105
106
    u_int32_t m_checksum;
    u_int64_t m_size;
107
108
    
    /**
109
     * The successful retrieve job to be reported immediately
110
111
     */
    std::unique_ptr<cta::RetrieveJob> m_successfulRetrieveJob;
112
  public:
113
    ReportSuccessful(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob,u_int32_t checksum,
114
      u_int64_t size): 
115
    Report(false),m_checksum(checksum),m_size(size), m_successfulRetrieveJob(std::move(successfulRetrieveJob)){}
116
    virtual void execute(RecallReportPacker& reportPacker);
117
118
  };
  class ReportError : public Report {
119
    const castor::exception::Exception m_ex;
120
121
122
123
124
    
    /**
     * The failed retrieve job to be reported immediately
     */
    std::unique_ptr<cta::RetrieveJob> m_failedRetrieveJob;
125
  public:
126
    ReportError(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob, const castor::exception::Exception &ex):
127
128
129
130
    Report(false),
    m_ex(ex),
    m_failedRetrieveJob(std::move(failedRetrieveJob)) {
    }
131

132
    virtual void execute(RecallReportPacker& reportPacker);
133
  };
134
  
135
136
  class ReportEndofSession : public Report {
  public:
137
    ReportEndofSession():Report(true){}
138
    virtual void execute(RecallReportPacker& reportPacker);
139
140
141
142
143
144
  };
  class ReportEndofSessionWithErrors : public Report {
    std::string m_message;
    int m_error_code;
  public:
    ReportEndofSessionWithErrors(std::string msg,int error_code):
145
    Report(true),m_message(msg),m_error_code(error_code){}
146
  
147
    virtual void execute(RecallReportPacker& reportPacker);
148
149
  };
  
150
  class WorkerThread: public castor::server::Thread {
151
152
153
154
155
156
    RecallReportPacker & m_parent;
  public:
    WorkerThread(RecallReportPacker& parent);
    virtual void run();
  } m_workerThread;
  
157
  castor::server::Mutex m_producterProtection;
158
159
160
161
  
  /** 
   * m_fifo is holding all the report waiting to be processed
   */
162
  castor::server::BlockingQueue<Report*> m_fifo;
163
  
164
165
166
167
168
  /**
   * 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  
   */
169
  bool m_errorHappened;
170
171
172
173
174
  
  /**
   * The mount object used to send reports
   */
  cta::RetrieveMount * m_retrieveMount;
175
176
177
178
179
};

}}}}