Tape.cpp 6.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * 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/>.
 */

#include "Tape.hpp"
#include "GenericObject.hpp"

cta::objectstore::Tape::Tape(const std::string& address, Backend& os):
  ObjectOps<serializers::Tape>(os, address) { }

cta::objectstore::Tape::Tape(GenericObject& go):
  ObjectOps<serializers::Tape>(go.objectStore()){
  // Here we transplant the generic object into the new object
  go.transplantHeader(*this);
  // And interpret the header.
  getPayloadFromHeader();
}

33
34
void cta::objectstore::Tape::initialize(const std::string &name, 
    const std::string &logicallibrary) {
35
36
37
38
39
  ObjectOps<serializers::Tape>::initialize();
  // Set the reguired fields
  m_payload.set_vid(name);
  m_payload.set_bytesstored(0);
  m_payload.set_lastfseq(0);
40
41
42
43
  m_payload.set_logicallibrary(logicallibrary);
  m_payload.set_oldestjobtime(0);
  m_payload.set_priority(0);
  m_payload.set_retrievejobstotalsize(0);
44
45
46
47
48
49
50
51
52
53
54
55
  m_payload.set_busy(false);
  m_payload.set_archived(false);
  m_payload.set_disabled(false);
  m_payload.set_readonly(false);
  m_payload.set_full(false);
  auto cm = m_payload.mutable_currentmount();
  cm->set_drivemodel("");
  cm->set_drivename("");
  cm->set_driveserial("");
  cm->set_drivevendor("");
  cm->set_host("");
  cm->set_time(0);
56
  m_payload.set_currentmounttype(serializers::MountType::Archive);
57
58
59
60
61
62
  m_payloadInterpreted = true;
}


bool cta::objectstore::Tape::isEmpty() {
  checkPayloadReadable();
63
  return !m_payload.retrievejobs_size();
64
65
66
67
68
}

void cta::objectstore::Tape::removeIfEmpty() {
  checkPayloadWritable();
  if (!isEmpty()) {
69
    throw NotEmpty("In Tape::removeIfEmpty: trying to remove an tape with retrieves queued");
70
71
72
  }
  remove();
}
73
74
75
76
void cta::objectstore::Tape::setStoredData(uint64_t bytes) {
  checkPayloadWritable();
  m_payload.set_bytesstored(bytes);
}
77
78
79
80
81
82
83
84
85
86
87

void cta::objectstore::Tape::addStoredData(uint64_t bytes) {
  checkPayloadWritable();
  m_payload.set_bytesstored(m_payload.bytesstored()+bytes);
}

uint64_t cta::objectstore::Tape::getStoredData() {
  checkPayloadReadable();
  return m_payload.bytesstored();
}

88
89
90
91
92
93
94
95
96
97
void cta::objectstore::Tape::setLastFseq(uint64_t lastFseq) {
  checkPayloadWritable();
  m_payload.set_lastfseq(lastFseq);
}

uint64_t cta::objectstore::Tape::getLastFseq() {
  checkPayloadReadable();
  return m_payload.lastfseq();
}

98
99
100
101
102
103
104
105
106
107
108
std::string cta::objectstore::Tape::getVid() {
  checkPayloadReadable();
  return m_payload.vid();
}

std::string cta::objectstore::Tape::dump() {
  checkPayloadReadable();
  std::stringstream ret;
  ret << "<<<< Tape dump start: vid=" << m_payload.vid() << std::endl;
  ret << "  lastFseq=" << m_payload.lastfseq() 
      << " bytesStored=" << m_payload.bytesstored() << std::endl;
109
  ret << "  Retrieve jobs queued: " << m_payload.retrievejobs_size() << std::endl;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  if (m_payload.readmounts_size()) {
    auto lrm = m_payload.readmounts(0);
    ret << "  Latest read for mount: " << lrm.host() << " " << lrm.time() << " " 
        << lrm.drivevendor() << " " << lrm.drivemodel() << " " 
        << lrm.driveserial() << std::endl;
  }
  if (m_payload.writemounts_size()) {
    auto lwm = m_payload.writemounts(0);
    ret << "  Latest write for mount: " << lwm.host() << " " << lwm.time() << " " 
        << lwm.drivevendor() << " " << lwm.drivemodel() << " " 
        << lwm.driveserial() << std::endl;
  }
  ret << ">>>> Tape dump end" << std::endl;
  return ret.str();
}

126
void cta::objectstore::Tape::addJob(const RetrieveToFileRequest::JobDump& job,
127
128
  const std::string & retrieveToFileAddress, uint64_t size, uint64_t priority,
  time_t startTime) {
129
  checkPayloadWritable();
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  // Manage the cumulative properties
  if (m_payload.retrievejobs_size()) {
    if (priority > m_payload.priority()) {
      m_payload.set_priority(priority);
    }
    if (m_payload.oldestjobtime() > (uint64_t)startTime) {
      m_payload.set_oldestjobtime(startTime);
    }
    m_payload.set_retrievejobstotalsize(m_payload.retrievejobstotalsize() + size);
  } else {
    m_payload.set_priority(priority);
    m_payload.set_oldestjobtime(startTime);
    m_payload.set_retrievejobstotalsize(size);
  }
144
  auto * j = m_payload.add_retrievejobs();
145
146
147
  j->set_address(retrieveToFileAddress);
  j->set_size(size);
}
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

std::string cta::objectstore::Tape::getLogicalLibrary() {
  checkPayloadReadable();
  return m_payload.logicallibrary();
}

cta::objectstore::Tape::JobsSummary cta::objectstore::Tape::getJobsSummary() {
  checkPayloadReadable();
  JobsSummary ret;
  ret.bytes = m_payload.retrievejobstotalsize();
  ret.files = m_payload.retrievejobs_size();
  ret.oldestJobStartTime = m_payload.oldestjobtime();
  ret.priority = m_payload.priority();
  return ret;
}
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

bool cta::objectstore::Tape::isArchived() {
  checkPayloadReadable();
  return m_payload.archived();
}

void cta::objectstore::Tape::setArchived(bool archived) {
  checkPayloadWritable();
  m_payload.set_archived(archived);
}

bool cta::objectstore::Tape::isDisabled() {
  checkPayloadReadable();
  return m_payload.disabled();
}

void cta::objectstore::Tape::setDisabled(bool disabled) {
  checkPayloadWritable();
  m_payload.set_disabled(disabled);
}

bool cta::objectstore::Tape::isReadOnly() {
  checkPayloadReadable();
  return m_payload.readonly();
}

void cta::objectstore::Tape::setReadOnly(bool readOnly) {
  checkPayloadWritable();
  m_payload.set_readonly(readOnly);
}

bool cta::objectstore::Tape::isFull() {
  checkPayloadReadable();
  return m_payload.full();
}

void cta::objectstore::Tape::setFull(bool full) {
  checkPayloadWritable();
  m_payload.set_full(full);
}

bool cta::objectstore::Tape::isBusy() {
  checkPayloadReadable();
  return m_payload.busy();
}

void cta::objectstore::Tape::setBusy(const std::string& drive, MountType mountType, 
  const std::string & host, time_t startTime, const std::string& agentAddress) {
  checkPayloadWritable();
  m_payload.set_busy(true);
  auto * cm = m_payload.mutable_currentmount();
  cm->set_drivemodel("");
  cm->set_driveserial("");
  cm->set_drivename(drive);
  cm->set_host(host);
  cm->set_time((uint64_t)time);
  switch (mountType) {
    case MountType::Archive:
221
      m_payload.set_currentmounttype(objectstore::serializers::MountType::Archive);
222
223
      break;
    case MountType::Retrieve:
224
      m_payload.set_currentmounttype(objectstore::serializers::MountType::Retrieve);
225
226
227
228
229
230
231
232
233
234
      break;
  }
}

void cta::objectstore::Tape::releaseBusy() {
  checkPayloadWritable();
  m_payload.set_busy(false);
}


235
236
237
238
239
240
241
242