cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [42/72] [abbrv] [partial] Moved most of the VOs and DAOs from server package into engine-schema as well
Date Tue, 07 May 2013 22:01:58 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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/d015fb35/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();
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
new file mode 100644
index 0000000..1bc8973
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDaoImpl.java
@@ -0,0 +1,621 @@
+// 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 java.util.Random;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.persistence.TableGenerator;
+
+import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network;
+import com.cloud.network.Network.GuestType;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.Network.State;
+import com.cloud.network.Network.Event;
+import com.cloud.network.Networks.BroadcastDomainType;
+import com.cloud.network.Networks.Mode;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.utils.db.*;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.net.NetUtils;
+
+@Component
+@Local(value = NetworkDao.class)
+@DB(txn = false)
+public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements NetworkDao {
+    SearchBuilder<NetworkVO> AllFieldsSearch;
+    SearchBuilder<NetworkVO> AccountSearch;
+    SearchBuilder<NetworkVO> RelatedConfigSearch;
+    SearchBuilder<NetworkVO> AccountNetworkSearch;
+    SearchBuilder<NetworkVO> ZoneBroadcastUriSearch;
+    SearchBuilder<NetworkVO> ZoneSecurityGroupSearch;
+    GenericSearchBuilder<NetworkVO, Integer> CountBy;
+    SearchBuilder<NetworkVO> PhysicalNetworkSearch;
+    SearchBuilder<NetworkVO> SecurityGroupSearch;
+    GenericSearchBuilder<NetworkVO, Long> NetworksRegularUserCanCreateSearch;
+    GenericSearchBuilder<NetworkVO, Integer> NetworksCount;
+    SearchBuilder<NetworkVO> SourceNATSearch;
+    GenericSearchBuilder<NetworkVO, Long>  CountByZoneAndURI;
+    GenericSearchBuilder<NetworkVO, Long> VpcNetworksCount;
+    SearchBuilder<NetworkVO> OfferingAccountNetworkSearch;
+
+    GenericSearchBuilder<NetworkVO, Long> GarbageCollectedSearch;
+    
+    
+    
+    @Inject ResourceTagDao _tagsDao;
+    @Inject NetworkAccountDao _accountsDao;
+    @Inject NetworkDomainDao _domainsDao;
+    @Inject NetworkOpDao _opDao;
+    @Inject NetworkServiceMapDao _ntwkSvcMap;
+    @Inject NetworkOfferingDao _ntwkOffDao;
+    @Inject NetworkOpDao _ntwkOpDao;
+
+    TableGenerator _tgMacAddress;
+
+    Random _rand = new Random(System.currentTimeMillis());
+    long _prefix = 0x2;
+
+    public NetworkDaoImpl() {
+    }
+
+    @PostConstruct
+    protected void init() {
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), Op.EQ);
+        AllFieldsSearch.and("cidr", AllFieldsSearch.entity().getCidr(), Op.EQ);
+        AllFieldsSearch.and("broadcastType", AllFieldsSearch.entity().getBroadcastDomainType(), Op.EQ);
+        AllFieldsSearch.and("offering", AllFieldsSearch.entity().getNetworkOfferingId(), Op.EQ);
+        AllFieldsSearch.and("datacenter", AllFieldsSearch.entity().getDataCenterId(), Op.EQ);
+        AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
+        AllFieldsSearch.and("related", AllFieldsSearch.entity().getRelated(), Op.EQ);
+        AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), Op.EQ);
+        AllFieldsSearch.and("physicalNetwork", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ);
+        AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
+        SearchBuilder<NetworkOfferingVO> join1 = _ntwkOffDao.createSearchBuilder();
+        join1.and("isSystem", join1.entity().isSystemOnly(), Op.EQ);
+        join1.and("isRedundant", join1.entity().getRedundantRouter(), Op.EQ);
+        AllFieldsSearch.join("offerings", join1, AllFieldsSearch.entity().getNetworkOfferingId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
+        AllFieldsSearch.done();
+
+        AccountSearch = createSearchBuilder();
+        AccountSearch.and("offering", AccountSearch.entity().getNetworkOfferingId(), Op.EQ);
+        SearchBuilder<NetworkAccountVO> join = _accountsDao.createSearchBuilder();
+        join.and("account", join.entity().getAccountId(), Op.EQ);
+        AccountSearch.join("accounts", join, AccountSearch.entity().getId(), join.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        AccountSearch.and("datacenter", AccountSearch.entity().getDataCenterId(), Op.EQ);
+        AccountSearch.and("cidr", AccountSearch.entity().getCidr(), Op.EQ);
+        AccountSearch.and("vpcId", AccountSearch.entity().getVpcId(), Op.EQ);
+        AccountSearch.done();
+
+        RelatedConfigSearch = createSearchBuilder();
+        RelatedConfigSearch.and("offering", RelatedConfigSearch.entity().getNetworkOfferingId(), Op.EQ);
+        RelatedConfigSearch.and("datacenter", RelatedConfigSearch.entity().getDataCenterId(), Op.EQ);
+        SearchBuilder<NetworkAccountVO> join2 = _accountsDao.createSearchBuilder();
+        join2.and("account", join2.entity().getAccountId(), Op.EQ);
+        RelatedConfigSearch.join("account", join2, join2.entity().getNetworkId(), RelatedConfigSearch.entity().getId(), JoinType.INNER);
+        RelatedConfigSearch.done();
+
+        AccountNetworkSearch = createSearchBuilder();
+        AccountNetworkSearch.and("networkId", AccountNetworkSearch.entity().getId(), Op.EQ);
+        SearchBuilder<NetworkAccountVO> mapJoin = _accountsDao.createSearchBuilder();
+        mapJoin.and("accountId", mapJoin.entity().getAccountId(), Op.EQ);
+        AccountNetworkSearch.join("networkSearch", mapJoin, AccountNetworkSearch.entity().getId(), mapJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        AccountNetworkSearch.done();
+
+        ZoneBroadcastUriSearch = createSearchBuilder();
+        ZoneBroadcastUriSearch.and("dataCenterId", ZoneBroadcastUriSearch.entity().getDataCenterId(), Op.EQ);
+        ZoneBroadcastUriSearch.and("broadcastUri", ZoneBroadcastUriSearch.entity().getBroadcastUri(), Op.EQ);
+        ZoneBroadcastUriSearch.and("guestType", ZoneBroadcastUriSearch.entity().getGuestType(), Op.EQ);
+        ZoneBroadcastUriSearch.done();
+
+        CountByZoneAndURI = createSearchBuilder(Long.class);
+        CountByZoneAndURI.select(null, Func.COUNT, null);
+        CountByZoneAndURI.and("dataCenterId", CountByZoneAndURI.entity().getDataCenterId(), Op.EQ);
+        CountByZoneAndURI.and("broadcastUri", CountByZoneAndURI.entity().getBroadcastUri(), Op.EQ);
+        CountByZoneAndURI.and("guestType", CountByZoneAndURI.entity().getGuestType(), Op.EQ);
+
+        CountByZoneAndURI.done();
+        
+        ZoneSecurityGroupSearch = createSearchBuilder();
+        ZoneSecurityGroupSearch.and("dataCenterId", ZoneSecurityGroupSearch.entity().getDataCenterId(), Op.EQ);
+        SearchBuilder<NetworkServiceMapVO> offJoin = _ntwkSvcMap.createSearchBuilder();
+        offJoin.and("service", offJoin.entity().getService(), Op.EQ);
+        ZoneSecurityGroupSearch.join("services", offJoin, ZoneSecurityGroupSearch.entity().getId(), offJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        ZoneSecurityGroupSearch.done();
+
+        CountBy = createSearchBuilder(Integer.class);
+        CountBy.select(null, Func.COUNT, CountBy.entity().getId());
+        CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ);
+        CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ);
+        CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
+        CountBy.done();
+
+        PhysicalNetworkSearch = createSearchBuilder();
+        PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        PhysicalNetworkSearch.done();
+
+        SecurityGroupSearch = createSearchBuilder();
+        SearchBuilder<NetworkServiceMapVO> join3 = _ntwkSvcMap.createSearchBuilder();
+        join3.and("service", join3.entity().getService(), Op.EQ);
+        SecurityGroupSearch.join("services", join3, SecurityGroupSearch.entity().getId(), join3.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        SecurityGroupSearch.done();
+        
+        NetworksCount = createSearchBuilder(Integer.class);
+        NetworksCount.select(null, Func.COUNT, NetworksCount.entity().getId());
+        NetworksCount.and("networkOfferingId", NetworksCount.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+        NetworksCount.done();
+        
+        NetworksRegularUserCanCreateSearch = createSearchBuilder(Long.class);
+        NetworksRegularUserCanCreateSearch.and("aclType", NetworksRegularUserCanCreateSearch.entity().getAclType(), Op.EQ);
+        NetworksRegularUserCanCreateSearch.select(null, Func.COUNT, NetworksRegularUserCanCreateSearch.entity().getId());
+        SearchBuilder<NetworkAccountVO> join4 = _accountsDao.createSearchBuilder();
+        join4.and("account", join4.entity().getAccountId(), Op.EQ);
+        join4.and("isOwner", join4.entity().isOwner(), Op.EQ);
+        NetworksRegularUserCanCreateSearch.join("accounts", join4, NetworksRegularUserCanCreateSearch.entity().getId(), join4.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        SearchBuilder<NetworkOfferingVO> join5 = _ntwkOffDao.createSearchBuilder();
+        join5.and("specifyVlan", join5.entity().getSpecifyVlan(), Op.EQ);
+        NetworksRegularUserCanCreateSearch.join("ntwkOff", join5, NetworksRegularUserCanCreateSearch.entity().getNetworkOfferingId(), join5.entity().getId(), JoinBuilder.JoinType.INNER);    
+        NetworksRegularUserCanCreateSearch.done();
+
+        _tgMacAddress = _tgs.get("macAddress");
+        
+        SourceNATSearch = createSearchBuilder();
+        SourceNATSearch.and("account", SourceNATSearch.entity().getAccountId(), Op.EQ);
+        SourceNATSearch.and("datacenter", SourceNATSearch.entity().getDataCenterId(), Op.EQ);
+        SourceNATSearch.and("guestType", SourceNATSearch.entity().getGuestType(), Op.EQ);
+        SearchBuilder<NetworkServiceMapVO> join6 = _ntwkSvcMap.createSearchBuilder();
+        join6.and("service", join6.entity().getService(), Op.EQ);
+        SourceNATSearch.join("services", join6, SourceNATSearch.entity().getId(), join6.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        SourceNATSearch.done();
+        
+        VpcNetworksCount = createSearchBuilder(Long.class);
+        VpcNetworksCount.and("vpcId", VpcNetworksCount.entity().getVpcId(), Op.EQ);
+        VpcNetworksCount.select(null, Func.COUNT, VpcNetworksCount.entity().getId());
+        VpcNetworksCount.done();
+
+        OfferingAccountNetworkSearch = createSearchBuilder();
+        OfferingAccountNetworkSearch.select(null, Func.DISTINCT, OfferingAccountNetworkSearch.entity().getId());
+        SearchBuilder<NetworkOfferingVO> ntwkOfferingJoin = _ntwkOffDao.createSearchBuilder();
+        ntwkOfferingJoin.and("isSystem", ntwkOfferingJoin.entity().isSystemOnly(), Op.EQ);
+        OfferingAccountNetworkSearch.join("ntwkOfferingSearch", ntwkOfferingJoin, OfferingAccountNetworkSearch.entity().getNetworkOfferingId(), ntwkOfferingJoin.entity().getId(), JoinBuilder.JoinType.LEFT);
+        SearchBuilder<NetworkAccountVO> ntwkAccountJoin = _accountsDao.createSearchBuilder();
+        ntwkAccountJoin.and("accountId", ntwkAccountJoin.entity().getAccountId(), Op.EQ);
+        OfferingAccountNetworkSearch.join("ntwkAccountSearch", ntwkAccountJoin, OfferingAccountNetworkSearch.entity().getId(), ntwkAccountJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+        OfferingAccountNetworkSearch.and("zoneId", OfferingAccountNetworkSearch.entity().getDataCenterId(), Op.EQ);
+        OfferingAccountNetworkSearch.and("type", OfferingAccountNetworkSearch.entity().getGuestType(), Op.EQ);
+        OfferingAccountNetworkSearch.done();
+
+        GarbageCollectedSearch = createSearchBuilder(Long.class);
+        GarbageCollectedSearch.selectField(GarbageCollectedSearch.entity().getId());
+        SearchBuilder<NetworkOpVO> join7 = _ntwkOpDao.createSearchBuilder();
+        join7.and("activenics", join7.entity().getActiveNicsCount(), Op.EQ);
+        join7.and("gc", join7.entity().isGarbageCollected(), Op.EQ);
+        join7.and("check", join7.entity().isCheckForGc(), Op.EQ);
+        GarbageCollectedSearch.join("ntwkOpGC", join7, GarbageCollectedSearch.entity().getId(), join7.entity().getId(), JoinBuilder.JoinType.INNER);
+        SearchBuilder<NetworkOfferingVO> join8 = _ntwkOffDao.createSearchBuilder();
+        join8.and("isPersistent", join8.entity().getIsPersistent(), Op.EQ);
+        GarbageCollectedSearch.join("ntwkOffGC", join8, GarbageCollectedSearch.entity().getNetworkOfferingId(), join8.entity().getId(), JoinBuilder.JoinType.INNER);
+        GarbageCollectedSearch.done();
+
+    }
+
+    @Override
+    public List<NetworkVO> listByZoneAndGuestType(long accountId, long dataCenterId, Network.GuestType type, Boolean isSystem) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("datacenter", dataCenterId);
+        sc.setParameters("account", accountId);
+        if (type != null) {
+            sc.setParameters("guestType", type);
+        }
+        
+        if (isSystem != null) {
+            sc.setJoinParameters("offerings", "isSystem", isSystem);
+        }
+        
+        return listBy(sc, null);
+    }
+
+    public List<NetworkVO> findBy(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastType, long networkOfferingId, long dataCenterId) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("trafficType", trafficType);
+        sc.setParameters("broadcastType", broadcastType);
+        sc.setParameters("offering", networkOfferingId);
+        sc.setParameters("datacenter", dataCenterId);
+
+        return search(sc, null);
+    }
+
+    @Override
+    public List<NetworkVO> listBy(long accountId, long offeringId, long dataCenterId) {
+        SearchCriteria<NetworkVO> sc = AccountSearch.create();
+        sc.setParameters("offering", offeringId);
+        sc.setJoinParameters("accounts", "account", accountId);
+        sc.setParameters("datacenter", dataCenterId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<NetworkVO> listBy(long accountId, long dataCenterId, String cidr, boolean skipVpc) {
+        SearchCriteria<NetworkVO> sc = AccountSearch.create();
+        sc.setJoinParameters("accounts", "account", accountId);
+        sc.setParameters("datacenter", dataCenterId);
+        sc.setParameters("cidr", cidr);
+        if (skipVpc) {
+            sc.setParameters("vpcId", (Object)null);
+        }
+
+        return listBy(sc);
+    }
+
+    @Override
+    @DB
+    public NetworkVO persist(NetworkVO network, boolean gc, Map<String, String> serviceProviderMap) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        // 1) create network
+        NetworkVO newNetwork = super.persist(network);
+        // 2) add account to the network
+        addAccountToNetwork(network.getId(), network.getAccountId(), true);
+        // 3) add network to gc monitor table
+        NetworkOpVO op = new NetworkOpVO(network.getId(), gc);
+        _opDao.persist(op);
+        // 4) add services/providers for the network
+        persistNetworkServiceProviders(newNetwork.getId(), serviceProviderMap);
+
+        txn.commit();
+        return newNetwork;
+    }
+
+    @Override
+    @DB
+    public boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        super.update(networkId, network);
+        if (serviceProviderMap != null) {
+            _ntwkSvcMap.deleteByNetworkId(networkId);
+            persistNetworkServiceProviders(networkId, serviceProviderMap);
+        }
+
+        txn.commit();
+        return true;
+    }
+
+    @Override
+    @DB
+    public void persistNetworkServiceProviders(long networkId, Map<String, String> serviceProviderMap) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        for (String service : serviceProviderMap.keySet()) {
+            NetworkServiceMapVO serviceMap = new NetworkServiceMapVO(networkId, Service.getService(service), Provider.getProvider(serviceProviderMap.get(service)));
+            _ntwkSvcMap.persist(serviceMap);
+        }
+        txn.commit();
+    }
+
+    protected void addAccountToNetwork(long networkId, long accountId, boolean isOwner) {
+        NetworkAccountVO account = new NetworkAccountVO(networkId, accountId, isOwner);
+        _accountsDao.persist(account);
+    }
+
+    @Override
+    public SearchBuilder<NetworkAccountVO> createSearchBuilderForAccount() {
+        return _accountsDao.createSearchBuilder();
+    }
+
+    @Override
+    public List<NetworkVO> getNetworksForOffering(long offeringId, long dataCenterId, long accountId) {
+        SearchCriteria<NetworkVO> sc = RelatedConfigSearch.create();
+        sc.setParameters("offering", offeringId);
+        sc.setParameters("dc", dataCenterId);
+        sc.setJoinParameters("account", "account", accountId);
+        return search(sc, null);
+    }
+
+    @Override
+    public String getNextAvailableMacAddress(long networkConfigId) {
+        SequenceFetcher fetch = SequenceFetcher.getInstance();
+
+        long seq = fetch.getNextSequence(Long.class, _tgMacAddress, networkConfigId);
+        seq = seq | _prefix << 40 | ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
+        return NetUtils.long2Mac(seq);
+    }
+
+    @Override
+    public List<NetworkVO> listBy(long accountId, long networkId) {
+        SearchCriteria<NetworkVO> sc = AccountNetworkSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setJoinParameters("networkSearch", "accountId", accountId);
+        return listBy(sc);
+    }
+
+    @Override
+    public long countByZoneAndUri(long zoneId, String broadcastUri) {
+
+        SearchCriteria<Long> sc = CountByZoneAndURI.create();
+        sc.setParameters("dataCenterId", zoneId);
+        sc.setParameters("broadcastUri", broadcastUri);
+        
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public List<NetworkVO> listByZone(long zoneId) {
+        SearchCriteria<NetworkVO> sc = ZoneBroadcastUriSearch.create();
+        sc.setParameters("dataCenterId", zoneId);
+        return search(sc, null);
+    }
+
+    @Override
+    public long countByZoneUriAndGuestType(long zoneId, String broadcastUri, GuestType guestType) {
+        SearchCriteria<Long> sc = CountByZoneAndURI.create();
+        sc.setParameters("dataCenterId", zoneId);
+        sc.setParameters("broadcastUri", broadcastUri);
+        sc.setParameters("guestType", guestType);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public List<NetworkVO> listByZoneSecurityGroup(Long zoneId) {
+        SearchCriteria<NetworkVO> sc = ZoneSecurityGroupSearch.create();
+        if (zoneId != null) {
+            sc.setParameters("dataCenterId", zoneId);
+        }
+        sc.setJoinParameters("services", "service", Service.SecurityGroup.getName());
+        return search(sc, null);
+    }
+
+    @Override
+    public void changeActiveNicsBy(long networkId, int count) {
+        _opDao.changeActiveNicsBy(networkId, count);
+    }
+
+    @Override
+    public int getActiveNicsIn(long networkId) {
+        return _opDao.getActiveNics(networkId);
+    }
+
+    @Override
+    public List<Long> findNetworksToGarbageCollect() {
+        SearchCriteria<Long> sc = GarbageCollectedSearch.create();
+        sc.setJoinParameters("ntwkOffGC", "isPersistent", false);
+        sc.setJoinParameters("ntwkOpGC", "activenics", 0);
+        sc.setJoinParameters("ntwkOpGC", "gc", true);
+        sc.setJoinParameters("ntwkOpGC", "check", true);
+        return customSearch(sc, null);
+    }
+
+    @Override
+    public void clearCheckForGc(long networkId) {
+        _opDao.clearCheckForGc(networkId);
+    }
+    
+    @Override
+    public void setCheckForGc(long networkId) {
+        _opDao.setCheckForGc(networkId);
+    }
+
+    @Override
+    public List<NetworkVO> listByOwner(long ownerId) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("account", ownerId);
+        return listBy(sc);
+    }
+
+    @Override
+    public void addDomainToNetwork(long networkId, long domainId, Boolean subdomainAccess) {
+        addDomainToNetworknetwork(networkId, domainId, subdomainAccess);
+    }
+
+    protected void addDomainToNetworknetwork(long networkId, long domainId, Boolean subdomainAccess) {
+        NetworkDomainVO domain = new NetworkDomainVO(networkId, domainId, subdomainAccess);
+        _domainsDao.persist(domain);
+    }
+    
+    
+    @Override
+    public int getNetworkCountByVpcId(long vpcId) {
+        SearchCriteria<Integer> sc = CountBy.create();
+        sc.setParameters("vpcId", vpcId);
+        List<Integer> results = customSearch(sc, null);
+        return results.get(0);
+    }
+    
+
+    @Override
+    public List<NetworkVO> listSecurityGroupEnabledNetworks() {
+        SearchCriteria<NetworkVO> sc = SecurityGroupSearch.create();
+        sc.setJoinParameters("services", "service", Service.SecurityGroup.getName());
+        return listBy(sc);
+    }
+
+    @Override
+    public List<NetworkVO> listByPhysicalNetwork(long physicalNetworkId) {
+        SearchCriteria<NetworkVO> sc = PhysicalNetworkSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<NetworkVO> listByPhysicalNetworkTrafficType(long physicalNetworkId, TrafficType trafficType) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("trafficType", trafficType);
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<NetworkVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String providerName) {
+        SearchBuilder<NetworkServiceMapVO> svcProviderMapSearch = _ntwkSvcMap.createSearchBuilder();
+        NetworkServiceMapVO svcProviderEntry = svcProviderMapSearch.entity();
+        svcProviderMapSearch.and("Provider", svcProviderMapSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+
+        SearchBuilder<NetworkVO> networksSearch = createSearchBuilder();
+        networksSearch.and("physicalNetworkId", networksSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        networksSearch.join("svcProviderMapSearch", svcProviderMapSearch, networksSearch.entity().getId(), svcProviderEntry.getNetworkId(), JoinBuilder.JoinType.INNER);
+
+        SearchCriteria<NetworkVO> sc = networksSearch.create();
+        sc.setJoinParameters("svcProviderMapSearch", "Provider", providerName);
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type, TrafficType trafficType) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("datacenter", dataCenterId);
+        sc.setParameters("account", accountId);
+        sc.setParameters("guestType", type);
+        sc.setParameters("trafficType", trafficType);
+
+        return listBy(sc, null);
+    }
+
+    @Override
+    public List<NetworkVO> listByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("datacenter", zoneId);
+        sc.setParameters("trafficType", trafficType);
+
+        return listBy(sc, null);
+    }
+    
+    @Override
+    public int getNetworkCountByNetworkOffId(long networkOfferingId) {
+        SearchCriteria<Integer> sc = NetworksCount.create();
+        sc.setParameters("networkOfferingId", networkOfferingId);
+        List<Integer> count = customSearch(sc, null);
+        return count.get(0);
+    }
+    
+    @Override
+    public long countNetworksUserCanCreate(long ownerId) {
+        SearchCriteria<Long> sc = NetworksRegularUserCanCreateSearch.create();
+        sc.setParameters("aclType", ACLType.Account);
+        sc.setJoinParameters("accounts", "account", ownerId);
+        sc.setJoinParameters("ntwkOff", "specifyVlan", false);
+        return customSearch(sc, null).get(0);
+    }
+    
+    
+    @Override
+    public List<NetworkVO> listSourceNATEnabledNetworks(long accountId, long dataCenterId, Network.GuestType type) {
+        SearchCriteria<NetworkVO> sc = SourceNATSearch.create();
+        sc.setParameters("datacenter", dataCenterId);
+        sc.setParameters("account", accountId);
+        sc.setParameters("guestType", type);
+        sc.setJoinParameters("services", "service", Service.SourceNat.getName());
+        return listBy(sc);
+    }
+    
+    @Override
+    public List<NetworkVO> listByVpc(long vpcId) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("vpcId", vpcId);
+
+        return listBy(sc, null);
+    }
+
+
+    @Override
+    public NetworkVO getPrivateNetwork(String broadcastUri, String cidr, long accountId, long zoneId) {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setParameters("datacenter", zoneId);
+        sc.setParameters("broadcastUri", broadcastUri);
+        sc.setParameters("cidr", cidr);
+        sc.setParameters("account", accountId);
+        sc.setParameters("offering", _ntwkOffDao.findByUniqueName(NetworkOffering.SystemPrivateGatewayNetworkOffering).getId());
+        return findOneBy(sc);
+    }
+
+    @Override
+    @DB
+    public boolean remove(Long id) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        NetworkVO entry = findById(id);
+        if (entry != null) {
+            _tagsDao.removeByIdAndType(id, TaggedResourceType.Network);
+        }
+        boolean result = super.remove(id);
+        txn.commit();
+        return result;
+    }
+
+    @Override
+    public long countVpcNetworks(long vpcId) {
+        SearchCriteria<Long> sc = VpcNetworksCount.create();
+        sc.setParameters("vpcId", vpcId);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public boolean updateState(State currentState, Event event, State nextState, Network vo, Object data) {
+       // TODO: ensure this update is correct
+       Transaction txn = Transaction.currentTxn();
+       txn.start();
+
+       NetworkVO networkVo = (NetworkVO) vo;
+       networkVo.setState(nextState);
+       super.update(networkVo.getId(), networkVo);
+
+       txn.commit();
+       return true;
+    }
+
+    @Override
+    public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType type, boolean isSystem) {
+        SearchCriteria<NetworkVO> sc = OfferingAccountNetworkSearch.create();
+        sc.setJoinParameters("ntwkOfferingSearch", "isSystem", isSystem);
+        sc.setJoinParameters("ntwkAccountSearch", "accountId", accountId);
+        sc.setParameters("zoneId", zoneId);
+        sc.setParameters("type", type);
+
+        List<NetworkVO> networks = search(sc, null);
+        return networks;
+    }
+
+    @Override
+    public List<NetworkVO> listRedundantNetworks() {
+        SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
+        sc.setJoinParameters("offerings", "isRedundant", true);
+        return listBy(sc, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkDomainDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDomainDao.java b/engine/schema/src/com/cloud/network/dao/NetworkDomainDao.java
new file mode 100644
index 0000000..6689892
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDomainDao.java
@@ -0,0 +1,27 @@
+// 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 NetworkDomainDao extends GenericDao<NetworkDomainVO, Long>{
+    List<NetworkDomainVO> listDomainNetworkMapByDomain(Object... domainId);
+    NetworkDomainVO getDomainNetworkMapByNetworkId(long networkId);
+    List<Long> listNetworkIdsByDomain(long domainId);
+}


Mime
View raw message