@Override public String call(BackupStorageInventory arg) { return arg.getUuid(); } });
void preDelete(BackupStorageInventory inv) throws BackupStorageException { for (BackupStorageDeleteExtensionPoint extp : delExts) { try { extp.preDeleteSecondaryStorage(inv); } catch (BackupStorageException be) { logger.debug(String.format("%s refused to delete backup storage[uuid:%s] because %s", extp.getClass().getName(), inv.getUuid(), be.getMessage()), be); throw be; } catch (Exception e) { logger.warn("Exception happened when calling preDelete of BackupStorageDeleteExtensionPoint", e); } } }
private void getSftpCredentials(final ReturnValueCompletion<GetSftpBackupStorageDownloadCredentialReply> completion) { GetSftpBackupStorageDownloadCredentialMsg gmsg = new GetSftpBackupStorageDownloadCredentialMsg(); gmsg.setBackupStorageUuid(backupStorage.getUuid()); bus.makeTargetServiceIdByResourceUuid(gmsg, BackupStorageConstant.SERVICE_ID, backupStorage.getUuid()); bus.send(gmsg, new CloudBusCallBack(completion) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { completion.fail(reply.getError()); } else { completion.success((GetSftpBackupStorageDownloadCredentialReply) reply); } } }); }
private void getSftpCredentials(final ReturnValueCompletion<GetSftpBackupStorageDownloadCredentialReply> completion) { GetSftpBackupStorageDownloadCredentialMsg gmsg = new GetSftpBackupStorageDownloadCredentialMsg(); gmsg.setBackupStorageUuid(backupStorage.getUuid()); bus.makeTargetServiceIdByResourceUuid(gmsg, BackupStorageConstant.SERVICE_ID, backupStorage.getUuid()); bus.send(gmsg, new CloudBusCallBack(completion) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { completion.fail(reply.getError()); } else { completion.success((GetSftpBackupStorageDownloadCredentialReply) reply); } } }); }
String preAttach(BackupStorageVO vo, String zoneUuid) { BackupStorageInventory inv = BackupStorageInventory.valueOf(vo); for (BackupStorageAttachExtensionPoint extp : attachExts) { try { String reason = extp.preAttachBackupStorage(inv, zoneUuid); if (reason != null) { logger.debug(String.format("%s refused to attach backup storage[uuid:%s] because %s", extp.getClass().getName(), inv.getUuid(), reason)); return reason; } } catch (Exception e) { logger.warn("Exception happened when calling preAttach of BackupStorageAttachExtensionPoint", e); } } return null; }
void preDetach(BackupStorageVO vo, String zoneUuid) throws BackupStorageException { BackupStorageInventory inv = BackupStorageInventory.valueOf(vo); for (BackupStorageDetachExtensionPoint extp : detachExts) { try { extp.preDetachBackupStorage(inv, zoneUuid); } catch (BackupStorageException be) { logger.debug(String.format("%s refused to detach backup storage[uuid:%s] because %s", extp.getClass().getName(), inv.getUuid(), be.getMessage())); throw be; } catch (Exception e) { logger.warn("Exception happened when calling preDetach of BackupStorageDetachExtensionPoint", e); } } }
public Result audit(APIMessage msg, APIEvent rsp) { String resUuid = ""; if (rsp.isSuccess()) { APIAddBackupStorageEvent evt = (APIAddBackupStorageEvent) rsp; resUuid = evt.getInventory().getUuid(); } return new Result(resUuid, BackupStorageVO.class); } }
@Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } List<String> uuids = new ArrayList<String>(); for (MessageReply r : replies) { BackupStorageInventory inv = bsinvs.get(replies.indexOf(r)); uuids.add(inv.getUuid()); logger.debug(String.format("delete backup storage[uuid:%s, name:%s]", inv.getUuid(), inv.getName())); } dbf.removeByPrimaryKeys(uuids, BackupStorageVO.class); completion.success(); } });
private void saveRefVOByBsInventorys(List<BackupStorageInventory> inventorys, String imageUuid) { List<ImageBackupStorageRefVO> refs = new ArrayList<>(); for (BackupStorageInventory backupStorageInventory : inventorys) { ImageBackupStorageRefVO ref = new ImageBackupStorageRefVO(); ref.setBackupStorageUuid(backupStorageInventory.getUuid()); ref.setStatus(ImageStatus.Creating); ref.setImageUuid(imageUuid); ref.setInstallPath(""); refs.add(ref); } dbf.persistCollection(refs); }
@Override public void success(SftpBackupStorageCommands.GetImagesMetaDataRsp rsp) { if (!rsp.isSuccess()) { logger.error(String.format("get images metadata: %s failed", rsp.getImagesMetaData())); } else { logger.info(String.format("get images metadata: %s success", rsp.getImagesMetaData())); restoreImagesBackupStorageMetadataToDatabase(rsp.getImagesMetaData(), backupStorage.getBackupStorageInventory().getUuid()); } }
@Override public void after(APIEvent evt) { if (evt.isSuccess()) { ntfy("Created").resource(((APIAddBackupStorageEvent)evt).getInventory().getUuid(), BackupStorageVO.class.getSimpleName()) .messageAndEvent(that, evt).done(); } } };
@Override public void after(APIEvent evt) { if (evt.isSuccess()) { ntfy("Added").resource(((APIAddBackupStorageEvent)evt).getInventory().getUuid(), BackupStorageVO.class.getSimpleName()) .messageAndEvent(that, evt).done(); } } };
protected void checkParam() { super.checkParam(); SimpleQuery<FusionstorBackupStorageVO> q = dbf.createQuery(FusionstorBackupStorageVO.class); q.select(FusionstorBackupStorageVO_.fsid); q.add(FusionstorBackupStorageVO_.uuid, Op.EQ, backupStorage.getUuid()); String bsFsid = q.findValue(); if (!getSelf().getFsid().equals(bsFsid)) { throw new OperationFailureException(operr( "the backup storage[uuid:%s, name:%s, fsid:%s] is not in the same fusionstor cluster" + " with the primary storage[uuid:%s, name:%s, fsid:%s]", backupStorage.getUuid(), backupStorage.getName(), bsFsid, self.getUuid(), self.getName(), getSelf().getFsid() )); } }
public void checkParam() { super.checkParam(); SimpleQuery<CephBackupStorageVO> q = dbf.createQuery(CephBackupStorageVO.class); q.select(CephBackupStorageVO_.fsid); q.add(CephBackupStorageVO_.uuid, Op.EQ, backupStorage.getUuid()); String bsFsid = q.findValue(); if (!getSelf().getFsid().equals(bsFsid)) { throw new OperationFailureException(operr( "the backup storage[uuid:%s, name:%s, fsid:%s] is not in the same ceph cluster" + " with the primary storage[uuid:%s, name:%s, fsid:%s]", backupStorage.getUuid(), backupStorage.getName(), bsFsid, self.getUuid(), self.getName(), getSelf().getFsid()) ); } }
@Override void handle(BackupVolumeSnapshotFromPrimaryStorageToBackupStorageMsg msg, final ReturnValueCompletion<BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply> completion) { VolumeSnapshotInventory sinv = msg.getSnapshot(); String bsUuid = msg.getBackupStorage().getUuid(); // Get the backup storage install path BackupStorageAskInstallPathMsg bmsg = new BackupStorageAskInstallPathMsg(); bmsg.setImageMediaType(VolumeSnapshotVO.class.getSimpleName()); bmsg.setBackupStorageUuid(msg.getBackupStorage().getUuid()); bmsg.setImageUuid(sinv.getUuid()); bus.makeTargetServiceIdByResourceUuid(bmsg, BackupStorageConstant.SERVICE_ID, msg.getBackupStorage().getUuid()); MessageReply br = bus.call(bmsg); if (!br.isSuccess()) { completion.fail(br.getError()); return; } final String installPath = ((BackupStorageAskInstallPathReply) br).getInstallPath(); BackupStorageKvmUploader uploader = getBackupStorageKvmUploader(bsUuid); uploader.uploadBits(null, installPath, sinv.getPrimaryStorageInstallPath(), new ReturnValueCompletion<String>(completion) { @Override public void success(String bsPath) { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply reply = new BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply(); reply.setBackupStorageInstallPath(bsPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { evt.setInventory(factory.reload(inv.getUuid())); bus.publish(evt); CollectionUtils.safeForEach(pluginRgty.getExtensionList(AddBackupStorageExtensionPoint.class), new ForEachFunction<AddBackupStorageExtensionPoint>() { @Override public void run(AddBackupStorageExtensionPoint ext) { ext.afterAddBackupStorage(addBackupStoragestruct); } }); } else { dbf.removeByPrimaryKey(inv.getUuid(), BackupStorageVO.class); evt.setError(err(SysErrors.CREATE_RESOURCE_ERROR, reply.getError(), reply.getError().getDetails())); bus.publish(evt); } } });
@Override void handle(BackupVolumeSnapshotFromPrimaryStorageToBackupStorageMsg msg, String hostUuid, final ReturnValueCompletion<BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply> completion) { VolumeSnapshotInventory sp = msg.getSnapshot(); LocalStorageBackupStorageMediator m = localStorageFactory.getBackupStorageMediator(KVMConstant.KVM_HYPERVISOR_TYPE, msg.getBackupStorage().getType()); BackupStorageAskInstallPathMsg bmsg = new BackupStorageAskInstallPathMsg(); bmsg.setImageMediaType(VolumeSnapshotVO.class.getSimpleName()); bmsg.setBackupStorageUuid(msg.getBackupStorage().getUuid()); bmsg.setImageUuid(sp.getUuid()); bus.makeTargetServiceIdByResourceUuid(bmsg, BackupStorageConstant.SERVICE_ID, msg.getBackupStorage().getUuid()); MessageReply br = bus.call(bmsg); if (!br.isSuccess()) { completion.fail(br.getError()); return; } final String installPath = ((BackupStorageAskInstallPathReply) br).getInstallPath(); m.uploadBits(sp.getUuid(), getSelfInventory(), msg.getBackupStorage(), installPath, sp.getPrimaryStorageInstallPath(), hostUuid, new ReturnValueCompletion<String>(completion) { @Override public void success(String installPath) { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply reply = new BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply(); reply.setBackupStorageInstallPath(installPath); completion.success(reply); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }
@Override public void run(MessageReply rsp) { if (!rsp.isSuccess()) { reply.setError(rsp.getError()); } else { BackupVolumeSnapshotFromPrimaryStorageToBackupStorageReply r = rsp.castReply(); VolumeSnapshotBackupStorageRefVO ref = new VolumeSnapshotBackupStorageRefVO(); ref.setInstallPath(r.getBackupStorageInstallPath()); ref.setVolumeSnapshotUuid(self.getUuid()); ref.setBackupStorageUuid(msg.getBackupStorage().getUuid()); dbf.persist(ref); } bus.reply(msg, reply); } });
@Override public void afterAddBackupStorage(AddBackupStorageStruct backupStorage) { logger.debug("starting to import ceph images metadata"); if (!(backupStorage.getType().equals(CephConstants.CEPH_BACKUP_STORAGE_TYPE) && backupStorage.isImportImages())) { logger.debug("will not to import ceph images metadata due to importImages didn't set or bs type is not ceph"); return; } String backupStorageUuid = backupStorage.getBackupStorageInventory().getUuid(); SimpleQuery<CephBackupStorageVO> query = dbf.createQuery(CephBackupStorageVO.class); query.add(CephBackupStorageVO_.uuid, SimpleQuery.Op.EQ, backupStorageUuid); CephBackupStorageVO cephBackupStorageVO = query.find(); CephBackupStorageInventory inv = CephBackupStorageInventory.valueOf(cephBackupStorageVO); BakeImageMetadataMsg msg = new BakeImageMetadataMsg(); msg.setBackupStorageUuid(backupStorageUuid); msg.setOperation(CephConstants.AFTER_ADD_BACKUPSTORAGE); msg.setPoolName(inv.getPoolName()); bus.makeLocalServiceId(msg, BackupStorageConstant.SERVICE_ID); bus.send(msg, new CloudBusCallBack(msg) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { logger.debug("import ceph backup storage images info successfully"); } else { logger.debug("import ceph backup storage images info failed"); reply.setError(reply.getError()); } bus.reply(msg, reply); } }); }
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); } }); }