@Override public String getName() { return String.format("revert-volume-%s-from-snapshot-%s", currentRoot.getVolumeUuid(), currentRoot.getUuid()); } });
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()); } }
@Override public String getName() { return String.format("revert-volume-%s-from-snapshot-%s", currentRoot.getVolumeUuid(), currentRoot.getUuid()); } });
@Transactional private VolumeSnapshotStruct saveIndividualTypeSnapshot(VolumeSnapshotVO vo) { String sql = "update VolumeSnapshotTreeVO tree" + " set tree.current = false" + " where tree.current = true" + " and tree.volumeUuid = :volUuid"; Query q = dbf.getEntityManager().createQuery(sql); q.setParameter("volUuid", vo.getVolumeUuid()); q.executeUpdate(); return newChain(vo, false); }
" and c.current = true"; TypedQuery<VolumeSnapshotTreeVO> cq = dbf.getEntityManager().createQuery(sql, VolumeSnapshotTreeVO.class); cq.setParameter("volUuid", vo.getVolumeUuid()); List<VolumeSnapshotTreeVO> rets = cq.getResultList(); DebugUtils.Assert(rets.size() < 2, "can not have more than one VolumeSnapshotTreeVO with current=1"); VolumeSnapshotTreeVO chain = rets.isEmpty() ? null : rets.get(0); final Integer maxIncrementalSnapshotNum = getMaxIncrementalSnapshotNum(vo.getVolumeUuid()); if (!CoreGlobalProperty.UNIT_TEST_ON) { if (maxIncrementalSnapshotNum <= 1) { throw new OperationFailureException(operr("Unsupported maximum snapshot number (%d) for volume [uuid:%s]", maxIncrementalSnapshotNum, vo.getVolumeUuid() )); " and s.treeUuid = :chainUuid"; TypedQuery<VolumeSnapshotVO> q = dbf.getEntityManager().createQuery(sql, VolumeSnapshotVO.class); q.setParameter("volUuid", vo.getVolumeUuid()); q.setParameter("chainUuid", chain.getUuid()); VolumeSnapshotVO latest = q.getSingleResult();
@Transactional private VolumeSnapshotStruct newChain(VolumeSnapshotVO vo, boolean fullsnapshot) { VolumeSnapshotTreeVO chain = new VolumeSnapshotTreeVO(); chain.setCurrent(true); chain.setVolumeUuid(vo.getVolumeUuid()); chain.setUuid(Platform.getUuid()); chain = dbf.getEntityManager().merge(chain); logger.debug(String.format("created new volume snapshot tree[tree uuid:%s, volume uuid:%s, full snapshot uuid:%s]", chain.getUuid(), vo.getVolumeUuid(), vo.getUuid())); vo.setTreeUuid(chain.getUuid()); vo.setDistance(fullsnapshot ? 0 : 1); vo.setParentUuid(null); vo.setLatest(true); vo.setFullSnapshot(fullsnapshot); dbf.getEntityManager().persist(vo); dbf.getEntityManager().flush(); dbf.getEntityManager().refresh(vo); VolumeSnapshotStruct struct = new VolumeSnapshotStruct(); struct.setCurrent(VolumeSnapshotInventory.valueOf(vo)); struct.setFullSnapshot(fullsnapshot); return struct; }
chain.setName(String.format("revert-volume-%s-from-snapshot-%s", currentRoot.getVolumeUuid(), currentRoot.getUuid())); chain.then(new ShareFlow() { String newVolumeInstallPath; String labelKey; long newSize; VolumeVO volume = dbf.findByUuid(currentRoot.getVolumeUuid(), VolumeVO.class); VolumeInventory volumeInventory = VolumeInventory.valueOf(volume); String oldVolumeInstallPath = volume.getInstallPath();
if (vo.getStatus().equals(VolumeSnapshotStatus.Ready)) { logger.warn(String.format("snapshot %s on volume %s is ready, no need to create again!", vo.getUuid(), vo.getVolumeUuid())); whileCompletion.done(); return;
@Override public void run(final FlowTrigger trigger, Map data) { MergeVolumeSnapshotOnPrimaryStorageMsg mmsg = new MergeVolumeSnapshotOnPrimaryStorageMsg(); VolumeSnapshotInventory from = currentLeaf.getParent() == null ? currentLeaf.getInventory() : currentLeaf.getParent().getInventory(); mmsg.setFrom(from); VolumeVO vol = dbf.findByUuid(currentRoot.getVolumeUuid(), VolumeVO.class); mmsg.setTo(VolumeInventory.valueOf(vol)); mmsg.setFullRebase(currentLeaf.getParent() == null); bus.makeTargetServiceIdByResourceUuid(mmsg, PrimaryStorageConstant.SERVICE_ID, currentRoot.getPrimaryStorageUuid()); bus.send(mmsg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { trigger.fail(reply.getError()); } else { trigger.next(); } } }); } });
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; }