public static List<ImageCacheInventory> valueOf(List<ImageCacheVO> vos) { List<ImageCacheInventory> invs = new ArrayList<>(vos.size()); for (ImageCacheVO vo : vos) { invs.add(ImageCacheInventory.valueOf(vo)); } return invs; }
public static ImageCacheInventory valueOf(ImageCacheVO vo) { ImageCacheInventory inv = new ImageCacheInventory(); inv.setCreateDate(vo.getCreateDate()); inv.setId(vo.getId()); inv.setImageUuid(vo.getImageUuid()); inv.setInstallUrl(vo.getInstallUrl()); inv.setLastOpDate(vo.getLastOpDate()); inv.setMd5sum(vo.getMd5sum()); inv.setMediaType(vo.getMediaType().toString()); inv.setPrimaryStorageUuid(vo.getPrimaryStorageUuid()); inv.setSize(vo.getSize()); inv.setState(vo.getState().toString()); return inv; }
public static String makeCopyImageCacheJobName(ImageCacheInventory cacheInv, PrimaryStorageInventory srcPs, PrimaryStorageInventory dstPs) { return String.format("copy-cache-of-image-%s-from-pri-%s-to-pri-%s", cacheInv.getImageUuid(), srcPs.getUuid(), dstPs.getUuid()); }
public static APIQueryImageCacheReply __example__() { APIQueryImageCacheReply reply = new APIQueryImageCacheReply(); String imageUuid = uuid(); ImageCacheInventory cache = new ImageCacheInventory(); cache.setPrimaryStorageUuid(uuid()); cache.setImageUuid(imageUuid); cache.setMediaType("RootVolumeTemplate"); cache.setSize(2308505600L); cache.setState(ImageCacheState.ready.toString()); cache.setMd5sum("not calculated"); cache.setInstallUrl(String.format("file:///zstack_ps/imagecache/template/%s/%s.qcow2;hostUuid://%s", imageUuid, imageUuid, uuid())); reply.setInventories(Collections.singletonList(cache)); return reply; } }
@Override public void success(ImageCacheInventory returnValue) { logger.debug(String.format("successfully downloaded iso[uuid:%s, name:%s] from backup storage[uuid:%s] to primary storage[uuid:%s, name:%s], path in cache: %s", img.getUuid(), img.getName(), msg.getIsoSpec().getSelectedBackupStorage().getBackupStorageUuid(), pinv.getUuid(), pinv.getName(), returnValue.getInstallUrl())); reply.setInstallPath(returnValue.getInstallUrl()); bus.reply(msg, reply); }
@Override public String getPrimaryStorageUuid() { return inventory.getPrimaryStorageUuid(); } }
final String accountUuid = acntMgr.getOwnerAccountUuidOfResource(volume.getUuid()); final CreateRootVolumeFromTemplateCmd cmd = new CreateRootVolumeFromTemplateCmd(); cmd.setTemplatePathInCache(image.getInstallUrl()); cmd.setInstallUrl(installPath); cmd.setAccountUuid(accountUuid);
private void deleteImageCacheOnPrimaryStorage(final ImageCacheVO ic) { PrimaryStorageRemoveCachedImageMsg msg = new PrimaryStorageRemoveCachedImageMsg(); msg.setInventory(ImageCacheInventory.valueOf(ic)); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, ic.getPrimaryStorageUuid()); bus.send(msg, new CloudBusCallBack(null) { private void fail(String error) { ic.setState(ImageCacheState.ready); dbf.update(ic); logger.warn(String.format("failed to garbage collect image cache[id:%s, install:%s] on primary storage[uuid], because %s. Change its state back to ready and try garbage collecting it next time", ic.getId(), ic.getInstallUrl(), ic.getPrimaryStorageUuid(), error)); } private void success() { dbf.remove(ic); logger.debug(String.format("successfully garbage collected image cache[id:%s, install url:%s] on primary storage[uuid:%s]", ic.getId(), ic.getInstallUrl(), ic.getPrimaryStorageUuid())); } @Override public void run(MessageReply reply) { if (reply.isSuccess()) { success(); } else { fail(reply.getError().toString()); } } }); }
FlowChain chain = FlowChainBuilder.newShareFlowChain(); chain.setName(String.format("copy-imagecache-%s-from-nfsps-%s-to-nfsps-%s", srcImageCache.getImageUuid(), srcPrimaryStorage.getUuid(), dstPrimaryStorage.getUuid())); chain.then(new ShareFlow() { @Override
@Override public void success(Boolean returnValue) { if (returnValue) { logger.debug(String.format("found image[uuid:%s] in image cache[id:%s, path:%s]", image.getInventory().getUuid(), cvo.getId(), cvo.getInstallUrl())); completion.success(ImageCacheInventory.valueOf(cvo)); return; } // return capacity and re-download IncreasePrimaryStorageCapacityMsg rmsg = new IncreasePrimaryStorageCapacityMsg(); rmsg.setPrimaryStorageUuid(cvo.getPrimaryStorageUuid()); rmsg.setDiskSize(cvo.getSize()); bus.makeLocalServiceId(rmsg, PrimaryStorageConstant.SERVICE_ID); bus.send(rmsg); dbf.remove(cvo); download(completion); }
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { completion.fail(reply.getError()); return; } CreateRootVolumeFromTemplateResponse rsp = ((KVMHostAsyncHttpCallReply)reply).toResponse(CreateRootVolumeFromTemplateResponse.class); if (!rsp.isSuccess()) { ErrorCode err = operr("fails to create root volume[uuid:%s] from cached image[path:%s] because %s", volume.getUuid(), image.getImageUuid(), rsp.getError()); completion.fail(err); return; } nfsMgr.reportCapacityIfNeeded(primaryStorage.getUuid(), rsp); completion.success(installPath); } });