cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [41/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:57 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkDomainDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDomainDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkDomainDaoImpl.java
new file mode 100644
index 0000000..bbb9203
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDomainDaoImpl.java
@@ -0,0 +1,75 @@
+// 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.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value=NetworkDomainDao.class) @DB(txn=false)
+public class NetworkDomainDaoImpl extends GenericDaoBase<NetworkDomainVO, Long> implements NetworkDomainDao {
+    final SearchBuilder<NetworkDomainVO> AllFieldsSearch;
+    final SearchBuilder<NetworkDomainVO> DomainsSearch;
+    
+    protected NetworkDomainDaoImpl() {
+        super();
+        
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), Op.EQ);
+        AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
+        AllFieldsSearch.done();
+        
+        DomainsSearch = createSearchBuilder();
+        DomainsSearch.and("domainId", DomainsSearch.entity().getDomainId(), Op.IN);
+        DomainsSearch.done();
+    }
+    
+    @Override
+    public List<NetworkDomainVO> listDomainNetworkMapByDomain(Object... domainId) {
+        SearchCriteria<NetworkDomainVO> sc = DomainsSearch.create();
+        sc.setParameters("domainId", (Object[])domainId);
+        
+        return listBy(sc);
+    }
+    
+    @Override
+    public NetworkDomainVO getDomainNetworkMapByNetworkId(long networkId) {
+        SearchCriteria<NetworkDomainVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public List<Long> listNetworkIdsByDomain(long domainId) {
+        List<Long> networkIdsToReturn = new ArrayList<Long>();
+        List<NetworkDomainVO> maps = listDomainNetworkMapByDomain(domainId);
+        for (NetworkDomainVO map : maps) {
+            networkIdsToReturn.add(map.getNetworkId());
+        } 
+        return networkIdsToReturn;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkDomainVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkDomainVO.java b/engine/schema/src/com/cloud/network/dao/NetworkDomainVO.java
new file mode 100644
index 0000000..bb4e904
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkDomainVO.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.domain.PartOf;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="domain_network_ref")
+public class NetworkDomainVO implements PartOf, InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    long id;
+    
+    @Column(name="domain_id")
+    long domainId;
+    
+    @Column(name="network_id")
+    long networkId;
+    
+    @Column(name="subdomain_access")
+    public
+    Boolean subdomainAccess;
+
+    protected NetworkDomainVO() {
+    }
+    
+    public NetworkDomainVO(long networkId, long domainId, Boolean subdomainAccess) {
+        this.networkId = networkId;
+        this.domainId = domainId;
+        this.subdomainAccess = subdomainAccess;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+    
+    public long getNetworkId() {
+        return networkId;
+    }
+
+	public Boolean isSubdomainAccess() {
+		return subdomainAccess;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDao.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDao.java
new file mode 100644
index 0000000..9e255dc
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDao.java
@@ -0,0 +1,38 @@
+// 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 NetworkExternalFirewallDao extends GenericDao<NetworkExternalFirewallVO, Long> {
+
+    /**
+     * find the network to firewall device mapping corresponding to a network
+     * @param lbDeviceId guest network Id
+     * @return return NetworkExternalFirewallDao for the guest network
+     */    
+    NetworkExternalFirewallVO findByNetworkId(long networkId);
+
+    /**
+     * list all network to firewall device mappings corresponding to a firewall device Id
+     * @param lbDeviceId firewall device Id
+     * @return list of NetworkExternalFirewallVO mappings corresponding to the networks mapped to the firewall device 
+     */    
+    List<NetworkExternalFirewallVO> listByFirewallDeviceId(long lbDeviceId);	
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDaoImpl.java
new file mode 100644
index 0000000..b176760
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallDaoImpl.java
@@ -0,0 +1,61 @@
+// 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.DB;
+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=NetworkExternalFirewallDao.class) @DB(txn=false)
+public class NetworkExternalFirewallDaoImpl extends GenericDaoBase<NetworkExternalFirewallVO, Long> implements NetworkExternalFirewallDao {
+
+    final SearchBuilder<NetworkExternalFirewallVO> networkIdSearch;
+    final SearchBuilder<NetworkExternalFirewallVO> deviceIdSearch;
+    protected NetworkExternalFirewallDaoImpl() {
+        super();
+        networkIdSearch = createSearchBuilder();
+        networkIdSearch.and("networkId", networkIdSearch.entity().getNetworkId(), Op.EQ);
+        networkIdSearch.done();
+        deviceIdSearch = createSearchBuilder();
+        deviceIdSearch.and("externalFWDeviceId", deviceIdSearch.entity().getExternalFirewallDeviceId(), Op.EQ);
+        deviceIdSearch.done();
+    }
+
+    @Override
+    public NetworkExternalFirewallVO findByNetworkId(long networkId) {
+        SearchCriteria<NetworkExternalFirewallVO> sc = networkIdSearch.create();
+        sc.setParameters("networkId", networkId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<NetworkExternalFirewallVO> listByFirewallDeviceId(long fwDeviceId) {
+        SearchCriteria<NetworkExternalFirewallVO> sc = deviceIdSearch.create();
+        sc.setParameters("externalFWDeviceId", fwDeviceId);
+        return search(sc, null);
+    }    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallVO.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallVO.java
new file mode 100644
index 0000000..3c33dd5
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalFirewallVO.java
@@ -0,0 +1,88 @@
+// 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.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+/**
+ * NetworkExternalFirewallVO contains information on the networks that are using external firewall
+  */
+
+@Entity
+@Table(name="network_external_firewall_device_map")
+public class NetworkExternalFirewallVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name="uuid")
+    private String uuid;
+
+    @Column(name = "network_id")
+    private long networkId;
+
+    @Column(name = "external_firewall_device_id")
+    private long externalFirewallDeviceId;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    Date created;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    public NetworkExternalFirewallVO(long networkId, long externalFirewallDeviceId) {
+        this.networkId = networkId;
+        this.externalFirewallDeviceId = externalFirewallDeviceId;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public NetworkExternalFirewallVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public long getExternalFirewallDeviceId() {
+        return externalFirewallDeviceId;
+    }
+
+    public String getUuid() {
+        return 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/NetworkExternalLoadBalancerDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDao.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDao.java
new file mode 100644
index 0000000..527d376
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDao.java
@@ -0,0 +1,38 @@
+// 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  NetworkExternalLoadBalancerDao extends GenericDao<NetworkExternalLoadBalancerVO, Long> {
+
+    /**
+     * find the network to load balancer device mapping corresponding to a network
+     * @param networkId guest network Id
+     * @return return NetworkExternalLoadBalancerVO for the guest network
+     */
+    NetworkExternalLoadBalancerVO findByNetworkId(long networkId);
+
+    /**
+     * list all network to load balancer device mappings corresponding to a load balancer device Id
+     * @param lbDeviceId load balancer device Id
+     * @return list of NetworkExternalLoadBalancerVO mappings corresponding to the networks mapped to the load balancer device 
+     */
+    List<NetworkExternalLoadBalancerVO> listByLoadBalancerDeviceId(long lbDeviceId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDaoImpl.java
new file mode 100644
index 0000000..c29c164
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerDaoImpl.java
@@ -0,0 +1,62 @@
+// 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.DB;
+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=NetworkExternalLoadBalancerDao.class) @DB(txn=false)
+public class NetworkExternalLoadBalancerDaoImpl extends GenericDaoBase<NetworkExternalLoadBalancerVO, Long> implements NetworkExternalLoadBalancerDao {
+
+    final SearchBuilder<NetworkExternalLoadBalancerVO> networkIdSearch;
+    final SearchBuilder<NetworkExternalLoadBalancerVO> deviceIdSearch;
+    
+    protected NetworkExternalLoadBalancerDaoImpl() {
+        super();
+        networkIdSearch = createSearchBuilder();
+        networkIdSearch.and("networkId", networkIdSearch.entity().getNetworkId(), Op.EQ);
+        networkIdSearch.done();
+
+        deviceIdSearch = createSearchBuilder();
+        deviceIdSearch.and("externalLBDeviceId", deviceIdSearch.entity().getExternalLBDeviceId(), Op.EQ);
+        deviceIdSearch.done();
+    }
+
+    @Override
+    public NetworkExternalLoadBalancerVO findByNetworkId(long networkId) {
+        SearchCriteria<NetworkExternalLoadBalancerVO> sc = networkIdSearch.create();
+        sc.setParameters("networkId", networkId);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public List<NetworkExternalLoadBalancerVO> listByLoadBalancerDeviceId(long lbDeviceId) {
+        SearchCriteria<NetworkExternalLoadBalancerVO> sc = deviceIdSearch.create();
+        sc.setParameters("externalLBDeviceId", lbDeviceId);
+        return search(sc, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerVO.java b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerVO.java
new file mode 100644
index 0000000..820759c
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkExternalLoadBalancerVO.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 java.util.Date;
+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.Table;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+/**
+ * NetworkExternalLoadBalancerVO contains mapping of a network and the external load balancer device id assigned to the network
+  */
+
+@Entity
+@Table(name="network_external_lb_device_map")
+public class NetworkExternalLoadBalancerVO implements InternalIdentity {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name="uuid")
+    private String uuid;
+
+    @Column(name = "network_id")
+    private long networkId;
+
+    @Column(name = "external_load_balancer_device_id")
+    private long externalLBDeviceId;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    Date created;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    public NetworkExternalLoadBalancerVO(long networkId, long externalLBDeviceID) {
+        this.networkId = networkId;
+        this.externalLBDeviceId = externalLBDeviceID;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public NetworkExternalLoadBalancerVO(){
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public long getExternalLBDeviceId() {
+        return externalLBDeviceId;
+    }
+
+    public String getUuid() {
+        return 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/NetworkOpDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkOpDao.java b/engine/schema/src/com/cloud/network/dao/NetworkOpDao.java
new file mode 100644
index 0000000..f492dbd
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkOpDao.java
@@ -0,0 +1,26 @@
+// 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 NetworkOpDao extends GenericDao<NetworkOpVO, Long> {
+    public int getActiveNics(long networkId);
+    public void changeActiveNicsBy(long networkId, int count);
+    public void setCheckForGc(long networkId);
+    public void clearCheckForGc(long networkId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkOpDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkOpDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkOpDaoImpl.java
new file mode 100644
index 0000000..a3f54b7
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkOpDaoImpl.java
@@ -0,0 +1,84 @@
+// 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 org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.Attribute;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.UpdateBuilder;
+
+@Component
+public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implements NetworkOpDao {
+    protected final SearchBuilder<NetworkOpVO> AllFieldsSearch;
+    protected final GenericSearchBuilder<NetworkOpVO, Integer> ActiveNicsSearch;
+    protected final Attribute _activeNicsAttribute;
+    
+    protected NetworkOpDaoImpl() {
+        super();
+        
+        ActiveNicsSearch = createSearchBuilder(Integer.class);
+        ActiveNicsSearch.selectField(ActiveNicsSearch.entity().getActiveNicsCount());
+        ActiveNicsSearch.and("network", ActiveNicsSearch.entity().getId(), Op.EQ);
+        ActiveNicsSearch.done();
+        
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("network", AllFieldsSearch.entity().getId(), Op.EQ);
+        AllFieldsSearch.done();
+
+        _activeNicsAttribute = _allAttributes.get("activeNicsCount");
+        assert _activeNicsAttribute != null : "Cannot find activeNicsCount";
+    }
+
+    public int getActiveNics(long networkId) {
+        SearchCriteria<Integer> sc = ActiveNicsSearch.create();
+        sc.setParameters("network", networkId);
+        
+        return customSearch(sc, null).get(0);
+    }
+    
+    public void changeActiveNicsBy(long networkId, int count) {
+        
+        SearchCriteria<NetworkOpVO> sc = AllFieldsSearch.create();
+        sc.setParameters("network", networkId);
+
+        NetworkOpVO vo = createForUpdate();
+        UpdateBuilder builder = getUpdateBuilder(vo);
+        builder.incr(_activeNicsAttribute, count);
+        
+        update(builder, sc, null);
+    }
+    
+    public void setCheckForGc(long networkId) {
+        NetworkOpVO vo = createForUpdate();
+        vo.setCheckForGc(true);
+        update(networkId, vo);
+    }
+    
+    public void clearCheckForGc(long networkId) {
+        NetworkOpVO vo = createForUpdate();
+        vo.setCheckForGc(false);
+        update(networkId, vo);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkOpVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkOpVO.java b/engine/schema/src/com/cloud/network/dao/NetworkOpVO.java
new file mode 100644
index 0000000..8d41727
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkOpVO.java
@@ -0,0 +1,76 @@
+// 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.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="op_networks")
+public class NetworkOpVO implements InternalIdentity {
+    
+    @Id
+    @Column(name="id")
+    long id;
+    
+    @Column(name="nics_count")
+    int activeNicsCount;
+    
+    @Column(name="gc")
+    boolean garbageCollected;
+    
+    @Column(name="check_for_gc")
+    boolean checkForGc;
+
+    protected NetworkOpVO() {
+    }
+    
+    public NetworkOpVO(long id, boolean gc) {
+        this.id = id;
+        this.garbageCollected = gc;
+        this.checkForGc = gc;
+        this.activeNicsCount = 0;
+    }
+    
+    public long getId() {
+        return id;
+    }
+    
+    public long getActiveNicsCount() {
+        return activeNicsCount;
+    }
+    
+    public void setActiveNicsCount(int number) {
+        activeNicsCount += number;
+    }
+    
+    public boolean isGarbageCollected() {
+        return garbageCollected;
+    }
+    
+    public boolean isCheckForGc() {
+        return checkForGc;
+    }
+    
+    public void setCheckForGc(boolean check) {
+        checkForGc = check;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDao.java b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDao.java
new file mode 100644
index 0000000..80e070a
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDao.java
@@ -0,0 +1,26 @@
+// 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 NetworkRuleConfigDao extends GenericDao<NetworkRuleConfigVO, Long> {
+    List<NetworkRuleConfigVO> listBySecurityGroupId(long securityGroupId);
+    void deleteBySecurityGroup(long securityGroupId);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDaoImpl.java
new file mode 100644
index 0000000..a5af4fe
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigDaoImpl.java
@@ -0,0 +1,51 @@
+// 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value={NetworkRuleConfigDao.class})
+public class NetworkRuleConfigDaoImpl extends GenericDaoBase<NetworkRuleConfigVO, Long> implements NetworkRuleConfigDao {
+    protected SearchBuilder<NetworkRuleConfigVO> SecurityGroupIdSearch;
+
+    protected NetworkRuleConfigDaoImpl() {
+        SecurityGroupIdSearch  = createSearchBuilder();
+        SecurityGroupIdSearch.and("securityGroupId", SecurityGroupIdSearch.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
+        SecurityGroupIdSearch.done();
+    }
+
+    public List<NetworkRuleConfigVO> listBySecurityGroupId(long securityGroupId) {
+        SearchCriteria<NetworkRuleConfigVO> sc = SecurityGroupIdSearch.create();
+        sc.setParameters("securityGroupId", securityGroupId);
+        return listBy(sc);
+    }
+
+    public void deleteBySecurityGroup(long securityGroupId) {
+        SearchCriteria<NetworkRuleConfigVO> sc = SecurityGroupIdSearch.create();
+        sc.setParameters("securityGroupId", securityGroupId);
+        expunge(sc);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigVO.java b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigVO.java
new file mode 100644
index 0000000..542c0bb
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkRuleConfigVO.java
@@ -0,0 +1,93 @@
+// 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.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.async.AsyncInstanceCreateStatus;
+import com.google.gson.annotations.Expose;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name=("network_rule_config"))
+public class NetworkRuleConfigVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    private Long id;
+
+    @Column(name="security_group_id")
+    private long securityGroupId;
+
+    @Column(name="public_port")
+    private String publicPort;
+
+    @Column(name="private_port")
+    private String privatePort;
+
+    @Column(name="protocol")
+    private String protocol;
+    
+    @Expose
+    @Column(name="create_status", updatable = true, nullable=false)
+    @Enumerated(value=EnumType.STRING)
+    private AsyncInstanceCreateStatus createStatus;
+
+    public NetworkRuleConfigVO() {}
+
+    public NetworkRuleConfigVO(long securityGroupId, String publicPort, String privatePort, String protocol) {
+        this.securityGroupId = securityGroupId;
+        this.publicPort = publicPort;
+        this.privatePort = privatePort;
+        this.protocol = protocol;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getSecurityGroupId() {
+        return securityGroupId;
+    }
+
+    public String getPublicPort() {
+        return publicPort;
+    }
+
+    public String getPrivatePort() {
+        return privatePort;
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+    
+    public AsyncInstanceCreateStatus getCreateStatus() {
+    	return createStatus;
+    }
+    
+    public void setCreateStatus(AsyncInstanceCreateStatus createStatus) {
+    	this.createStatus = createStatus;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDao.java b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDao.java
new file mode 100644
index 0000000..6d401c4
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDao.java
@@ -0,0 +1,39 @@
+// 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.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * NetworkServiceDao deals with searches and operations done on the
+ * ntwk_service_map table.
+ *
+ */
+public interface NetworkServiceMapDao extends GenericDao<NetworkServiceMapVO, Long>{
+    boolean areServicesSupportedInNetwork(long networkId, Service... services);
+    boolean canProviderSupportServiceInNetwork(long networkId, Service service, Provider provider);
+    List<NetworkServiceMapVO> getServicesInNetwork(long networkId);
+    String getProviderForServiceInNetwork(long networkid, Service service);
+	void deleteByNetworkId(long networkId);
+	List<String> getDistinctProviders(long networkId);
+	String isProviderForNetwork(long networkId, Provider provider);
+	List<String> getProvidersForServiceInNetwork(long networkId, Service service);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDaoImpl.java
new file mode 100644
index 0000000..3cdd738
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapDaoImpl.java
@@ -0,0 +1,176 @@
+// 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.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.exception.UnsupportedServiceException;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value=NetworkServiceMapDao.class) @DB(txn=false)
+public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO, Long> implements NetworkServiceMapDao {
+    final SearchBuilder<NetworkServiceMapVO> AllFieldsSearch;
+    final SearchBuilder<NetworkServiceMapVO> MultipleServicesSearch;
+    final GenericSearchBuilder<NetworkServiceMapVO, String> DistinctProvidersSearch;
+    
+    protected NetworkServiceMapDaoImpl() {
+        super();
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.done();
+        
+        MultipleServicesSearch = createSearchBuilder();
+        MultipleServicesSearch.and("networkId", MultipleServicesSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
+        MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        MultipleServicesSearch.done();
+        
+        DistinctProvidersSearch = createSearchBuilder(String.class);
+        DistinctProvidersSearch.and("networkId", DistinctProvidersSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+        DistinctProvidersSearch.and("service", DistinctProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
+        DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
+        DistinctProvidersSearch.done();
+    }
+    
+    @Override
+    public boolean areServicesSupportedInNetwork(long networkId, Service... services) {
+        SearchCriteria<NetworkServiceMapVO> sc = MultipleServicesSearch.create();
+        sc.setParameters("networkId", networkId);
+        
+        if (services != null) {
+            String[] servicesStr = new String[services.length];
+            
+            int i = 0;
+            for (Service service : services) {
+                servicesStr[i] = service.getName();
+                i++;
+            }
+            
+            sc.setParameters("service", (Object[])servicesStr);
+        }
+        
+        List<NetworkServiceMapVO> networkServices = listBy(sc);
+        
+        if (services != null) {
+            if (networkServices.size() == services.length) {
+                return true;
+            }
+        } else if (!networkServices.isEmpty()) {
+            return true;
+        }
+        
+        return false;
+    }
+    
+    @Override
+    public boolean canProviderSupportServiceInNetwork(long networkId, Service service, Provider provider) {
+        SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("service", service.getName());
+        sc.setParameters("provider", provider.getName());
+        if (findOneBy(sc) != null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+    
+    protected List<String> getServicesForProviderInNetwork(long networkId, Provider provider) {
+        List<String> services = new ArrayList<String>();
+        SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("provider", provider.getName());
+        List<NetworkServiceMapVO> map = listBy(sc);
+        for (NetworkServiceMapVO instance : map) {
+            services.add(instance.getService());
+        }
+        
+        return services;
+    }
+    
+    @Override
+    public String getProviderForServiceInNetwork(long networkId, Service service) {
+        SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("service", service.getName());
+        NetworkServiceMapVO ntwkSvc = findOneBy(sc);
+        if (ntwkSvc == null) {
+            throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId);
+        }
+        
+        return ntwkSvc.getProvider();
+    }
+ 
+    @Override
+    public List<NetworkServiceMapVO> getServicesInNetwork(long networkId) {
+        SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        return listBy(sc);
+    }
+    
+    @Override
+    public void deleteByNetworkId(long networkId) {
+        SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
+        sc.setParameters("networkId", networkId);
+        remove(sc);
+    }
+    
+    @Override
+    public List<String> getDistinctProviders(long networkId) {
+        SearchCriteria<String> sc = DistinctProvidersSearch.create();
+        sc.setParameters("networkId", networkId);
+        List<String> results = customSearch(sc, null);
+        return results;
+    }
+    
+    @Override
+    public String isProviderForNetwork(long networkId, Provider provider) {
+    	SearchCriteria<String> sc = DistinctProvidersSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("provider", provider.getName());
+        List<String> results = customSearch(sc, null);
+        if (results.isEmpty()) {
+        	return null;
+        } else {
+        	return results.get(0);
+        }
+    }
+
+    @Override
+    public List<String> getProvidersForServiceInNetwork(long networkId, Service service) {
+        SearchCriteria<String> sc = DistinctProvidersSearch.create();
+        sc.setParameters("networkId", networkId);
+        sc.setParameters("service", service.getName());
+        return customSearch(sc, null);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkServiceMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkServiceMapVO.java b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapVO.java
new file mode 100644
index 0000000..7bb480b
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkServiceMapVO.java
@@ -0,0 +1,92 @@
+// 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 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.network.Network;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="ntwk_service_map")
+public class NetworkServiceMapVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    @Column(name="id")
+    long id;
+    
+    @Column(name="network_id")
+    long networkId;
+    
+    @Column(name="service")
+    String service;
+    
+    @Column(name="provider")
+    String provider;
+    
+    @Column(name=GenericDao.CREATED_COLUMN)
+    Date created;
+
+    public long getId() {
+        return id;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public String getService() {
+        return service;
+    }
+
+    public String getProvider() {
+        return provider;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+    
+    public NetworkServiceMapVO() {
+    }
+    
+    public NetworkServiceMapVO(long networkId, Service service, Provider provider) {
+        this.networkId = networkId;
+        this.service = service.getName();
+        this.provider = provider.getName();
+    }
+    
+    public String toString() {
+        StringBuilder buf = new StringBuilder("[Network Service[");
+        return buf.append(networkId).append("-").append(service).append("-").append(provider).append("]").toString();
+    }
+}
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/NetworkVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkVO.java b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
new file mode 100644
index 0000000..8e728ab
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
@@ -0,0 +1,540 @@
+// 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.net.URI;
+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.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Transient;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.BroadcastDomainType;
+import com.cloud.network.Networks.Mode;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.net.NetUtils;
+
+/**
+ * NetworkConfigurationVO contains information about a specific network.
+ *
+ */
+@Entity
+@Table(name="networks")
+public class NetworkVO implements Network {
+    @Id
+    @TableGenerator(name="networks_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="networks_seq", allocationSize=1)
+    @Column(name="id")
+    long id;
+
+    @Column(name="mode")
+    @Enumerated(value=EnumType.STRING)
+    Mode mode;
+
+    @Column(name="broadcast_domain_type")
+    @Enumerated(value=EnumType.STRING)
+    BroadcastDomainType broadcastDomainType;
+
+    @Column(name="traffic_type")
+    @Enumerated(value=EnumType.STRING)
+    TrafficType trafficType;
+
+    @Column(name="name")
+    String name;
+
+    @Column(name="display_text")
+    String displayText;;
+
+    @Column(name="broadcast_uri")
+    URI broadcastUri;
+
+    @Column(name="gateway")
+    String gateway;
+
+    @Column(name="cidr")
+    String cidr;
+
+    @Column(name="network_cidr")
+    String networkCidr;
+
+    @Column(name="network_offering_id")
+    long networkOfferingId;
+
+    @Column(name="vpc_id")
+    Long vpcId;
+
+    @Column(name="physical_network_id")
+    Long physicalNetworkId;
+
+    @Column(name="data_center_id")
+    long dataCenterId;
+
+    @Column(name="related")
+    long related;
+
+    @Column(name="guru_name")
+    String guruName;
+
+    @Column(name="state")
+    @Enumerated(value=EnumType.STRING)
+    State state;
+
+    @Column(name="dns1")
+    String dns1;
+
+    @Column(name="domain_id")
+    long domainId;
+
+    @Column(name="account_id")
+    long accountId;
+
+    @Column(name="set_fields")
+    long setFields;
+
+    @TableGenerator(name="mac_address_seq", table="op_networks", pkColumnName="id", valueColumnName="mac_address_seq", allocationSize=1)
+    @Transient
+    long macAddress = 1;
+
+    @Column(name="guru_data", length=1024)
+    String guruData;
+
+    @Column(name="dns2")
+    String dns2;
+
+    @Column(name="network_domain")
+    String networkDomain;
+
+    @Column(name=GenericDao.REMOVED_COLUMN)
+    Date removed;
+
+    @Column(name=GenericDao.CREATED_COLUMN)
+    Date created;
+
+    @Column(name="reservation_id")
+    String reservationId;
+
+    @Column(name="uuid")
+    String uuid;
+
+    @Column(name="guest_type")
+    @Enumerated(value=EnumType.STRING)
+    Network.GuestType guestType;
+
+    @Column(name="acl_type")
+    @Enumerated(value=EnumType.STRING)
+    ControlledEntity.ACLType aclType;
+
+    @Column(name="restart_required")
+    boolean restartRequired = false;
+
+    @Column(name="specify_ip_ranges")
+    boolean specifyIpRanges = false;
+
+    @Column(name="ip6_gateway")
+    String ip6Gateway;
+
+    @Column(name="ip6_cidr")
+    String ip6Cidr;
+
+    public NetworkVO() {
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    /**
+     * Constructor to be used for the adapters because it only initializes what's needed.
+     * @param trafficType
+     * @param mode
+     * @param broadcastDomainType
+     * @param networkOfferingId
+     * @param state TODO
+     * @param dataCenterId
+     * @param physicalNetworkId TODO
+     */
+    public NetworkVO(TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId,
+            State state, long dataCenterId, Long physicalNetworkId) {
+        this.trafficType = trafficType;
+        this.mode = mode;
+        this.broadcastDomainType = broadcastDomainType;
+        this.networkOfferingId = networkOfferingId;
+        this.dataCenterId = dataCenterId;
+        this.physicalNetworkId = physicalNetworkId;
+        if (state == null) {
+            state = State.Allocated;
+        } else {
+            this.state = state;
+        }
+        this.id = -1;
+    	this.uuid = UUID.randomUUID().toString();
+    }
+
+    public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId,
+            long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId,
+            Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
+        this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId,
+                related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges, vpcId);
+        this.gateway = that.getGateway();
+        this.cidr = that.getCidr();
+        this.networkCidr = that.getNetworkCidr();
+        this.broadcastUri = that.getBroadcastUri();
+        this.broadcastDomainType = that.getBroadcastDomainType();
+        this.guruName = guruName;
+        this.state = that.getState();
+        if (state == null) {
+            state = State.Allocated;
+        }
+    	this.uuid = UUID.randomUUID().toString();
+    	this.ip6Gateway = that.getIp6Gateway();
+    	this.ip6Cidr = that.getIp6Cidr();
+    }
+
+    /**
+     * Constructor for the actual DAO object.
+     * @param trafficType
+     * @param mode
+     * @param broadcastDomainType
+     * @param networkOfferingId
+     * @param domainId
+     * @param accountId
+     * @param name
+     * @param displayText
+     * @param networkDomain
+     * @param guestType TODO
+     * @param aclType TODO
+     * @param specifyIpRanges TODO
+     * @param vpcId TODO
+     * @param dataCenterId
+     */
+    public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType,
+            long networkOfferingId, long domainId, long accountId, long related, String name, String displayText,
+            String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
+        this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId);
+        this.domainId = domainId;
+        this.accountId = accountId;
+        this.related = related;
+        this.id = id;
+        this.name = name;
+        this.displayText = displayText;
+        this.aclType = aclType;
+        this.networkDomain = networkDomain;
+    	this.uuid = UUID.randomUUID().toString();
+        this.guestType = guestType;
+        this.specifyIpRanges = specifyIpRanges;
+        this.vpcId = vpcId;
+    }
+
+    @Override
+    public String getReservationId() {
+        return reservationId;
+    }
+
+    public void setReservationId(String reservationId) {
+        this.reservationId = reservationId;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
+    // don't use this directly when possible, use Network state machine instead
+    public void setState(State state) {
+        this.state = state;
+    }
+
+    @Override
+    public long getRelated() {
+        return related;
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    @Override
+    public Mode getMode() {
+        return mode;
+    }
+
+    @Override
+    public long getAccountId() {
+        return accountId;
+    }
+
+    @Override
+    public long getDomainId() {
+        return domainId;
+    }
+
+    @Override
+    public long getNetworkOfferingId() {
+        return networkOfferingId;
+    }
+
+    public void setNetworkOfferingId(long networkOfferingId) {
+        this.networkOfferingId = networkOfferingId;
+    }
+
+    public void setMode(Mode mode) {
+        this.mode = mode;
+    }
+
+    @Override
+    public BroadcastDomainType getBroadcastDomainType() {
+        return broadcastDomainType;
+    }
+
+    public String getGuruData() {
+        return guruData;
+    }
+
+    public void setGuruData(String guruData) {
+        this.guruData = guruData;
+    }
+
+    public String getGuruName() {
+        return guruName;
+    }
+
+    public void setGuruName(String guruName) {
+        this.guruName = guruName;
+    }
+
+    public void setBroadcastDomainType(BroadcastDomainType broadcastDomainType) {
+        this.broadcastDomainType = broadcastDomainType;
+    }
+
+    @Override
+    public String getNetworkDomain() {
+        return networkDomain;
+    }
+
+    public void setNetworkDomain(String networkDomain) {
+        this.networkDomain = networkDomain;
+    }
+
+    @Override
+    public TrafficType getTrafficType() {
+        return trafficType;
+    }
+
+    public void setTrafficType(TrafficType trafficType) {
+        this.trafficType = trafficType;
+    }
+
+    @Override
+    public String getGateway() {
+        return gateway;
+    }
+
+    public void setGateway(String gateway) {
+        this.gateway = gateway;
+    }
+    // "cidr" is the Cloudstack managed address space, all CloudStack managed vms get IP address from "cidr"
+    // In general "cidr" also serves as the network cidr
+    // But in case IP reservation feature is configured for a Guest network, "network_cidr" is the Effective network cidr for the network,
+    //  "cidr" will still continue to be the effective address space for CloudStack managed vms in that Guest network
+    @Override
+    public String getCidr() {
+        return cidr;
+    }
+
+    public void setCidr(String cidr) {
+        this.cidr = cidr;
+    }
+
+    // "networkcidr" is the network CIDR of the guest network which is configured with IP reservation feature
+    // It is the summation of "cidr" and the reservedIPrange(the address space used for non cloudstack purposes.)
+    //  For networks not using IP reservation "networkcidr" is always null
+    @Override
+    public String getNetworkCidr() {
+        return networkCidr;
+    }
+
+    public void setNetworkCidr(String networkCidr) {
+        this.networkCidr = networkCidr;
+    }
+
+    @Override
+    public URI getBroadcastUri() {
+        return broadcastUri;
+    }
+
+    public void setBroadcastUri(URI broadcastUri) {
+        this.broadcastUri = broadcastUri;
+    }
+
+    @Override
+    public int hashCode() {
+        return NumbersUtil.hash(id);
+    }
+
+    @Override
+    public Long getPhysicalNetworkId() {
+        return physicalNetworkId;
+    }
+
+    @Override
+    public void setPhysicalNetworkId(Long physicalNetworkId) {
+        this.physicalNetworkId = physicalNetworkId;
+    }
+
+    @Override
+    public long getDataCenterId() {
+        return dataCenterId;
+    }
+
+    public String getDns1() {
+        return dns1;
+    }
+
+    public void setDns1(String dns) {
+        this.dns1 = dns;
+    }
+
+    public String getDns2() {
+        return dns2;
+    }
+
+    public void setDns2(String dns) {
+        this.dns2 = dns;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String getDisplayText() {
+        return displayText;
+    }
+
+    public void setDisplayText(String displayText) {
+        this.displayText = displayText;
+    }
+
+    public Date getRemoved() {
+        return removed;
+    }
+
+    public void setRemoved(Date removed) {
+        this.removed = removed;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+
+    @Override
+    public Network.GuestType getGuestType() {
+        return guestType;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof NetworkVO)) {
+            return false;
+        }
+        NetworkVO that = (NetworkVO)obj;
+        if (this.trafficType != that.trafficType) {
+            return false;
+        }
+
+        if ((this.cidr == null && that.cidr != null) || (this.cidr != null && that.cidr == null)) {
+            return false;
+        }
+
+        if (this.cidr == null && that.cidr == null) {
+            return true;
+        }
+
+        return NetUtils.isNetworkAWithinNetworkB(this.cidr, that.cidr);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder("Ntwk[");
+        buf.append(id).append("|").append(trafficType).append("|").append(networkOfferingId).append("]");
+        return buf.toString();
+    }
+
+    public String getUuid() {
+    	return this.uuid;
+    }
+
+    public void setUuid(String uuid) {
+    	this.uuid = uuid;
+    }
+
+	public ControlledEntity.ACLType getAclType() {
+		return aclType;
+	}
+
+	public void setRestartRequired(boolean restartRequired) {
+		this.restartRequired = restartRequired;
+	}
+
+	@Override
+	public boolean isRestartRequired() {
+		return restartRequired;
+	}
+
+    @Override
+    public boolean getSpecifyIpRanges() {
+    	return specifyIpRanges;
+    }
+
+    @Override
+    public Long getVpcId() {
+        return vpcId;
+    }
+
+	public String getIp6Cidr() {
+		return ip6Cidr;
+	}
+
+	public void setIp6Cidr(String ip6Cidr) {
+		this.ip6Cidr = ip6Cidr;
+	}
+
+	public String getIp6Gateway() {
+		return ip6Gateway;
+	}
+
+	public void setIp6Gateway(String ip6Gateway) {
+		this.ip6Gateway = ip6Gateway;
+	}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDao.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDao.java
new file mode 100644
index 0000000..891fbfd
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDao.java
@@ -0,0 +1,28 @@
+// 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.Networks.TrafficType;
+import com.cloud.utils.db.GenericDao;
+
+public interface PhysicalNetworkDao extends GenericDao<PhysicalNetworkVO, Long> {
+    List<PhysicalNetworkVO> listByZone(long zoneId);
+    List<PhysicalNetworkVO> listByZoneIncludingRemoved(long zoneId);
+    List<PhysicalNetworkVO> listByZoneAndTrafficType(long dataCenterId, TrafficType trafficType);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.java
new file mode 100644
index 0000000..1e26a51
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkDaoImpl.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.Networks.TrafficType;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value=PhysicalNetworkDao.class) @DB(txn=false)
+public class PhysicalNetworkDaoImpl extends GenericDaoBase<PhysicalNetworkVO, Long> implements PhysicalNetworkDao {
+    final SearchBuilder<PhysicalNetworkVO> ZoneSearch;
+
+    @Inject protected PhysicalNetworkTrafficTypeDao _trafficTypeDao;
+
+    protected PhysicalNetworkDaoImpl() {
+        super();
+        ZoneSearch = createSearchBuilder();
+        ZoneSearch.and("dataCenterId", ZoneSearch.entity().getDataCenterId(), Op.EQ);
+        ZoneSearch.done();
+    }
+
+    @Override
+    public List<PhysicalNetworkVO> listByZone(long zoneId) {
+        SearchCriteria<PhysicalNetworkVO> sc = ZoneSearch.create();
+        sc.setParameters("dataCenterId", zoneId);
+        return search(sc, null);
+    }
+
+    @Override
+    public List<PhysicalNetworkVO> listByZoneIncludingRemoved(long zoneId) {
+        SearchCriteria<PhysicalNetworkVO> sc = ZoneSearch.create();
+        sc.setParameters("dataCenterId", zoneId);
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<PhysicalNetworkVO> listByZoneAndTrafficType(long dataCenterId, TrafficType trafficType) {
+
+        SearchBuilder<PhysicalNetworkTrafficTypeVO> trafficTypeSearch = _trafficTypeDao.createSearchBuilder();
+        PhysicalNetworkTrafficTypeVO trafficTypeEntity = trafficTypeSearch.entity();
+        trafficTypeSearch.and("trafficType", trafficTypeSearch.entity().getTrafficType(), SearchCriteria.Op.EQ);
+
+        SearchBuilder<PhysicalNetworkVO> pnSearch = createSearchBuilder();
+        pnSearch.and("dataCenterId", pnSearch.entity().getDataCenterId(), Op.EQ);
+        pnSearch.join("trafficTypeSearch", trafficTypeSearch, pnSearch.entity().getId(), trafficTypeEntity.getPhysicalNetworkId(), JoinBuilder.JoinType.INNER);
+
+        SearchCriteria<PhysicalNetworkVO> sc = pnSearch.create();
+        sc.setJoinParameters("trafficTypeSearch", "trafficType", trafficType);
+        sc.setParameters("dataCenterId", dataCenterId);
+
+        return listBy(sc);  
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodDaoImpl.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodDaoImpl.java
new file mode 100644
index 0000000..04508e7
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodDaoImpl.java
@@ -0,0 +1,70 @@
+// 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 org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+public class PhysicalNetworkIsolationMethodDaoImpl extends GenericDaoBase<PhysicalNetworkIsolationMethodVO, Long> implements GenericDao<PhysicalNetworkIsolationMethodVO, Long> {
+    private final GenericSearchBuilder<PhysicalNetworkIsolationMethodVO, String> IsolationMethodSearch;
+    private final SearchBuilder<PhysicalNetworkIsolationMethodVO> AllFieldsSearch;
+
+    protected PhysicalNetworkIsolationMethodDaoImpl() {
+        super();
+        IsolationMethodSearch = createSearchBuilder(String.class);
+        IsolationMethodSearch.selectField(IsolationMethodSearch.entity().getIsolationMethod());
+        IsolationMethodSearch.and("physicalNetworkId", IsolationMethodSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        IsolationMethodSearch.done();
+
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+        AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        AllFieldsSearch.and("isolationMethod", AllFieldsSearch.entity().getIsolationMethod(), Op.EQ);
+        AllFieldsSearch.done();
+    }
+
+    public List<String> getAllIsolationMethod(long physicalNetworkId) {
+        SearchCriteria<String> sc = IsolationMethodSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+
+        return customSearch(sc, null);
+    }
+
+    public String getIsolationMethod(long physicalNetworkId) {
+        SearchCriteria<String> sc = IsolationMethodSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+
+        return customSearch(sc, null).get(0);
+    }
+    
+    public int clearIsolationMethods(long physicalNetworkId) {
+        SearchCriteria<PhysicalNetworkIsolationMethodVO> sc = AllFieldsSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+
+        return remove(sc);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodVO.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodVO.java
new file mode 100644
index 0000000..5996704
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkIsolationMethodVO.java
@@ -0,0 +1,68 @@
+// 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 = "physical_network_isolation_methods")
+public class PhysicalNetworkIsolationMethodVO implements InternalIdentity {
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "physical_network_id")
+    private long physicalNetworkId;
+
+    @Column(name = "isolation_method")
+    private String isolationMethod;
+
+    /**
+     * There should never be a public constructor for this class. Since it's
+     * only here to define the table for the DAO class.
+     */
+    protected PhysicalNetworkIsolationMethodVO() {
+    }
+
+    protected PhysicalNetworkIsolationMethodVO(long physicalNetworkId, String isolationMethod) {
+        this.physicalNetworkId = physicalNetworkId;
+        this.isolationMethod = isolationMethod;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public long getPhysicalNetworkId() {
+        return physicalNetworkId;
+    }
+
+    public String getIsolationMethod() {
+        return isolationMethod;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDao.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDao.java
new file mode 100644
index 0000000..9e0ba17
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDao.java
@@ -0,0 +1,28 @@
+// 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 PhysicalNetworkServiceProviderDao extends GenericDao<PhysicalNetworkServiceProviderVO, Long> {
+    List<PhysicalNetworkServiceProviderVO> listBy(long physicalNetworkId);
+    PhysicalNetworkServiceProviderVO findByServiceProvider(long physicalNetworkId, String providerType);
+    void deleteProviders(long physicalNetworkId);
+    boolean isServiceProviderEnabled(long physicalNetworkId, String providerType, String serviceType);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d015fb35/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDaoImpl.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDaoImpl.java
new file mode 100644
index 0000000..16a23dd
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkServiceProviderDaoImpl.java
@@ -0,0 +1,131 @@
+// 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.Network.Service;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+@Local(value=PhysicalNetworkServiceProviderDao.class) @DB(txn=false)
+public class PhysicalNetworkServiceProviderDaoImpl extends GenericDaoBase<PhysicalNetworkServiceProviderVO, Long> implements PhysicalNetworkServiceProviderDao {
+    final SearchBuilder<PhysicalNetworkServiceProviderVO> physicalNetworkSearch;
+    final SearchBuilder<PhysicalNetworkServiceProviderVO> physicalNetworkServiceProviderSearch;
+    final SearchBuilder<PhysicalNetworkServiceProviderVO> AllFieldsSearch;
+
+    protected PhysicalNetworkServiceProviderDaoImpl() {
+        super();
+        physicalNetworkSearch = createSearchBuilder();
+        physicalNetworkSearch.and("physicalNetworkId", physicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        physicalNetworkSearch.done();
+
+        physicalNetworkServiceProviderSearch = createSearchBuilder();
+        physicalNetworkServiceProviderSearch.and("physicalNetworkId", physicalNetworkServiceProviderSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        physicalNetworkServiceProviderSearch.and("serviceProvderType", physicalNetworkServiceProviderSearch.entity().getProviderName(), Op.EQ);
+        physicalNetworkServiceProviderSearch.done();
+        
+        AllFieldsSearch = createSearchBuilder();
+        AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
+        AllFieldsSearch.and("serviceProvderType", AllFieldsSearch.entity().getProviderName(), Op.EQ);
+        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+        AllFieldsSearch.and("vpnService", AllFieldsSearch.entity().isVpnServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("dhcpService", AllFieldsSearch.entity().isDhcpServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("dnsService", AllFieldsSearch.entity().isDnsServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("gatewayService", AllFieldsSearch.entity().isGatewayServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("firewallService", AllFieldsSearch.entity().isFirewallServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("sourceNatService", AllFieldsSearch.entity().isSourcenatServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("lbService", AllFieldsSearch.entity().isLbServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("staticNatService", AllFieldsSearch.entity().isStaticnatServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("pfService", AllFieldsSearch.entity().isPortForwardingServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("userDataService", AllFieldsSearch.entity().isUserdataServiceProvided(), Op.EQ);
+        AllFieldsSearch.and("securityGroupService", AllFieldsSearch.entity().isSecuritygroupServiceProvided(), Op.EQ);
+        AllFieldsSearch.done();
+    }
+
+    @Override
+    public List<PhysicalNetworkServiceProviderVO> listBy(long physicalNetworkId) {
+        SearchCriteria<PhysicalNetworkServiceProviderVO> sc = physicalNetworkSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        return search(sc, null);
+    }
+
+    @Override
+    public PhysicalNetworkServiceProviderVO findByServiceProvider(long physicalNetworkId, String providerType) {
+        SearchCriteria<PhysicalNetworkServiceProviderVO> sc = physicalNetworkServiceProviderSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        sc.setParameters("serviceProvderType", providerType);
+        return findOneBy(sc);
+    }
+    
+    @Override
+    public void deleteProviders(long physicalNetworkId) {
+        SearchCriteria<PhysicalNetworkServiceProviderVO> sc = physicalNetworkSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        remove(sc);
+    }
+    
+    @Override
+    public boolean isServiceProviderEnabled(long physicalNetworkId, String providerType, String serviceType) {
+    	 SearchCriteria<PhysicalNetworkServiceProviderVO> sc = AllFieldsSearch.create();
+         sc.setParameters("physicalNetworkId", physicalNetworkId);
+         sc.setParameters("serviceProvderType", providerType);
+         sc.setParameters("state", PhysicalNetworkServiceProvider.State.Enabled.toString());
+         
+         if (serviceType.equalsIgnoreCase(Service.Dhcp.getName())) {
+             sc.setParameters("dhcpService", true);
+         } else if (serviceType.equalsIgnoreCase(Service.Dns.getName())) {
+             sc.setParameters("dnsService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.Firewall.getName())) {
+             sc.setParameters("firewallService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.Gateway.getName())) {
+             sc.setParameters("gatewayService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.Lb.getName())) {
+             sc.setParameters("lbService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.PortForwarding.getName())) {
+             sc.setParameters("pfService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.SecurityGroup.getName())) {
+             sc.setParameters("securityGroupService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.SourceNat.getName())) {
+             sc.setParameters("sourceNatService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.StaticNat.getName())) {
+             sc.setParameters("staticNatService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.UserData.getName())) {
+             sc.setParameters("userDataService", true);
+         }else if (serviceType.equalsIgnoreCase(Service.Vpn.getName())) {
+             sc.setParameters("vpnService", true);
+         }
+         
+         PhysicalNetworkServiceProviderVO map = findOneBy(sc);
+
+         if (map != null) {
+        	 return true;
+         } else {
+        	 return false;
+         }
+    }
+
+}


Mime
View raw message