Map<Long, Long> podHostCandidates = new HashMap<Long, Long>(); for (HostPodVO pod : podsInZone) { long podId = pod.getId(); if (!avoids.contains(podId)) { if (template != null && !templateAvailableInPod(template.getId(), pod.getDataCenterId(), podId)) { continue; List<UserVmVO> vmsInPod = _vmDao.listByAccountAndPod(accountId, pod.getId()); if (!vmsInPod.isEmpty()) { return new Pair<Pod, Long>(pod, podHostCandidates.get(podId)); List<VolumeVO> volumesInPod = _volumeDao.findByAccountAndPod(accountId, pod.getId()); if (!volumesInPod.isEmpty()) { return new Pair<Pod, Long>(pod, podHostCandidates.get(podId)); s_logger.debug("Found pod " + selectedPod.getName() + " in zone " + zone.getName()); return new Pair<Pod, Long>(selectedPod, podHostCandidates.get(selectedPod.getId()));
public HostPodDaoImpl() { DataCenterAndNameSearch = createSearchBuilder(); DataCenterAndNameSearch.and("dc", DataCenterAndNameSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DataCenterAndNameSearch.and("name", DataCenterAndNameSearch.entity().getName(), SearchCriteria.Op.EQ); DataCenterAndNameSearch.done(); DataCenterIdSearch = createSearchBuilder(); DataCenterIdSearch.and("dcId", DataCenterIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); DataCenterIdSearch.done(); PodIdSearch = createSearchBuilder(Long.class); PodIdSearch.selectFields(PodIdSearch.entity().getId()); PodIdSearch.and("dataCenterId", PodIdSearch.entity().getDataCenterId(), Op.EQ); PodIdSearch.and("allocationState", PodIdSearch.entity().getAllocationState(), Op.EQ); PodIdSearch.done(); }
eventDescription.put("podId", pod.getUuid()); } else { eventDescription.put("podId", null);
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { final long zoneId = pod.getDataCenterId(); pod.setName(nameFinal); pod.setDataCenterId(zoneId); pod.setGateway(gatewayFinal); pod.setCidrAddress(getCidrAddress(cidr)); pod.setCidrSize(getCidrSize(cidr)); Grouping.AllocationState allocationState = null; if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) { allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal); pod.setAllocationState(allocationState); } _podDao.update(id, pod); } });
@Override public AllocationState findPodAllocationState(final HostPodVO pod) { if (pod.getAllocationState() == AllocationState.Disabled) { return AllocationState.Disabled; } else { final DataCenterVO zone = ApiDBUtils.findZoneById(pod.getDataCenterId()); return zone.getAllocationState(); } }
private void updatePodNetmaskIfNeeded(HostPodVO pod, String agentNetmask) { // If the server's private netmask is less inclusive than the pod's CIDR // netmask, update cidrSize of the default POD //(reason: we are maintaining pods only for internal accounting.) long cidrSize = pod.getCidrSize(); String cidrNetmask = NetUtils.getCidrSubNet("255.255.255.255", cidrSize); long cidrNetmaskNumeric = NetUtils.ip2Long(cidrNetmask); long serverNetmaskNumeric = NetUtils.ip2Long(agentNetmask);// if (serverNetmaskNumeric > cidrNetmaskNumeric) { //update pod's cidrsize int newCidrSize = new Long(NetUtils.getCidrSize(agentNetmask)).intValue(); pod.setCidrSize(newCidrSize); _podDao.update(pod.getId(), pod); } }
if (!_privateIPAddressDao.mark(dc.getId(), pod.getId(), serverPrivateIP)) { final List<DataCenterIpAddressVO> existingPrivateIPs = _privateIPAddressDao.listByPodIdDcIdIpAddress(pod.getId(), dc.getId(), serverPrivateIP); throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + pod.getName() + " and zone: " + dc.getName()); final DataCenterIpAddressVO vo = existingPrivateIPs.get(0); if (vo.getInstanceId() != null) { throw new IllegalArgumentException("The private ip address of the server (" + serverPrivateIP + ") is already in use in pod: " + pod.getName() + " and zone: " + dc.getName());
HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId()); if (pod != null) { clusterResponse.setPodId(pod.getUuid()); clusterResponse.setPodName(pod.getName()); capacityResponses.addAll(getStatsCapacityresponse(null, cluster.getId(), pod.getId(), pod.getDataCenterId())); clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
long podId = pod.getId(); long dcId = pod.getDataCenterId();
final long oldCidr = pod.getCidrSize(); gateway = pod.getGateway(); netmask = NetUtils.getCidrNetmask(pod.getCidrSize()); final String oldPodName = pod.getName(); if (name == null) { name = oldPodName; allocationStateStr = pod.getAllocationState().toString(); checkPodAttributes(id, name, pod.getDataCenterId(), gateway, cidr, startIp, endIp, allocationStateStr, checkForDuplicates, true); final String[] existingPodIpRanges = pod.getDescription().split(",");
@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); } });
while (it.hasNext()) { PodCluster pc = it.next(); if (pc.getPod().getId() != podId) { it.remove(); pcs.remove(new PodCluster(new HostPodVO(pcId.first()), pcId.second() != null ? new ClusterVO(pcId.second()) : null)); if (p.getPod().getAllocationState() != Grouping.AllocationState.Enabled) { if (s_logger.isDebugEnabled()) { s_logger.debug("Pod name: " + p.getPod().getName() + ", podId: " + p.getPod().getId() + " is in " + p.getPod().getAllocationState().name() + " state, skipping this and trying other pods"); DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null, null); hosts = super.allocateTo(vm, newPlan, type, avoid, returnUpTo); if (hosts != null && !hosts.isEmpty()) {
private String getPodName(final long podId) { return _podDao.findById(new Long(podId)).getName(); }
final long zoneId = pod.getDataCenterId(); final String cidrAddress = pod.getCidrAddress(); final long cidrSize = pod.getCidrSize(); if (!gateway.equals(pod.getGateway())) { throw new InvalidParameterValueException("Multiple gateways for the POD: " + pod.getId() + " are not allowed. The Gateway should be same as the existing Gateway " + pod.getGateway()); throw new InvalidParameterValueException("Multiple subnets for the POD: " + pod.getId() + " are not allowed. The Netmask should be same as the existing Netmask " + NetUtils.getCidrNetmask(cidrSize)); final String[] existingPodIpRanges = pod.getDescription().split(",");
@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); }
capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity()); if (summedCapacity.getPodId() != null) { capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid()); HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId()); if (pod != null) { capacityResponse.setPodId(pod.getUuid()); capacityResponse.setPodName(pod.getName()); if (summedCapacity.getPodId() == null) { HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId()); capacityResponse.setPodId(pod.getUuid()); capacityResponse.setPodName(pod.getName()); capacityResponse.setPodId(pod.getUuid()); capacityResponse.setPodName(pod.getName());
@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()); } } } });
@Override public HostPodVO doInTransaction(final TransactionStatus status) { final HostPodVO pod = _podDao.persist(podFinal); if (!Strings.isNullOrEmpty(startIp)) { _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal, false, null); } final String[] linkLocalIpRanges = getLinkLocalIPRange(); if (linkLocalIpRanges != null) { _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); } 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; }
if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) { final InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified podId" + podId + " doesn't belong to the zone with specified zoneId" + dcId); ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex; final CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod with specified podId and data center with specified dcID", e); ex.addProxyObject(pod.getUuid(), "podId"); ex.addProxyObject(zone.getUuid(), "dcId"); throw ex;