@Override public String call(BackupStorageInventory arg) { return arg.getUuid(); } });
protected BackupStorageInventory getSelfInventory() { return BackupStorageInventory.valueOf(self); }
@Override public String getPrimaryStoragePriorityMap(BackupStorageInventory bs, ImageInventory image) { if (!bs.getType().equals("Ceph")) { return null; } return CephBackupStorageGlobalProperty.CEPH_BACKUPSTORAGE_PRIORITY; }
public static APIAttachBackupStorageToZoneEvent __example__() { APIAttachBackupStorageToZoneEvent event = new APIAttachBackupStorageToZoneEvent(); BackupStorageInventory bs = new BackupStorageInventory(); bs.setName("My Backup Storage"); bs.setDescription("Public Backup Storage"); bs.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setLastOpDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setType("Ceph"); bs.setState(BackupStorageState.Enabled.toString()); bs.setStatus(BackupStorageStatus.Connected.toString()); bs.setAvailableCapacity(924L * 1024L * 1024L); bs.setTotalCapacity(1024L * 1024L * 1024L); bs.setAttachedZoneUuids(Collections.singletonList(uuid())); event.setInventory(bs); return event; }
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; }
@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 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); } }); }
private void download(final ReturnValueCompletion<Object> completion) { BackupStorageVO bsvo = dbf.findByUuid(image.getSelectedBackupStorage().getBackupStorageUuid(), BackupStorageVO.class); final BackupStorageInventory backupStorage = BackupStorageInventory.valueOf(bsvo); final NfsPrimaryToBackupStorageMediator mediator = nfsFactory.getPrimaryToBackupStorageMediator( BackupStorageType.valueOf(backupStorage.getType()), nfsMgr.findHypervisorTypeByImageFormatAndPrimaryStorageUuid(image.getInventory().getFormat(), primaryStorage.getUuid()) );
public static BackupStorageInventory valueOf(BackupStorageVO vo) { BackupStorageInventory inv = new BackupStorageInventory(vo); return inv; }
public static APIReconnectBackupStorageEvent __example__() { APIReconnectBackupStorageEvent event = new APIReconnectBackupStorageEvent(); BackupStorageInventory bs = new BackupStorageInventory(); bs.setName("My Backup Storage"); bs.setDescription("Public Backup Storage"); bs.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setLastOpDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setType("Ceph"); bs.setState(BackupStorageState.Enabled.toString()); bs.setStatus(BackupStorageStatus.Connected.toString()); bs.setAvailableCapacity(924L * 1024L * 1024L); bs.setTotalCapacity(1024L * 1024L * 1024L); bs.setAttachedZoneUuids(Collections.singletonList(uuid())); event.setInventory(bs); return event; }
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); } } }
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() )); } }
@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); } }); }
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); } } }
public static List<BackupStorageInventory> valueOf(Collection<BackupStorageVO> vos) { List<BackupStorageInventory> invs = new ArrayList<BackupStorageInventory>(vos.size()); for (BackupStorageVO vo : vos) { invs.add(BackupStorageInventory.valueOf(vo)); } return invs; }
public static APIChangeBackupStorageStateEvent __example__() { APIChangeBackupStorageStateEvent event = new APIChangeBackupStorageStateEvent(); BackupStorageInventory bs = new BackupStorageInventory(); bs.setName("My Backup Storage"); bs.setDescription("Public Backup Storage"); bs.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setLastOpDate(new Timestamp(org.zstack.header.message.DocUtils.date)); bs.setType("Ceph"); bs.setState(BackupStorageState.Disabled.toString()); bs.setStatus(BackupStorageStatus.Connected.toString()); bs.setAvailableCapacity(924L * 1024L * 1024L); bs.setTotalCapacity(1024L * 1024L * 1024L); bs.setAttachedZoneUuids(Collections.singletonList(uuid())); event.setInventory(bs); return event; }
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 public void afterAddBackupStorage(AddBackupStorageStruct backupStorage) { String backupStorageType = backupStorage.getBackupStorageInventory().getType(); if (!( backupStorageType.equals(SftpBackupStorageConstant.SFTP_BACKUP_STORAGE_TYPE) && backupStorage.isImportImages())) { return;
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); } } }); }
void afterAttach(BackupStorageVO vo, final String zoneUuid) { final BackupStorageInventory inv = BackupStorageInventory.valueOf(vo); CollectionUtils.safeForEach(attachExts, new ForEachFunction<BackupStorageAttachExtensionPoint>() { @Override public void run(BackupStorageAttachExtensionPoint arg) { arg.afterAttachBackupStorage(inv, zoneUuid); } }); }