@Override public String getName() { return String.format("delete-volume-snapshot-%s", currentRoot.getUuid()); } });
@Override public String getName() { return String.format("create-data-volume-from-snapshot-%s", currentRoot.getUuid()); } });
@Override public String getName() { return String.format("create-template-from-volume-snapshot-%s", currentRoot.getUuid()); } });
@Override public String getName() { return String.format("delete-volume-snapshot-%s-on-backup-storage", currentRoot.getUuid()); } });
@Override public String getName() { return String.format("revert-volume-%s-from-snapshot-%s", currentRoot.getVolumeUuid(), currentRoot.getUuid()); } });
@Override public String getName() { return String.format("revert-volume-%s-from-snapshot-%s", currentRoot.getVolumeUuid(), currentRoot.getUuid()); } });
@Override public Boolean call(VolumeSnapshotInventory arg) { return arg.getUuid().equals(currentRoot.getUuid()); } });
@Override public void entityLifeCycleEvent(EntityEvent evt, Object o) { VolumeSnapshotVO s = (VolumeSnapshotVO) o; String info = String.format("[VolumeSnapshot:Create][name=%s, uuid=%s]: %s", s.getName(), s.getUuid(), s.getSize()); logger.debug(info); loggerd.debug(info); printCallTrace(); } });
@Override public Boolean call(VolumeSnapshotInventory arg) { Info info = new Info(); info.snapshot = arg; if (arg.getUuid().equals(currentRoot.getUuid()) && requiredBsUuid != null) { info.backupStorageUuid = requiredBsUuid; needBackup.add(info); return false; } if (arg.getBackupStorageRefs().isEmpty()) { needBackup.add(info); } return false; } });
private ErrorCode isOperationAllowed(Message msg) { if (allowedStatus.isOperationAllowed(msg.getClass().getName(), currentRoot.getStatus().toString())) { return null; } else { return err(VolumeSnapshotErrors.NOT_IN_CORRECT_STATE, "snapshot[uuid:%s, name:%s]'s status[%s] is not allowed for message[%s], allowed status%s", currentRoot.getUuid(), currentRoot.getName(), currentRoot.getStatus(), msg.getClass().getName(), allowedStatus.getStatesForOperation(msg.getClass().getName())); } }
private void validate(APICreateDataVolumeTemplateFromVolumeSnapshotMsg msg) { VolumeSnapshotVO vsvo = dbf.findByUuid(msg.getSnapshotUuid(), VolumeSnapshotVO.class); if (VolumeSnapshotStatus.Ready != vsvo.getStatus()) { throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is not Ready, it's %s", vsvo.getUuid(), vsvo.getStatus())); } if (VolumeSnapshotState.Enabled != vsvo.getState()) { throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is not Enabled, it's %s", vsvo.getUuid(), vsvo.getState())); } }
private void refreshVO() { VolumeSnapshotVO vo = dbf.reload(currentRoot); if (vo == null) { throw new OperationFailureException(operr("cannot find volume snapshot[uuid:%s, name:%s], it may have been deleted by previous operation", currentRoot.getUuid(), currentRoot.getName())); } currentRoot = vo; buildFullSnapshotTree(); currentLeaf = fullTree.findSnapshot(new Function<Boolean, VolumeSnapshotInventory>() { @Override public Boolean call(VolumeSnapshotInventory arg) { return arg.getUuid().equals(currentRoot.getUuid()); } }); }
@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();
msg.setSnapshotUuid(currentRoot.getUuid()); msg.setBackupStorageUuids(bsUuids); bus.makeLocalServiceId(msg, VolumeSnapshotConstant.SERVICE_ID);
vo.setParentUuid(latest.getUuid()); vo.setDistance(latest.getDistance() + 1); dbf.getEntityManager().persist(vo);
@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("delete-volume-snapshot-%s-from-backup-stroage", currentRoot.getUuid())); chain.then(new ShareFlow() { @Override
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(MessageReply rsp) { if (!rsp.isSuccess()) { reply.setError(rsp.getError()); } else { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply r = rsp.castReply(); VolumeSnapshotBackupStorageRefVO ref = new VolumeSnapshotBackupStorageRefVO(); ref.setInstallPath(r.getBackupStorageInstallPath()); ref.setVolumeSnapshotUuid(self.getUuid()); ref.setBackupStorageUuid(msg.getBackupStorage().getUuid()); dbf.persist(ref); } bus.reply(msg, reply); } });
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; }