ArchiveMount.cpp 5.62 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
cta::MountType::Enum cta::ArchiveMount::getMountType() const {
45
  return 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
//------------------------------------------------------------------------------
// getMountTransactionId
//------------------------------------------------------------------------------
80
std::string cta::ArchiveMount::getMountTransactionId() const {
81
82
83
84
85
  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();
86
}
87

88
89
90
91
//------------------------------------------------------------------------------
// getNextJob
//------------------------------------------------------------------------------
std::unique_ptr<cta::ArchiveJob> cta::ArchiveMount::getNextJob() {
92
93
94
  // Check we are still running the session
  if (!m_sessionRunning)
    throw SessionNotRunning("In ArchiveMount::getNextJob(): trying to get job from complete/not started session");
95
96
97
  // try and get a new job from the DB side
  std::unique_ptr<cta::SchedulerDatabase::ArchiveJob> dbJob(m_dbMount->getNextJob().release());
  if (!dbJob.get())
98
    return std::unique_ptr<cta::ArchiveJob>();
99
  // We have something to archive: prepare the response
100
  std::unique_ptr<cta::ArchiveJob> ret(new ArchiveJob(*this, m_catalogue,
101
      dbJob->archiveFile, dbJob->srcURL, dbJob->tapeFile));
102
103
  ret->m_dbJob.reset(dbJob.release());
  return ret;
104
}
105
    
106
//------------------------------------------------------------------------------
107
// complete
108
//------------------------------------------------------------------------------
109
void cta::ArchiveMount::complete() {
110
111
112
113
  // 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;
114
}
115

116
117
118
119
120
121
122
//------------------------------------------------------------------------------
// abort
//------------------------------------------------------------------------------
void cta::ArchiveMount::abort() {
  complete();
}

123
124
125
126
127
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::ArchiveMount::~ArchiveMount() throw() {
}
128
129
130
131

//------------------------------------------------------------------------------
// setDriveStatus()
//------------------------------------------------------------------------------
132
void cta::ArchiveMount::setDriveStatus(cta::common::DriveStatus status) {
133
134
  m_dbMount->setDriveStatus(status, time(NULL));
}
135
136
137
138
139
140
141
142

//------------------------------------------------------------------------------
// setTapeFull()
//------------------------------------------------------------------------------
void cta::ArchiveMount::setTapeFull() {
  m_catalogue.noSpaceLeftOnTape(m_dbMount->getMountInfo().vid);
}