private String selectRandomHostFromPS(PrimaryStorageInventory ps) { List<String> cuuids = ps.getAttachedClusterUuids(); if (cuuids.isEmpty()) { return null; } List<String> hosts = SQL.New("select host.uuid from ClusterVO cluster, HostVO host " + "where cluster.uuid = host.clusterUuid and host.status = :hostStatus and cluster.uuid in (:cuuids) order by rand()"). param("hostStatus", HostStatus.Connected).param("cuuids", cuuids).list(); if (hosts == null || hosts.size() == 0) { return null; } return hosts.get(0); }
@Transactional public List<HostInventory> getConnectedHostForOperation(PrimaryStorageInventory pri, int startPage, int pageLimit) { if (pri.getAttachedClusterUuids().isEmpty()) { throw new OperationFailureException(operr("cannot find a Connected host to execute command for nfs primary storage[uuid:%s]", pri.getUuid())); } String sql = "select h from HostVO h " + "where h.status = :connectionState and h.clusterUuid in (:clusterUuids) " + "and h.uuid not in (select ref.hostUuid from PrimaryStorageHostRefVO ref " + "where ref.primaryStorageUuid = :psUuid and ref.hostUuid = h.uuid and ref.status = :status)"; TypedQuery<HostVO> q = dbf.getEntityManager().createQuery(sql, HostVO.class); q.setParameter("connectionState", HostStatus.Connected); q.setParameter("clusterUuids", pri.getAttachedClusterUuids()); q.setParameter("psUuid", pri.getUuid()); q.setParameter("status", PrimaryStorageHostStatus.Disconnected); q.setFirstResult(startPage * pageLimit); if (pageLimit > 0){ q.setMaxResults(pageLimit); } List<HostVO> ret = q.getResultList(); if (ret.isEmpty() && startPage == 0) { //check is first page throw new OperationFailureException( operr("cannot find a host which has Connected host-NFS connection to execute command " + "for nfs primary storage[uuid:%s]", pri.getUuid())); } else { Collections.shuffle(ret); return HostInventory.valueOf(ret); } }
@Transactional public List<HostInventory> getConnectedHostForOperation(PrimaryStorageInventory pri, int startPage, int pageLimit) { if (pri.getAttachedClusterUuids().isEmpty()) { throw new OperationFailureException(operr("cannot find a Connected host to execute command for smp primary storage[uuid:%s]", pri.getUuid())); } String sql = "select h from HostVO h " + "where h.status = :connectionState and h.clusterUuid in (:clusterUuids) " + "and h.uuid not in (select ref.hostUuid from PrimaryStorageHostRefVO ref " + "where ref.primaryStorageUuid = :psUuid and ref.hostUuid = h.uuid and ref.status = :status)"; TypedQuery<HostVO> q = dbf.getEntityManager().createQuery(sql, HostVO.class); q.setParameter("connectionState", HostStatus.Connected); q.setParameter("clusterUuids", pri.getAttachedClusterUuids()); q.setParameter("psUuid", pri.getUuid()); q.setParameter("status", PrimaryStorageHostStatus.Disconnected); q.setFirstResult(startPage * pageLimit); if (pageLimit > 0){ q.setMaxResults(pageLimit); } List<HostVO> ret = q.getResultList(); if (ret.isEmpty() && startPage == 0) { //check is first page throw new OperationFailureException(operr( "cannot find a host which has Connected host-SMP connection to execute command for smp primary storage[uuid:%s]", pri.getUuid())); } else { Collections.shuffle(ret); return HostInventory.valueOf(ret); } }
private void pingAll(PrimaryStorageInventory inv, int limit, final Completion completion){ List<String> huuids = Q.New(HostVO.class).select(HostVO_.uuid) .in(HostVO_.clusterUuid, inv.getAttachedClusterUuids()) .eq(HostVO_.status, HostStatus.Connected) .eq(HostVO_.state, HostState.Enabled) .listValues(); if(huuids.size() == 0){ completion.fail(operr("no host in is Connected or primary storage[uuid:%s] attach no cluster", inv.getUuid())); return; } Collections.shuffle(huuids); doPing(huuids.subList(0, min(limit,huuids.size())), inv, new Completion(completion) { @Override public void success() { completion.success(); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); }