@Override public Boolean doInTransaction(final TransactionStatus status) { // delete vlans for this zone final List<VlanVO> vlans = _vlanDao.listByZone(zoneId); for (final VlanVO vlan : vlans) { _vlanDao.remove(vlan.getId()); } final boolean success = _zoneDao.remove(zoneId); if (success) { // delete all capacity records for the zone _capacityDao.removeBy(null, zoneId, null, null, null); // remove from dedicated resources final DedicatedResourceVO dr = _dedicatedDao.findByZoneId(zoneId); if (dr != null) { _dedicatedDao.remove(dr.getId()); // find the group associated and check if there are any more // resources under that group final List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(dr.getAffinityGroupId()); if (resourcesInGroup.isEmpty()) { // delete the group _affinityGroupService.deleteAffinityGroup(dr.getAffinityGroupId(), null, null, null, null); } } } return success; } });
@Override public List<DedicatedResourceVO> doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, null, hostId, null, null, group.getId()); try { dedicatedResource.setDomainId(domainId); if (accountIdFinal != null) { dedicatedResource.setAccountId(accountIdFinal); } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { s_logger.error("Unable to dedicate host due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support.", e); } List<DedicatedResourceVO> result = new ArrayList<DedicatedResourceVO>(); result.add(dedicatedResource); return result; } });
private Long accountOfDedicatedHost(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null) { return dedicatedHost.getAccountId(); } if (dedicatedClusterOfHost != null) { return dedicatedClusterOfHost.getAccountId(); } if (dedicatedPodOfHost != null) { return dedicatedPodOfHost.getAccountId(); } return null; }
protected DedicatedResourceDaoImpl() { PodSearch = createSearchBuilder(); PodSearch.and("podId", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); PodSearch.done(); ZoneSearch.and("zoneId", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); ZoneSearch.done(); ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ); ClusterSearch.done(); HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostSearch.done(); ListZonesByDomainIdSearch.and("zoneId", ListZonesByDomainIdSearch.entity().getDataCenterId(), SearchCriteria.Op.NNULL); ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); ListZonesByDomainIdSearch.and("accountId", ListZonesByDomainIdSearch.entity().getAccountId(), SearchCriteria.Op.NULL); ListZonesByDomainIdSearch.done(); ListZonesByAccountIdSearch.and("zoneId", ListZonesByAccountIdSearch.entity().getDataCenterId(), SearchCriteria.Op.NNULL); ListZonesByAccountIdSearch.and("accountId", ListZonesByAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); ListZonesByAccountIdSearch.done(); ListPodsByDomainIdSearch.and("podId", ListPodsByDomainIdSearch.entity().getPodId(), SearchCriteria.Op.NNULL); ListPodsByDomainIdSearch.and("domainId", ListPodsByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); ListPodsByDomainIdSearch.and("accountId", ListPodsByDomainIdSearch.entity().getAccountId(), SearchCriteria.Op.NULL); ListPodsByDomainIdSearch.done(); ListPodsByAccountIdSearch.and("podId", ListPodsByAccountIdSearch.entity().getPodId(), SearchCriteria.Op.NNULL); ListPodsByAccountIdSearch.and("accountId", ListPodsByAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfPod.getDomainId()).contains(domainId); if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId()); s_logger.error("Cannot dedicate Pod. Its zone is already dedicated"); DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId()); if (dCluster != null) { if (!(childDomainIds.contains(dCluster.getDomainId()))) { throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { if (dCluster.getAccountId() == null && dCluster.getDomainId().equals(domainId)) { clustersToRelease.add(dCluster); releaseDedicatedResource(null, null, dr.getClusterId(), null); DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId()); if (dHost != null) { if (!(getDomainChildIds(domainId).contains(dHost.getDomainId()))) { throw new CloudRuntimeException("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else {
if (dedicatedZone.getAccountId() != null) { if (dedicatedZone.getAccountId().equals(accountId)) { return; } else { if (!_affinityGroupService.isAffinityGroupAvailableInDomain(dedicatedZone.getAffinityGroupId(), accountDomainId)) { throw new CloudRuntimeException("Failed to deploy VM, Zone " + dc.getName() + " not available for the user domain " + vmProfile.getOwner()); allPodsFromDedicatedID.add(vo.getPodId()); allClustersFromDedicatedID.add(vo.getClusterId()); allHostsFromDedicatedID.add(vo.getHostId()); allPodsFromDedicatedID.add(vo.getPodId()); allClustersFromDedicatedID.add(vo.getClusterId()); allHostsFromDedicatedID.add(vo.getHostId());
if (resourceList != null && resourceList.size() != 0) { for (DedicatedResourceVO resource : resourceList) { if ((resource.getHostId() != null && resource.getHostId().longValue() == plan.getHostId().longValue()) || (resource.getClusterId() != null && resource.getClusterId().longValue() == clusterofHost.getId()) || (resource.getPodId() != null && resource.getPodId().longValue() == podOfHost.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId().longValue() == zoneOfHost.getId())) { canUse = true; if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster.getId())) { canUse = true; if (resource.getHostId() != null) { HostVO dHost = _hostDao.findById(resource.getHostId()); if (dHost.getClusterId() == cluster.getId()) { hostToUse.add(dHost); if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) { canUse = true; if (resource.getClusterId() != null) { ClusterVO dCluster = _clusterDao.findById(resource.getClusterId()); if (dCluster.getPodId() == pod.getId()) { clustersToUse.add(dCluster); if (resource.getHostId() != null) { HostVO dHost = _hostDao.findById(resource.getHostId());
boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfCluster.getDomainId()).contains(domainId); if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { s_logger.error("Cannot dedicate Cluster. Its Pod is already dedicated"); HostPodVO pod = _podDao.findById(cluster.getPodId()); boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfCluster.getDomainId()).contains(domainId); if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { s_logger.error("Cannot dedicate Cluster. Its zone is already dedicated"); DataCenterVO zone = _zoneDao.findById(cluster.getDataCenterId()); DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId()); if (dHost != null) { if (!(childDomainIds.contains(dHost.getDomainId()))) { throw new CloudRuntimeException("Host " + host.getName() + " under this Cluster " + cluster.getName() + " is dedicated to different account/domain"); if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { if (dHost.getAccountId() == null && dHost.getDomainId().equals(domainId)) { hostsToRelease.add(dHost); releaseDedicatedResource(null, null, null, dr.getHostId());
boolean domainIdInChildreanList = getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId); if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { ClusterVO cluster = _clusterDao.findById(host.getClusterId()); s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated"); boolean domainIdInChildreanList = getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId); if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { HostPodVO pod = _podDao.findById(host.getPodId()); s_logger.error("Host's Pod " + pod.getName() + " is already dedicated"); boolean domainIdInChildreanList = getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId); if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(host.getDataCenterId()); s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated");
List<DedicatedResourceVO> resourcesInGroup = _dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId()); if (resourcesInGroup.isEmpty()) { _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(), null, null, null, null);
private Long domainOfDedicatedHost(HostVO host) { long hostId = host.getId(); DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); if (dedicatedHost != null) { return dedicatedHost.getDomainId(); } if (dedicatedClusterOfHost != null) { return dedicatedClusterOfHost.getDomainId(); } if (dedicatedPodOfHost != null) { return dedicatedPodOfHost.getDomainId(); } return null; }
private List<Long> removeDedicatedZoneNotSuitabe(List<Long> domainIds) { // remove dedicated zone of other domain List<Long> dedicatedZoneIds = new ArrayList<Long>(); List<DedicatedResourceVO> dedicatedResources = _dedicatedDao.listZonesNotInDomainIds(domainIds); for (DedicatedResourceVO dr : dedicatedResources) { if (dr != null) { dedicatedZoneIds.add(dr.getDataCenterId()); } } return dedicatedZoneIds; }
@Override public DataCenterVO doInTransaction(final TransactionStatus status) { final DataCenterVO zone = _zoneDao.persist(zoneFinal); CallContext.current().putContextParameter(DataCenter.class, zone.getUuid()); if (domainId != null) { // zone is explicitly dedicated to this domain // create affinity group associated and dedicate the zone. final AffinityGroup group = createDedicatedAffinityGroup(null, domainId, null); final DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(zone.getId(), null, null, null, domainId, null, group.getId()); _dedicatedDao.persist(dedicatedResource); } // Create default system networks createDefaultSystemNetworks(zone.getId()); return zone; } });
DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId()); if (dPod != null) { if (!(childDomainIds.contains(dPod.getDomainId()))) { throw new CloudRuntimeException("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); if (dPod.getAccountId().equals(accountId)) { podsToRelease.add(dPod); } else { if (dPod.getAccountId() == null && dPod.getDomainId().equals(domainId)) { podsToRelease.add(dPod); releaseDedicatedResource(null, dr.getPodId(), null, null); DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId()); if (dCluster != null) { if (!(childDomainIds.contains(dCluster.getDomainId()))) { throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { if (dCluster.getAccountId() == null && dCluster.getDomainId().equals(domainId)) { clustersToRelease.add(dCluster); releaseDedicatedResource(null, null, dr.getClusterId(), null); DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
private ExcludeList updateAvoidList(List<DedicatedResourceVO> dedicatedResources, ExcludeList avoidList, DataCenter dc) { ExcludeList includeList = new ExcludeList(); for (DedicatedResourceVO dr : dedicatedResources) { if (dr.getHostId() != null) { includeList.addHost(dr.getHostId()); HostVO dedicatedHost = _hostDao.findById(dr.getHostId()); includeList.addCluster(dedicatedHost.getClusterId()); includeList.addPod(dedicatedHost.getPodId()); if (dr.getClusterId() != null) { includeList.addCluster(dr.getClusterId()); List<HostVO> hostList = _hostDao.findByClusterId(dr.getClusterId()); for (HostVO host : hostList) { DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId()); ClusterVO dedicatedCluster = _clusterDao.findById(dr.getClusterId()); includeList.addPod(dedicatedCluster.getPodId()); if (dr.getPodId() != null) { includeList.addPod(dr.getPodId()); List<ClusterVO> clusterList = _clusterDao.listByPodId(dr.getPodId()); for (ClusterVO cluster : clusterList) { DedicatedResourceVO dCluster = _dedicatedDao.findByClusterId(cluster.getId()); List<HostVO> hostList = _hostDao.findByPodId(dr.getPodId()); for (HostVO host : hostList) { DedicatedResourceVO dHost = _dedicatedDao.findByHostId(host.getId());
s_logger.debug("Releasing dedicated resources for domain" + domainId); for (DedicatedResourceVO dr : dedicatedResources) { if (!_dedicatedDao.remove(dr.getId())) { s_logger.warn("Fail to release dedicated resources for domain " + domainId);
@Override public void doInTransactionWithoutResult(TransactionStatus status) { SearchBuilder<DedicatedResourceVO> listByAffinityGroup = _dedicatedDao.createSearchBuilder(); listByAffinityGroup.and("affinityGroupId", listByAffinityGroup.entity().getAffinityGroupId(), SearchCriteria.Op.EQ); listByAffinityGroup.done(); SearchCriteria<DedicatedResourceVO> sc = listByAffinityGroup.create(); sc.setParameters("affinityGroupId", group.getId()); _dedicatedDao.lockRows(sc, null, true); _dedicatedDao.remove(sc); } });
DomainVO domain = _domainDao.findById(dedicatedZone.getDomainId()); if (domain == null) { throw new CloudRuntimeException("Unable to find the domain " + zone.getDomainId() + " for the zone: " + zone);
@Override public List<DedicatedResourceVO> doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, clusterId, null, null, null, group.getId()); try { dedicatedResource.setDomainId(domainId); if (accountIdFinal != null) { dedicatedResource.setAccountId(accountIdFinal); } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { s_logger.error("Unable to dedicate cluster due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate cluster. Please contact Cloud Support.", e); } List<DedicatedResourceVO> result = new ArrayList<DedicatedResourceVO>(); result.add(dedicatedResource); return result; } });