EmptyDriveProbe.hpp 3.23 KB
Newer Older
1
2
3
4
5
6
7
/*
 * @project        The CERN Tape Archive (CTA)
 * @copyright      Copyright(C) 2021 CERN
 * @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.
Daniele Kruse's avatar
Daniele Kruse 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.
Daniele Kruse's avatar
Daniele Kruse 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/>.
 */
Daniele Kruse's avatar
Daniele Kruse 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"
Daniele Kruse's avatar
Daniele Kruse committed
22
23
24
#include "castor/tape/tapeserver/drive/DriveInterface.hpp"
#include "castor/tape/tapeserver/file/Structures.hpp"
#include "castor/tape/tapeserver/SCSI/Device.hpp"
25
#include "castor/tape/tapeserver/system/Wrapper.hpp"
26
#include "mediachanger/MediaChangerFacade.hpp"
27
#include "common/optional.hpp"
Daniele Kruse's avatar
Daniele Kruse committed
28
29
30
31
32
33
34
35

#include <memory>

namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  /**
36
   * Class responsible for probing a tape drive to see if it empty and
37
   * accessible.
Daniele Kruse's avatar
Daniele Kruse committed
38
   */
39
  class EmptyDriveProbe {
Daniele Kruse's avatar
Daniele Kruse committed
40
  public:
41

Daniele Kruse's avatar
Daniele Kruse committed
42
43
44
45
46
47
48
    /**
     * Constructor
     * 
     * @param log Object representing the API to the CASTOR logging system.
     * @param driveConfig Configuration of the tape drive to be probed.
     * @param sysWrapper Object representing the operating system.
     */
49
    EmptyDriveProbe(
Victor Kotlyar's avatar
Victor Kotlyar committed
50
      cta::log::Logger &log,
51
      const cta::tape::daemon::TpconfigLine &driveConfig,
52
      System::virtualWrapper &sysWrapper);
Daniele Kruse's avatar
Daniele Kruse committed
53
54
    
    /** 
55
     * Probes the tape drive to determine whether it is empty and accessible.
Daniele Kruse's avatar
Daniele Kruse committed
56
     *
57
     * @return True if the drive is empty and accessible.
Daniele Kruse's avatar
Daniele Kruse committed
58
     */
59
    bool driveIsEmpty() throw();
Daniele Kruse's avatar
Daniele Kruse committed
60
    
61
62
63
64
65
    /**
     * Returns the eventual probe error message
     */
    cta::optional<std::string> getProbeErrorMsg();
    
Daniele Kruse's avatar
Daniele Kruse committed
66
67
68
69
70
  private:

    /**
     * The logging object     
     */
Victor Kotlyar's avatar
Victor Kotlyar committed
71
    cta::log::Logger &m_log;
Daniele Kruse's avatar
Daniele Kruse committed
72
73
74
75
    
    /**
     * The configuration of the tape drive to be probed.
     */
76
    const cta::tape::daemon::TpconfigLine m_driveConfig;
Daniele Kruse's avatar
Daniele Kruse committed
77
78
79
80
    
    /**
     * The system wrapper used to find the device and instantiate the drive object
     */
81
    System::virtualWrapper &m_sysWrapper;
Daniele Kruse's avatar
Daniele Kruse committed
82
83

    /** 
84
     * Probes the tape drive to determine whether it is empty and accessible.
Daniele Kruse's avatar
Daniele Kruse committed
85
     *
86
     * @return True if the drive is empty and accessible.
Daniele Kruse's avatar
Daniele Kruse committed
87
     */
88
    bool exceptionThrowingDriveIsEmpty();
Daniele Kruse's avatar
Daniele Kruse committed
89
90
91
92
93
94
95

    /**
     * Creates and returns the object that represents the tape drive to be
     * probed.
     *
     * @return The tape drive.
     */
96
    std::unique_ptr<drive::DriveInterface> createDrive();
Daniele Kruse's avatar
Daniele Kruse committed
97
    
98
99
100
101
102
    /**
     * Eventual error message if we could not check whether the drive is empty or not
     */
    cta::optional<std::string> m_probeErrorMsg;
    
103
  }; // class EmptyDriveProbe
Daniele Kruse's avatar
Daniele Kruse committed
104
105
106
107
108

} // namespace daemon
} // namespace tapeserver
} // namespace tape
} // namespace castor