public static HostPodVO findPodById(Long podId) { return s_podDao.findById(podId); }
@Override public List<PodCluster> listByDataCenter(final long dcId) { final List<HostPodVO> pods = _podDao.listByDataCenterId(dcId); final ArrayList<PodCluster> pcs = new ArrayList<PodCluster>(); for (final HostPodVO pod : pods) { final List<ClusterVO> clusters = _clusterDao.listByPodId(pod.getId()); if (clusters.size() == 0) { pcs.add(new PodCluster(pod, null)); } else { for (final ClusterVO cluster : clusters) { pcs.add(new PodCluster(pod, cluster)); } } } return pcs; }
@Override public InfrastructureResponse listInfrastructure() { final InfrastructureResponse response = new InfrastructureResponse(); response.setZones(dataCenterDao.listAllZones().size()); response.setPods(podDao.listAllPods(null).size()); response.setClusters(clusterDao.listAllClusters(null).size()); response.setHosts(hostDao.listByType(Host.Type.Routing).size()); response.setStoragePools(storagePoolDao.listAll().size()); response.setImageStores(imageStoreDao.listImageStores().size()); response.setSystemvms(vmInstanceDao.listByTypes(VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm).size()); response.setRouters(domainRouterDao.listAll().size()); int cpuSockets = 0; for (final Host host : hostDao.listByType(Host.Type.Routing)) { if (host.getCpuSockets() != null) { cpuSockets += host.getCpuSockets(); } } response.setCpuSockets(cpuSockets); return response; }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { String ipRange = pod.getDescription(); /* * POD Description is refactored to: * <START_IP>-<END_IP>-<FOR_SYSTEM_VMS>-<VLAN>,<START_IP>-<END_IP>-<FOR_SYSTEM_VMS>-<VLAN>,... */ String range = startIp + "-" + endIpFinal + "-" + (forSystemVms ? "1" : "0") + "-" + (vlanId == null ? DefaultVlanForPodIpRange : vlanId); if(ipRange != null && !ipRange.isEmpty()) ipRange += ("," + range); else ipRange = (range); pod.setDescription(ipRange); HostPodVO lock = null; try { lock = _podDao.acquireInLockTable(podId); if (lock == null) { String msg = "Unable to acquire lock on table to update the ip range of POD: " + pod.getName() + ", Creation failed."; s_logger.warn(msg); throw new CloudRuntimeException(msg); } _podDao.update(podId, pod); } finally { if (lock != null) { _podDao.releaseFromLockTable(podId); } } _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal, forSystemVms, vlanId); } });
final List<HostPodVO> pods = _podDao.listAllIncludingRemoved(); for (final HostPodVO hpv : pods) { if (checkCIDR(hpv, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) { HostPodVO p = _podDao.findByName(pod, dcId); if (p == null) { try { final long podId = Long.parseLong(pod); p = _podDao.findById(podId); } catch (final NumberFormatException e) { s_logger.debug("Cannot parse " + pod + " into Long.");
throw new ResourceAllocationException("Please do not provide NULL podId", ResourceType.network); HostPodVO podvo = null; podvo = _hpDao.findByUuid(podId); if (podvo == null) throw new ResourceAllocationException("No sush pod exists", ResourceType.network); throw new ResourceAllocationException("Unable to allocate IP from this Pod", ResourceType.network); HostPodVO pod_vo = _hpDao.findById(vo.getPodId()); AcquirePodIpCmdResponse ret = new AcquirePodIpCmdResponse(); ret.setCidrAddress(pod_vo.getCidrAddress());
final SearchBuilder<HostPodVO> sb = _hostPodDao.createSearchBuilder(); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); final SearchCriteria<HostPodVO> ssc = _hostPodDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); final Pair<List<HostPodVO>, Integer> result = _hostPodDao.searchAndCount(sc, searchFilter); return new Pair<List<? extends Pod>, Integer>(result.first(), result.second());
/** * Lists all pods given a Data Center Id, a {@link VirtualMachine.Type} and * a list of {@link VirtualMachine.State} * @param id * @param type * @param states * @return */ protected List<HostPodVO> listByDataCenterIdVMTypeAndStates(final long id, final VirtualMachine.Type type, final VirtualMachine.State... states) { final SearchBuilder<VMInstanceVO> vmInstanceSearch = vmDao.createSearchBuilder(); vmInstanceSearch.and("type", vmInstanceSearch.entity().getType(), SearchCriteria.Op.EQ); vmInstanceSearch.and("states", vmInstanceSearch.entity().getState(), SearchCriteria.Op.IN); final SearchBuilder<HostPodVO> podIdSearch = podDao.createSearchBuilder(); podIdSearch.and("dc", podIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); podIdSearch.select(null, SearchCriteria.Func.DISTINCT, podIdSearch.entity().getId()); podIdSearch.join("vmInstanceSearch", vmInstanceSearch, podIdSearch.entity().getId(), vmInstanceSearch.entity().getPodIdToDeployIn(), JoinBuilder.JoinType.INNER); podIdSearch.done(); final SearchCriteria<HostPodVO> sc = podIdSearch.create(); sc.setParameters("dc", id); sc.setJoinParameters("vmInstanceSearch", "type", type); sc.setJoinParameters("vmInstanceSearch", "states", (Object[]) states); return podDao.search(sc, null); }
@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 void doInTransactionWithoutResult(final TransactionStatus status) { pod.setDescription(newPodIpRange.toString()); HostPodVO lock = null; try { lock = _podDao.acquireInLockTable(podId); if (lock == null) { String msg = "Unable to acquire lock on table to update the ip range of POD: " + pod.getName() + ", Deletion failed."; s_logger.warn(msg); throw new CloudRuntimeException(msg); } _podDao.update(podId, pod); } finally { if (lock != null) { _podDao.releaseFromLockTable(podId); } } for(long ipAddr = NetUtils.ip2Long(startIp); ipAddr <= NetUtils.ip2Long(endIp); ipAddr++) { if (!_privateIpAddressDao.deleteIpAddressByPodDc(NetUtils.long2Ip(ipAddr), podId, pod.getDataCenterId())) { throw new CloudRuntimeException("Failed to cleanup private ip address: " + NetUtils.long2Ip(ipAddr) + " of Pod: " + podId + " DC: " + pod.getDataCenterId()); } } } });
private boolean validPod(final long podId) { return _podDao.findById(podId) != null; }
private void checkOverlapPrivateIpRange(final Long zoneId, final String startIp, final String endIp) { final List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId); for (final HostPodVO hostPod : podsInZone) { final String[] existingPodIpRanges = hostPod.getDescription().split(","); for(String podIpRange: existingPodIpRanges) { final String[] existingPodIpRange = podIpRange.split("-"); if (existingPodIpRange.length > 1) { if (!NetUtils.isValidIp4(existingPodIpRange[0]) || !NetUtils.isValidIp4(existingPodIpRange[1])) { continue; } if (NetUtils.ipRangesOverlap(startIp, endIp, existingPodIpRange[0], existingPodIpRange[1])) { throw new InvalidParameterValueException("The Start IP and EndIP address range overlap with private IP :" + existingPodIpRange[0] + ":" + existingPodIpRange[1]); } } } } }
List<Long> allPodsInDc = _podDao.listAllPods(dc.getId()); List<Long> allDedicatedPods = _dedicatedDao.listAllPods(); allPodsInDc.retainAll(allDedicatedPods);
private String getPodName(final long podId) { return _podDao.findById(new Long(podId)).getName(); }
private HostPodVO findPod(StartupCommand startup, long zoneId, Host.Type type) { HostPodVO pod = null; List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId); for (HostPodVO hostPod : podsInZone) { if (checkCIDR(type, hostPod, startup.getPrivateIpAddress(), startup.getPrivateNetmask())) { pod = hostPod; //found the default POD having the same subnet. updatePodNetmaskIfNeeded(pod, startup.getPrivateNetmask()); break; } } return pod; }
private boolean podHasAllocatedPrivateIPs(final long podId) { final HostPodVO pod = _podDao.findById(podId); final int count = _privateIpAddressDao.countIPs(podId, pod.getDataCenterId(), true); return count > 0; }
@Override public Pair<Pod, Long> allocateTo(VirtualMachineTemplate template, ServiceOffering offering, DataCenter zone, long accountId, Set<Long> avoids) { long zoneId = zone.getId(); List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
private boolean isEnabledForAllocation(long zoneId, Long podId, Long clusterId) { // Check if the zone exists in the system DataCenterVO zone = _dcDao.findById(zoneId); if (zone != null && Grouping.AllocationState.Disabled == zone.getAllocationState()) { s_logger.info("Zone is currently disabled, cannot allocate to this zone: " + zoneId); return false; } Pod pod = _podDao.findById(podId); if (pod != null && Grouping.AllocationState.Disabled == pod.getAllocationState()) { s_logger.info("Pod is currently disabled, cannot allocate to this pod: " + podId); return false; } Cluster cluster = _clusterDao.findById(clusterId); if (cluster != null && Grouping.AllocationState.Disabled == cluster.getAllocationState()) { s_logger.info("Cluster is currently disabled, cannot allocate to this cluster: " + clusterId); return false; } return true; }
if (!_podDao.listByDataCenterId(zoneId).isEmpty()) { throw new CloudRuntimeException(errorMsg + "there are pods in this zone.");
HostPodVO pod = s_podDao.findById(podId);