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());
}
}
});
}