mirror of https://github.com/apache/cloudstack.git
address host/cluster dao listall
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
ad275e7a36
commit
a1ee64344d
|
|
@ -16,14 +16,14 @@
|
|||
// under the License.
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ClusterDao extends GenericDao<ClusterVO, Long> {
|
||||
List<ClusterVO> listByPodId(long podId);
|
||||
|
||||
|
|
@ -54,4 +54,6 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
|
|||
List<Long> listAllClusterIds(Long zoneId);
|
||||
|
||||
boolean getSupportsResigning(long clusterId);
|
||||
|
||||
List<Long> listAllIds();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,20 @@
|
|||
// under the License.
|
||||
package com.cloud.dc.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterDetailsVO;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
|
|
@ -32,18 +46,6 @@ import com.cloud.utils.db.SearchCriteria.Func;
|
|||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Component
|
||||
public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao {
|
||||
|
|
@ -309,4 +311,12 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listAllIds() {
|
||||
GenericSearchBuilder<ClusterVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.done();
|
||||
return customSearch(sb.create(), null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,4 +170,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
|
|||
|
||||
List<Long> findHostIdsByZoneClusterResourceStateAndType(final Long zoneId, final Long clusterId,
|
||||
final List<ResourceState> resourceStates, final List<Type> types);
|
||||
|
||||
List<Long> listAllIds();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1543,4 +1543,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
sc.setParameters("type", types.toArray());
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listAllIds() {
|
||||
GenericSearchBuilder<HostVO, Long> sb = createSearchBuilder(Long.class);
|
||||
sb.selectFields(sb.entity().getId());
|
||||
sb.done();
|
||||
return customSearch(sb.create(), null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,8 +263,8 @@ public class PrometheusExporterImpl extends ManagerBase implements PrometheusExp
|
|||
metricsList.add(new ItemHostMemory(zoneName, zoneUuid, null, null, null, null, ALLOCATED, allocatedCapacityByTag.third(), 0, tag));
|
||||
});
|
||||
|
||||
List<String> allHostTags = hostDao.listAll().stream()
|
||||
.flatMap( h -> _hostTagsDao.getHostTags(h.getId()).stream())
|
||||
List<String> allHostTags = hostDao.listAllIds().stream()
|
||||
.flatMap( h -> _hostTagsDao.getHostTags(h).stream())
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
|
|
|||
|
|
@ -225,17 +225,17 @@ public class StorPoolHelper {
|
|||
}
|
||||
|
||||
public static Long findClusterIdByGlobalId(String globalId, ClusterDao clusterDao) {
|
||||
List<ClusterVO> clusterVo = clusterDao.listAll();
|
||||
if (clusterVo.size() == 1) {
|
||||
List<Long> clusterIds = clusterDao.listAllIds();
|
||||
if (clusterIds.size() == 1) {
|
||||
StorPoolUtil.spLog("There is only one cluster, sending backup to secondary command");
|
||||
return null;
|
||||
}
|
||||
for (ClusterVO clusterVO2 : clusterVo) {
|
||||
if (globalId != null && StorPoolConfigurationManager.StorPoolClusterId.valueIn(clusterVO2.getId()) != null
|
||||
&& globalId.contains(StorPoolConfigurationManager.StorPoolClusterId.valueIn(clusterVO2.getId()).toString())) {
|
||||
StorPoolUtil.spLog("Found cluster with id=%s for object with globalId=%s", clusterVO2.getId(),
|
||||
for (Long clusterId : clusterIds) {
|
||||
if (globalId != null && StorPoolConfigurationManager.StorPoolClusterId.valueIn(clusterId) != null
|
||||
&& globalId.contains(StorPoolConfigurationManager.StorPoolClusterId.valueIn(clusterId))) {
|
||||
StorPoolUtil.spLog("Found cluster with id=%s for object with globalId=%s", clusterId,
|
||||
globalId);
|
||||
return clusterVO2.getId();
|
||||
return clusterId;
|
||||
}
|
||||
}
|
||||
throw new CloudRuntimeException(
|
||||
|
|
|
|||
Loading…
Reference in New Issue