@Override public String call(BackupStorageType arg) { return arg.toString(); } });
void init() { type.setPrimaryStorageFinder(new BackupStorageFindRelatedPrimaryStorage() { @Override @Transactional(readOnly = true) public List<String> findRelatedPrimaryStorage(String backupStorageUuid) { String sql = "select p.uuid from CephPrimaryStorageVO p, CephBackupStorageVO b where b.fsid = p.fsid" + " and b.uuid = :buuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("buuid", backupStorageUuid); return q.getResultList(); } }); }
@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; }
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); }
public static List<String> getAllTypeNames() { List<BackupStorageType> exposedTypes = new ArrayList<BackupStorageType>(); for (BackupStorageType type : types.values()) { if (type.isExposed()) { exposedTypes.add(type); } } Collections.sort(exposedTypes, new Comparator<BackupStorageType>() { @Override public int compare(BackupStorageType o1, BackupStorageType o2) { return o1.getOrder() - o2.getOrder(); } }); return CollectionUtils.transformToList(exposedTypes, new Function<String, BackupStorageType>() { @Override public String call(BackupStorageType arg) { return arg.toString(); } }); }
private void handle(APIGetBackupStorageTypesMsg msg) { List<String> types = new ArrayList<String>(); APIGetBackupStorageTypesReply reply = new APIGetBackupStorageTypesReply(); types.addAll(BackupStorageType.getAllTypeNames()); reply.setBackupStorageTypes(types); bus.reply(msg, reply); }
URI uri = new URI(url); String scheme = uri.getScheme(); if (!SftpBackupStorageFactory.type.getSupportedSchemes().contains(scheme)) { throw new OperationFailureException(operr("SftpBackupStorage doesn't support scheme[%s] in url[%s]", scheme, url));
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);
@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); } }); }
BackupStorageType bsType = BackupStorageType.valueOf(bs.getType()); List<String> relatedPrimaryStorageUuids = bsType.findRelatedPrimaryStorage(bs.getUuid()); if (relatedPrimaryStorageUuids == null) {
@Override public boolean equals(Object t) { if (t == null || !(t instanceof BackupStorageType)) { return false; } BackupStorageType type = (BackupStorageType) t; return type.toString().equals(typeName); }
private void handle(final BackupVolumeSnapshotFromPrimaryStorageToBackupStorageMsg msg) { BackupStorageInventory bs = msg.getBackupStorage(); VolumeSnapshotInventory sinv = msg.getSnapshot(); NfsPrimaryToBackupStorageMediator mediator = factory.getPrimaryToBackupStorageMediator( BackupStorageType.valueOf(bs.getType()), nfsMgr.findHypervisorTypeByImageFormatAndPrimaryStorageUuid(sinv.getFormat(), self.getUuid()) ); final BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply reply = new BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply(); final String installPath = mediator.makeVolumeSnapshotInstallPath(bs.getUuid(), sinv.getUuid()); mediator.uploadBits(null, getSelfInventory(), bs, installPath, sinv.getPrimaryStorageInstallPath(), new ReturnValueCompletion<String>(msg) { @Override public void success(String installPath) { reply.setBackupStorageInstallPath(installPath); bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
void init() { type.setPrimaryStorageFinder(new BackupStorageFindRelatedPrimaryStorage() { @Override @Transactional(readOnly = true) public List<String> findRelatedPrimaryStorage(String backupStorageUuid) { String sql = "select p.uuid from FusionstorPrimaryStorageVO p, FusionstorBackupStorageVO b where b.fsid = p.fsid" + " and b.uuid = :buuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("buuid", backupStorageUuid); return q.getResultList(); } }); }
q.add(BackupStorageVO_.uuid, Op.EQ, spec.getRequiredBackupStorageUuid()); String type = q.findValue(); BackupStorageType bsType = BackupStorageType.valueOf(type); List<String> psUuids = bsType.findRelatedPrimaryStorage(spec.getRequiredBackupStorageUuid()); List<HostVO> result; if (psUuids == null) {
@Override public BackupStorageFactory getBackupStorageFactory(BackupStorageType type) { BackupStorageFactory factory = backupStorageFactories.get(type.toString()); if (factory == null) { throw new CloudRuntimeException(String.format("No BackupStorageFactory for type: %s found", type)); } return factory; }
@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); } }); }
public NfsPrimaryToBackupStorageMediator getPrimaryToBackupStorageMediator(BackupStorageType bsType, HypervisorType hvType) { Map<String, NfsPrimaryToBackupStorageMediator> mediatorMap = mediators.get(bsType.toString()); if (mediatorMap == null) { throw new CloudRuntimeException( String.format("primary storage[type:%s] wont have mediator supporting backup storage[type:%s]", type, bsType)); } NfsPrimaryToBackupStorageMediator mediator = mediatorMap.get(hvType.toString()); if (mediator == null) { throw new CloudRuntimeException( String.format("PrimaryToBackupStorageMediator[primary storage type: %s, backup storage type: %s] doesn't have backend supporting hypervisor type[%s]", type, bsType, hvType)); } return mediator; }
final BackupStorageInventory backupStorage = BackupStorageInventory.valueOf(bsvo); final NfsPrimaryToBackupStorageMediator mediator = nfsFactory.getPrimaryToBackupStorageMediator( BackupStorageType.valueOf(backupStorage.getType()), nfsMgr.findHypervisorTypeByImageFormatAndPrimaryStorageUuid(image.getInventory().getFormat(), primaryStorage.getUuid()) );