public long getClusterIdForClusterUuid(String clusterUuid) { ClusterVO cluster = clusterDao.findByUuid(clusterUuid); if (cluster == null) { throw new CloudRuntimeException("Unable to find Volume for ID: " + clusterUuid); } return cluster.getId(); }
private String getClusterName(Long clusterId) { ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null) { throw new CloudRuntimeException("Cannot get cluster for id " + clusterId); } String clusterName = "OvmCluster" + cluster.getId(); return clusterName; }
protected HypervisorType getClusterToStartDomainRouterForOvm(final long podId) { final List<ClusterVO> clusters = _clusterDao.listByPodId(podId); for (final ClusterVO cv : clusters) { if (cv.getHypervisorType() == HypervisorType.Ovm || cv.getHypervisorType() == HypervisorType.BareMetal) { continue; } final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cv.getId()); if (hosts == null || hosts.isEmpty()) { continue; } for (final HostVO h : hosts) { if (h.getState() == Status.Up) { s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " + cv.getId() + " to start domain router for OVM"); return h.getHypervisorType(); } } } final String errMsg = new StringBuilder("Cannot find an available cluster in Pod ").append(podId) .append(" to start domain router for Ovm. \n Ovm won't support any system vm including domain router, ") .append("please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod") .append(" with Ovm cluster. And there is at least one host in UP status in that cluster.").toString(); throw new CloudRuntimeException(errMsg); }
void setClusterGuid(ClusterVO cluster, String guid) { cluster.setGuid(guid); try { _clusterDao.update(cluster.getId(), cluster); } catch (EntityExistsException e) { QueryBuilder<ClusterVO> sc = QueryBuilder.create(ClusterVO.class); sc.and(sc.entity().getGuid(), Op.EQ, guid); List<ClusterVO> clusters = sc.list(); ClusterVO clu = clusters.get(0); List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clu.getId()); if (clusterHosts == null || clusterHosts.size() == 0) { clu.setGuid(null); _clusterDao.update(clu.getId(), clu); _clusterDao.update(cluster.getId(), cluster); return; } throw e; } }
private static boolean isStorageApplicableToZoneOrCluster(StoragePoolVO storagePoolVO, long clusterId, ClusterDao clusterDao) { if (storagePoolVO.getClusterId() != null) { if (storagePoolVO.getClusterId() == clusterId) { return true; } } else { List<ClusterVO> clustersInZone = clusterDao.listByZoneId(storagePoolVO.getDataCenterId()); if (clustersInZone != null) { for (ClusterVO clusterInZone : clustersInZone) { if (clusterInZone.getId() == clusterId) { return true; } } } } return false; }
@Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { StartupCommand firstCmd = cmd[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; } StartupRoutingCommand ssCmd = ((StartupRoutingCommand)firstCmd); if (ssCmd.getHypervisorType() != getHypervisorType()) { return null; } /* KVM requires host are the same in cluster */ ClusterVO clusterVO = _clusterDao.findById(host.getClusterId()); if (clusterVO == null) { s_logger.debug("cannot find cluster: " + host.getClusterId()); throw new IllegalArgumentException("cannot add host, due to can't find cluster: " + host.getClusterId()); } List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId()); if (!hostsInCluster.isEmpty()) { HostVO oneHost = hostsInCluster.get(0); _hostDao.loadDetails(oneHost); String hostOsInCluster = oneHost.getDetail("Host.OS"); String hostOs = ssCmd.getHostDetails().get("Host.OS"); if (!hostOsInCluster.equalsIgnoreCase(hostOs)) { throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster," + "in which there are " + hostOsInCluster + " hosts added"); } } _hostDao.loadDetails(host); return _resourceMgr.fillRoutingHostVO(host, ssCmd, getHypervisorType(), host.getDetails(), null); }
@Override public Answer sendTo(final Long dcId, final HypervisorType type, final Command cmd) { final List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, type.toString()); int retry = 0; for (final ClusterVO cluster : clusters) { final List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), null, dcId); for (final HostVO host : hosts) { retry++; if (retry > _retry) { return null; } Answer answer = null; try { final long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(host.getId(), cmd); answer = easySend(targetHostId, cmd); } catch (final Exception e) { } if (answer != null) { return answer; } } } return null; }
if (cluster.getGuid() == null) { cluster.setGuid(startup.getPool()); _clusterDao.update(cluster.getId(), cluster); } else if (!cluster.getGuid().equals(startup.getPool())) { String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool(); s_logger.warn(msg); throw new CloudRuntimeException(msg);
Long clusterId = p.getCluster() == null ? null : p.getCluster().getId(); if (p.getCluster() != null && p.getCluster().getAllocationState() != Grouping.AllocationState.Enabled) { if (s_logger.isDebugEnabled()) {
if (cluster.getGuid() == null) { cluster.setGuid(startup.getPool()); _clusterDao.update(cluster.getId(), cluster);
List<HostVO> hosts; for (ClusterVO cluster : clusters) { hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); if (hostTag != null) { for (HostVO h : hosts) { hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); } else { s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId()); return null;
throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + clusterVO.getHypervisorType());
@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); }
if (scope.equals(ScopeType.CLUSTER)) { ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId()); hosts = _resourceMgr.listAllHostsInCluster(cluster.getId()); } else if (scope.equals(ScopeType.ZONE)) { hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, volume.getDataCenterId());
@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<HostVO> listByDataCenterIdAndHypervisorType(long zoneId, Hypervisor.HypervisorType hypervisorType) { SearchBuilder<ClusterVO> clusterSearch = _clusterDao.createSearchBuilder(); clusterSearch.and("allocationState", clusterSearch.entity().getAllocationState(), SearchCriteria.Op.EQ); clusterSearch.and("hypervisorType", clusterSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ); SearchBuilder<HostVO> hostSearch = createSearchBuilder(); hostSearch.and("dc", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); hostSearch.and("type", hostSearch.entity().getType(), Op.EQ); hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ); hostSearch.and("resourceState", hostSearch.entity().getResourceState(), Op.EQ); hostSearch.join("clusterSearch", clusterSearch, hostSearch.entity().getClusterId(), clusterSearch.entity().getId(), JoinBuilder.JoinType.INNER); hostSearch.done(); SearchCriteria<HostVO> sc = hostSearch.create(); sc.setParameters("dc", zoneId); sc.setParameters("type", Host.Type.Routing); sc.setParameters("status", Status.Up); sc.setParameters("resourceState", ResourceState.Enabled); sc.setJoinParameters("clusterSearch", "allocationState", Grouping.AllocationState.Enabled); sc.setJoinParameters("clusterSearch", "hypervisorType", hypervisorType.toString()); return listBy(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(); }
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);