private void handle(final APIGetBackupStorageCapacityMsg msg) {
APIGetBackupStorageCapacityReply reply = new APIGetBackupStorageCapacityReply();
Tuple ret = new Callable<Tuple>() {
@Override
@Transactional(readOnly = true)
public Tuple call() {
if (msg.getBackupStorageUuids() != null && !msg.getBackupStorageUuids().isEmpty()) {
String sql = "select sum(bs.totalCapacity), sum(bs.availableCapacity) from BackupStorageVO bs where bs.uuid in (:bsUuids)";
TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class);
q.setParameter("bsUuids", msg.getBackupStorageUuids());
return q.getSingleResult();
} else if (msg.getZoneUuids() != null && !msg.getZoneUuids().isEmpty()) {
String sql = "select sum(bs.totalCapacity), sum(bs.availableCapacity) from BackupStorageVO bs, BackupStorageZoneRefVO ref where ref.backupStorageUuid = bs.uuid and ref.zoneUuid in (:zoneUuids)";
TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class);
q.setParameter("zoneUuids", msg.getZoneUuids());
return q.getSingleResult();
}
throw new CloudRuntimeException("should not be here");
}
}.call();
Long total = ret.get(0, Long.class);
Long avail = ret.get(1, Long.class);
reply.setTotalCapacity(total == null ? 0 : total);
reply.setAvailableCapacity(avail == null ? 0 : avail);
bus.reply(msg, reply);
}