@Override public void run(MessageReply reply) { if (reply.isSuccess()) { BackupStorageVO srcBS = dbf.findByUuid(self.getUuid(), BackupStorageVO.class); srcBS.setAvailableCapacity(srcBS.getAvailableCapacity() + spec.getSize()); dbf.update(srcBS); logger.info(String.format("Deleted image %s and returned space[size:%s] to BS[uuid:%s] after image migration", spec.getInstallPath(), spec.getSize(), self.getUuid())); trash.removeFromDb(spec.getTrashId()); result.setSize(spec.getSize()); result.setResourceUuids(CollectionDSL.list(spec.getResourceUuid())); completion.success(result); } else { logger.warn(String.format("Failed to delete image %s in image migration.", spec.getInstallPath())); completion.fail(reply.getError()); } } });
@Override public JsonLabelInventory createTrash(TrashType type, StorageTrashSpec spec) { if (spec.getStorageUuid() == null || spec.getResourceUuid() == null) { throw new OperationFailureException(inerr("both resourceUuid and storageUuid must be set for createTrash")); } if (spec.getResourceType() == null) { spec.setResourceType(getResourceType(spec.getResourceUuid())); } if (spec.getStorageType() == null) { spec.setStorageType(getResourceType(spec.getStorageUuid())); } spec.setTrashType(type.toString()); return new JsonLabel().create(makeTrashKey(type), spec, spec.getStorageUuid()); }
public static APIGetTrashOnPrimaryStorageReply __example__() { APIGetTrashOnPrimaryStorageReply reply = new APIGetTrashOnPrimaryStorageReply(); StorageTrashSpec spec1 = new StorageTrashSpec(uuid(), "VolumeVO", uuid(), "PrimaryStorageVO", "/zstack_ps/installpath", 1024000L); spec1.setTrashId(1L); spec1.setTrashType("MigrateVolume"); spec1.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); StorageTrashSpec spec2 = new StorageTrashSpec(uuid(), "VolumeSnapshotVO", uuid(), "PrimaryStorageVO", "/zstack_ps/installpath/snapshot", 1024000L); spec2.setTrashId(2L); spec2.setTrashType("MigrateVolumeSnapshot"); spec2.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); reply.setStorageTrashSpecs(asList(spec1, spec2)); return reply; } }
@Override public boolean makeSureInstallPathNotUsed(StorageTrashSpec spec) { if (spec.getResourceType().equals(VolumeVO.class.getSimpleName())) { return makeSureInstallPathNotUsedByVolume(spec.getInstallPath()); } else if (spec.getResourceType().equals(ImageVO.class.getSimpleName())) { return makeSureInstallPathNotUsedByImage(spec.getInstallPath()); } else if (spec.getResourceType().equals(VolumeSnapshotVO.class.getSimpleName())) { return makeSureInstallPathNotUsedBySnapshot(spec.getInstallPath()); } return true; } }
logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); completion.success(result); return; msg.setInstallPath(spec.getInstallPath()); msg.setBackupStorageUuid(self.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, BackupStorageConstant.SERVICE_ID, self.getUuid());
logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); completion.success(result); return; msg.setInstallPath(spec.getInstallPath()); msg.setHypervisorType(spec.getHypervisorType()); msg.setFolder(spec.isFolder()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(msg, new CloudBusCallBack(msg) {
@Override public StorageTrashSpec getTrash(String storageUuid, Long trashId) { JsonLabelVO lable = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).eq(JsonLabelVO_.id, trashId).find(); if (lable == null) { return null; } StorageTrashSpec spec = JSONObjectUtil.toObject(lable.getLabelValue(), StorageTrashSpec.class); spec.setTrashId(trashId); spec.setCreateDate(lable.getCreateDate()); if (spec.getTrashType() == null) { spec.setTrashType(lable.getLabelKey().split("-")[0]); } return spec; }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { logger.info(String.format("Deleted volume %s in Trash.", spec.getInstallPath())); IncreasePrimaryStorageCapacityMsg imsg = new IncreasePrimaryStorageCapacityMsg(); imsg.setPrimaryStorageUuid(self.getUuid()); imsg.setDiskSize(spec.getSize()); bus.makeTargetServiceIdByResourceUuid(imsg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(imsg); trash.removeFromDb(trashId); logger.info(String.format("Returned space[size:%s] to PS %s after volume migration", spec.getSize(), self.getUuid())); result.setSize(spec.getSize()); result.setResourceUuids(CollectionDSL.list(spec.getResourceUuid())); completion.success(result); } else { logger.warn(String.format("Failed to delete volume %s in Trash.", spec.getInstallPath())); completion.fail(reply.getError()); } } });
@Override public void handle(Map data) { IncreasePrimaryStorageCapacityMsg imsg = new IncreasePrimaryStorageCapacityMsg(); imsg.setPrimaryStorageUuid(self.getUuid()); imsg.setDiskSize(spec.getSize()); bus.makeTargetServiceIdByResourceUuid(imsg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(imsg); logger.info(String.format("Returned space[size:%s] to PS %s after volume migration", spec.getSize(), self.getUuid())); trash.removeFromDb(trashId); result.setSize(spec.getSize()); result.setResourceUuids(CollectionDSL.list(spec.getResourceUuid())); completion.success(result); } }).error(new FlowErrorHandler(completion) {
@Override public Long getTrashId(String storageUuid, String installPath) { DebugUtils.Assert(installPath != null, "installPath is not allowed null here"); List<JsonLabelVO> lables = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).like(JsonLabelVO_.labelValue, String.format("%%%s%%", installPath)).list(); if (!lables.isEmpty()) { for (JsonLabelVO lable: lables) { for (TrashType type: TrashType.values()) { if (!lable.getLabelKey().startsWith(type.name())) { // if lable key not starts with type, it may not be storage trash continue; } } StorageTrashSpec spec = JSONObjectUtil.toObject(lable.getLabelValue(), StorageTrashSpec.class); if (spec.getInstallPath().equals(installPath)) { return lable.getId(); } } } return null; }
protected void handle(final CheckInstallPathOnBSMsg msg) { CheckInstallPathOnBSReply reply = new CheckInstallPathOnBSReply(); Long trashId = trash.getTrashId(self.getUuid(), msg.getInstallPath()); if (trashId != null) { StorageTrashSpec spec = trash.getTrash(self.getUuid(), trashId); reply.setResourceUuid(spec.getResourceUuid()); reply.setTrashId(trashId); } bus.reply(msg, reply); }
StorageTrashSpec spec = t.getValue(); if (!trash.makeSureInstallPathNotUsed(spec)) { logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); coml.done(); return; msg.setInstallPath(spec.getInstallPath()); msg.setBackupStorageUuid(self.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, BackupStorageConstant.SERVICE_ID, self.getUuid());
logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); coml.done(); return; msg.setInstallPath(spec.getInstallPath()); msg.setHypervisorType(spec.getHypervisorType()); msg.setFolder(spec.isFolder()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(msg, new CloudBusCallBack(coml) {
@Override public Map<String, StorageTrashSpec> getTrashList(String storageUuid, List<TrashType> types) { Map<String, StorageTrashSpec> specs = new HashMap<>(); for (TrashType type: types) { List<JsonLabelVO> labels = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).like(JsonLabelVO_.labelKey, type.toString() + "-%").list(); labels.forEach(l -> { StorageTrashSpec spec = JSONObjectUtil.toObject(l.getLabelValue(), StorageTrashSpec.class); spec.setTrashId(l.getId()); spec.setCreateDate(l.getCreateDate()); if (spec.getTrashType() == null) { spec.setTrashType(type.toString()); } specs.put(l.getLabelKey(), spec); }); } return specs; }
@Override public void run(FlowTrigger trigger, Map data) { DeleteVolumeBitsOnPrimaryStorageMsg msg = new DeleteVolumeBitsOnPrimaryStorageMsg(); msg.setPrimaryStorageUuid(self.getUuid()); msg.setInstallPath(spec.getInstallPath()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(msg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { logger.info(String.format("Deleted volume %s in Trash.", spec.getInstallPath())); } else { logger.warn(String.format("Failed to delete volume %s in Trash.", spec.getInstallPath())); } trigger.next(); } }); } });
protected void handle(final CheckInstallPathMsg msg) { CheckInstallPathReply reply = new CheckInstallPathReply(); Long trashId = trash.getTrashId(self.getUuid(), msg.getInstallPath()); if (trashId != null) { StorageTrashSpec spec = trash.getTrash(self.getUuid(), trashId); reply.setTrashId(trashId); reply.setResourceUuid(spec.getResourceUuid()); } bus.reply(msg, reply); }
logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); completion.success(result); return; chain.setName(String.format("clean-trash-on-volume-%s", spec.getInstallPath())); chain.then(new NoRollbackFlow() { @Override
public static APIGetTrashOnBackupStorageReply __example__() { APIGetTrashOnBackupStorageReply reply = new APIGetTrashOnBackupStorageReply(); StorageTrashSpec spec = new StorageTrashSpec(uuid(), "ImageVO", uuid(), "BackupStorageVO", "/zstack_bs/installpath", 1024000L); spec.setTrashId(1L); spec.setTrashType("MigrateImage"); spec.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); reply.setStorageTrashSpecs(asList(spec)); return reply; } }
@Override public void run(FlowTrigger trigger, Map data) { PurgeSnapshotOnPrimaryStorageMsg msg = new PurgeSnapshotOnPrimaryStorageMsg(); msg.setPrimaryStorageUuid(self.getUuid()); msg.setVolumePath(spec.getInstallPath()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, self.getUuid()); bus.send(msg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { logger.info(String.format("Purged all snapshots of volume %s.", spec.getInstallPath())); } else { logger.warn(String.format("Failed to purge snapshots of volume %s.", spec.getInstallPath())); } trigger.next(); } }); } }).then(new NoRollbackFlow() {
logger.warn(String.format("%s is still in using by %s, only remove it from trash...", spec.getInstallPath(), spec.getResourceType())); trash.removeFromDb(spec.getTrashId()); coml.done(); return; chain.setName(String.format("clean-trash-on-volume-%s", spec.getInstallPath())); chain.then(new NoRollbackFlow() { @Override