@Override @Transactional(readOnly = true) public HostMaintenancePolicy getHostMaintenancePolicy(HostInventory host) { String sql = "select count(ps) from PrimaryStorageVO ps, PrimaryStorageClusterRefVO ref where ps.uuid = ref.primaryStorageUuid" + " and ps.type = :type and ref.clusterUuid = :cuuid"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("type", LocalStorageConstants.LOCAL_STORAGE_TYPE); q.setParameter("cuuid", host.getClusterUuid()); q.setMaxResults(1); Long count = q.getSingleResult(); return count > 0 ? HostMaintenancePolicy.StopVm : null; }
@Override public void afterDeleteHost(final HostInventory inventory) { final String priUuid = getLocalStorageInCluster(inventory.getClusterUuid()); if (priUuid != null) { RemoveHostFromLocalStorageMsg msg = new RemoveHostFromLocalStorageMsg(); msg.setPrimaryStorageUuid(priUuid); msg.setHostUuid(inventory.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, priUuid); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { // TODO logger.warn( String.format( "failed to remove host[uuid:%s] from local primary storage[uuid:%s], %s", inventory.getUuid(), priUuid, reply.getError())); } else { logger.debug( String.format( "removed host[uuid:%s] from local primary storage[uuid:%s]", inventory.getUuid(), priUuid)); } } }