DataTransferSession.hpp 5.87 KB
Newer Older
1
2
/*
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        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 3 of the License, or
 *                 (at your option) any later version.
Eric Cano's avatar
Eric Cano committed
8
 *
9
10
11
12
 *                 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.
Eric Cano's avatar
Eric Cano committed
13
 *
14
15
16
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Eric Cano's avatar
Eric Cano committed
17
18
19

#pragma once

Victor Kotlyar's avatar
Victor Kotlyar committed
20
21
#include "common/log/LogContext.hpp"
#include "common/log/Logger.hpp"
22
#include "common/processCap/ProcessCap.hpp"
23
24
#include "mediachanger/MediaChangerFacade.hpp"
#include "tapeserver/daemon/TapedProxy.hpp"
25
#include "DataTransferConfig.hpp"
26
#include "tapeserver/daemon/TpconfigLine.hpp"
27
28
29
#include "Session.hpp"
#include "TapeSingleThreadInterface.hpp"
#include "tapeserver/castor/tape/tapeserver/system/Wrapper.hpp"
30
31
#include "scheduler/ArchiveMount.hpp"
#include "scheduler/RetrieveMount.hpp"
32
#include "scheduler/LabelMount.hpp"
33
#include "scheduler/Scheduler.hpp"
34
#include "scheduler/TapeMount.hpp"
Eric Cano's avatar
Eric Cano committed
35
36
37

namespace castor {
namespace tape {
38
39
namespace tapeserver {
namespace daemon {
Eric Cano's avatar
Eric Cano committed
40
41
42
43
44
  /**
   * 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.
   */
45
  class DataTransferSession: public Session {
Eric Cano's avatar
Eric Cano committed
46
  public:
47
48
49
50
51
    /**
     * Constructor.
     *
     * @param log Object representing the API of the CASTOR logging system.
     */
52
    DataTransferSession(
53
      const std::string & hostname,
Victor Kotlyar's avatar
Victor Kotlyar committed
54
      cta::log::Logger & log,
55
      System::virtualWrapper & sysWrapper,
56
      const cta::tape::daemon::TpconfigLine & driveConfig,
57
      cta::mediachanger::MediaChangerFacade & mc,
58
      cta::tape::daemon::TapedProxy & initialProcess,
59
      cta::server::ProcessCap &capUtils,
60
      const DataTransferConfig & castorConf,
61
      cta::Scheduler &scheduler);
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

    /**
     * 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();

85
86
87
88
89
90
91
    /**
     * Sets the capabilities of the process and logs the result.
     *
     * @param capabilities The string representation of the capabilities.
     */
    void setProcessCapabilities(const std::string &capabilities);

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
     * Object representing the API of the CASTOR logging system.
104
     */
Victor Kotlyar's avatar
Victor Kotlyar committed
105
    cta::log::Logger & m_log;
106
    VolumeInfo m_volInfo;
107
    System::virtualWrapper & m_sysWrapper;
108
109
110
    /**
     * The configuration of the tape drive to be used by this session.
     */
111
    const cta::tape::daemon::TpconfigLine m_driveConfig;
112
    const DataTransferConfig & m_castorConf;
113
114
115
116
117
    /**
     * The drive information bundle allowing drive register update.
     * Filled up at construction time.
     */
    const cta::common::dataStructures::DriveInfo m_driveInfo;
118
119
120
    /** 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. */
121
    castor::tape::tapeserver::drive::DriveInterface * findDrive(
122
     const cta::tape::daemon::TpconfigLine &driveConfig, cta::log::LogContext & lc, cta::TapeMount *mount);
123
        
124
    /** sub-part of execute for the read sessions */
Victor Kotlyar's avatar
Victor Kotlyar committed
125
    EndOfSessionAction executeRead(cta::log::LogContext & lc, cta::RetrieveMount *retrieveMount);
126
    /** sub-part of execute for a write session */
Victor Kotlyar's avatar
Victor Kotlyar committed
127
    EndOfSessionAction executeWrite(cta::log::LogContext & lc, cta::ArchiveMount *archiveMount);
128
129
    /** sub-part of execute for a label session */
    EndOfSessionAction executeLabel(cta::log::LogContext & lc, cta::LabelMount *labelMount);
130
    /** Reference to the MediaChangerFacade, allowing the mounting of the tape
131
     * by the library. It will be used exclusively by the tape thread. */
132
    cta::mediachanger::MediaChangerFacade & m_mc;
133
    /** Reference to the tape server's parent process to report detailed status */
134
    cta::tape::daemon::TapedProxy & m_intialProcess;
135
    /** Object providing utilities for working UNIX capabilities. */
136
    cta::server::ProcessCap &m_capUtils;
137
138
    /** hostname, used to report status of the drive */
    const std::string m_hostname;
139
140
141
    /**
     * The scheduler, i.e. the local interface to the Objectstore DB
     */
142
    cta::Scheduler &m_scheduler;
Steven Murray's avatar
Steven Murray committed
143
144

    /**
145
     * Returns the string representation of the specified mount type
Steven Murray's avatar
Steven Murray committed
146
     */
147
    const char *mountTypeToString(const cta::common::dataStructures::MountType mountType) const
Steven Murray's avatar
Steven Murray committed
148
      throw();
Eric Cano's avatar
Eric Cano committed
149
150
151
152
  };
}
}
}
153
}