DataTransferSession.hpp 5.81 KB
Newer Older
Eric Cano's avatar
Eric Cano committed
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
/******************************************************************************
 *
 * 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

26
#include "castor/legacymsg/RtcpJobRqstMsgBody.hpp"
27
#include "castor/log/LogContext.hpp"
28
#include "castor/log/Logger.hpp"
Steven Murray's avatar
Steven Murray committed
29
30
#include "castor/mediachanger/MediaChangerFacade.hpp"
#include "castor/messages/TapeserverProxy.hpp"
31
#include "castor/server/ProcessCap.hpp"
32
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
33
#include "castor/tape/tapeserver/daemon/DataTransferConfig.hpp"
34
#include "castor/tape/tapeserver/daemon/DriveConfig.hpp"
35
#include "castor/tape/tapeserver/daemon/Session.hpp"
36
#include "castor/tape/tapeserver/daemon/TapeSingleThreadInterface.hpp"
37
#include "castor/tape/tapeserver/system/Wrapper.hpp"
Eric Cano's avatar
Eric Cano committed
38
39

namespace castor {
40
41
42
43
namespace legacymsg {
  class VdqmProxy;
  class VmgrProxy;
}
Eric Cano's avatar
Eric Cano committed
44
namespace tape {
45
46
namespace tapeserver {
namespace daemon {
Eric Cano's avatar
Eric Cano committed
47
48
49
50
51
  /**
   * The main class handling a tape session. This is the main container started
   * by the master process. It will drive a separate process. Only the sub
   * process interface is not included here to allow testability.
   */
52
  class DataTransferSession: public Session {
Eric Cano's avatar
Eric Cano committed
53
  public:
54
55
56
57
58
    /**
     * Constructor.
     *
     * @param log Object representing the API of the CASTOR logging system.
     */
59
    DataTransferSession(
60
61
      const std::string & hostname,
      const legacymsg::RtcpJobRqstMsgBody & clientRequest, 
62
      castor::log::Logger & log,
63
      System::virtualWrapper & sysWrapper,
64
      const DriveConfig & driveConfig,
65
      castor::mediachanger::MediaChangerFacade & mc,
66
      castor::messages::TapeserverProxy & initialProcess,
67
      castor::server::ProcessCap &capUtils,
68
      const DataTransferConfig & castorConf);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

    /**
     * Execute the session and return the type of action to be performed
     * immediately after the session has completed.
     *
     * The session is responsible for mounting a tape into the tape drive,
     * working with that tape, unloading the tape from the drive and then
     * dismounting the tape from the drive and storing it back in its home slot
     * within the tape library.
     *
     * If this method throws an exception and the session is not a cleaner
     * session then it assumed that the post session action is
     * EndOfSessionAction::CLEAN_DRIVE.
     *
     * If this method throws an exception and the session is a cleaner
     * session then it assumed that the post session action is
     * EndOfSessionAction::MARK_DRIVE_AS_DOWN.
     *
     * @return Returns the type of action to be performed after the session has
     * completed.
     */
    EndOfSessionAction execute();

Eric Cano's avatar
Eric Cano committed
92
93
    /** Temporary method used for debugging while building the session class */
    std::string getVid() { return m_volInfo.vid; }
94
    
95
    /**
96
     * Destructor.
97
     */
98
    ~DataTransferSession() throw();
99

Eric Cano's avatar
Eric Cano committed
100
  private:
101

102
103
    legacymsg::RtcpJobRqstMsgBody m_request;

104
    /**
105
     * Object representing the API of the CASTOR logging system.
106
     */
107
    castor::log::Logger & m_log;
108

109
110
    client::ClientProxy m_clientProxy;
    client::ClientProxy::VolumeInfo m_volInfo;
111
    System::virtualWrapper & m_sysWrapper;
112
113
114
    /**
     * The configuration of the tape drive to be used by this session.
     */
115
    const DriveConfig m_driveConfig;
116
    const DataTransferConfig & m_castorConf;
117
118
119
    /** utility to find the drive on the system. This function logs 
     * all errors and hence does not throw exceptions. It returns NULL
     * in case of failure. */
120
    castor::tape::tapeserver::drive::DriveInterface * findDrive(
121
     const DriveConfig &driveConfig,log::LogContext & lc);
122
        
123
    /** sub-part of execute for the read sessions */
124
    EndOfSessionAction executeRead(log::LogContext & lc);
125
    /** sub-part of execute for a write session */
126
    EndOfSessionAction executeWrite(log::LogContext & lc);
127
    /** sub-part of execute for a dump session */
128
    void executeDump(log::LogContext & lc);
129
    /** Reference to the MediaChangerFacade, allowing the mounting of the tape
130
     * by the library. It will be used exclusively by the tape thread. */
131
    castor::mediachanger::MediaChangerFacade & m_mc;
132
    /** Reference to the tape server's parent process to report detailed status */
133
    castor::messages::TapeserverProxy & m_intialProcess;
134
    /** Object providing utilities for working UNIX capabilities. */
135
    castor::server::ProcessCap &m_capUtils;
136
137
    /** hostname, used to report status of the drive */
    const std::string m_hostname;
Steven Murray's avatar
Steven Murray committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151

    /**
     * Returns the string representation of the specified tapebridge client type
     * from a tapegateay::Volume message (READ, WRITE or DUMP).
     */
    const char *volumeClientTypeToString(const tapegateway::ClientType mode)
      const throw();

    /**
     * Returns the string representation of the specified volume mode from a
     * tapegateay::Volume message (READ, WRITE or DUMP).
     */
    const char *volumeModeToString(const tapegateway::VolumeMode mode) const
      throw();
Eric Cano's avatar
Eric Cano committed
152
153
154
155
  };
}
}
}
156
}