@Override @Transactional( readOnly = true, noRollbackForClassName = {"org.zstack.header.errorcode.OperationFailureException"}) public void preVmMigration(VmInstanceInventory vm) { List<String> volUuids = CollectionUtils.transformToList( vm.getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) { return arg.getUuid(); } }); String sql = "select count(ps) from PrimaryStorageVO ps, VolumeVO vol where ps.uuid = vol.primaryStorageUuid and" + " vol.uuid in (:volUuids) and ps.type = :ptype"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("volUuids", volUuids); q.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE); q.setMaxResults(1); Long count = q.getSingleResult(); if (count > 0) { throw new OperationFailureException( errf.stringToOperationError( String.format( "unable to live migrate with local storage. The vm[uuid:%s] has volumes on local storage," + "to protect your data, please stop the vm and do the volume migration", vm.getUuid()))); } }