ArchiveMount.cpp 6.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  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 3 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, see <http://www.gnu.org/licenses/>.
 */

19
#include "scheduler/ArchiveMount.hpp"
20

21
22
23
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
24
cta::ArchiveMount::ArchiveMount(catalogue::Catalogue & catalogue): m_catalogue(catalogue), m_sessionRunning(false){
25
26
}

27
28
29
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
30
31
cta::ArchiveMount::ArchiveMount(catalogue::Catalogue & catalogue,
  std::unique_ptr<SchedulerDatabase::ArchiveMount> dbMount): m_catalogue(catalogue), 
32
    m_sessionRunning(false) {
33
34
35
36
37
  m_dbMount.reset(
    dynamic_cast<SchedulerDatabase::ArchiveMount*>(dbMount.release()));
  if(!m_dbMount.get()) {
    throw WrongMountType(std::string(__FUNCTION__) +
      ": could not cast mount to SchedulerDatabase::ArchiveMount");
38
39
40
  }
}

41
42
43
//------------------------------------------------------------------------------
// getMountType
//------------------------------------------------------------------------------
44
45
cta::common::dataStructures::MountType cta::ArchiveMount::getMountType() const {
  return cta::common::dataStructures::MountType::Archive;
46
}
47

Steven Murray's avatar
Steven Murray committed
48
49
50
//------------------------------------------------------------------------------
// getVid
//------------------------------------------------------------------------------
51
std::string cta::ArchiveMount::getVid() const {
52
  return m_dbMount->mountInfo.vid;
Steven Murray's avatar
Steven Murray committed
53
54
}

55
56
57
58
59
60
61
62
//------------------------------------------------------------------------------
// getDrive
//------------------------------------------------------------------------------
std::string cta::ArchiveMount::getDrive() const {
  return m_dbMount->mountInfo.drive;
}


63
64
65
//------------------------------------------------------------------------------
// getPoolName
//------------------------------------------------------------------------------
66
std::string cta::ArchiveMount::getPoolName() const {
67
  return m_dbMount->mountInfo.tapePool;
68
69
}

70
71
72
73
74
75
76
//------------------------------------------------------------------------------
// getNbFiles
//------------------------------------------------------------------------------
uint32_t cta::ArchiveMount::getNbFiles() const {
  return m_dbMount->nbFilesCurrentlyOnTape;
}

77
78
79
//------------------------------------------------------------------------------
// createDiskReporter
//------------------------------------------------------------------------------
80
81
cta::eos::DiskReporter* cta::ArchiveMount::createDiskReporter(std::string& URL, std::promise<void> &reporterState) {
  return m_reporterFactory.createDiskReporter(URL, reporterState);
82
83
}

84
85
86
//------------------------------------------------------------------------------
// getMountTransactionId
//------------------------------------------------------------------------------
87
std::string cta::ArchiveMount::getMountTransactionId() const {
88
89
90
91
92
  std::stringstream id;
  if (!m_dbMount.get())
    throw exception::Exception("In cta::ArchiveMount::getMountTransactionId(): got NULL dbMount");
  id << m_dbMount->mountInfo.mountId;
  return id.str();
93
}
94

95
//------------------------------------------------------------------------------
96
97
98
99
100
101
// updateCatalogueWithTapeFilesWritten
//------------------------------------------------------------------------------
void cta::ArchiveMount::updateCatalogueWithTapeFilesWritten(const std::set<cta::catalogue::TapeFileWritten> &tapeFilesWritten) {
  m_catalogue.filesWrittenToTape(tapeFilesWritten);
}

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// getNextJobBatch
//------------------------------------------------------------------------------
std::list<std::unique_ptr<cta::ArchiveJob> > cta::ArchiveMount::getNextJobBatch(uint64_t filesRequested, 
  uint64_t bytesRequested, log::LogContext& logContext) {
  // Check we are still running the session
  if (!m_sessionRunning)
    throw SessionNotRunning("In ArchiveMount::getNextJobBatch(): trying to get job from complete/not started session");
  // try and get a new job from the DB side
  std::list<std::unique_ptr<cta::SchedulerDatabase::ArchiveJob>> dbJobBatch(m_dbMount->getNextJobBatch(filesRequested, 
    bytesRequested, logContext));
  std::list<std::unique_ptr<ArchiveJob>> ret;
  // We prepare the response
  for (auto & sdaj: dbJobBatch) {
    ret.emplace_back(new ArchiveJob(*this, m_catalogue,
      sdaj->archiveFile, sdaj->srcURL, sdaj->tapeFile));
    ret.back()->m_dbJob.reset(sdaj.release());
  }
  return ret;
}

122
//------------------------------------------------------------------------------
123
// complete
124
//------------------------------------------------------------------------------
125
void cta::ArchiveMount::complete() {
126
127
128
129
  // Just set the session as complete in the DB.
  m_dbMount->complete(time(NULL));
  // and record we are done with the mount
  m_sessionRunning = false;
130
}
131

132
133
134
135
136
137
138
//------------------------------------------------------------------------------
// abort
//------------------------------------------------------------------------------
void cta::ArchiveMount::abort() {
  complete();
}

139
140
141
142
143
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::ArchiveMount::~ArchiveMount() throw() {
}
144
145
146
147

//------------------------------------------------------------------------------
// setDriveStatus()
//------------------------------------------------------------------------------
148
void cta::ArchiveMount::setDriveStatus(cta::common::dataStructures::DriveStatus status) {
149
150
  m_dbMount->setDriveStatus(status, time(NULL));
}
151

152
153
154
155
156
157
158
//------------------------------------------------------------------------------
// setTapeSessionStats()
//------------------------------------------------------------------------------
void cta::ArchiveMount::setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) {
  m_dbMount->setTapeSessionStats(stats);
}

159
160
161
162
163
164
165
//------------------------------------------------------------------------------
// setTapeFull()
//------------------------------------------------------------------------------
void cta::ArchiveMount::setTapeFull() {
  m_catalogue.noSpaceLeftOnTape(m_dbMount->getMountInfo().vid);
}