| 186 | } |
| 187 | |
| 188 | std::string BackupDescription::toJSON() const { |
| 189 | JsonBuilderObject doc; |
| 190 | |
| 191 | doc.setKey("SchemaVersion", "1.0.0"); |
| 192 | doc.setKey("URL", url.c_str()); |
| 193 | doc.setKey("Restorable", maxRestorableVersion.present()); |
| 194 | doc.setKey("Partitioned", partitioned); |
| 195 | |
| 196 | auto formatVersion = [&](Version v) { |
| 197 | JsonBuilderObject doc; |
| 198 | doc.setKey("Version", v); |
| 199 | if (!versionTimeMap.empty()) { |
| 200 | auto i = versionTimeMap.find(v); |
| 201 | if (i != versionTimeMap.end()) { |
| 202 | doc.setKey("Timestamp", BackupAgentBase::formatTime(i->second)); |
| 203 | doc.setKey("EpochSeconds", i->second); |
| 204 | } |
| 205 | } else if (maxLogEnd.present()) { |
| 206 | double days = double(v - maxLogEnd.get()) / (CLIENT_KNOBS->CORE_VERSIONSPERSECOND * 24 * 60 * 60); |
| 207 | doc.setKey("RelativeDays", days); |
| 208 | } |
| 209 | return doc; |
| 210 | }; |
| 211 | |
| 212 | JsonBuilderArray snapshotsArray; |
| 213 | for (const KeyspaceSnapshotFile& m : snapshots) { |
| 214 | JsonBuilderObject snapshotDoc; |
| 215 | snapshotDoc.setKey("Start", formatVersion(m.beginVersion)); |
| 216 | snapshotDoc.setKey("End", formatVersion(m.endVersion)); |
| 217 | snapshotDoc.setKey("Restorable", m.restorable.orDefault(false)); |
| 218 | snapshotDoc.setKey("TotalBytes", m.totalSize); |
| 219 | snapshotDoc.setKey("PercentageExpired", m.expiredPct(expiredEndVersion)); |
| 220 | snapshotsArray.push_back(snapshotDoc); |
| 221 | } |
| 222 | doc.setKey("Snapshots", snapshotsArray); |
| 223 | |
| 224 | doc.setKey("TotalSnapshotBytes", snapshotBytes); |
| 225 | |
| 226 | if (expiredEndVersion.present()) |
| 227 | doc.setKey("ExpiredEnd", formatVersion(expiredEndVersion.get())); |
| 228 | if (unreliableEndVersion.present()) |
| 229 | doc.setKey("UnreliableEnd", formatVersion(unreliableEndVersion.get())); |
| 230 | if (minLogBegin.present()) |
| 231 | doc.setKey("MinLogBegin", formatVersion(minLogBegin.get())); |
| 232 | if (contiguousLogEnd.present()) |
| 233 | doc.setKey("ContiguousLogEnd", formatVersion(contiguousLogEnd.get())); |
| 234 | if (maxLogEnd.present()) |
| 235 | doc.setKey("MaxLogEnd", formatVersion(maxLogEnd.get())); |
| 236 | if (minRestorableVersion.present()) |
| 237 | doc.setKey("MinRestorablePoint", formatVersion(minRestorableVersion.get())); |
| 238 | if (maxRestorableVersion.present()) |
| 239 | doc.setKey("MaxRestorablePoint", formatVersion(maxRestorableVersion.get())); |
| 240 | |
| 241 | if (!extendedDetail.empty()) |
| 242 | doc.setKey("ExtendedDetail", extendedDetail); |
| 243 | |
| 244 | return doc.getJson(); |
| 245 | } |
no test coverage detected