Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57BE8105C1 for ; Wed, 8 May 2013 11:59:46 +0000 (UTC) Received: (qmail 9215 invoked by uid 500); 8 May 2013 11:59:36 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 8918 invoked by uid 500); 8 May 2013 11:59:36 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 8128 invoked by uid 99); 8 May 2013 11:59:31 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 May 2013 11:59:31 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id CD15D889968; Wed, 8 May 2013 11:59:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tsp@apache.org To: commits@cloudstack.apache.org Date: Wed, 08 May 2013 11:59:45 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/90] [abbrv] [partial] Moved most of the VOs and DAOs from server package into engine-schema as well http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java deleted file mode 100755 index 4d9d010..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterDaoImpl.java +++ /dev/null @@ -1,425 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; -import javax.persistence.TableGenerator; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.dc.DataCenterIpAddressVO; -import com.cloud.dc.DataCenterLinkLocalIpAddressVO; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.DataCenterVnetVO; -import com.cloud.dc.PodVlanVO; -import com.cloud.network.dao.AccountGuestVlanMapDao; -import com.cloud.network.dao.AccountGuestVlanMapVO; -import com.cloud.org.Grouping; -import com.cloud.utils.NumbersUtil; -import com.cloud.utils.Pair; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SequenceFetcher; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.net.NetUtils; - -/** - * @config - * {@table - * || Param Name | Description | Values | Default || - * || mac.address.prefix | prefix to attach to all public and private mac addresses | number | 06 || - * } - **/ -@Component -@Local(value={DataCenterDao.class}) -public class DataCenterDaoImpl extends GenericDaoBase implements DataCenterDao { - private static final Logger s_logger = Logger.getLogger(DataCenterDaoImpl.class); - - protected SearchBuilder NameSearch; - protected SearchBuilder ListZonesByDomainIdSearch; - protected SearchBuilder PublicZonesSearch; - protected SearchBuilder ChildZonesSearch; - protected SearchBuilder DisabledZonesSearch; - protected SearchBuilder TokenSearch; - - @Inject protected DataCenterIpAddressDao _ipAllocDao = null; - @Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao = null; - @Inject protected DataCenterVnetDao _vnetAllocDao = null; - @Inject protected PodVlanDao _podVlanAllocDao = null; - @Inject protected DcDetailsDao _detailsDao = null; - @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao = null; - - protected long _prefix; - protected Random _rand = new Random(System.currentTimeMillis()); - protected TableGenerator _tgMacAddress; - - - @Override - public DataCenterVO findByName(String name) { - SearchCriteria sc = NameSearch.create(); - sc.setParameters("name", name); - return findOneBy(sc); - } - - @Override - public DataCenterVO findByToken(String zoneToken){ - SearchCriteria sc = TokenSearch.create(); - sc.setParameters("zoneToken", zoneToken); - return findOneBy(sc); - } - - @Override - public List findZonesByDomainId(Long domainId){ - SearchCriteria sc = ListZonesByDomainIdSearch.create(); - sc.setParameters("domainId", domainId); - return listBy(sc); - } - - @Override - public List findZonesByDomainId(Long domainId, String keyword){ - SearchCriteria sc = ListZonesByDomainIdSearch.create(); - sc.setParameters("domainId", domainId); - if (keyword != null) { - SearchCriteria ssc = createSearchCriteria(); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } - return listBy(sc); - } - - @Override - public List findChildZones(Object[] ids, String keyword){ - SearchCriteria sc = ChildZonesSearch.create(); - sc.setParameters("domainid", ids); - if (keyword != null) { - SearchCriteria ssc = createSearchCriteria(); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } - return listBy(sc); - } - - @Override - public List listPublicZones(String keyword){ - SearchCriteria sc = PublicZonesSearch.create(); - if (keyword != null) { - SearchCriteria ssc = createSearchCriteria(); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } - //sc.setParameters("domainId", domainId); - return listBy(sc); - } - - @Override - public List findByKeyword(String keyword){ - SearchCriteria ssc = createSearchCriteria(); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - return listBy(ssc); - } - - @Override - public void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId) { - _vnetAllocDao.release(vnet, physicalNetworkId, accountId, reservationId); - } - - @Override - public List findVnet(long dcId, long physicalNetworkId, String vnet) { - return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet); - } - - @Override - public int countZoneVlans(long dcId, boolean onlyCountAllocated){ - return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated); - } - - @Override - public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) { - _ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); - } - - @Override - public void releasePrivateIpAddress(long nicId, String reservationId) { - _ipAllocDao.releaseIpAddress(nicId, reservationId); - } - - @Override - public void releaseLinkLocalIpAddress(long nicId, String reservationId) { - _LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId); - } - - @Override - public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) { - _LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); - } - - @Override - public boolean deletePrivateIpAddressByPod(long podId) { - return _ipAllocDao.deleteIpAddressByPod(podId); - } - - @Override - public boolean deleteLinkLocalIpAddressByPod(long podId) { - return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId); - } - - @Override - public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId) { - ArrayList dedicatedVlanDbIds = new ArrayList(); - List maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId); - for (AccountGuestVlanMapVO map : maps) { - dedicatedVlanDbIds.add(map.getId()); - } - if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) { - DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds); - if (vo != null) - return vo.getVnet(); - } - DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null); - if (vo == null) { - return null; - } - return vo.getVnet(); - } - - @Override - public String allocatePodVlan(long podId, long accountId) { - PodVlanVO vo = _podVlanAllocDao.take(podId, accountId); - if (vo == null) { - return null; - } - return vo.getVlan(); - } - - @Override - public String[] getNextAvailableMacAddressPair(long id) { - return getNextAvailableMacAddressPair(id, 0); - } - - @Override - public String[] getNextAvailableMacAddressPair(long id, long mask) { - SequenceFetcher fetch = SequenceFetcher.getInstance(); - - long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id); - seq = seq | _prefix | ((id & 0x7f) << 32); - seq |= mask; - seq |= ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l); - String[] pair = new String[2]; - pair[0] = NetUtils.long2Mac(seq); - pair[1] = NetUtils.long2Mac(seq | 0x1l << 39); - return pair; - } - - @Override - public Pair allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId) { - DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); - if (vo == null) { - return null; - } - return new Pair(vo.getIpAddress(), vo.getMacAddress()); - } - - @Override - public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservationId) { - DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId); - return vo; - } - - @Override - public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) { - DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); - if (vo == null) { - return null; - } - return vo.getIpAddress(); - } - - @Override - public void addVnet(long dcId, long physicalNetworkId, int start, int end) { - _vnetAllocDao.add(dcId, physicalNetworkId, start, end); - } - - @Override - public void deleteVnet(long physicalNetworkId) { - _vnetAllocDao.delete(physicalNetworkId); - } - - @Override - public List listAllocatedVnets(long physicalNetworkId) { - return _vnetAllocDao.listAllocatedVnets(physicalNetworkId); - } - - @Override - public void addPrivateIpAddress(long dcId,long podId, String start, String end) { - _ipAllocDao.addIpRange(dcId, podId, start, end); - } - - @Override - public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) { - _LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end); - } - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - if (!super.configure(name, params)) { - return false; - } - - String value = (String)params.get("mac.address.prefix"); - _prefix = (long)NumbersUtil.parseInt(value, 06) << 40; - - if (!_ipAllocDao.configure("Ip Alloc", params)) { - return false; - } - - if (!_vnetAllocDao.configure("vnet Alloc", params)) { - return false; - } - return true; - } - - public DataCenterDaoImpl() { - super(); - NameSearch = createSearchBuilder(); - NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); - NameSearch.done(); - - ListZonesByDomainIdSearch = createSearchBuilder(); - ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); - ListZonesByDomainIdSearch.done(); - - PublicZonesSearch = createSearchBuilder(); - PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL); - PublicZonesSearch.done(); - - ChildZonesSearch = createSearchBuilder(); - ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN); - ChildZonesSearch.done(); - - DisabledZonesSearch = createSearchBuilder(); - DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ); - DisabledZonesSearch.done(); - - TokenSearch = createSearchBuilder(); - TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ); - TokenSearch.done(); - - _tgMacAddress = _tgs.get("macAddress"); - assert _tgMacAddress != null : "Couldn't get mac address table generator"; - } - - @Override @DB - public boolean update(Long zoneId, DataCenterVO zone) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - boolean persisted = super.update(zoneId, zone); - if (!persisted) { - return persisted; - } - saveDetails(zone); - txn.commit(); - return persisted; - } - - @Override - public void loadDetails(DataCenterVO zone) { - Map details =_detailsDao.findDetails(zone.getId()); - zone.setDetails(details); - } - - @Override - public void saveDetails(DataCenterVO zone) { - Map details = zone.getDetails(); - if (details == null) { - return; - } - _detailsDao.persist(zone.getId(), details); - } - - @Override - public List listDisabledZones(){ - SearchCriteria sc = DisabledZonesSearch.create(); - sc.setParameters("allocationState", Grouping.AllocationState.Disabled); - - List dcs = listBy(sc); - - return dcs; - } - - @Override - public List listEnabledZones(){ - SearchCriteria sc = DisabledZonesSearch.create(); - sc.setParameters("allocationState", Grouping.AllocationState.Enabled); - - List dcs = listBy(sc); - - return dcs; - } - - @Override - public DataCenterVO findByTokenOrIdOrName(String tokenOrIdOrName) { - DataCenterVO result = findByToken(tokenOrIdOrName); - if (result == null) { - result = findByName(tokenOrIdOrName); - if (result == null) { - try { - Long dcId = Long.parseLong(tokenOrIdOrName); - return findById(dcId); - } catch (NumberFormatException nfe) { - - } - } - } - return result; - } - - @Override - public boolean remove(Long id) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - DataCenterVO zone = createForUpdate(); - zone.setName(null); - - update(id, zone); - - boolean result = super.remove(id); - txn.commit(); - return result; - } - - @Override - public List listAllZones(){ - SearchCriteria sc = NameSearch.create(); - List dcs = listBy(sc); - - return dcs; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterIpAddressDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterIpAddressDao.java b/server/src/com/cloud/dc/dao/DataCenterIpAddressDao.java deleted file mode 100644 index 7a19b24..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterIpAddressDao.java +++ /dev/null @@ -1,38 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.DataCenterIpAddressVO; -import com.cloud.utils.db.GenericDao; - -public interface DataCenterIpAddressDao extends GenericDao { - - public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId); - public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId); - public void addIpRange(long dcId, long podId, String start, String end); - public void releaseIpAddress(String ipAddress, long dcId, Long instanceId); - public void releaseIpAddress(long nicId, String reservationId); - - boolean mark(long dcId, long podId, String ip); - List listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress); - List listByPodIdDcId(long podId, long dcId); - int countIPs(long podId, long dcId, boolean onlyCountAllocated); - boolean deleteIpAddressByPod(long podId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java deleted file mode 100755 index 353402d..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java +++ /dev/null @@ -1,225 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.dc.DataCenterIpAddressVO; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Func; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.net.NetUtils; - -@Component -@Local(value={DataCenterIpAddressDao.class}) @DB(txn=false) -public class DataCenterIpAddressDaoImpl extends GenericDaoBase implements DataCenterIpAddressDao { - private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class); - - private final SearchBuilder AllFieldsSearch; - private final GenericSearchBuilder AllIpCount; - private final GenericSearchBuilder AllAllocatedIpCount; - - @DB - public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - sc.setParameters("taken", (Date)null); - - Transaction txn = Transaction.currentTxn(); - txn.start(); - DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); - if (vo == null) { - txn.rollback(); - return null; - } - vo.setTakenAt(new Date()); - vo.setInstanceId(instanceId); - vo.setReservationId(reservationId); - update(vo.getId(), vo); - txn.commit(); - return vo; - } - - @DB - public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("dc", dcId); - sc.setParameters("taken", (Date)null); - - Transaction txn = Transaction.currentTxn(); - txn.start(); - DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); - if (vo == null) { - txn.rollback(); - return null; - } - vo.setTakenAt(new Date()); - vo.setReservationId(reservationId); - update(vo.getId(), vo); - txn.commit(); - return vo; - } - - @Override - public boolean deleteIpAddressByPod(long podId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - return remove(sc) > 0; - } - - @Override - public boolean mark(long dcId, long podId, String ip) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - sc.setParameters("ipAddress", ip); - - DataCenterIpAddressVO vo = createForUpdate(); - vo.setTakenAt(new Date()); - - return update(vo, sc) >= 1; - } - - @DB - public void addIpRange(long dcId, long podId, String start, String end) { - Transaction txn = Transaction.currentTxn(); - String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))"; - String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?"; - PreparedStatement stmt = null; - - long startIP = NetUtils.ip2Long(start); - long endIP = NetUtils.ip2Long(end); - - try { - txn.start(); - - while (startIP <= endIP) { - stmt = txn.prepareStatement(insertSql); - stmt.setString(1, NetUtils.long2Ip(startIP++)); - stmt.setLong(2, dcId); - stmt.setLong(3, podId); - stmt.setLong(4, dcId); - stmt.executeUpdate(); - stmt.close(); - stmt = txn.prepareStatement(updateSql); - stmt.setLong(1, dcId); - stmt.executeUpdate(); - stmt.close(); - } - txn.commit(); - } catch (SQLException ex) { - throw new CloudRuntimeException("Unable to persist ip address range ", ex); - } - } - - public void releaseIpAddress(String ipAddress, long dcId, Long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); - } - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("ip", ipAddress); - sc.setParameters("dc", dcId); - sc.setParameters("instance", instanceId); - - DataCenterIpAddressVO vo = createForUpdate(); - - vo.setTakenAt(null); - vo.setInstanceId(null); - vo.setReservationId(null); - update(vo, sc); - } - - public void releaseIpAddress(long nicId, String reservationId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address for reservationId=" + reservationId + ", instance=" + nicId); - } - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("instance", nicId); - sc.setParameters("reservation", reservationId); - - DataCenterIpAddressVO vo = createForUpdate(); - vo.setTakenAt(null); - vo.setInstanceId(null); - vo.setReservationId(null); - update(vo, sc); - } - - public List listByPodIdDcId(long podId, long dcId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - return listBy(sc); - } - - @Override - public List listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - sc.setParameters("ipAddress", ipAddress); - return listBy(sc); - } - - @Override - public int countIPs(long podId, long dcId, boolean onlyCountAllocated) { - SearchCriteria sc; - if (onlyCountAllocated) { - sc = AllAllocatedIpCount.create(); - } else { - sc = AllIpCount.create(); - } - - sc.setParameters("pod", podId); - List count = customSearch(sc, null); - return count.get(0); - } - - public DataCenterIpAddressDaoImpl() { - super(); - - AllFieldsSearch = createSearchBuilder(); - AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ); - AllFieldsSearch.done(); - - AllIpCount = createSearchBuilder(Integer.class); - AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId()); - AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ); - AllIpCount.done(); - - AllAllocatedIpCount = createSearchBuilder(Integer.class); - AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId()); - AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ); - AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL); - AllAllocatedIpCount.done(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java b/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java deleted file mode 100644 index 7fe9467..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.DataCenterLinkLocalIpAddressVO; -import com.cloud.utils.db.GenericDao; - -public interface DataCenterLinkLocalIpAddressDao extends GenericDao{ - public DataCenterLinkLocalIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId); - public boolean deleteIpAddressByPod(long podId); - public void addIpRange(long dcId, long podId, String start, String end); - public void releaseIpAddress(String ipAddress, long dcId, long instanceId); - public void releaseIpAddress(long nicId, String reservationId); - public List listByPodIdDcId(long podId, long dcId); - public int countIPs(long podId, long dcId, boolean onlyCountAllocated); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java deleted file mode 100644 index b52e373..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java +++ /dev/null @@ -1,188 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.dc.DataCenterLinkLocalIpAddressVO; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Func; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.net.NetUtils; - -@Component -@Local(value={DataCenterLinkLocalIpAddressDaoImpl.class}) @DB(txn=false) -public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase implements DataCenterLinkLocalIpAddressDao { - private static final Logger s_logger = Logger.getLogger(DataCenterLinkLocalIpAddressDaoImpl.class); - - private final SearchBuilder AllFieldsSearch; - private final GenericSearchBuilder AllIpCount; - private final GenericSearchBuilder AllAllocatedIpCount; - - @DB - public DataCenterLinkLocalIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - sc.setParameters("taken", (Date)null); - - Transaction txn = Transaction.currentTxn(); - txn.start(); - - DataCenterLinkLocalIpAddressVO vo = lockOneRandomRow(sc, true); - if (vo == null) { - return null; - } - - vo.setTakenAt(new Date()); - vo.setInstanceId(instanceId); - vo.setReservationId(reservationId); - update(vo.getId(), vo); - txn.commit(); - return vo; - } - - public boolean deleteIpAddressByPod(long podId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - return remove(sc) > 0; - } - - @DB - public void addIpRange(long dcId, long podId, String start, String end) { - String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)"; - PreparedStatement stmt = null; - - long startIP = NetUtils.ip2Long(start); - long endIP = NetUtils.ip2Long(end); - - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - stmt = txn.prepareAutoCloseStatement(insertSql); - while (startIP <= endIP) { - stmt.setString(1, NetUtils.long2Ip(startIP++)); - stmt.setLong(2, dcId); - stmt.setLong(3, podId); - stmt.addBatch(); - } - stmt.executeBatch(); - txn.commit(); - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to insert", e); - } - } - - public void releaseIpAddress(String ipAddress, long dcId, long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); - } - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("ip", ipAddress); - sc.setParameters("dc", dcId); - sc.setParameters("instance", instanceId); - - DataCenterLinkLocalIpAddressVO vo = createForUpdate(); - - vo.setTakenAt(null); - vo.setInstanceId(null); - vo.setReservationId(null); - update(vo, sc); - } - - public void releaseIpAddress(long nicId, String reservationId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("instance", nicId); - sc.setParameters("reservation", reservationId); - - DataCenterLinkLocalIpAddressVO vo = createForUpdate(); - - vo.setTakenAt(null); - vo.setInstanceId(null); - vo.setReservationId(null); - update(vo, sc); - } - - public List listByPodIdDcId(long podId, long dcId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("pod", podId); - return listBy(sc); - } - - public int countIPs(long podId, long dcId, boolean onlyCountAllocated) { - SearchCriteria sc; - if (onlyCountAllocated) { - sc = AllAllocatedIpCount.create(); - } else { - sc = AllIpCount.create(); - } - - sc.setParameters("pod", podId); - List count = customSearch(sc, null); - return count.get(0); - } - - public DataCenterLinkLocalIpAddressDaoImpl() { - super(); - AllFieldsSearch = createSearchBuilder(); - AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ); - AllFieldsSearch.done(); - - AllIpCount = createSearchBuilder(Integer.class); - AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId()); - AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ); - AllIpCount.done(); - - AllAllocatedIpCount = createSearchBuilder(Integer.class); - AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId()); - AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ); - AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL); - AllAllocatedIpCount.done(); - - } - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - super.configure(name, params); - - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("ip", NetUtils.getLinkLocalGateway()); - remove(sc); - - return true; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterVnetDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterVnetDao.java b/server/src/com/cloud/dc/dao/DataCenterVnetDao.java deleted file mode 100644 index 778498d..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterVnetDao.java +++ /dev/null @@ -1,49 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.DataCenterVnetVO; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.db.Transaction; - -public interface DataCenterVnetDao extends GenericDao { - public List listAllocatedVnets(long physicalNetworkId); - public List listAllocatedVnetsInRange(long dcId, long physicalNetworkId, Integer start, Integer end); - public List findVnet(long dcId, String vnet); - public int countZoneVlans(long dcId, boolean onlyCountAllocated); - public List findVnet(long dcId, long physicalNetworkId, String vnet); - - public void add(long dcId, long physicalNetworkId, int start, int end); - - public void delete(long physicalNetworkId); - - public void deleteRange(Transaction txn, long dcId, long physicalNetworkId, int start, int end); - - public void lockRange(long dcId, long physicalNetworkId, Integer start, Integer end); - - public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId, List vlanDbIds); - - public void release(String vnet, long physicalNetworkId, long accountId, String reservationId); - - public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId); - - public int countVnetsAllocatedToAccount(long dcId, long accountId); - - public int countVnetsDedicatedToAccount(long dcId, long accountId); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java b/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java deleted file mode 100755 index e97f2c6..0000000 --- a/server/src/com/cloud/dc/dao/DataCenterVnetDaoImpl.java +++ /dev/null @@ -1,318 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import com.cloud.exception.InvalidParameterValueException; -import org.springframework.stereotype.Component; - -import com.cloud.dc.DataCenterVnetVO; -import com.cloud.network.dao.AccountGuestVlanMapDao; -import com.cloud.network.dao.AccountGuestVlanMapVO; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.JoinBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Func; -import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; - -/** - * DataCenterVnetDaoImpl maintains the one-to-many relationship between - * data center/physical_network and the vnet that appears within the physical network. - */ -@Component -@DB(txn=false) -public class DataCenterVnetDaoImpl extends GenericDaoBase implements DataCenterVnetDao { - - private final SearchBuilder FreeVnetSearch; - private final SearchBuilder FreeDedicatedVnetSearch; - private final SearchBuilder VnetDcSearch; - private final SearchBuilder VnetDcSearchAllocated; - private final SearchBuilder DcSearchAllocated; - private final SearchBuilder DcSearchAllocatedInRange; - private final GenericSearchBuilder countZoneVlans; - private final GenericSearchBuilder countAllocatedZoneVlans; - private final SearchBuilder SearchRange; - private final SearchBuilder DedicatedGuestVlanRangeSearch; - private final GenericSearchBuilder countVnetsAllocatedToAccount; - protected GenericSearchBuilder countVnetsDedicatedToAccount; - protected SearchBuilder AccountGuestVlanMapSearch; - - @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao; - - public List listAllocatedVnets(long physicalNetworkId) { - SearchCriteria sc = DcSearchAllocated.create(); - sc.setParameters("physicalNetworkId", physicalNetworkId); - return listBy(sc); - } - - public List listAllocatedVnetsInRange(long dcId, long physicalNetworkId, Integer start, Integer end) { - SearchCriteria sc = DcSearchAllocatedInRange.create(); - sc.setParameters("dc",dcId); - sc.setParameters("physicalNetworkId", physicalNetworkId); - sc.setParameters("vnetRange", start.toString(), end.toString()); - return listBy(sc); - } - - public void lockRange(long dcId, long physicalNetworkId, Integer start, Integer end) { - SearchCriteria sc = SearchRange.create(); - sc.setParameters("dc",dcId); - sc.setParameters("physicalNetworkId", physicalNetworkId); - sc.setParameters("vnetRange", start.toString(), end.toString()); - lockRows(sc,null,true); - } - - public List findVnet(long dcId, String vnet) { - SearchCriteria sc = VnetDcSearch.create();; - sc.setParameters("dc", dcId); - sc.setParameters("vnet", vnet); - return listBy(sc); - } - - public int countZoneVlans(long dcId, boolean onlyCountAllocated){ - SearchCriteria sc = onlyCountAllocated ? countAllocatedZoneVlans.create() : countZoneVlans.create(); - sc.setParameters("dc", dcId); - return customSearch(sc, null).get(0); - } - - public List findVnet(long dcId, long physicalNetworkId, String vnet) { - SearchCriteria sc = VnetDcSearch.create(); - sc.setParameters("dc", dcId); - sc.setParameters("physicalNetworkId", physicalNetworkId); - sc.setParameters("vnet", vnet); - - return listBy(sc); - } - - @DB - public void add(long dcId, long physicalNetworkId, int start, int end) { - String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id, physical_network_id) VALUES ( ?, ?, ?)"; - - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - PreparedStatement stmt = txn.prepareAutoCloseStatement(insertVnet); - for (int i = start; i <= end; i++) { - stmt.setString(1, String.valueOf(i)); - stmt.setLong(2, dcId); - stmt.setLong(3, physicalNetworkId); - stmt.addBatch(); - } - stmt.executeBatch(); - txn.commit(); - } catch (SQLException e) { - if (!e.getMessage().contains("Duplicate")){ - txn.rollback(); - txn.close(); - throw new CloudRuntimeException("Exception caught adding vnet ", e); - } - } - } - - public void deleteRange(Transaction txn, long dcId, long physicalNetworkId, int start, int end) { - String deleteVnet = "DELETE FROM `cloud`.`op_dc_vnet_alloc` WHERE data_center_id=? AND physical_network_id=? AND taken IS NULL AND vnet BETWEEN ? AND ?"; - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteVnet); - stmt.setLong(1,dcId); - stmt.setLong(2,physicalNetworkId); - stmt.setString(3,((Integer)start).toString()); - stmt.setString(4,((Integer)end).toString()); - stmt.execute(); - } catch (SQLException e) { - throw new CloudRuntimeException("Exception caught adding vnet ", e); - } - } - public void delete(long physicalNetworkId) { - SearchCriteria sc = VnetDcSearch.create(); - sc.setParameters("physicalNetworkId", physicalNetworkId); - remove(sc); - } - - @DB - public DataCenterVnetVO take(long physicalNetworkId, long accountId, String reservationId, List vlanDbIds) { - SearchCriteria sc; - if (vlanDbIds != null) { - sc = FreeDedicatedVnetSearch.create(); - sc.setParameters("accountGuestVlanMapId", vlanDbIds.toArray()); - } else { - sc = FreeVnetSearch.create(); - } - sc.setParameters("physicalNetworkId", physicalNetworkId); - Date now = new Date(); - Transaction txn = Transaction.currentTxn(); - txn.start(); - DataCenterVnetVO vo = lockOneRandomRow(sc, true); - if (vo == null) { - return null; - } - - vo.setTakenAt(now); - vo.setAccountId(accountId); - vo.setReservationId(reservationId); - update(vo.getId(), vo); - txn.commit(); - return vo; - } - - - public void release(String vnet, long physicalNetworkId, long accountId, String reservationId) { - SearchCriteria sc = VnetDcSearchAllocated.create(); - sc.setParameters("vnet", vnet); - sc.setParameters("physicalNetworkId", physicalNetworkId); - sc.setParameters("account", accountId); - sc.setParameters("reservation", reservationId); - - DataCenterVnetVO vo = findOneIncludingRemovedBy(sc); - if (vo == null) { - return; - } - - vo.setTakenAt(null); - vo.setAccountId(null); - vo.setReservationId(null); - update(vo.getId(), vo); - } - - @Override - public void releaseDedicatedGuestVlans(Long dedicatedGuestVlanRangeId) { - SearchCriteria sc = DedicatedGuestVlanRangeSearch.create(); - sc.setParameters("dedicatedGuestVlanRangeId", dedicatedGuestVlanRangeId); - List vnets = listBy(sc); - for(DataCenterVnetVO vnet : vnets) { - vnet.setAccountGuestVlanMapId(null); - update(vnet.getId(), vnet); - } - } - - @Override - public int countVnetsAllocatedToAccount(long dcId, long accountId) { - SearchCriteria sc = countVnetsAllocatedToAccount.create(); - sc.setParameters("dc", dcId); - sc.setParameters("accountId", accountId); - return customSearch(sc, null).get(0); - } - - @Override - public int countVnetsDedicatedToAccount(long dcId, long accountId) { - SearchCriteria sc = countVnetsDedicatedToAccount.create(); - sc.setParameters("dc", dcId); - sc.setParameters("accountId", accountId); - return customSearch(sc, null).get(0); - } - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - boolean result = super.configure(name, params); - - countVnetsDedicatedToAccount = createSearchBuilder(Integer.class); - countVnetsDedicatedToAccount.and("dc", countVnetsDedicatedToAccount.entity().getDataCenterId(), SearchCriteria.Op.EQ); - countVnetsDedicatedToAccount.and("accountGuestVlanMapId", countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(), Op.NNULL); - AccountGuestVlanMapSearch = _accountGuestVlanMapDao.createSearchBuilder(); - AccountGuestVlanMapSearch.and("accountId", AccountGuestVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - countVnetsDedicatedToAccount.join("AccountGuestVlanMapSearch", AccountGuestVlanMapSearch, countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(), - AccountGuestVlanMapSearch.entity().getId(), JoinBuilder.JoinType.INNER); - countVnetsDedicatedToAccount.select(null, Func.COUNT, countVnetsDedicatedToAccount.entity().getId()); - countVnetsDedicatedToAccount.done(); - AccountGuestVlanMapSearch.done(); - - return result; - } - - public DataCenterVnetDaoImpl() { - super(); - DcSearchAllocated = createSearchBuilder(); - DcSearchAllocated.and("dc", DcSearchAllocated.entity().getDataCenterId(), SearchCriteria.Op.EQ); - DcSearchAllocated.and("physicalNetworkId", DcSearchAllocated.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); - DcSearchAllocated.and("allocated", DcSearchAllocated.entity().getTakenAt(), SearchCriteria.Op.NNULL); - DcSearchAllocated.done(); - - DcSearchAllocatedInRange = createSearchBuilder(); - DcSearchAllocatedInRange.and("dc",DcSearchAllocatedInRange.entity().getDataCenterId(), Op.EQ); - DcSearchAllocatedInRange.and("physicalNetworkId", DcSearchAllocatedInRange.entity().getPhysicalNetworkId(), Op.EQ); - DcSearchAllocatedInRange.and("allocated", DcSearchAllocatedInRange.entity().getTakenAt(), Op.NNULL); - DcSearchAllocatedInRange.and("vnetRange", DcSearchAllocatedInRange.entity().getVnet(), Op.BETWEEN); - DcSearchAllocatedInRange.done(); - - SearchRange = createSearchBuilder(); - SearchRange.and("dc", SearchRange.entity().getDataCenterId(), Op.EQ); - SearchRange.and("physicalNetworkId", SearchRange.entity().getPhysicalNetworkId(), Op.EQ); - SearchRange.and("vnetRange", SearchRange.entity().getVnet(), Op.BETWEEN); - - FreeVnetSearch = createSearchBuilder(); - FreeVnetSearch.and("dc", FreeVnetSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - FreeVnetSearch.and("physicalNetworkId", FreeVnetSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); - FreeVnetSearch.and("taken", FreeVnetSearch.entity().getTakenAt(), SearchCriteria.Op.NULL); - FreeVnetSearch.and("accountGuestVlanMapId", FreeVnetSearch.entity().getAccountGuestVlanMapId(), SearchCriteria.Op.NULL); - FreeVnetSearch.done(); - - FreeDedicatedVnetSearch = createSearchBuilder(); - FreeDedicatedVnetSearch.and("dc", FreeDedicatedVnetSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - FreeDedicatedVnetSearch.and("physicalNetworkId", FreeDedicatedVnetSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); - FreeDedicatedVnetSearch.and("taken", FreeDedicatedVnetSearch.entity().getTakenAt(), SearchCriteria.Op.NULL); - FreeDedicatedVnetSearch.and("accountGuestVlanMapId", FreeDedicatedVnetSearch.entity().getAccountGuestVlanMapId(), SearchCriteria.Op.IN); - FreeDedicatedVnetSearch.done(); - - VnetDcSearch = createSearchBuilder(); - VnetDcSearch.and("vnet", VnetDcSearch.entity().getVnet(), SearchCriteria.Op.EQ); - VnetDcSearch.and("dc", VnetDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); - VnetDcSearch.and("physicalNetworkId", VnetDcSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); - VnetDcSearch.done(); - - countZoneVlans = createSearchBuilder(Integer.class); - countZoneVlans.select(null, Func.COUNT, countZoneVlans.entity().getId()); - countZoneVlans.and("dc", countZoneVlans.entity().getDataCenterId(), Op.EQ); - countZoneVlans.done(); - - countAllocatedZoneVlans = createSearchBuilder(Integer.class); - countAllocatedZoneVlans.select(null, Func.COUNT, countAllocatedZoneVlans.entity().getId()); - countAllocatedZoneVlans.and("dc", countAllocatedZoneVlans.entity().getDataCenterId(), Op.EQ); - countAllocatedZoneVlans.and("allocated", countAllocatedZoneVlans.entity().getTakenAt(), SearchCriteria.Op.NNULL); - countAllocatedZoneVlans.done(); - - VnetDcSearchAllocated = createSearchBuilder(); - VnetDcSearchAllocated.and("vnet", VnetDcSearchAllocated.entity().getVnet(), SearchCriteria.Op.EQ); - VnetDcSearchAllocated.and("dc", VnetDcSearchAllocated.entity().getDataCenterId(), SearchCriteria.Op.EQ); - VnetDcSearchAllocated.and("physicalNetworkId", VnetDcSearchAllocated.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); - VnetDcSearchAllocated.and("taken", VnetDcSearchAllocated.entity().getTakenAt(), SearchCriteria.Op.NNULL); - VnetDcSearchAllocated.and("account", VnetDcSearchAllocated.entity().getAccountId(), SearchCriteria.Op.EQ); - VnetDcSearchAllocated.and("reservation", VnetDcSearchAllocated.entity().getReservationId(), SearchCriteria.Op.EQ); - VnetDcSearchAllocated.done(); - - DedicatedGuestVlanRangeSearch = createSearchBuilder(); - DedicatedGuestVlanRangeSearch.and("dedicatedGuestVlanRangeId", DedicatedGuestVlanRangeSearch.entity().getAccountGuestVlanMapId(), SearchCriteria.Op.EQ); - DedicatedGuestVlanRangeSearch.done(); - - countVnetsAllocatedToAccount = createSearchBuilder(Integer.class); - countVnetsAllocatedToAccount.and("dc", countVnetsAllocatedToAccount.entity().getDataCenterId(), SearchCriteria.Op.EQ); - countVnetsAllocatedToAccount.and("accountId", countVnetsAllocatedToAccount.entity().getAccountId(), SearchCriteria.Op.EQ); - countVnetsAllocatedToAccount.select(null, Func.COUNT, countVnetsAllocatedToAccount.entity().getId()); - countVnetsAllocatedToAccount.done(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DcDetailsDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DcDetailsDao.java b/server/src/com/cloud/dc/dao/DcDetailsDao.java deleted file mode 100644 index a3b72a8..0000000 --- a/server/src/com/cloud/dc/dao/DcDetailsDao.java +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.Map; - -import com.cloud.dc.DcDetailVO; -import com.cloud.utils.db.GenericDao; - -public interface DcDetailsDao extends GenericDao { - Map findDetails(long dcId); - - void persist(long dcId, Map details); - - DcDetailVO findDetail(long dcId, String name); - - void deleteDetails(long dcId); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/DcDetailsDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/DcDetailsDaoImpl.java b/server/src/com/cloud/dc/dao/DcDetailsDaoImpl.java deleted file mode 100644 index 278fdb4..0000000 --- a/server/src/com/cloud/dc/dao/DcDetailsDaoImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; - -import org.springframework.stereotype.Component; - -import com.cloud.dc.DcDetailVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; - -@Component -@Local(value=DcDetailsDao.class) -public class DcDetailsDaoImpl extends GenericDaoBase implements DcDetailsDao { - protected final SearchBuilder DcSearch; - protected final SearchBuilder DetailSearch; - - public DcDetailsDaoImpl() { - DcSearch = createSearchBuilder(); - DcSearch.and("dcId", DcSearch.entity().getDcId(), SearchCriteria.Op.EQ); - DcSearch.done(); - - DetailSearch = createSearchBuilder(); - DetailSearch.and("dcId", DetailSearch.entity().getDcId(), SearchCriteria.Op.EQ); - DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ); - DetailSearch.done(); - } - - @Override - public DcDetailVO findDetail(long dcId, String name) { - SearchCriteria sc = DetailSearch.create(); - sc.setParameters("dcId", dcId); - sc.setParameters("name", name); - - return findOneIncludingRemovedBy(sc); - } - - @Override - public Map findDetails(long dcId) { - SearchCriteria sc = DcSearch.create(); - sc.setParameters("dcId", dcId); - - List results = search(sc, null); - Map details = new HashMap(results.size()); - for (DcDetailVO result : results) { - details.put(result.getName(), result.getValue()); - } - return details; - } - - @Override - public void deleteDetails(long dcId) { - SearchCriteria sc = DcSearch.create(); - sc.setParameters("dcId", dcId); - - List results = search(sc, null); - for (DcDetailVO result : results) { - remove(result.getId()); - } - } - - @Override - public void persist(long dcId, Map details) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - SearchCriteria sc = DcSearch.create(); - sc.setParameters("dcId", dcId); - expunge(sc); - - for (Map.Entry detail : details.entrySet()) { - DcDetailVO vo = new DcDetailVO(dcId, detail.getKey(), detail.getValue()); - persist(vo); - } - txn.commit(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/HostPodDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/HostPodDao.java b/server/src/com/cloud/dc/dao/HostPodDao.java deleted file mode 100644 index 03f7155..0000000 --- a/server/src/com/cloud/dc/dao/HostPodDao.java +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.HashMap; -import java.util.List; - -import com.cloud.dc.HostPodVO; -import com.cloud.utils.db.GenericDao; -import com.cloud.vm.VirtualMachine; - -public interface HostPodDao extends GenericDao { - public List listByDataCenterId(long id); - - public HostPodVO findByName(String name, long dcId); - - public HashMap> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip); - - public List listDisabledPods(long zoneId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/HostPodDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/HostPodDaoImpl.java b/server/src/com/cloud/dc/dao/HostPodDaoImpl.java deleted file mode 100644 index 07b4ad1..0000000 --- a/server/src/com/cloud/dc/dao/HostPodDaoImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import javax.ejb.Local; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.dc.HostPodVO; -import com.cloud.org.Grouping; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.utils.db.Transaction; - -@Component -@Local(value={HostPodDao.class}) -public class HostPodDaoImpl extends GenericDaoBase implements HostPodDao { - private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class); - - protected SearchBuilder DataCenterAndNameSearch; - protected SearchBuilder DataCenterIdSearch; - - 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(); - } - - @Override - public List listByDataCenterId(long id) { - SearchCriteria sc = DataCenterIdSearch.create(); - sc.setParameters("dcId", id); - - return listBy(sc); - } - - @Override - public HostPodVO findByName(String name, long dcId) { - SearchCriteria sc = DataCenterAndNameSearch.create(); - sc.setParameters("dc", dcId); - sc.setParameters("name", name); - - return findOneBy(sc); - } - - @Override - public HashMap> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) { - HashMap> currentPodCidrSubnets = new HashMap>(); - - String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL"; - Transaction txn = Transaction.currentTxn(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); - ResultSet rs = stmt.executeQuery(); - while (rs.next()) { - Long podId = rs.getLong("id"); - if (podId.longValue() == podIdToSkip) { - continue; - } - String cidrAddress = rs.getString("cidr_address"); - long cidrSize = rs.getLong("cidr_size"); - List cidrPair = new ArrayList(); - cidrPair.add(0, cidrAddress); - cidrPair.add(1, new Long(cidrSize)); - currentPodCidrSubnets.put(podId, cidrPair); - } - } catch (SQLException ex) { - s_logger.warn("DB exception " + ex.getMessage(), ex); - return null; - } - - return currentPodCidrSubnets; - } - - @Override - public boolean remove(Long id) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - HostPodVO pod = createForUpdate(); - pod.setName(null); - - update(id, pod); - - boolean result = super.remove(id); - txn.commit(); - return result; - } - - @Override - public List listDisabledPods(long zoneId) { - GenericSearchBuilder podIdSearch = createSearchBuilder(Long.class); - podIdSearch.selectField(podIdSearch.entity().getId()); - podIdSearch.and("dataCenterId", podIdSearch.entity().getDataCenterId(), Op.EQ); - podIdSearch.and("allocationState", podIdSearch.entity().getAllocationState(), Op.EQ); - podIdSearch.done(); - - - SearchCriteria sc = podIdSearch.create(); - sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId); - sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled); - return customSearch(sc, null); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/PodVlanDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/PodVlanDao.java b/server/src/com/cloud/dc/dao/PodVlanDao.java deleted file mode 100644 index 6359dfe..0000000 --- a/server/src/com/cloud/dc/dao/PodVlanDao.java +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.PodVlanVO; -import com.cloud.utils.db.GenericDao; - -public interface PodVlanDao extends GenericDao { - public List listAllocatedVnets(long podId); - public void add(long podId, int start, int end); - public void delete(long podId); - public PodVlanVO take(long podId, long accountId); - public void release(String vlan, long podId, long accountId); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/PodVlanDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/PodVlanDaoImpl.java b/server/src/com/cloud/dc/dao/PodVlanDaoImpl.java deleted file mode 100755 index 413f9ed..0000000 --- a/server/src/com/cloud/dc/dao/PodVlanDaoImpl.java +++ /dev/null @@ -1,139 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -import org.springframework.stereotype.Component; - -import com.cloud.dc.PodVlanVO; -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; - -/** - * PodVlanDaoImpl maintains the one-to-many relationship between - */ -@Component -public class PodVlanDaoImpl extends GenericDaoBase implements PodVlanDao { - private final SearchBuilder FreeVlanSearch; - private final SearchBuilder VlanPodSearch; - private final SearchBuilder PodSearchAllocated; - - public List listAllocatedVnets(long podId) { - SearchCriteria sc = PodSearchAllocated.create(); - sc.setParameters("podId", podId); - return listBy(sc); - } - - public void add(long podId, int start, int end) { - String insertVnet = "INSERT INTO `cloud`.`op_pod_vlan_alloc` (vlan, pod_id) VALUES ( ?, ?)"; - - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - PreparedStatement stmt = txn.prepareAutoCloseStatement(insertVnet); - for (int i = start; i < end; i++) { - stmt.setString(1, String.valueOf(i)); - stmt.setLong(2, podId); - stmt.addBatch(); - } - stmt.executeBatch(); - txn.commit(); - } catch (SQLException e) { - throw new CloudRuntimeException("Exception caught adding vnet ", e); - } - } - - public void delete(long podId) { - String deleteVnet = "DELETE FROM `cloud`.`op_pod_vlan_alloc` WHERE pod_id = ?"; - - Transaction txn = Transaction.currentTxn(); - try { - PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteVnet); - stmt.setLong(1, podId); - stmt.executeUpdate(); - } catch (SQLException e) { - throw new CloudRuntimeException("Exception caught deleting vnet ", e); - } - } - - public PodVlanVO take(long podId, long accountId) { - SearchCriteria sc = FreeVlanSearch.create(); - sc.setParameters("podId", podId); - Date now = new Date(); - Transaction txn = Transaction.currentTxn(); - try { - txn.start(); - PodVlanVO vo = lockOneRandomRow(sc, true); - if (vo == null) { - return null; - } - - vo.setTakenAt(now); - vo.setAccountId(accountId); - update(vo.getId(), vo); - txn.commit(); - return vo; - - } catch (Exception e) { - throw new CloudRuntimeException("Caught Exception ", e); - } - } - - public void release(String vlan, long podId, long accountId) { - SearchCriteria sc = VlanPodSearch.create(); - sc.setParameters("vlan", vlan); - sc.setParameters("podId", podId); - sc.setParameters("account", accountId); - - PodVlanVO vo = findOneIncludingRemovedBy(sc); - if (vo == null) { - return; - } - - vo.setTakenAt(null); - vo.setAccountId(null); - update(vo.getId(), vo); - } - - public PodVlanDaoImpl() { - super(); - PodSearchAllocated = createSearchBuilder(); - PodSearchAllocated.and("podId", PodSearchAllocated.entity().getPodId(), SearchCriteria.Op.EQ); - PodSearchAllocated.and("allocated", PodSearchAllocated.entity().getTakenAt(), SearchCriteria.Op.NNULL); - PodSearchAllocated.done(); - - FreeVlanSearch = createSearchBuilder(); - FreeVlanSearch.and("podId", FreeVlanSearch.entity().getPodId(), SearchCriteria.Op.EQ); - FreeVlanSearch.and("taken", FreeVlanSearch.entity().getTakenAt(), SearchCriteria.Op.NULL); - FreeVlanSearch.done(); - - VlanPodSearch = createSearchBuilder(); - VlanPodSearch.and("vlan", VlanPodSearch.entity().getVlan(), SearchCriteria.Op.EQ); - VlanPodSearch.and("podId", VlanPodSearch.entity().getPodId(), SearchCriteria.Op.EQ); - VlanPodSearch.and("taken", VlanPodSearch.entity().getTakenAt(), SearchCriteria.Op.NNULL); - VlanPodSearch.and("account", VlanPodSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - VlanPodSearch.done(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/PodVlanMapDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/PodVlanMapDao.java b/server/src/com/cloud/dc/dao/PodVlanMapDao.java deleted file mode 100644 index 841ed1b..0000000 --- a/server/src/com/cloud/dc/dao/PodVlanMapDao.java +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.PodVlanMapVO; -import com.cloud.utils.db.GenericDao; - -public interface PodVlanMapDao extends GenericDao { - - public List listPodVlanMapsByPod(long podId); - public PodVlanMapVO listPodVlanMapsByVlan(long vlanDbId); - public PodVlanMapVO findPodVlanMap(long podId, long vlanDbId); - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/PodVlanMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/PodVlanMapDaoImpl.java b/server/src/com/cloud/dc/dao/PodVlanMapDaoImpl.java deleted file mode 100644 index df7a5d9..0000000 --- a/server/src/com/cloud/dc/dao/PodVlanMapDaoImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import javax.ejb.Local; - -import org.springframework.stereotype.Component; - -import com.cloud.dc.PodVlanMapVO; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; - -@Component -@Local(value={PodVlanMapDao.class}) -public class PodVlanMapDaoImpl extends GenericDaoBase implements PodVlanMapDao { - - protected SearchBuilder PodSearch; - protected SearchBuilder VlanSearch; - protected SearchBuilder PodVlanSearch; - - @Override - public List listPodVlanMapsByPod(long podId) { - SearchCriteria sc = PodSearch.create(); - sc.setParameters("podId", podId); - return listIncludingRemovedBy(sc); - } - - @Override - public PodVlanMapVO listPodVlanMapsByVlan(long vlanDbId) { - SearchCriteria sc = VlanSearch.create(); - sc.setParameters("vlanDbId", vlanDbId); - return findOneBy(sc); - } - - @Override - public PodVlanMapVO findPodVlanMap(long podId, long vlanDbId) { - SearchCriteria sc = PodVlanSearch.create(); - sc.setParameters("podId", podId); - sc.setParameters("vlanDbId", vlanDbId); - return findOneIncludingRemovedBy(sc); - } - - public PodVlanMapDaoImpl() { - PodSearch = createSearchBuilder(); - PodSearch.and("podId", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ); - PodSearch.done(); - - VlanSearch = createSearchBuilder(); - VlanSearch.and("vlanDbId", VlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ); - VlanSearch.done(); - - PodVlanSearch = createSearchBuilder(); - PodVlanSearch.and("podId", PodVlanSearch.entity().getPodId(), SearchCriteria.Op.EQ); - PodVlanSearch.and("vlanDbId", PodVlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ); - PodVlanSearch.done(); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/server/src/com/cloud/dc/dao/StorageNetworkIpAddressDao.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/dc/dao/StorageNetworkIpAddressDao.java b/server/src/com/cloud/dc/dao/StorageNetworkIpAddressDao.java deleted file mode 100755 index f1fd2bd..0000000 --- a/server/src/com/cloud/dc/dao/StorageNetworkIpAddressDao.java +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc.dao; - -import java.util.List; - -import com.cloud.dc.StorageNetworkIpAddressVO; -import com.cloud.utils.db.GenericDao; - -public interface StorageNetworkIpAddressDao extends GenericDao { - long countInUseIpByRangeId(long rangeId); - - List listInUseIpByRangeId(long rangeId); - - StorageNetworkIpAddressVO takeIpAddress(long rangeId); - - void releaseIpAddress(String ip); -}