DataTransferSession.hpp 5.7 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/log/LogContext.hpp"
27
#include "castor/log/Logger.hpp"
Steven Murray's avatar
Steven Murray committed
28
29
#include "castor/mediachanger/MediaChangerFacade.hpp"
#include "castor/messages/TapeserverProxy.hpp"
30
#include "castor/server/ProcessCap.hpp"
31
#include "castor/tape/tapeserver/client/ClientProxy.hpp"
32
#include "castor/tape/tapeserver/daemon/DataTransferConfig.hpp"
33
#include "castor/tape/tapeserver/daemon/DriveConfig.hpp"
34
#include "castor/tape/tapeserver/daemon/Session.hpp"
35
#include "castor/tape/tapeserver/daemon/TapeSingleThreadInterface.hpp"
36
#include "castor/tape/tapeserver/system/Wrapper.hpp"
37
38
#include "scheduler/ArchiveMount.hpp"
#include "scheduler/RetrieveMount.hpp"
39
#include "scheduler/Scheduler.hpp"
40
#include "scheduler/TapeMount.hpp"
Eric Cano's avatar
Eric Cano committed
41
42

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

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

Eric Cano's avatar
Eric Cano committed
103
  private:
104
    
105
    /**
106
     * Object representing the API of the CASTOR logging system.
107
     */
108
    castor::log::Logger & m_log;
109

110
111
    client::ClientProxy m_clientProxy;
    client::ClientProxy::VolumeInfo m_volInfo;
112
    System::virtualWrapper & m_sysWrapper;
113
114
115
    /**
     * The configuration of the tape drive to be used by this session.
     */
116
    const DriveConfig m_driveConfig;
117
    const DataTransferConfig & m_castorConf;
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 DriveConfig &driveConfig,log::LogContext & lc);
123
        
124
    /** sub-part of execute for the read sessions */
125
    EndOfSessionAction executeRead(log::LogContext & lc, cta::RetrieveMount *retrieveMount);
126
    /** sub-part of execute for a write session */
127
    EndOfSessionAction executeWrite(log::LogContext & lc, cta::ArchiveMount *archiveMount);
128
    /** sub-part of execute for a dump session */
129
    void executeDump(log::LogContext & lc);
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
    castor::mediachanger::MediaChangerFacade & m_mc;
133
    /** Reference to the tape server's parent process to report detailed status */
134
    castor::messages::TapeserverProxy & m_intialProcess;
135
    /** Object providing utilities for working UNIX capabilities. */
136
    castor::server::ProcessCap &m_capUtils;
137
138
    /** hostname, used to report status of the drive */
    const std::string m_hostname;
139
140
141
142
    /**
     * The scheduler, i.e. the local interface to the Objectstore DB
     */
    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::MountType::Enum mountType) const
Steven Murray's avatar
Steven Murray committed
148
      throw();
Eric Cano's avatar
Eric Cano committed
149
150
151
152
  };
}
}
}
153
}