@Override public Long call(ImageCacheVO arg) { return arg.getId(); } });
ids.add(i.getId());
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); } }
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 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; }