cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject [11/57] [abbrv] [partial] merge master
Date Mon, 13 May 2013 12:25:41 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
new file mode 100755
index 0000000..73f310f
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java
@@ -0,0 +1,376 @@
+// 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.network.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.Vlan.VlanType;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.VlanDao;
+import com.cloud.dc.dao.VlanDaoImpl;
+import com.cloud.network.IpAddress.State;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.utils.db.DB;
+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.net.Ip;
+
+@Component
+@Local(value = { IPAddressDao.class })
+@DB
+public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implements IPAddressDao {
+    private static final Logger s_logger = Logger.getLogger(IPAddressDaoImpl.class);
+
+    protected SearchBuilder<IPAddressVO> AllFieldsSearch;
+    protected SearchBuilder<IPAddressVO> VlanDbIdSearchUnallocated;
+    protected GenericSearchBuilder<IPAddressVO, Integer> AllIpCount;
+    protected GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCount;
+    protected GenericSearchBuilder<IPAddressVO, Integer> AllIpCountForDashboard;    
+    protected GenericSearchBuilder<IPAddressVO, Long> AllocatedIpCountForAccount;    
+    @Inject protected VlanDao _vlanDao;
+    protected GenericSearchBuilder<IPAddressVO, Long> CountFreePublicIps;
+    @Inject ResourceTagDao _tagsDao;
+
+    // make it public for JUnit test
+    public IPAddressDaoImpl() {
+    }
+
+    @PostConstruct
+    public void init() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+        AllFieldsSearch.and("dataCenterId", AllFieldsSearch.entity().getDataCenterId(), Op.EQ);
+        AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getAddress(), Op.EQ);
+        AllFieldsSearch.and("vlan", AllFieldsSearch.entity().getVlanId(), Op.EQ);
+        AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAllocatedToAccountId(), Op.EQ);
+        AllFieldsSearch.and("sourceNat", AllFieldsSearch.entity().isSourceNat(), Op.EQ);
+        AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
+        AllFieldsSearch.and("associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ);
+        AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ);
+        AllFieldsSearch.and("sourcenetwork", AllFieldsSearch.entity().getSourceNetworkId(), Op.EQ);
+        AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
+        AllFieldsSearch.and("associatedVmIp", AllFieldsSearch.entity().getVmIp(), Op.EQ);
+        AllFieldsSearch.done();
+
+        VlanDbIdSearchUnallocated = createSearchBuilder();
+        VlanDbIdSearchUnallocated.and("allocated", VlanDbIdSearchUnallocated.entity().getAllocatedTime(), Op.NULL);
+        VlanDbIdSearchUnallocated.and("vlanDbId", VlanDbIdSearchUnallocated.entity().getVlanId(), Op.EQ);
+        VlanDbIdSearchUnallocated.done();
+
+        AllIpCount = createSearchBuilder(Integer.class);
+        AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getAddress());
+        AllIpCount.and("dc", AllIpCount.entity().getDataCenterId(), Op.EQ);
+        AllIpCount.and("vlan", AllIpCount.entity().getVlanId(), Op.EQ);
+        AllIpCount.done();
+
+        AllocatedIpCount = createSearchBuilder(Integer.class);
+        AllocatedIpCount.select(null, Func.COUNT, AllocatedIpCount.entity().getAddress());
+        AllocatedIpCount.and("dc", AllocatedIpCount.entity().getDataCenterId(), Op.EQ);
+        AllocatedIpCount.and("vlan", AllocatedIpCount.entity().getVlanId(), Op.EQ);
+        AllocatedIpCount.and("allocated", AllocatedIpCount.entity().getAllocatedTime(), Op.NNULL);
+        AllocatedIpCount.done();              
+
+        AllIpCountForDashboard = createSearchBuilder(Integer.class);
+        AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress());
+        AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ);        
+        AllIpCountForDashboard.and("state", AllIpCountForDashboard.entity().getState(), SearchCriteria.Op.NEQ);                
+
+        SearchBuilder<VlanVO> virtaulNetworkVlan = _vlanDao.createSearchBuilder();
+        virtaulNetworkVlan.and("vlanType", virtaulNetworkVlan.entity().getVlanType(), SearchCriteria.Op.EQ);
+
+        AllIpCountForDashboard.join("vlan", virtaulNetworkVlan, virtaulNetworkVlan.entity().getId(),
+                AllIpCountForDashboard.entity().getVlanId(), JoinBuilder.JoinType.INNER);
+        virtaulNetworkVlan.done();
+        AllIpCountForDashboard.done();
+
+        AllocatedIpCountForAccount = createSearchBuilder(Long.class);
+        AllocatedIpCountForAccount.select(null, Func.COUNT, AllocatedIpCountForAccount.entity().getAddress());
+        AllocatedIpCountForAccount.and("account", AllocatedIpCountForAccount.entity().getAllocatedToAccountId(), Op.EQ);
+        AllocatedIpCountForAccount.and("allocated", AllocatedIpCountForAccount.entity().getAllocatedTime(), Op.NNULL);
+        AllocatedIpCountForAccount.and("network", AllocatedIpCountForAccount.entity().getAssociatedWithNetworkId(), Op.NNULL);        
+        AllocatedIpCountForAccount.done();
+
+        CountFreePublicIps = createSearchBuilder(Long.class);
+        CountFreePublicIps.select(null, Func.COUNT, null);
+        CountFreePublicIps.and("state", CountFreePublicIps.entity().getState(), SearchCriteria.Op.EQ);
+        CountFreePublicIps.and("networkId", CountFreePublicIps.entity().getSourceNetworkId(), SearchCriteria.Op.EQ);
+        SearchBuilder<VlanVO> join = _vlanDao.createSearchBuilder();
+        join.and("vlanType", join.entity().getVlanType(), Op.EQ);
+        CountFreePublicIps.join("vlans", join, CountFreePublicIps.entity().getVlanId(), join.entity().getId(), JoinBuilder.JoinType.INNER);
+        CountFreePublicIps.done();
+    }
+
+    @Override
+    public boolean mark(long dcId, Ip ip) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("dataCenterId", dcId);
+        sc.setParameters("ipAddress", ip);
+
+        IPAddressVO vo = createForUpdate();
+        vo.setAllocatedTime(new Date());
+        vo.setState(State.Allocated);
+
+        return update(vo, sc) >= 1;
+    }
+
+    @Override
+    public void unassignIpAddress(long ipAddressId) {
+        IPAddressVO address = createForUpdate();
+        address.setAllocatedToAccountId(null);
+        address.setAllocatedInDomainId(null);
+        address.setAllocatedTime(null);
+        address.setSourceNat(false);
+        address.setOneToOneNat(false);
+        address.setAssociatedWithVmId(null);
+        address.setState(State.Free);
+        address.setAssociatedWithNetworkId(null);
+        address.setVpcId(null);
+        address.setSystem(false);
+        update(ipAddressId, address);
+    }
+
+    @Override
+    public List<IPAddressVO> listByAccount(long accountId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<IPAddressVO> listByVlanId(long vlanId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("vlan", vlanId);
+        return listBy(sc);
+    }
+
+    @Override
+    public IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("sourcenetwork", networkId);
+        sc.setParameters("ipAddress", ipAddress);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public IPAddressVO findByIpAndNetworkId(long networkId, String ipAddress) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+        sc.setParameters("ipAddress", ipAddress);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public IPAddressVO findByIpAndDcId(long dcId, String ipAddress) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("dataCenterId", dcId);
+        sc.setParameters("ipAddress", ipAddress);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<IPAddressVO> listByDcId(long dcId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("dataCenterId", dcId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<IPAddressVO> listByDcIdIpAddress(long dcId, String ipAddress) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("dataCenterId", dcId);
+        sc.setParameters("ipAddress", ipAddress);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<IPAddressVO> listByAssociatedNetwork(long networkId, Boolean isSourceNat) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+
+        if (isSourceNat != null) {
+            sc.setParameters("sourceNat", isSourceNat);
+        }
+
+        return listBy(sc);
+    }
+
+    @Override 
+    public List<IPAddressVO> listStaticNatPublicIps(long networkId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+        sc.setParameters("oneToOneNat", true);
+        return listBy(sc);        
+    }
+
+    @Override
+    public IPAddressVO findByAssociatedVmId(long vmId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("associatedWithVmId", vmId);
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public IPAddressVO findByVmIp(String vmIp) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("associatedVmIp", vmIp);
+        return findOneBy(sc);
+    }
+    @Override
+    public int countIPs(long dcId, long vlanId, boolean onlyCountAllocated) {
+        SearchCriteria<Integer> sc = onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create();
+        sc.setParameters("dc", dcId);
+        sc.setParameters("vlan", vlanId);
+
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public int countIPsForNetwork(long dcId, boolean onlyCountAllocated, VlanType vlanType) {
+        SearchCriteria<Integer> sc = AllIpCountForDashboard.create();
+        sc.setParameters("dc", dcId);
+        if (onlyCountAllocated){
+            sc.setParameters("state", State.Free);
+        }
+        sc.setJoinParameters("vlan", "vlanType", vlanType.toString());
+        return customSearch(sc, null).get(0);
+    }
+
+
+    @Override
+    @DB
+    public int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask) {
+        Transaction txn = Transaction.currentTxn();
+        int ipCount = 0;
+        try {
+            String sql = "SELECT count(*) FROM user_ip_address u INNER JOIN vlan v on (u.vlan_db_id = v.id AND v.data_center_id = ? AND v.vlan_id = ? AND v.vlan_gateway = ? AND v.vlan_netmask = ? AND u.account_id = ?)";
+
+            PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, dcId);
+            pstmt.setString(2, vlanId);
+            pstmt.setString(3, vlanGateway);
+            pstmt.setString(4, vlanNetmask);
+            pstmt.setLong(5, accountId);
+            ResultSet rs = pstmt.executeQuery();
+
+            if (rs.next()) {
+                ipCount = rs.getInt(1);
+            }
+        } catch (Exception e) {
+            s_logger.warn("Exception counting IP addresses", e);
+        }
+
+        return ipCount;
+    }
+
+    @Override @DB
+    public IPAddressVO markAsUnavailable(long ipAddressId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("id", ipAddressId);
+
+        IPAddressVO ip = createForUpdate();
+        ip.setState(State.Releasing);
+        if (update(ip, sc) != 1) {
+            return null;
+        }
+
+        return findOneBy(sc);
+    }
+
+    @Override
+    public long countAllocatedIPsForAccount(long accountId) {
+        SearchCriteria<Long> sc = AllocatedIpCountForAccount.create();
+        sc.setParameters("account", accountId);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public List<IPAddressVO> listByPhysicalNetworkId(long physicalNetworkId) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        return listBy(sc);
+    }
+
+    @Override
+    public long countFreePublicIPs() {
+        SearchCriteria<Long> sc = CountFreePublicIps.create();
+        sc.setParameters("state", State.Free);
+        sc.setJoinParameters("vlans", "vlanType", VlanType.VirtualNetwork);
+        return customSearch(sc, null).get(0);       
+    }
+
+    @Override
+    public List<IPAddressVO> listByAssociatedVpc(long vpcId, Boolean isSourceNat) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("vpcId", vpcId);
+
+        if (isSourceNat != null) {
+            sc.setParameters("sourceNat", isSourceNat);
+        }
+
+        return listBy(sc);
+    }
+
+    @Override
+    public long countFreeIPsInNetwork(long networkId) {
+        SearchCriteria<Long> sc = CountFreePublicIps.create();
+        sc.setParameters("state", State.Free);
+        sc.setParameters("networkId", networkId);
+        return customSearch(sc, null).get(0);       
+    }
+
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        IPAddressVO entry = findById(id);
+        if (entry != null) {
+            _tagsDao.removeByIdAndType(id, TaggedResourceType.SecurityGroup);
+        }
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
+
+    @Override
+    public IPAddressVO findByAssociatedVmIdAndVmIp(long vmId, String vmIp) {
+        SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
+        sc.setParameters("associatedWithVmId", vmId);
+        sc.setParameters("associatedVmIp", vmIp);
+        return findOneBy(sc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressVO.java b/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
new file mode 100644
index 0000000..ae27e95
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressVO.java
@@ -0,0 +1,308 @@
+// 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.network.dao;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import com.cloud.network.IpAddress;
+import com.cloud.utils.net.Ip;
+
+/**
+ * A bean representing a public IP Address
+ *
+ */
+@Entity
+@Table(name=("user_ip_address"))
+public class IPAddressVO implements IpAddress {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+
+	@Column(name="account_id")
+	private Long allocatedToAccountId = null;
+
+    @Column(name="domain_id")
+    private Long allocatedInDomainId = null;
+
+	@Id
+	@Column(name="public_ip_address")
+	@Enumerated(value=EnumType.STRING)
+	private Ip address = null;
+
+	@Column(name="data_center_id", updatable=false)
+	private long dataCenterId;
+
+	@Column(name="source_nat")
+	private boolean sourceNat;
+
+	@Column(name="allocated")
+	@Temporal(value=TemporalType.TIMESTAMP)
+	private Date allocatedTime;
+
+	@Column(name="vlan_db_id")
+	private long vlanId;
+
+	@Column(name="one_to_one_nat")
+	private boolean oneToOneNat;
+
+	@Column(name="vm_id")
+    private Long associatedWithVmId;
+
+	@Column(name="state")
+	private State state;
+
+	@Column(name="mac_address")
+	private long macAddress;
+
+	@Column(name="source_network_id")
+    private Long sourceNetworkId;
+
+	@Column(name="network_id")
+	private Long associatedWithNetworkId;
+
+	@Column(name="uuid")
+	private String uuid;
+
+    @Column(name="physical_network_id")
+    private Long physicalNetworkId;
+
+    @Column(name="is_system")
+    private boolean system;
+
+	@Column(name="account_id")
+	@Transient
+	private Long accountId = null;
+
+	@Transient
+    @Column(name="domain_id")
+    private Long domainId = null;
+
+    @Column(name="vpc_id")
+    private Long vpcId;
+
+    @Column(name="dnat_vmip")
+    private String vmIp;
+
+
+	protected IPAddressVO() {
+		this.uuid = UUID.randomUUID().toString();
+	}
+
+	@Override
+    public boolean readyToUse() {
+	    return state == State.Allocated;
+	}
+
+	public IPAddressVO(Ip address, long dataCenterId, long macAddress, long vlanDbId, boolean sourceNat) {
+		this.address = address;
+		this.dataCenterId = dataCenterId;
+		this.vlanId = vlanDbId;
+		this.sourceNat = sourceNat;
+		this.allocatedInDomainId = null;
+		this.allocatedToAccountId = null;
+		this.allocatedTime = null;
+		this.state = State.Free;
+		this.macAddress = macAddress;
+		this.uuid = UUID.randomUUID().toString();
+	}
+
+    public long getMacAddress() {
+	    return macAddress;
+	}
+
+	@Override
+    public long getDataCenterId() {
+	    return dataCenterId;
+	}
+
+	@Override
+    public Ip getAddress() {
+		return address;
+	}
+
+	@Override
+    public Long getAllocatedToAccountId() {
+		return allocatedToAccountId;
+	}
+
+    @Override
+    public Long getAllocatedInDomainId() {
+        return allocatedInDomainId;
+    }
+
+	@Override
+	public Long getAssociatedWithNetworkId() {
+	    return associatedWithNetworkId;
+	}
+
+	public void setAssociatedWithNetworkId(Long networkId) {
+	    this.associatedWithNetworkId = networkId;
+	}
+
+	@Override
+    public Long getAssociatedWithVmId() {
+        return associatedWithVmId;
+    }
+
+    public void setAssociatedWithVmId(Long associatedWithVmId) {
+        this.associatedWithVmId = associatedWithVmId;
+    }
+
+	@Override
+    public Date getAllocatedTime() {
+		return allocatedTime;
+	}
+
+    public void setAllocatedToAccountId(Long accountId) {
+		this.allocatedToAccountId = accountId;
+	}
+
+    public void setAllocatedInDomainId(Long domainId) {
+        this.allocatedInDomainId = domainId;
+    }
+
+    public void setSourceNat(boolean sourceNat) {
+		this.sourceNat = sourceNat;
+	}
+
+	@Override
+    public boolean isSourceNat() {
+		return sourceNat;
+	}
+
+    public void setAllocatedTime(Date allocated) {
+		this.allocatedTime = allocated;
+	}
+
+	@Override
+    public long getVlanId() {
+		return this.vlanId;
+	}
+
+    public void setVlanId(long vlanDbId) {
+		this.vlanId = vlanDbId;
+	}
+
+	@Override
+    public boolean isOneToOneNat() {
+		return oneToOneNat;
+	}
+
+    public void setOneToOneNat(boolean oneToOneNat) {
+		this.oneToOneNat = oneToOneNat;
+	}
+
+    @Override
+    public long getDomainId() {
+        return allocatedInDomainId == null ? -1 : allocatedInDomainId;
+    }
+
+    @Override
+    public long getAccountId() {
+        return allocatedToAccountId == null ? -1 : allocatedToAccountId;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    public void setState(State state) {
+        this.state = state;
+    }
+
+	@Override
+    public String toString() {
+	    return new StringBuilder("Ip[").append(address).append("-").append(dataCenterId).append("]").toString();
+	}
+
+	@Override
+    public long getId() {
+        return id;
+    }
+
+    public Long getSourceNetworkId() {
+        return sourceNetworkId;
+    }
+
+    public void setSourceNetworkId(Long sourceNetworkId) {
+        this.sourceNetworkId = sourceNetworkId;
+    }
+
+    @Override
+    public String getUuid() {
+    	return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+    public Long getPhysicalNetworkId() {
+        return physicalNetworkId;
+    }
+
+    public void setPhysicalNetworkId(Long physicalNetworkId) {
+        this.physicalNetworkId = physicalNetworkId;
+    }
+
+    @Override
+	public boolean getSystem() {
+		return system;
+	}
+
+	public void setSystem(boolean isSystem) {
+		this.system = isSystem;
+	}
+
+	@Override
+    public Long getVpcId() {
+        return vpcId;
+    }
+
+    public void setVpcId(Long vpcId) {
+        this.vpcId = vpcId;
+    }
+
+    @Override
+    public String getVmIp() {
+        return vmIp;
+    }
+
+    public void setVmIp(String vmIp) {
+        this.vmIp = vmIp;
+    }
+
+    @Override
+    public Long getNetworkId() {
+        return sourceNetworkId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java
new file mode 100644
index 0000000..36a8eef
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java
@@ -0,0 +1,24 @@
+// 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.network.dao;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface InlineLoadBalancerNicMapDao extends GenericDao<InlineLoadBalancerNicMapVO, Long> {
+	InlineLoadBalancerNicMapVO findByPublicIpAddress(String publicIpAddress);
+	InlineLoadBalancerNicMapVO findByNicId(long nicId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java
new file mode 100644
index 0000000..f3f04ed
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java
@@ -0,0 +1,46 @@
+// 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.network.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value={InlineLoadBalancerNicMapDao.class})
+public class InlineLoadBalancerNicMapDaoImpl extends GenericDaoBase<InlineLoadBalancerNicMapVO, Long> implements InlineLoadBalancerNicMapDao {
+
+    @Override
+    public InlineLoadBalancerNicMapVO findByPublicIpAddress(String publicIpAddress) {
+        SearchCriteria<InlineLoadBalancerNicMapVO> sc = createSearchCriteria();
+        sc.addAnd("publicIpAddress", SearchCriteria.Op.EQ, publicIpAddress);
+
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public InlineLoadBalancerNicMapVO findByNicId(long nicId) {
+    	SearchCriteria<InlineLoadBalancerNicMapVO> sc = createSearchCriteria();
+    	sc.addAnd("nicId", SearchCriteria.Op.EQ, nicId);
+    	
+    	return findOneBy(sc);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapVO.java b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapVO.java
new file mode 100644
index 0000000..35aeefa
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/InlineLoadBalancerNicMapVO.java
@@ -0,0 +1,60 @@
+// 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.network.dao;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name=("inline_load_balancer_nic_map"))
+public class InlineLoadBalancerNicMapVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+
+    @Column(name="public_ip_address")
+    private String publicIpAddress;
+
+    @Column(name="nic_id")
+    private long nicId;
+
+    public InlineLoadBalancerNicMapVO() { }
+
+    public InlineLoadBalancerNicMapVO(String publicIpAddress, long nicId) {
+        this.publicIpAddress = publicIpAddress;
+        this.nicId = nicId;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public String getPublicIpAddress() {
+    	return publicIpAddress;
+    }
+
+    public long getNicId() {
+    	return nicId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDao.java b/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDao.java
new file mode 100644
index 0000000..42a9e42
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDao.java
@@ -0,0 +1,35 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import com.cloud.network.LBHealthCheckPolicyVO;
+import com.cloud.utils.db.GenericDao;
+
+
+public interface LBHealthCheckPolicyDao extends
+        GenericDao<LBHealthCheckPolicyVO, Long> {
+    void remove(long loadBalancerId);
+
+    void remove(long loadBalancerId, Boolean pending);
+
+    List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId);
+
+    List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId,
+            boolean revoke);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDaoImpl.java b/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDaoImpl.java
new file mode 100644
index 0000000..65e0689
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LBHealthCheckPolicyDaoImpl.java
@@ -0,0 +1,71 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.LBHealthCheckPolicyVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+
+
+@Component
+@Local(value = { LBHealthCheckPolicyDao.class })
+public class LBHealthCheckPolicyDaoImpl extends
+        GenericDaoBase<LBHealthCheckPolicyVO, Long> implements
+        LBHealthCheckPolicyDao {
+
+    @Override
+    public void remove(long loadBalancerId) {
+        SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        expunge(sc);
+    }
+
+    @Override
+    public void remove(long loadBalancerId, Boolean revoke) {
+        SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
+
+        expunge(sc);
+    }
+
+    @Override
+    public List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId) {
+        SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId,
+            boolean pending) {
+        SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("revoke", SearchCriteria.Op.EQ, pending);
+
+        return listBy(sc);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDao.java b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDao.java
new file mode 100644
index 0000000..9a25c1a
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDao.java
@@ -0,0 +1,34 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import com.cloud.utils.db.GenericDao;
+
+
+public interface LBStickinessPolicyDao extends
+        GenericDao<LBStickinessPolicyVO, Long> {
+    void remove(long loadBalancerId);
+
+    void remove(long loadBalancerId, Boolean pending);
+
+    List<LBStickinessPolicyVO> listByLoadBalancerId(long loadBalancerId);
+
+    List<LBStickinessPolicyVO> listByLoadBalancerId(long loadBalancerId,
+            boolean revoke);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDaoImpl.java b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDaoImpl.java
new file mode 100644
index 0000000..43b4669
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyDaoImpl.java
@@ -0,0 +1,69 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value = { LBStickinessPolicyDao.class })
+public class LBStickinessPolicyDaoImpl extends
+        GenericDaoBase<LBStickinessPolicyVO, Long> implements
+        LBStickinessPolicyDao {
+
+    @Override
+    public void remove(long loadBalancerId) {
+        SearchCriteria<LBStickinessPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        expunge(sc);
+    }
+
+    @Override
+    public void remove(long loadBalancerId, Boolean revoke) {
+        SearchCriteria<LBStickinessPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
+
+        expunge(sc);
+    }
+
+    @Override
+    public List<LBStickinessPolicyVO> listByLoadBalancerId(long loadBalancerId) {
+        SearchCriteria<LBStickinessPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LBStickinessPolicyVO> listByLoadBalancerId(long loadBalancerId,
+            boolean pending) {
+        SearchCriteria<LBStickinessPolicyVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("revoke", SearchCriteria.Op.EQ, pending);
+
+        return listBy(sc);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyVO.java b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyVO.java
new file mode 100644
index 0000000..3fbba68
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LBStickinessPolicyVO.java
@@ -0,0 +1,145 @@
+// 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.network.dao;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+import com.cloud.network.rules.StickinessPolicy;
+import com.cloud.utils.Pair;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = ("load_balancer_stickiness_policies"))
+@PrimaryKeyJoinColumn(name = "load_balancer_id", referencedColumnName = "id")
+public class LBStickinessPolicyVO implements StickinessPolicy {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "load_balancer_id")
+    private long loadBalancerId;
+
+    @Column(name = "name")
+    private String name;
+
+    @Column(name = "description")
+    private String description;
+
+    @Column(name = "method_name")
+    private String methodName;
+
+    @Column(name = "params")
+    private String paramsInDB;
+
+    @Column(name = "uuid")
+    private String uuid;
+    
+    @Column(name = "revoke")
+    private boolean revoke = false;
+    protected LBStickinessPolicyVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+/*  get the params in Map format and converts in to string format and stores in DB
+ *  paramsInDB represent the string stored in database :
+ *  Format :  param1=value1&param2=value2&param3=value3& 
+ *  Example for App cookie method:  "name=cookapp&length=12&holdtime=3h" . Here 3 parameters name,length and holdtime with corresponding values.
+ *  getParams function is used to get in List<Pair<string,String>> Format.
+ *           - API response use Map format
+ *           - In database plain String with DB_PARM_DELIMITER 
+ *           - rest of the code uses List<Pair<string,String>> 
+ */
+    public LBStickinessPolicyVO(long loadBalancerId, String name, String methodName, Map paramList, String description) {
+        this.loadBalancerId = loadBalancerId;
+        this.name = name;
+        this.methodName = methodName;
+        StringBuilder sb = new StringBuilder("");
+
+        if (paramList != null) {
+            Iterator<HashMap<String, String>> iter = paramList.values().iterator();
+            while (iter.hasNext())  {
+                HashMap<String, String>  paramKVpair =  iter.next();
+                String paramName = paramKVpair.get("name");
+                String paramValue =  paramKVpair.get("value");
+                sb.append(paramName + "=" + paramValue + "&");
+            }
+        } 
+        paramsInDB = sb.toString();
+        this.description = description;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public List<Pair<String, String>> getParams() {
+        List<Pair<String, String>> paramsList = new ArrayList<Pair<String, String>>();
+        String[] params = paramsInDB.split("[=&]");
+ 
+        for (int i = 0; i < (params.length - 1); i = i + 2) {
+            paramsList.add(new Pair<String, String>(params[i], params[i + 1]));
+        }
+        return paramsList;
+    }
+    
+    public long getId() {
+        return id;
+    }
+
+    public long getLoadBalancerId() {
+        return loadBalancerId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getMethodName() {
+        return methodName;
+    }
+    
+    public boolean isRevoke() {
+        return revoke;
+    }
+
+    public void setRevoke(boolean revoke) {
+        this.revoke = revoke;
+    }
+    
+    @Override
+    public String getUuid() {
+        return this.uuid;
+    }
+    
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerDao.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerDao.java
new file mode 100644
index 0000000..331f755
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerDao.java
@@ -0,0 +1,32 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.utils.db.GenericDao;
+
+public interface LoadBalancerDao extends GenericDao<LoadBalancerVO, Long> {
+
+    List<LoadBalancerVO> listByIpAddress(long ipAddressId);
+
+    List<LoadBalancerVO> listByNetworkIdAndScheme(long networkId, Scheme scheme);
+
+    List<LoadBalancerVO> listInTransitionStateByNetworkIdAndScheme(long networkId, Scheme scheme);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerDaoImpl.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
new file mode 100644
index 0000000..c20d8b2
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerDaoImpl.java
@@ -0,0 +1,79 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.rules.FirewallRule.State;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value = { LoadBalancerDao.class })
+public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> implements LoadBalancerDao {
+    private final SearchBuilder<LoadBalancerVO> ListByIp;
+    protected final SearchBuilder<LoadBalancerVO> TransitionStateSearch;
+
+    @Inject protected FirewallRulesCidrsDao _portForwardingRulesCidrsDao;
+
+    protected LoadBalancerDaoImpl() {
+        ListByIp = createSearchBuilder();
+        ListByIp.and("ipAddressId", ListByIp.entity().getSourceIpAddressId(), SearchCriteria.Op.EQ);
+        ListByIp.and("networkId", ListByIp.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        ListByIp.and("scheme", ListByIp.entity().getScheme(), SearchCriteria.Op.EQ);
+        ListByIp.done();
+
+        TransitionStateSearch = createSearchBuilder();
+        TransitionStateSearch.and("networkId", TransitionStateSearch.entity().getNetworkId(), Op.EQ);
+        TransitionStateSearch.and("state", TransitionStateSearch.entity().getState(), Op.IN);
+        TransitionStateSearch.and("scheme", TransitionStateSearch.entity().getScheme(), Op.EQ);
+        TransitionStateSearch.done();
+    }
+    
+    @Override
+    public List<LoadBalancerVO> listByIpAddress(long ipAddressId) {
+        SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
+        sc.setParameters("ipAddressId", ipAddressId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LoadBalancerVO> listByNetworkIdAndScheme(long networkId, Scheme scheme) {
+        SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("scheme", scheme);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LoadBalancerVO> listInTransitionStateByNetworkIdAndScheme(long networkId, Scheme scheme) {
+        SearchCriteria<LoadBalancerVO> sc = TransitionStateSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("state", State.Add.toString(), State.Revoke.toString());
+        sc.setParameters("scheme", scheme);
+        return listBy(sc);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
new file mode 100644
index 0000000..e122d0a
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
@@ -0,0 +1,31 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface LoadBalancerVMMapDao extends GenericDao<LoadBalancerVMMapVO, Long> {
+    void remove(long loadBalancerId);
+    void remove(long loadBalancerId, List<Long> instanceIds, Boolean pending);
+    List<LoadBalancerVMMapVO> listByInstanceId(long instanceId);
+    List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId);
+    List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean revoke);
+    LoadBalancerVMMapVO findByLoadBalancerIdAndVmId(long loadBalancerId, long instanceId);
+    boolean isVmAttachedToLoadBalancer(long loadBalancerId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
new file mode 100644
index 0000000..8f979cd
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
@@ -0,0 +1,97 @@
+// 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.network.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+
+@Component
+@Local(value={LoadBalancerVMMapDao.class})
+public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO, Long> implements LoadBalancerVMMapDao {
+
+    @Override
+    public void remove(long loadBalancerId) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        expunge(sc);
+    }
+
+    @Override
+    public void remove(long loadBalancerId, List<Long> instanceIds, Boolean revoke) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("instanceId", SearchCriteria.Op.IN, instanceIds.toArray());
+        if (revoke != null) {
+            sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
+        }
+
+        expunge(sc);
+    }
+
+    @Override
+    public List<LoadBalancerVMMapVO> listByInstanceId(long instanceId) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<LoadBalancerVMMapVO> listByLoadBalancerId(long loadBalancerId, boolean pending) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("revoke", SearchCriteria.Op.EQ, pending);
+
+        return listBy(sc);
+    }
+    
+    @Override
+    public LoadBalancerVMMapVO findByLoadBalancerIdAndVmId(long loadBalancerId, long instanceId) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public boolean isVmAttachedToLoadBalancer(long loadBalancerId) {
+        GenericSearchBuilder<LoadBalancerVMMapVO, Long> CountByAccount = createSearchBuilder(Long.class);
+        CountByAccount.select(null, Func.COUNT, null);
+        CountByAccount.and("loadBalancerId", CountByAccount.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
+
+        SearchCriteria<Long> sc = CountByAccount.create();
+        sc.setParameters("loadBalancerId", loadBalancerId);
+        return customSearch(sc, null).get(0) > 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapVO.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapVO.java
new file mode 100644
index 0000000..852302e
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapVO.java
@@ -0,0 +1,89 @@
+// 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.network.dao;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name=("load_balancer_vm_map"))
+public class LoadBalancerVMMapVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private long id;
+
+    @Column(name="load_balancer_id")
+    private long loadBalancerId;
+
+    @Column(name="instance_id")
+    private long instanceId;
+
+    @Column(name = "revoke")
+    private boolean revoke = false;
+
+    @Column(name = "state")
+    private String state;
+
+    public LoadBalancerVMMapVO() {
+    }
+
+    public LoadBalancerVMMapVO(long loadBalancerId, long instanceId) {
+        this.loadBalancerId = loadBalancerId;
+        this.instanceId = instanceId;
+    }
+
+    public LoadBalancerVMMapVO(long loadBalancerId, long instanceId, boolean revoke) {
+        this.loadBalancerId = loadBalancerId;
+        this.instanceId = instanceId;
+        this.revoke = revoke;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getLoadBalancerId() {
+        return loadBalancerId;
+    }
+
+    public long getInstanceId() {
+        return instanceId;
+    }
+
+    public boolean isRevoke() {
+        return revoke;
+    }
+
+    public void setRevoke(boolean revoke) {
+        this.revoke = revoke;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/LoadBalancerVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVO.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVO.java
new file mode 100644
index 0000000..fee88cf
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVO.java
@@ -0,0 +1,116 @@
+// 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.network.dao;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.network.rules.LoadBalancer;
+import com.cloud.utils.net.NetUtils;
+
+/**
+ * This VO represent Public Load Balancer
+ * It references source ip address by its Id. 
+ * To get the VO for Internal Load Balancer rule, please refer to LoadBalancerRuleVO
+ *
+ */
+@Entity
+@Table(name=("load_balancing_rules"))
+@DiscriminatorValue(value="LoadBalancing")
+@PrimaryKeyJoinColumn(name="id")
+public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
+    
+    @Column(name="name")
+    private String name;
+
+    @Column(name="description", length=4096)
+    private String description;
+
+    @Column(name="algorithm")
+    private String algorithm;
+
+    @Column(name="default_port_start")
+    private int defaultPortStart;
+    
+    @Column(name="default_port_end")
+    private int defaultPortEnd;
+    
+    @Enumerated(value=EnumType.STRING)
+    @Column(name="scheme")
+    Scheme scheme = Scheme.Public;
+
+    public LoadBalancerVO() { 
+    }
+
+    public LoadBalancerVO(String xId, String name, String description, long srcIpId, int srcPort, int dstPort, String algorithm, long networkId, long accountId, long domainId) {
+        super(xId, srcIpId, srcPort, NetUtils.TCP_PROTO, networkId, accountId, domainId, Purpose.LoadBalancing, null, null, null, null);
+        this.name = name;
+        this.description = description;
+        this.algorithm = algorithm;
+        this.defaultPortStart = dstPort;
+        this.defaultPortEnd = dstPort;
+        this.scheme = Scheme.Public;
+    }
+    
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String getAlgorithm() {
+        return algorithm;
+    }
+    
+    @Override
+    public int getDefaultPortStart() { 
+        return defaultPortStart;
+    }
+
+    @Override
+    public int getDefaultPortEnd() {
+        return defaultPortEnd;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public Scheme getScheme() {
+        return scheme;
+    }  
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java
new file mode 100644
index 0000000..c4435c8
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java
@@ -0,0 +1,22 @@
+// 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.network.dao;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface NetworkAccountDao extends GenericDao<NetworkAccountVO, Long> {
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java
new file mode 100644
index 0000000..0947905
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java
@@ -0,0 +1,29 @@
+// 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.network.dao;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.GenericDaoBase;
+
+@Component
+public class NetworkAccountDaoImpl extends GenericDaoBase<NetworkAccountVO, Long> implements NetworkAccountDao {
+    public NetworkAccountDaoImpl() {
+        super();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/NetworkAccountVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountVO.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountVO.java
new file mode 100644
index 0000000..afce805
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkAccountVO.java
@@ -0,0 +1,72 @@
+// 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.network.dao;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.user.OwnedBy;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="account_network_ref")
+public class NetworkAccountVO implements OwnedBy, InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    long id;
+    
+    @Column(name="account_id")
+    long accountId;
+    
+    @Column(name="network_id")
+    long networkId;
+    
+    @Column(name="is_owner")
+    boolean owner;
+
+    protected NetworkAccountVO() {
+    }
+    
+    public NetworkAccountVO(long networkId, long accountId, boolean owner) {
+        this.networkId = networkId;
+        this.accountId = accountId;
+        this.owner = owner;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+    
+    public long getNetworkId() {
+        return networkId;
+    }
+    
+    public boolean isOwner() {
+        return owner;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/NetworkDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDao.java b/engine/schema/src/com/cloud/network/dao/NetworkDao.java
new file mode 100644
index 0000000..1d3f0b8
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDao.java
@@ -0,0 +1,114 @@
+// 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.network.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.network.Network;
+import com.cloud.network.Network.GuestType;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.Network.State;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.fsm.StateDao;
+
+public interface NetworkDao extends GenericDao<NetworkVO, Long> , StateDao<State, Network.Event, Network> {
+
+    List<NetworkVO> listByOwner(long ownerId);
+
+    List<NetworkVO> listBy(long accountId, long offeringId, long dataCenterId);
+
+    List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr, boolean skipVpc);
+
+    List<NetworkVO> listByZoneAndGuestType(long accountId, long dataCenterId, Network.GuestType type, Boolean isSystem);
+
+    NetworkVO persist(NetworkVO network, boolean gc, Map<String, String> serviceProviderMap);
+
+    SearchBuilder<NetworkAccountVO> createSearchBuilderForAccount();
+
+    List<NetworkVO> getNetworksForOffering(long offeringId, long dataCenterId, long accountId);
+
+    @Override
+    @Deprecated
+    NetworkVO persist(NetworkVO vo);
+
+    /**
+     * Retrieves the next available mac address in this network configuration.
+     * 
+     * @param networkConfigId
+     *            id
+     * @return mac address if there is one. null if not.
+     */
+    String getNextAvailableMacAddress(long networkConfigId);
+
+    List<NetworkVO> listBy(long accountId, long networkId);
+
+    long countByZoneAndUri(long zoneId, String broadcastUri);
+    
+    long countByZoneUriAndGuestType(long zoneId, String broadcastUri, GuestType guestType);
+
+    List<NetworkVO> listByZone(long zoneId);
+
+    void changeActiveNicsBy(long networkId, int nicsCount);
+
+    int getActiveNicsIn(long networkId);
+
+    List<Long> findNetworksToGarbageCollect();
+
+    void clearCheckForGc(long networkId);
+
+    List<NetworkVO> listByZoneSecurityGroup(Long zoneId);
+
+    void addDomainToNetwork(long networkId, long domainId, Boolean subdomainAccess);
+
+    List<NetworkVO> listByPhysicalNetwork(long physicalNetworkId);
+
+    List<NetworkVO> listSecurityGroupEnabledNetworks();
+
+    List<NetworkVO> listByPhysicalNetworkTrafficType(long physicalNetworkId, TrafficType trafficType);
+
+    List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type, TrafficType trafficType);
+
+    List<NetworkVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String providerName);
+
+    void persistNetworkServiceProviders(long networkId, Map<String, String> serviceProviderMap);
+
+    boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap);
+
+    List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType);
+
+    void setCheckForGc(long networkId);
+    
+    int getNetworkCountByNetworkOffId(long networkOfferingId);
+    
+    long countNetworksUserCanCreate(long ownerId);
+
+    List<NetworkVO> listSourceNATEnabledNetworks(long accountId, long dataCenterId, GuestType type);
+    
+    int getNetworkCountByVpcId(long vpcId);
+    
+    List<NetworkVO> listByVpc(long vpcId);
+    
+    NetworkVO getPrivateNetwork(String broadcastUri, String cidr, long accountId, long zoneId);
+    
+    long countVpcNetworks(long vpcId);
+
+    List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType type, boolean isSystem);
+
+    List<NetworkVO> listRedundantNetworks();
+}


Mime
View raw message