@Override public boolean remove(Long id) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); ClusterVO cluster = createForUpdate(); cluster.setName(null); cluster.setGuid(null); update(id, cluster); boolean result = super.remove(id); txn.commit(); return result; }
@Override public List<Long> listAllClusters(Long zoneId) { SearchCriteria<Long> sc = ClusterIdSearch.create(); if (zoneId != null) { sc.setParameters("dataCenterId", zoneId); } return customSearch(sc, null); }
@Override public boolean getSupportsResigning(long clusterId) { ClusterVO cluster = findById(clusterId); if (cluster == null || cluster.getAllocationState() != Grouping.AllocationState.Enabled) { return false; } ClusterDetailsVO clusterDetailsVO = clusterDetailsDao.findDetail(clusterId, "supportsResign"); if (clusterDetailsVO != null) { String value = clusterDetailsVO.getValue(); return Boolean.parseBoolean(value); } return false; } }
@Override public List<Long> listDisabledClusters(long zoneId, Long podId) { GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class); clusterIdSearch.selectFields(clusterIdSearch.entity().getId()); clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ); if (podId != null) { clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ); } clusterIdSearch.and("allocationState", clusterIdSearch.entity().getAllocationState(), Op.EQ); clusterIdSearch.done(); SearchCriteria<Long> sc = clusterIdSearch.create(); sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); if (podId != null) { sc.addAnd("podId", SearchCriteria.Op.EQ, podId); } sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled); return customSearch(sc, null); }
@Override public List<ClusterVO> listByHyTypeWithoutGuid(String hyType) { SearchCriteria<ClusterVO> sc = HyTypeWithoutGuidSearch.create(); sc.setParameters("hypervisorType", hyType); return listBy(sc); }
@Override public ClusterVO findBy(String name, long podId) { SearchCriteria<ClusterVO> sc = PodSearch.create(); sc.setParameters("pod", podId); sc.setParameters("name", name); return findOneBy(sc); }
public ClusterDaoImpl() { super(); HyTypeWithoutGuidSearch = createSearchBuilder(); HyTypeWithoutGuidSearch.and("hypervisorType", HyTypeWithoutGuidSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); HyTypeWithoutGuidSearch.and("guid", HyTypeWithoutGuidSearch.entity().getGuid(), SearchCriteria.Op.NULL); HyTypeWithoutGuidSearch.done(); ZoneHyTypeSearch = createSearchBuilder(); ZoneHyTypeSearch.and("hypervisorType", ZoneHyTypeSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); ZoneHyTypeSearch.and("dataCenterId", ZoneHyTypeSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneHyTypeSearch.done(); PodSearch = createSearchBuilder(); PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); PodSearch.and("name", PodSearch.entity().getName(), SearchCriteria.Op.EQ); PodSearch.done(); ZoneSearch = createSearchBuilder(); ZoneSearch.and("dataCenterId", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneSearch.groupBy(ZoneSearch.entity().getHypervisorType()); ZoneSearch.done(); AvailHyperSearch = createSearchBuilder(); AvailHyperSearch.and("zoneId", AvailHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AvailHyperSearch.select(null, Func.DISTINCT, AvailHyperSearch.entity().getHypervisorType()); AvailHyperSearch.done(); ZoneClusterSearch = createSearchBuilder(); ZoneClusterSearch.and("dataCenterId", ZoneClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneClusterSearch.done(); ClusterIdSearch = createSearchBuilder(Long.class); ClusterIdSearch.selectFields(ClusterIdSearch.entity().getId()); ClusterIdSearch.and("dataCenterId", ClusterIdSearch.entity().getDataCenterId(), Op.EQ); ClusterIdSearch.done(); }
@Override public List<Long> listClustersWithDisabledPods(long zoneId) { GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = hostPodDao.createSearchBuilder(Long.class); disabledPodIdSearch.selectFields(disabledPodIdSearch.entity().getId()); disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ); disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ); GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class); clusterIdSearch.selectFields(clusterIdSearch.entity().getId()); clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER); clusterIdSearch.done(); SearchCriteria<Long> sc = clusterIdSearch.create(); sc.setJoinParameters("disabledPodIdSearch", "dataCenterId", zoneId); sc.setJoinParameters("disabledPodIdSearch", "allocationState", Grouping.AllocationState.Disabled); return customSearch(sc, null); }
@Override public List<ClusterVO> listClustersByDcId(long zoneId) { SearchCriteria<ClusterVO> sc = ZoneClusterSearch.create(); sc.setParameters("dataCenterId", zoneId); return listBy(sc); }
@Override public List<ClusterVO> listByZoneId(long zoneId) { SearchCriteria<ClusterVO> sc = ZoneSearch.create(); sc.setParameters("dataCenterId", zoneId); return listBy(sc); }
@Override public List<ClusterVO> listByPodId(long podId) { SearchCriteria<ClusterVO> sc = PodSearch.create(); sc.setParameters("pod", podId); return listBy(sc); }
@Override public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) { SearchCriteria<ClusterVO> sc = AvailHyperSearch.create(); if (zoneId != null) { sc.setParameters("zoneId", zoneId); } List<ClusterVO> clusters = listBy(sc); List<HypervisorType> hypers = new ArrayList<HypervisorType>(4); for (ClusterVO cluster : clusters) { hypers.add(cluster.getHypervisorType()); } return hypers; }
@Override public List<ClusterVO> listByDcHyType(long dcId, String hyType) { SearchCriteria<ClusterVO> sc = ZoneHyTypeSearch.create(); sc.setParameters("dataCenterId", dcId); sc.setParameters("hypervisorType", hyType); return listBy(sc); }