DriveCatalogue.hpp 5.82 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/RtcpJobRqstMsgBody.hpp"
28
#include "castor/legacymsg/TapeLabelRqstMsgBody.hpp"
29
30
#include "castor/legacymsg/VdqmProxy.hpp"
#include "castor/log/Logger.hpp"
31
#include "castor/tape/utils/DriveConfigMap.hpp"
32
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
Steven Murray's avatar
Steven Murray committed
33
#include "castor/tape/tapeserver/daemon/DriveCatalogueEntry.hpp"
34
#include "castor/tape/tapeserver/daemon/ProcessForkerProxy.hpp"
35
36
37
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.
 */
class DriveCatalogue {
public:

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  /**
   * Constructor.
   *
   * @param log Object representing the API of the CASTOR logging system.
   * @param dataTransferConfig The configuration of a data-transfer session.
   * @param processForker Proxy object representing the ProcessForker.
   * @param vdqm Proxy object representing the vdqmd daemon.
   * @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.
   */
  DriveCatalogue(
    log::Logger &log,
    const DataTransferSession::CastorConf &dataTransferConfig,
    ProcessForkerProxy &processForker,
    legacymsg::VdqmProxy &m_vdqm,
    const std::string &hostName);

69
70
71
72
73
74
75
76
  /**
   * Destructor.
   *
   * Closes the connection with the label command if the drive catalogue owns
   * the connection at the time of destruction.
   */
  ~DriveCatalogue() throw();

77
  /**
78
   * Poplates the catalogue using the specified tape-drive configurations.
79
   *
80
   * @param driveConfigs Tape-drive configurations.
81
   */
82
  void populate(const utils::DriveConfigMap &driveConfigs);
Steven Murray's avatar
Steven Murray committed
83

Steven Murray's avatar
Steven Murray committed
84
85
86
87
88
89
90
91
  /**
   * 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.
   */
92
  const DriveCatalogueEntry &findDrive(const std::string &unitName)
Steven Murray's avatar
Steven Murray committed
93
94
    const;

95
  /**
96
97
   * 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
98
   *
99
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
100
101
102
   *
   * @param sessionPid The process ID of the session.
   */
103
  const DriveCatalogueEntry &findDrive(const pid_t sessionPid) const;
104
105

  /**
106
107
   * Returns a reference to the tape-drive entry corresponding to the tape
   * drive with the specified unit name.
108
   *
109
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
110
111
   *
   * @param unitName The unit name of the tape drive.
112
   */
113
  DriveCatalogueEntry &findDrive(const std::string &unitName);
114
115

  /**
116
117
   * Returns a reference to the tape-drive entry associated with the
   * session with the specified process ID.
118
   *
119
   * This method throws an exception if the tape-drive entry cannot be found.
Steven Murray's avatar
Steven Murray committed
120
   *
121
   * @param sessionPid The process ID of the session.
Steven Murray's avatar
Steven Murray committed
122
   */
123
  DriveCatalogueEntry &findDrive(const pid_t sessionPid);
Steven Murray's avatar
Steven Murray committed
124
125

  /**
126
127
   * 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
128
   *
129
   * @return Unordered list of the unit names.
Steven Murray's avatar
Steven Murray committed
130
   */
131
  std::list<std::string> getUnitNames() const;
Steven Murray's avatar
Steven Murray committed
132
133

  /**
134
135
   * Returns an unordered list of the unit names of the tape drives in the
   * specified state.
Steven Murray's avatar
Steven Murray committed
136
   *
137
   * @return Unordered list of the unit names.
Daniele Kruse's avatar
Daniele Kruse committed
138
   */
139
140
  std::list<std::string> getUnitNames(const DriveCatalogueEntry::DriveState
    state) const;
Daniele Kruse's avatar
Daniele Kruse committed
141
  
142
143
private:

Daniele Kruse's avatar
Daniele Kruse committed
144
  /**
145
   * Object representing the API of the CASTOR logging system.
Daniele Kruse's avatar
Daniele Kruse committed
146
   */
147
148
  log::Logger &m_log;

Daniele Kruse's avatar
Daniele Kruse committed
149
  /**
150
   * The configuration of a data-transfer session.
Daniele Kruse's avatar
Daniele Kruse committed
151
   */
152
153
  const DataTransferSession::CastorConf m_dataTransferConfig;

154
  /**
155
   * Proxy object representing the ProcessForker.
156
   */
157
  ProcessForkerProxy &m_processForker;
158

159
160
161
162
163
164
165
166
167
168
  /**
   * Proxy object representing the vdqmd daemon.
   */
  legacymsg::VdqmProxy &m_vdqm;

  /**
   * 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;
169
170
171
172
173

  /**
   * Type that maps the unit name of a tape drive to the catalogue entry of
   * that drive.
   */
Daniele Kruse's avatar
Daniele Kruse committed
174
  typedef std::map<std::string, DriveCatalogueEntry *> DriveMap;
175
176
177
178
179
180
181

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

182
  /** 
183
   * Enters the specified tape-drive configuration into the catalogue.
184
   *
185
   * @param driveConfig The tape-drive configuration.
186
   */
187
  void enterDriveConfig(const utils::DriveConfig &driveConfig);
188

189
190
191
192
193
194
}; // class DriveCatalogue

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