private void validate(APIBackupVolumeSnapshotMsg msg) {
SimpleQuery<VolumeSnapshotVO> q = dbf.createQuery(VolumeSnapshotVO.class);
q.select(VolumeSnapshotVO_.primaryStorageUuid);
q.add(VolumeSnapshotVO_.uuid, Op.EQ, msg.getUuid());
String priUuid = q.findValue();
if (priUuid == null) {
throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is not on primary storage, cannot be backed up", msg.getUuid()));
}
if (msg.getBackupStorageUuid() != null) {
SimpleQuery<VolumeSnapshotBackupStorageRefVO> rq = dbf.createQuery(VolumeSnapshotBackupStorageRefVO.class);
rq.add(VolumeSnapshotBackupStorageRefVO_.volumeSnapshotUuid, Op.EQ, msg.getUuid());
rq.add(VolumeSnapshotBackupStorageRefVO_.backupStorageUuid, Op.EQ, msg.getBackupStorageUuid());
if (rq.isExists()) {
throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is already on backup storage[uuid: %s]", msg.getUuid(), msg.getBackupStorageUuid()));
}
SimpleQuery<PrimaryStorageVO> pq = dbf.createQuery(PrimaryStorageVO.class);
pq.select(PrimaryStorageVO_.zoneUuid);
pq.add(PrimaryStorageVO_.uuid, Op.EQ, priUuid);
String zoneUuid = pq.findValue();
SimpleQuery<BackupStorageZoneRefVO> brq = dbf.createQuery(BackupStorageZoneRefVO.class);
brq.add(BackupStorageZoneRefVO_.zoneUuid, Op.EQ, zoneUuid);
brq.add(BackupStorageZoneRefVO_.backupStorageUuid, Op.EQ, msg.getBackupStorageUuid());
if (!brq.isExists()) {
throw new ApiMessageInterceptionException(operr("volume snapshot[uuid:%s] is on primary storage[uuid:%s] which is in zone[uuid:%s] that backup storage[uuid:%s] is not attached to",
msg.getUuid(), priUuid, zoneUuid, msg.getBackupStorageUuid()));
}
}
}