public static APIGetBackupStorageCapacityReply __example__() { APIGetBackupStorageCapacityReply reply = new APIGetBackupStorageCapacityReply(); reply.setTotalCapacity(1024L * 1024L * 1024L); reply.setAvailableCapacity(924L * 1024L * 1024L); return reply; }
private void validate(APIGetBackupStorageCapacityMsg msg) { boolean pass = false; if (msg.getBackupStorageUuids() != null && !msg.getBackupStorageUuids().isEmpty()) { pass = true; } if (msg.getZoneUuids() != null && !msg.getZoneUuids().isEmpty()) { pass = true; } if (!pass && !msg.isAll()) { throw new ApiMessageInterceptionException(argerr("zoneUuids, backupStorageUuids must have at least one be none-empty list, or all is set to true")); } if (msg.isAll() && (msg.getBackupStorageUuids() == null || msg.getBackupStorageUuids().isEmpty())) { SimpleQuery<BackupStorageVO> q = dbf.createQuery(BackupStorageVO.class); q.select(BackupStorageVO_.uuid); List<String> bsUuids = q.listValue(); msg.setBackupStorageUuids(bsUuids); if (msg.getBackupStorageUuids().isEmpty()) { APIGetBackupStorageCapacityReply reply = new APIGetBackupStorageCapacityReply(); bus.reply(msg, reply); throw new StopRoutingException(); } } }
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); }