private DomainRouterVO findELBVmWithCapacity(Network guestNetwork, IPAddressVO ipAddr) { List<DomainRouterVO> unusedElbVms = _elbVmMapDao.listUnusedElbVms(); if (unusedElbVms.size() > 0) { List<DomainRouterVO> candidateVms = new ArrayList<DomainRouterVO>(); for (DomainRouterVO candidateVm : unusedElbVms) { if (candidateVm.getPodIdToDeployIn() == getPodIdForDirectIp(ipAddr)) candidateVms.add(candidateVm); } return candidateVms.size() == 0 ? null : candidateVms.get(new Random().nextInt(candidateVms.size())); } return null; }
void garbageCollectUnusedElbVms() { List<DomainRouterVO> unusedElbVms = _elbVmMapDao.listUnusedElbVms(); if (unusedElbVms != null && unusedElbVms.size() > 0) s_logger.info("Found " + unusedElbVms.size() + " unused ELB vms"); Set<Long> currentGcCandidates = new HashSet<Long>(); for (DomainRouterVO elbVm : unusedElbVms) { currentGcCandidates.add(elbVm.getId()); } _gcCandidateElbVmIds.retainAll(currentGcCandidates); currentGcCandidates.removeAll(_gcCandidateElbVmIds); User user = _accountService.getSystemUser(); for (Long elbVmId : _gcCandidateElbVmIds) { DomainRouterVO elbVm = _routerDao.findById(elbVmId); boolean gceed = false; try { s_logger.info("Attempting to stop ELB VM: " + elbVm); stop(elbVm, true, user, _systemAcct); gceed = true; } catch (ConcurrentOperationException e) { s_logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); } catch (ResourceUnavailableException e) { s_logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); continue; } if (gceed) { try { s_logger.info("Attempting to destroy ELB VM: " + elbVm); _itMgr.expunge(elbVm, user, _systemAcct); } catch (ResourceUnavailableException e) { s_logger.warn("Unable to destroy unused ELB vm " + elbVm + " due to ", e); gceed = false; } } if (!gceed) { currentGcCandidates.add(elbVm.getId()); } } _gcCandidateElbVmIds = currentGcCandidates; }