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(); }
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 entityLifeCycleEvent(EntityEvent evt, Object o) { ImageCacheVO img = (ImageCacheVO) o; String info = String.format("[ImageCache:Delete][uuid=%s]: -%s", img.getImageUuid(), img.getSize()); logger.debug(info); loggerd.debug(info); printCallTrace(); } });
@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); }
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())); }
@Transactional private void fixImageCacheUuid() { String sql = "select c, pri.type from ImageCacheVO c, PrimaryStorageVO pri where c.primaryStorageUuid = pri.uuid" + " and c.imageUuid is null"; TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class); List<Tuple> ts = q.getResultList(); for (Tuple t : ts) { ImageCacheVO c = t.get(0, ImageCacheVO.class); String psType = t.get(1, String.class); String imgUuid; if ("Ceph".equals(psType)) { imgUuid = c.getInstallUrl().split("@")[1]; } else if ("NFS".equals(psType) || "SharedMountPoint".equals(psType)) { imgUuid = new File(c.getInstallUrl()).getName().split("\\.")[0]; } else if ("LocalStorage".equals(psType)) { String[] pair = c.getInstallUrl().split(";"); imgUuid = new File(pair[0]).getName().split("\\.")[0]; } else { throw new CloudRuntimeException(String.format("unknown primary storage type[%s] for the ImageCacheVO[id:%s]", psType, c.getId())); } if (!StringDSL.isZStackUuid(imgUuid)) { throw new CloudRuntimeException(String.format("the image UUID[%s] parsed from the URL[%s] of the ImageCacheVO[id:%s] " + "on the primary storage[type:%s] looks no correct", imgUuid, c.getInstallUrl(), c.getId(), psType)); } c.setImageUuid(imgUuid); dbf.getEntityManager().merge(c); } }
@Override public void success(ImageCacheVO returnValue) { reply.setInstallPath(returnValue.getInstallUrl()); bus.reply(msg, reply); }
@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())); } } }); } }
@Override public Long call(ImageCacheVO arg) { return arg.getId(); } });
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()); } } }); }
for (ImageCacheVO c : deleted) { CacheInstallPath p = new CacheInstallPath(); p.fullPath = c.getInstallUrl(); p.disassemble(); String hostUuid = p.hostUuid;
@Override public void entityLifeCycleEvent(EntityEvent evt, Object o) { ImageCacheVO img = (ImageCacheVO) o; String info = String.format("[ImageCache:Create][uuid=%s]: %s", img.getImageUuid(), img.getSize()); logger.debug(info); loggerd.debug(info); printCallTrace(); } });
ids.add(i.getId());
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; }
private void useExistingCache(final ImageCacheVO cvo, final ReturnValueCompletion<Object> completion) { NfsPrimaryStorageBackend bkd = nfsFactory.getHypervisorBackend(nfsMgr.findHypervisorTypeByImageFormatAndPrimaryStorageUuid(image.getInventory().getFormat(), primaryStorage.getUuid())); bkd.checkIsBitsExisting(primaryStorage, cvo.getInstallUrl(), new ReturnValueCompletion<Boolean>(completion) { @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 fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
cmd.setInstallPath(cache.getInstallUrl()); httpCall(CHECK_BITS_PATH, cmd, CheckIsBitsExistingRsp.class, new ReturnValueCompletion<CheckIsBitsExistingRsp>(chain) { @Override