private BackupStorageMediator getBackupStorageMediator(String bsUuid) { BackupStorageVO bsvo = dbf.findByUuid(bsUuid, BackupStorageVO.class); BackupStorageMediator mediator = backupStorageMediators.get(bsvo.getType()); if (mediator == null) { throw new CloudRuntimeException(String.format("cannot find BackupStorageMediator for type[%s]", bsvo.getType())); } mediator.backupStorage = BackupStorageInventory.valueOf(bsvo); return mediator; }
private BackupStorageMediator getBackupStorageMediator(String bsUuid) { BackupStorageVO bsvo = dbf.findByUuid(bsUuid, BackupStorageVO.class); BackupStorageMediator mediator = backupStorageMediators.get(bsvo.getType()); if (mediator == null) { throw new CloudRuntimeException(String.format("cannot find BackupStorageMediator for type[%s]", bsvo.getType())); } mediator.backupStorage = BackupStorageInventory.valueOf(bsvo); return mediator; }
@Transactional(readOnly = true) private List<PrimaryStorageVO> considerImageBackupStorageRef(PrimaryStorageAllocationSpec spec, List<PrimaryStorageVO> vos){ List<BackupStorageVO> bsvos = SQL.New("select bs" + " from BackupStorageVO bs, ImageBackupStorageRefVO ref" + " where ref.imageUuid = :imgUuid" + " and bs.uuid = ref.backupStorageUuid", BackupStorageVO.class) .param("imgUuid", spec.getImageUuid()) .list(); vos.removeIf(ps -> bsvos.stream().noneMatch(bs -> { List<String> relatedPsUuids = BackupStorageType.valueOf(bs.getType()).findRelatedPrimaryStorage(bs.getUuid()); return relatedPsUuids == null || relatedPsUuids.contains(ps.getUuid()); }) ); return vos; }
List<String> psTypes = new ArrayList<>(); for (BackupStorageVO bs : bss) { BackupStorageType bsType = BackupStorageType.valueOf(bs.getType()); List<String> lst = bsType.findRelatedPrimaryStorage(bs.getUuid()); if (lst != null) { psUuids.addAll(lst); } else { psTypes.addAll(hostAllocatorMgr.getPrimaryStorageTypesByBackupStorageTypeFromMetrics(bs.getType()));
BackupStorageType bsType = BackupStorageType.valueOf(bs.getType()); List<String> relatedPrimaryStorageUuids = bsType.findRelatedPrimaryStorage(bs.getUuid()); if (relatedPrimaryStorageUuids == null) { List<String> psTypes = hostAllocatorMgr.getPrimaryStorageTypesByBackupStorageTypeFromMetrics(bs.getType()); sql = "select l3" + " from L3NetworkVO l3, L2NetworkClusterRefVO l2ref," + } else { logger.warn(String.format("the backup storage[uuid:%s, type: %s] needs a strongly-bound primary storage," + " but seems the primary storage is not added", bs.getUuid(), bs.getType()));
private void passThrough(BackupStorageMessage pmsg) { BackupStorageVO vo = dbf.findByUuid(pmsg.getBackupStorageUuid(), BackupStorageVO.class); if (vo == null && allowedMessageAfterDeletion.contains(pmsg.getClass())) { BackupStorageEO eo = dbf.findByUuid(pmsg.getBackupStorageUuid(), BackupStorageEO.class); vo = ObjectUtils.newAndCopy(eo, BackupStorageVO.class); } Message msg = (Message) pmsg; if (vo == null) { String err = String.format("Cannot find backup storage[uuid:%s], it may have been deleted", pmsg.getBackupStorageUuid()); bus.replyErrorByMessageType(msg, err); return; } BackupStorageFactory factory = getBackupStorageFactory(BackupStorageType.valueOf(vo.getType())); BackupStorageVO finalVo = vo; BackupStorage ss = New(()-> factory.getBackupStorage(finalVo)); ss.handleMessage(msg); }
@Override void handle(final UploadBitsFromLocalStorageToBackupStorageMsg msg, String hostUuid, final ReturnValueCompletion<UploadBitsFromLocalStorageToBackupStorageReply> completion) { final BackupStorageVO bs = dbf.findByUuid(msg.getBackupStorageUuid(), BackupStorageVO.class); BackupStorageInventory bsinv = BackupStorageInventory.valueOf(bs); LocalStorageBackupStorageMediator m = localStorageFactory.getBackupStorageMediator(KVMConstant.KVM_HYPERVISOR_TYPE, bs.getType()); m.uploadBits(msg.getImageUuid(), getSelfInventory(), bsinv, msg.getBackupStorageInstallPath(), msg.getPrimaryStorageInstallPath(), hostUuid, new ReturnValueCompletion<String>(completion) { @Override public void success(String installPath) { UploadBitsFromLocalStorageToBackupStorageReply reply = new UploadBitsFromLocalStorageToBackupStorageReply(); reply.setBackupStorageInstallPath(installPath); bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { logger.warn(String.format("failed to upload template[%s] from local primary storage[uuid: %s] to the backup storage[uuid: %s, path: %s]", msg.getPrimaryStorageInstallPath(), self.getUuid(), bs.getUuid(), msg.getBackupStorageInstallPath())); completion.fail(errorCode); } }); }
protected BackupStorageInventory(BackupStorageVO vo) { this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setLastOpDate(vo.getLastOpDate()); this.setName(vo.getName()); this.setState(vo.getState().toString()); this.setStatus(vo.getStatus().toString()); this.setTotalCapacity(vo.getTotalCapacity()); this.setAvailableCapacity(vo.getAvailableCapacity()); this.setType(vo.getType()); this.setUrl(vo.getUrl()); this.setUuid(vo.getUuid()); this.attachedZoneUuids = new ArrayList<String>(vo.getAttachedZoneRefs().size()); for (BackupStorageZoneRefVO ref : vo.getAttachedZoneRefs()) { if (!this.attachedZoneUuids.contains(ref.getZoneUuid())) { this.attachedZoneUuids.add(ref.getZoneUuid()); } } }
@Override public void handle(PrimaryStorageInventory inv, UploadBitsToBackupStorageMsg msg, final ReturnValueCompletion<UploadBitsToBackupStorageReply> completion) { BackupStorageVO bs = dbf.findByUuid(msg.getBackupStorageUuid(), BackupStorageVO.class); NfsPrimaryToBackupStorageMediator m = nfsFactory.getPrimaryToBackupStorageMediator(BackupStorageType.valueOf(bs.getType()), HypervisorType.valueOf(msg.getHypervisorType())); m.uploadBits(msg.getImageUuid(), inv, BackupStorageInventory.valueOf(bs), msg.getBackupStorageInstallPath(), msg.getPrimaryStorageInstallPath(), new ReturnValueCompletion<String>(completion) { @Override public void success(String installPath) { UploadBitsToBackupStorageReply reply = new UploadBitsToBackupStorageReply(); reply.setBackupStorageInstallPath(installPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
@Override void handle(final DownloadDataVolumeToPrimaryStorageMsg msg, final ReturnValueCompletion<DownloadDataVolumeToPrimaryStorageReply> completion) { BackupStorageVO bsvo = dbf.findByUuid(msg.getBackupStorageRef().getBackupStorageUuid(), BackupStorageVO.class); LocalStorageBackupStorageMediator m = localStorageFactory.getBackupStorageMediator(KVMConstant.KVM_HYPERVISOR_TYPE, bsvo.getType()); final String installPath = makeDataVolumeInstallUrl(msg.getVolumeUuid()); m.downloadBits(getSelfInventory(), BackupStorageInventory.valueOf(bsvo), msg.getBackupStorageRef().getInstallPath(), installPath, msg.getHostUuid(), new Completion(completion) { @Override public void success() { DownloadDataVolumeToPrimaryStorageReply reply = new DownloadDataVolumeToPrimaryStorageReply(); reply.setFormat(msg.getImage().getFormat()); reply.setInstallPath(installPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
protected BackupStorageVO(BackupStorageVO vo) { this.setUuid(vo.getUuid()); this.setAttachedZoneRefs(vo.getAttachedZoneRefs()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setLastOpDate(vo.getLastOpDate()); this.setName(vo.getName()); this.setState(vo.getState()); this.setStatus(vo.getStatus()); this.setTotalCapacity(vo.getTotalCapacity()); this.setType(vo.getType()); this.setUrl(vo.getUrl()); this.setAvailableCapacity(vo.getAvailableCapacity()); }
@Override protected void handle(final DownloadDataVolumeToPrimaryStorageMsg msg) { final DownloadDataVolumeToPrimaryStorageReply reply = new DownloadDataVolumeToPrimaryStorageReply(); final String installPath = PathUtil.join(self.getMountPath(), PrimaryStoragePathMaker.makeDataVolumeInstallPath(msg.getVolumeUuid())); BackupStorageVO bsvo = dbf.findByUuid(msg.getBackupStorageRef().getBackupStorageUuid(), BackupStorageVO.class); NfsPrimaryToBackupStorageMediator mediator = factory.getPrimaryToBackupStorageMediator( BackupStorageType.valueOf(bsvo.getType()), nfsMgr.findHypervisorTypeByImageFormatAndPrimaryStorageUuid(msg.getImage().getFormat(), self.getUuid()) ); mediator.downloadBits(getSelfInventory(), BackupStorageInventory.valueOf(bsvo), msg.getBackupStorageRef().getInstallPath(), installPath, new Completion(msg) { @Override public void success() { reply.setInstallPath(installPath); bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
addBackupStoragestruct.setType(vo.getType());