ArchiveJob.cpp 6.69 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/ArchiveJob.hpp"
20
#include "scheduler/ArchiveMount.hpp"
21
#include "eos/DiskReporterFactory.hpp"
22
#include <limits>
23
24
25
26

//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
27
cta::ArchiveJob::~ArchiveJob() throw() {
28
29
}

30
31
32
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
33
cta::ArchiveJob::ArchiveJob(ArchiveMount &mount,
34
  catalogue::Catalogue & catalogue,
35
  const common::dataStructures::ArchiveFile &archiveFile,
36
  const std::string &srcURL,
37
  const common::dataStructures::TapeFile &tapeFile):
38
  m_mount(mount), m_catalogue(catalogue),
39
  archiveFile(archiveFile),
40
  srcURL(srcURL),
41
  tapeFile(tapeFile) {}
Steven Murray's avatar
Steven Murray committed
42

43
//------------------------------------------------------------------------------
44
// asyncSetJobSucceed
45
//------------------------------------------------------------------------------
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
void cta::ArchiveJob::asyncSetJobSucceed() {
  m_dbJob->asyncSucceed();
}

//------------------------------------------------------------------------------
// checkAndReportComplete
//------------------------------------------------------------------------------
bool cta::ArchiveJob::checkAndAsyncReportComplete() {
  if (m_dbJob->checkSucceed()) {
    std::unique_ptr<eos::DiskReporter> reporter(m_mount.createDiskReporter(m_dbJob->archiveReportURL, m_reporterState));
    reporter->asyncReportArchiveFullyComplete();
    return true;
  }
  return false;
}

//------------------------------------------------------------------------------
// ArchiveJob::writeToCatalogue
//------------------------------------------------------------------------------
void cta::ArchiveJob::writeToCatalogue() {
66
  catalogue::TapeFileWritten fileReport;
67
68
69
70
71
72
  fileReport.archiveFileId = archiveFile.archiveFileID;
  fileReport.blockId = tapeFile.blockId;
  fileReport.checksumType = tapeFile.checksumType;
  fileReport.checksumValue = tapeFile.checksumValue;
  fileReport.compressedSize = tapeFile.compressedSize;
  fileReport.copyNb = tapeFile.copyNb;
73
74
75
76
77
78
  fileReport.diskFileId = archiveFile.diskFileId;
  fileReport.diskFileUser = archiveFile.diskFileInfo.owner;
  fileReport.diskFileGroup = archiveFile.diskFileInfo.group;
  fileReport.diskFilePath = archiveFile.diskFileInfo.path;
  fileReport.diskFileRecoveryBlob = archiveFile.diskFileInfo.recoveryBlob;
  fileReport.diskInstance = archiveFile.diskInstance;
79
80
  fileReport.fSeq = tapeFile.fSeq;
  fileReport.size = archiveFile.fileSize;
81
82
  fileReport.storageClassName = archiveFile.storageClass;
  fileReport.tapeDrive = m_mount.getDrive();
83
  fileReport.vid = tapeFile.vid;
84
  m_catalogue.filesWrittenToTape (std::set<catalogue::TapeFileWritten>{fileReport});
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
}
//------------------------------------------------------------------------------
// ArchiveJob::validateAndGetTapeFileWritten
//------------------------------------------------------------------------------
cta::catalogue::TapeFileWritten cta::ArchiveJob::validateAndGetTapeFileWritten() {
  validate();
  catalogue::TapeFileWritten fileReport;
  fileReport.archiveFileId = archiveFile.archiveFileID;
  fileReport.blockId = tapeFile.blockId;
  fileReport.checksumType = tapeFile.checksumType;
  fileReport.checksumValue = tapeFile.checksumValue;
  fileReport.compressedSize = tapeFile.compressedSize;
  fileReport.copyNb = tapeFile.copyNb;
  fileReport.diskFileId = archiveFile.diskFileId;
  fileReport.diskFileUser = archiveFile.diskFileInfo.owner;
  fileReport.diskFileGroup = archiveFile.diskFileInfo.group;
  fileReport.diskFilePath = archiveFile.diskFileInfo.path;
  fileReport.diskFileRecoveryBlob = archiveFile.diskFileInfo.recoveryBlob;
  fileReport.diskInstance = archiveFile.diskInstance;
  fileReport.fSeq = tapeFile.fSeq;
  fileReport.size = archiveFile.fileSize;
  fileReport.storageClassName = archiveFile.storageClass;
  fileReport.tapeDrive = m_mount.getDrive();
  fileReport.vid = tapeFile.vid;
  return fileReport;
}

//------------------------------------------------------------------------------
// ArchiveJob::validate
//------------------------------------------------------------------------------
void cta::ArchiveJob::validate(){
  // First check that the block Id for the file has been set.
  if (tapeFile.blockId ==
      std::numeric_limits<decltype(tapeFile.blockId)>::max())
    throw BlockIdNotSet("In cta::ArchiveJob::validate(): Block ID not set");
  // Also check the checksum has been set
  if (archiveFile.checksumType.empty() || archiveFile.checksumValue.empty() || 
      tapeFile.checksumType.empty() || tapeFile.checksumValue.empty())
    throw ChecksumNotSet("In cta::ArchiveJob::validate(): checksums not set");
  // And matches
  if (archiveFile.checksumType != tapeFile.checksumType || 
      archiveFile.checksumValue != tapeFile.checksumValue)
    throw ChecksumMismatch(std::string("In cta::ArchiveJob::validate(): checksum mismatch!")
            +" Archive file checksum type: "+archiveFile.checksumType
            +" Archive file checksum value: "+archiveFile.checksumValue
            +" Tape file checksum type: "+tapeFile.checksumType
            +" Tape file checksum value: "+tapeFile.checksumValue);
132
133
134
135
136
137
138
}

//------------------------------------------------------------------------------
// ArchiveJob::reportURL
//------------------------------------------------------------------------------
std::string cta::ArchiveJob::reportURL() {
  return m_dbJob->archiveReportURL;
139
140
141
142
143
}
  
//------------------------------------------------------------------------------
// failed
//------------------------------------------------------------------------------
144
145
void cta::ArchiveJob::failed(const cta::exception::Exception &ex,  log::LogContext & lc) {
  m_dbJob->fail(lc);
146
}
147
148
149
150
151
152
153

//------------------------------------------------------------------------------
// waitForReporting
//------------------------------------------------------------------------------
void cta::ArchiveJob::waitForReporting() {
  m_reporterState.get_future().get();
}