DataTransferSession.hpp 6.01 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

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

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

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

91
92
93
94
95
96
97
    /**
     * 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
98
99
    /** Temporary method used for debugging while building the session class */
    std::string getVid() { return m_volInfo.vid; }
100
    
101
    /**
102
     * Destructor.
103
     */
104
    ~DataTransferSession() throw();
105

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

    /**
151
     * Returns the string representation of the specified mount type
Steven Murray's avatar
Steven Murray committed
152
     */
153
    const char *mountTypeToString(const cta::common::dataStructures::MountType mountType) const
Steven Murray's avatar
Steven Murray committed
154
      throw();
Eric Cano's avatar
Eric Cano committed
155
156
157
158
  };
}
}
}
159
}