DataTransferSession.hpp 5.53 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 "tapeserver/castor/mediachanger/MediaChangerFacade.hpp"
29
#include "tapeserver/daemon/TapedProxy.hpp"
30
#include "common/processCap/ProcessCap.hpp"
31
32
33
34
35
#include "DataTransferConfig.hpp"
#include "DriveConfig.hpp"
#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 DriveConfig & driveConfig,
63
      castor::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();

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

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

    /**
139
     * Returns the string representation of the specified mount type
Steven Murray's avatar
Steven Murray committed
140
     */
141
    const char *mountTypeToString(const cta::MountType::Enum mountType) const
Steven Murray's avatar
Steven Murray committed
142
      throw();
Eric Cano's avatar
Eric Cano committed
143
144
145
146
  };
}
}
}
147
}