ArchiveMount.cpp 4.51 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(NameServer & ns): m_ns(ns), m_sessionRunning(false){
25
26
}

27
28
29
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
30
cta::ArchiveMount::ArchiveMount(NameServer & ns,
31
32
  std::unique_ptr<SchedulerDatabase::ArchiveMount> dbMount): m_ns(ns), 
    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
//------------------------------------------------------------------------------
// getPoolName
//------------------------------------------------------------------------------
58
std::string cta::ArchiveMount::getPoolName() const {
59
  return m_dbMount->mountInfo.tapePool;
60
61
}

62
63
64
65
66
67
68
//------------------------------------------------------------------------------
// getNbFiles
//------------------------------------------------------------------------------
uint32_t cta::ArchiveMount::getNbFiles() const {
  return m_dbMount->nbFilesCurrentlyOnTape;
}

69
70
71
//------------------------------------------------------------------------------
// getMountTransactionId
//------------------------------------------------------------------------------
72
std::string cta::ArchiveMount::getMountTransactionId() const {
73
74
75
76
77
  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();
78
}
79

80
81
82
83
//------------------------------------------------------------------------------
// getNextJob
//------------------------------------------------------------------------------
std::unique_ptr<cta::ArchiveJob> cta::ArchiveMount::getNextJob() {
84
85
86
  // Check we are still running the session
  if (!m_sessionRunning)
    throw SessionNotRunning("In ArchiveMount::getNextJob(): trying to get job from complete/not started session");
87
88
89
90
  // try and get a new job from the DB side
  std::unique_ptr<cta::SchedulerDatabase::ArchiveJob> dbJob(m_dbMount->getNextJob().release());
  if (!dbJob.get())
    return std::unique_ptr<cta::ArchiveJob>(NULL);
91
  // We have something to archive: prepare the response
92
93
94
95
  std::unique_ptr<cta::ArchiveJob> ret(new ArchiveJob(*this, m_ns,
      dbJob->archiveFile, dbJob->remoteFile, dbJob->nameServerTapeFile));
  ret->m_dbJob.reset(dbJob.release());
  return ret;
96
}
97
    
98
//------------------------------------------------------------------------------
99
// complete
100
//------------------------------------------------------------------------------
101
void cta::ArchiveMount::complete() {
102
103
104
105
  // 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;
106
}
107

108
109
110
111
112
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::ArchiveMount::~ArchiveMount() throw() {
}