public VolumeSnapshotTreeBase(VolumeSnapshotVO vo, boolean syncOnVolume) { currentRoot = vo; if (syncOnVolume) { syncSignature = String.format("volume.snapshot.volume.%s", currentRoot.getVolumeUuid()); } else { syncSignature = String.format("volume.snapshot.tree.%s", currentRoot.getTreeUuid()); } }
@Transactional private void rollbackSnapshot(String uuid) { VolumeSnapshotVO vo = dbf.getEntityManager().find(VolumeSnapshotVO.class, uuid); dbf.getEntityManager().remove(vo); String sql = "delete from AccountResourceRefVO where resourceUuid = :vsUuid and resourceType = 'VolumeSnapshotVO'"; Query q = dbf.getEntityManager().createQuery(sql); q.setParameter("vsUuid", uuid); q.executeUpdate(); if (vo.getParentUuid() != null) { VolumeSnapshotVO parent = dbf.getEntityManager().find(VolumeSnapshotVO.class, vo.getParentUuid()); parent.setLatest(true); dbf.getEntityManager().merge(parent); } else { VolumeSnapshotTreeVO chain = dbf.getEntityManager().find(VolumeSnapshotTreeVO.class, vo.getTreeUuid()); dbf.getEntityManager().remove(chain); } }
private void buildFullSnapshotTree() { SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.add(VolumeSnapshotVO_.treeUuid, SimpleQuery.Op.EQ, currentRoot.getTreeUuid()); List<VolumeSnapshotVO> vos = q.list(); fullTree = VolumeSnapshotTree.fromVOs(vos); }
@Override protected void scripts() { String psUuid = q(VolumeSnapshotVO.class) .select(VolumeSnapshotVO_.primaryStorageUuid) .eq(VolumeSnapshotVO_.uuid, currentRoot.getUuid()) .findValue(); if (psUuid != null) { ret.value = false; return; } // the snapshot is on neither primary storage, delete it and descendants List<String> uuids = currentLeaf.getDescendants().stream().map(VolumeSnapshotInventory::getUuid).collect(Collectors.toList()); if (!uuids.isEmpty()) { sql(VolumeSnapshotVO.class).in(VolumeSnapshotVO_.uuid, uuids).hardDelete(); } if (!q(VolumeSnapshotVO.class).eq(VolumeSnapshotVO_.treeUuid, currentRoot.getTreeUuid()).isExists()) { logger.debug(String.format("volume snapshot tree[uuid:%s] has no leaf, delete it", currentRoot.getTreeUuid())); sql(VolumeSnapshotTreeVO.class).eq(VolumeSnapshotTreeVO_.uuid, currentRoot.getTreeUuid()).hardDelete(); } ret.value = true; } }.execute();
public SnapshotLeaf buildRootLeaf(String uuid) { VolumeSnapshotVO s = dbf.findByUuid(uuid, VolumeSnapshotVO.class); SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class); q.add(VolumeSnapshotVO_.treeUuid, Op.EQ, s.getTreeUuid()); List<VolumeSnapshotVO> vos = q.list(); VolumeSnapshotTree tree = VolumeSnapshotTree.fromVOs(vos); SnapshotLeaf leaf = tree.getRoot(); if (!leaf.getInventory().getUuid().equals(uuid)) { Assert.fail(String.format("snapshot[%s] is not root snapshot", uuid)); } return leaf; } }
latest = dbf.getEntityManager().merge(latest); vo.setTreeUuid(latest.getTreeUuid()); vo.setLatest(true); vo.setParentUuid(latest.getUuid());
m.computeIfAbsent(vo.getTreeUuid(), k -> new ArrayList<>()).add(vo);
tq.add(VolumeSnapshotTreeVO_.uuid, Op.EQ, currentRoot.getTreeUuid()); Boolean onCurrentTree = tq.findValue();
public static VolumeSnapshotInventory valueOf(VolumeSnapshotVO vo) { VolumeSnapshotInventory inv = new VolumeSnapshotInventory(); inv.setName(vo.getName()); inv.setCreateDate(vo.getCreateDate()); inv.setDescription(vo.getDescription()); inv.setLastOpDate(vo.getLastOpDate()); inv.setParentUuid(vo.getParentUuid()); inv.setState(vo.getState().toString()); inv.setType(vo.getType()); inv.setVolumeUuid(vo.getVolumeUuid()); inv.setFormat(vo.getFormat()); inv.setUuid(vo.getUuid()); inv.setStatus(vo.getStatus().toString()); inv.setPrimaryStorageUuid(vo.getPrimaryStorageUuid()); inv.setPrimaryStorageInstallPath(vo.getPrimaryStorageInstallPath()); inv.setLatest(vo.isLatest()); inv.setSize(vo.getSize()); inv.setVolumeType(vo.getVolumeType()); inv.setTreeUuid(vo.getTreeUuid()); inv.setBackupStorageRefs(VolumeSnapshotBackupStorageRefInventory.valueOf(vo.getBackupStorageRefs())); return inv; }