private void walkDownLeaf(SnapshotLeaf leaf, List<VolumeSnapshotInventory> path, List<List<VolumeSnapshotInventory>> ret) { if (leaf.getChildren().isEmpty()) { List<VolumeSnapshotInventory> copy = new ArrayList<VolumeSnapshotInventory>(); copy.addAll(path); copy.add(leaf.getInventory()); ret.add(copy); return; } path.add(leaf.getInventory()); for (SnapshotLeaf l : leaf.getChildren()) { walkDownLeaf(l, path, ret); } path.remove(leaf.getInventory()); }
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; } }
public SnapshotLeafInventory toLeafInventory() { SnapshotLeafInventory leafInventory = new SnapshotLeafInventory(); leafInventory.setInventory(getInventory()); if (parent != null) { leafInventory.setParentUuid(parent.getUuid()); } for (SnapshotLeaf leaf : children) { leafInventory.getChildren().add(leaf.toLeafInventory()); } return leafInventory; } }
paramIn.setSnapshot(currentLeaf.getInventory()); paramIn.setImage(ImageInventory.valueOf(dbf.findByUuid(msg.getImageUuid(), ImageVO.class))); WorkflowTemplate workflowTemplate = ext.createTemplateFromVolumeSnapshot(paramIn); chain.setName(String.format("create-template-from-snapshot-%s-%s", currentLeaf.getInventory().getName(), currentLeaf.getUuid())); chain.putData(
@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(); } } }); } });
private SnapshotLeaf findSnapshot(final List<SnapshotLeaf> leafs, final Function<Boolean, VolumeSnapshotInventory> func) { for (SnapshotLeaf leaf : leafs) { SnapshotLeaf ret = findSnapshot(leaf.children, func); if (ret != null) { return ret; } if (func.call(leaf.getInventory())) { return leaf; } } return null; }
public SnapshotLeaf findSnapshot(Function<Boolean, VolumeSnapshotInventory> func) { if (func.call(root.getInventory())) { return root; } return findSnapshot(root.children, func); } }