Catalogue.hpp 6.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******************************************************************************
 *
 * 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.
 *
 *
 *
21
 * @author Castor Dev team, castor-dev@cern.ch
22
23
 *****************************************************************************/

24
#pragma once
25
26

#include "castor/exception/Exception.hpp"
27
#include "castor/legacymsg/CupvProxy.hpp"
28
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
29
#include "castor/legacymsg/TapeLabelRqstMsgBody.hpp"
30
#include "castor/legacymsg/VdqmProxy.hpp"
31
#include "castor/legacymsg/VmgrProxy.hpp"
32
#include "castor/log/Logger.hpp"
33
#include "castor/tape/utils/DriveConfigMap.hpp"
34
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
35
#include "castor/tape/tapeserver/daemon/CatalogueConfig.hpp"
36
#include "castor/tape/tapeserver/daemon/CatalogueDrive.hpp"
37
#include "castor/tape/tapeserver/daemon/ProcessForkerProxy.hpp"
38
39
40
41
42
43
44
45
46
47
48
49
50
51

#include <map>
#include <string>
#include <string.h>

namespace castor     {
namespace tape       {
namespace tapeserver {
namespace daemon     {

/**
 * Class responsible for keeping track of the tape drive being controlled by
 * the tapeserverd daemon.
 */
52
class Catalogue {
53
54
public:

55
56
57
  /**
   * Constructor.
   *
58
59
   * @param netTimeout Timeout in seconds to be used when performing network
   * I/O.
60
61
   * @param log Object representing the API of the CASTOR logging system.
   * @param processForker Proxy object representing the ProcessForker.
62
   * @param cupv Proxy object representing the cupvd daemon.
63
   * @param vdqm Proxy object representing the vdqmd daemon.
64
   * @param vmgr Proxy object representing the vmgrd daemon.
65
66
   * @param hostName The name of the host on which the daemon is running.  This
   * name is needed to fill in messages to be sent to the vdqmd daemon.
67
68
   * @param catalogueConfig The CASTOR configuration parameters to be used by
   * the catalogue.
69
   */
70
  Catalogue(
71
    const int netTimeout,
72
73
    log::Logger &log,
    ProcessForkerProxy &processForker,
74
75
76
    legacymsg::CupvProxy &cupv,
    legacymsg::VdqmProxy &vdqm,
    legacymsg::VmgrProxy &vmgr,
77
    const std::string &hostName,
78
    const CatalogueConfig &catalogueConfig);
79

80
81
82
83
84
85
  /**
   * Destructor.
   *
   * Closes the connection with the label command if the drive catalogue owns
   * the connection at the time of destruction.
   */
86
  ~Catalogue() throw();
87

88
  /**
89
90
   * Handles a tick in time.  Time driven actions such as alarms should be
   * implemented here.
91
92
93
94
   *
   * This method does not have to be called at any time precise interval,
   * though it should be called at least twice as fast as the quickest reaction
   * time imposed on the catalogue.
95
96
   *
   * @return True if the main event loop should continue, else false.
97
   */
98
  bool handleTick();
99

100
101
102
103
104
  /**
   * Returns true if all of teh tape-drives are shutdown.
   */
  bool allDrivesAreShutdown() const throw();

105
  /**
106
   * Poplates the catalogue using the specified tape-drive configurations.
107
   *
108
   * @param driveConfigs Tape-drive configurations.
109
   */
110
  void populate(const utils::DriveConfigMap &driveConfigs);
Steven Murray's avatar
Steven Murray committed
111

Steven Murray's avatar
Steven Murray committed
112
113
114
115
116
117
118
119
  /**
   * Returns a const reference to the tape-drive entry corresponding to the
   * tape drive with the specified unit name.
   *
   * This method throws an exception if the tape-drive entry cannot be found.
   *
   * @param unitName The unit name of the tape drive.
   */
120
  const CatalogueDrive &findDrive(const std::string &unitName)
Steven Murray's avatar
Steven Murray committed
121
122
    const;

123
  /**
124
125
   * Returns a const reference to the tape-drive entry associated with the
   * session with the specified process ID.
Steven Murray's avatar
Steven Murray committed
126
   *
127
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
128
129
130
   *
   * @param sessionPid The process ID of the session.
   */
131
  const CatalogueDrive &findDrive(const pid_t sessionPid) const;
132
133

  /**
134
135
   * Returns a reference to the tape-drive entry corresponding to the tape
   * drive with the specified unit name.
136
   *
137
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
138
139
   *
   * @param unitName The unit name of the tape drive.
140
   */
141
  CatalogueDrive &findDrive(const std::string &unitName);
142
143

  /**
144
145
   * Returns a reference to the tape-drive entry associated with the
   * session with the specified process ID.
146
   *
147
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
148
   *
149
   * @param sessionPid The process ID of the session.
Steven Murray's avatar
Steven Murray committed
150
   */
151
  CatalogueDrive &findDrive(const pid_t sessionPid);
Steven Murray's avatar
Steven Murray committed
152
153

  /**
154
155
   * Returns an unordered list of the unit names of all of the tape drives
   * stored within the tape drive catalogue.
Steven Murray's avatar
Steven Murray committed
156
   *
157
   * @return Unordered list of the unit names.
Steven Murray's avatar
Steven Murray committed
158
   */
159
  std::list<std::string> getUnitNames() const;
Steven Murray's avatar
Steven Murray committed
160

161
162
163
164
  /**
   */
  void shutdown();

165
166
167
168
169
170
171
  /**
   * If there are running sessions (one per tape drive) then this method kills
   * tem and sets their corresponding drives down in the vdqm and the drive
   * catalogue.
   */
  void killSessions();

172
173
private:

Steven Murray's avatar
Steven Murray committed
174
  /**
175
   * Timeout in seconds to be used when performing network I/O.
Daniele Kruse's avatar
Daniele Kruse committed
176
   */
177
  const int m_netTimeout;
178

Daniele Kruse's avatar
Daniele Kruse committed
179
  /**
180
   * Object representing the API of the CASTOR logging system.
Daniele Kruse's avatar
Daniele Kruse committed
181
   */
182
183
  log::Logger &m_log;

184
  /**
185
   * Proxy object representing the ProcessForker.
186
   */
187
  ProcessForkerProxy &m_processForker;
188

189
190
191
192
193
  /**
   * Proxy object representing the cupvd daemon.
   */
  legacymsg::CupvProxy &m_cupv;

194
195
196
197
198
  /**
   * Proxy object representing the vdqmd daemon.
   */
  legacymsg::VdqmProxy &m_vdqm;

199
200
201
202
203
  /**
   * Proxy object representing the vmgrd daemon.
   */
  legacymsg::VmgrProxy &m_vmgr;

204
205
206
207
208
  /**
   * The name of the host on which the daemon is running.  This name is
   * needed to fill in messages to be sent to the vdqmd daemon.
   */
  const std::string m_hostName;
209

210
  /**
211
   * The CASTOR configuration parameters to be used by the catalogue.
212
   */
213
  const CatalogueConfig m_catalogueConfig;
214

215
216
217
218
  /**
   * Type that maps the unit name of a tape drive to the catalogue entry of
   * that drive.
   */
219
  typedef std::map<std::string, CatalogueDrive *> DriveMap;
220
221
222
223
224
225
226

  /**
   * Map from the unit name of a tape drive to the catalogue entry of that
   * drive.
   */
  DriveMap m_drives;

227
  /** 
228
   * Enters the specified tape-drive configuration into the catalogue.
229
   *
230
   * @param driveConfig The tape-drive configuration.
231
   */
232
  void enterDriveConfig(const utils::DriveConfig &driveConfig);
233

234
}; // class Catalogue
235
236
237
238
239

} // namespace daemon
} // namespace tapeserver
} // namespace tape
} // namespace castor