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())); }
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)); }
@Override public void run() { List<ImageCacheVO> staleCache = getStaleCache(); if (staleCache == null || staleCache.isEmpty()) { return; } for (final ImageCacheVO c : staleCache) { DeleteVolumeBitsOnPrimaryStorageMsg msg = new DeleteVolumeBitsOnPrimaryStorageMsg(); msg.setInstallPath(c.getInstallUrl().split("@")[0]); msg.setPrimaryStorageUuid(c.getPrimaryStorageUuid()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, c.getPrimaryStorageUuid()); bus.send(msg, new CloudBusCallBack(null) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { logger.debug(String.format("successfully cleanup a stale image cache[path:%s, primary storage uuid:%s]", c.getInstallUrl(), c.getPrimaryStorageUuid())); dbf.remove(c); } else { logger.warn(String.format("failed to cleanup a stale image cache[path:%s, primary storage uuid:%s], %s", c.getInstallUrl(), c.getPrimaryStorageUuid(), reply.getError())); } } }); } }
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()); } } }); }
public ImageCacheShadowVO(ImageCacheVO c) { primaryStorageUuid = c.getPrimaryStorageUuid(); imageUuid = c.getImageUuid(); installUrl = c.getInstallUrl(); mediaType = c.getMediaType(); size = c.getSize(); state = c.getState(); md5sum = c.getMd5sum(); createDate = c.getCreateDate(); lastOpDate = c.getLastOpDate(); }
@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); }
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; }