ClientProxy.hpp 7.2 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
/******************************************************************************
 *                      clientInterface.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

Eric Cano's avatar
Eric Cano committed
27
28
#include "castor/tape/legacymsg/RtcpJobRqstMsgBody.hpp"
#include "castor/tape/tapeserver/exception/Exception.hpp"
29
30
31
#include "castor/tape/tapegateway/GatewayMessage.hpp"
#include "castor/tape/tapegateway/ClientType.hpp"
#include "castor/tape/tapegateway/VolumeMode.hpp"
32
#include "castor/tape/tapegateway/FilesToMigrateList.hpp"
Eric Cano's avatar
Eric Cano committed
33
34
35
#include "castor/tape/tapegateway/FileMigrationReportList.hpp"
#include "castor/tape/tapegateway/FilesToRecallList.hpp"
#include "castor/tape/tapegateway/FileRecallReportList.hpp"
David COME's avatar
David COME committed
36
#include "castor/tape/tapeserver/daemon/ClientInterface.hpp"
37
38
39
40
#include "../threading/Threading.hpp"

namespace castor {
namespace tape {
41
42
namespace tapeserver {
namespace daemon {
43
44
45
46
47
  /**
   * A class managing the communications with the tape server's client.
   * The client address will have been received from the VDQM by the main
   * process. 
   */
David COME's avatar
David COME committed
48
  class ClientProxy : public ClientInterface {
49
50
51
52
53
54
55
  public:
    /**
     * Constructor: contact client, gather initial information about the
     * session and decide get that information ready for th user of the class
     * (read/write session, first file information, etc...)
     * @param clientRequest the client information as sent by VDQM.
     */
56
    ClientProxy(const legacymsg::RtcpJobRqstMsgBody & clientRequest)
57
58
            throw (castor::tape::Exception);
    
Eric Cano's avatar
Eric Cano committed
59
60
61
62
63
64
65
66
67
68
69
70
71
    /**
     * Retrieves the volume Id from the client (with transfer direction)
     * Throws an EndOfSession exception
     * @param report report on timing and request Id. It will still be filled
     * up and can be used when a exception is thrown.
     * @return the transaction id
     */
    void fetchVolumeId(VolumeInfo & volInfo, RequestReport &report) throw (castor::tape::Exception);
    
    /**
     * Reports end of session to the client. This should be the last call to
     * the client.
     */
72
    virtual void reportEndOfSession(RequestReport &report) throw (Exception);
73
    
74
75
76
    /**
     * Reports end of session to the client. This should be the last call to
     * the client.
77
78
79
80
81
     * @param transactionReport Placeholder to network timing information,
     * populated during the call and used by the caller to log performance 
     * and context information
     * @param errorMsg (sent to the client)
     * @param errorCode (sent to the client)
82
     */
83
    virtual void reportEndOfSessionWithError(const std::string & errorMsg, int errorCode, 
84
85
86
87
88
89
90
91
92
93
94
    RequestReport &transactionReport) throw (castor::tape::Exception);
    
    /**
     * Asks the the client for files to migrate, with at least files files, or
     * bytes bytes of data, whichever limit is passed first.
     * Detailed interface is still TBD.
     * @param files files count requested.
     * @param bytes total bytes count requested
     * @param report Placeholder to network timing information,
     * populated during the call and used by the caller to log performance 
     * and context information
95
96
97
     * @return a pointer (to be deleted by the user) to a 
     * tapegateway::FilesToMigrateList is non-empty or NULL if not more
     * files could be retrieved.
98
     */
99
100
    tapegateway::FilesToMigrateList * getFilesToMigrate(uint64_t files, 
    uint64_t bytes, RequestReport &report)
101
102
103
104
105
106
107
    throw (castor::tape::Exception);
    
    /**
     * Reports the result of migrations to the client.
     * Detailed interface is still TBD.
     * @param report Placeholder to network timing information
     */
Eric Cano's avatar
Eric Cano committed
108
109
    void reportMigrationResults(tapegateway::FileMigrationReportList & migrationReport,
      RequestReport &report) throw (castor::tape::Exception);
110
111
112
113
114
115
116
117
118
119
120
    
    /**
     * Asks the the client for files to recall, with at least files files, or
     * bytes bytes of data, whichever limit is passed first.
     * Detailed interface is still TBD.
     * @param files files count requested.
     * @param bytes total bytes count requested
     * @param report Placeholder to network timing information,
     * populated during the call and used by the caller to log performance 
     * and context information
     */
Eric Cano's avatar
Eric Cano committed
121
122
    tapegateway::FilesToRecallList * getFilesToRecall(uint64_t files,
    uint64_t bytes, RequestReport &report)
123
124
125
126
127
128
129
    throw (castor::tape::Exception);
    
    /**
     * Reports the result of recall to the client.
     * Detailed interface is still TBD.
     * @param report Placeholder to network timing information
     */
Eric Cano's avatar
Eric Cano committed
130
131
    void reportRecallResults(tapegateway::FileRecallReportList & recallReport,
      RequestReport &report) throw (castor::tape::Exception);
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    /**
     * Exception thrown when the wrong response type was received from
     * the client after a request. Extracts the type and prints it.
     */
    class UnexpectedResponse: public castor::tape::Exception {
    public:
      UnexpectedResponse(const castor::IObject * resp, const std::string & w="");
    };
    
    /**
     * Exception marking end of session
     */
    class EndOfSession: public castor::tape::Exception {
    public:
      EndOfSession(std::string w=""):castor::tape::Exception(w) {}
    };
Eric Cano's avatar
Eric Cano committed
148
   
149
150
151
152
153
154
155
156
157
158
159
    
  private:
    /** The VDQM request that kickstarted the session */
    legacymsg::RtcpJobRqstMsgBody m_request;
    /**
     * A helper function managing a single request-response session with the
     * client.
     * @param req the request to send to the client
     * @return the response from the client
     */
    tapegateway::GatewayMessage * requestResponseSession(
Eric Cano's avatar
Eric Cano committed
160
161
            const tapegateway::GatewayMessage &req,
            RequestReport & report) throw (castor::tape::Exception);
162
163
164
165
166
167
168
169
170
171
    
    /**
     * A helper class managing a thread safe message counter (we need it thread
     * safe as the ClientInterface class will be used by both the getting of
     * the work to be done and the reporting of the completed work, in parallel
     */
    template <typename T>
    class ThreadSafeCounter {
    public:
      ThreadSafeCounter(): m_val(0) {};
172
      T operator ++ () {
173
174
175
176
177
178
179
180
181
182
183
184
185
186
        threading::MutexLocker ml(&m_mutex);
        return ++m_val;
      }
    private:
      T m_val;
      threading::Mutex m_mutex;
    };
    /** The file transaction id a.k.a. aggregator transaction id. This is the 
     * serial number of the message in the session */
    ThreadSafeCounter<uint32_t> m_transactionId;
  };
  
}
}
187
}
188
}