You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ni...@apache.org on 2013/05/13 14:25:42 UTC
[12/57] [abbrv] [partial] merge master
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/as/dao/ConditionDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/dao/ConditionDao.java b/engine/schema/src/com/cloud/network/as/dao/ConditionDao.java
new file mode 100644
index 0000000..128920d
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/as/dao/ConditionDao.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.as.dao;
+
+import com.cloud.network.as.ConditionVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ConditionDao extends GenericDao<ConditionVO, Long> {
+
+ ConditionVO findByCounterId(long ctrId);
+
+ int removeByAccountId(long accountId);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/as/dao/ConditionDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/dao/ConditionDaoImpl.java b/engine/schema/src/com/cloud/network/as/dao/ConditionDaoImpl.java
new file mode 100644
index 0000000..8235823
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/as/dao/ConditionDaoImpl.java
@@ -0,0 +1,56 @@
+// 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.as.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.as.ConditionVO;
+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 = ConditionDao.class)
+public class ConditionDaoImpl extends GenericDaoBase<ConditionVO, Long> implements ConditionDao {
+ final SearchBuilder<ConditionVO> AllFieldsSearch;
+
+ protected ConditionDaoImpl() {
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.and("counterId", AllFieldsSearch.entity().getCounterid(), Op.EQ);
+ AllFieldsSearch.done();
+ }
+
+ @Override
+ public ConditionVO findByCounterId(long ctrId) {
+ SearchCriteria<ConditionVO> sc = AllFieldsSearch.create();
+ sc.setParameters("counterId", ctrId);
+ return findOneBy(sc);
+ }
+
+ public int removeByAccountId(long accountId) {
+ SearchCriteria<ConditionVO> sc = createSearchCriteria();
+
+ sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+
+ return remove(sc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/as/dao/CounterDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/dao/CounterDao.java b/engine/schema/src/com/cloud/network/as/dao/CounterDao.java
new file mode 100644
index 0000000..47b0d48
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/as/dao/CounterDao.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.as.dao;
+
+import java.util.List;
+
+import com.cloud.network.as.CounterVO;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDao;
+
+public interface CounterDao extends GenericDao<CounterVO, Long> {
+ public List<CounterVO> listCounters(Long id, String name, String source, String keyword, Filter filter);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/as/dao/CounterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/as/dao/CounterDaoImpl.java b/engine/schema/src/com/cloud/network/as/dao/CounterDaoImpl.java
new file mode 100644
index 0000000..0abc3a0
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/as/dao/CounterDaoImpl.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.as.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.as.CounterVO;
+import com.cloud.utils.db.Filter;
+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 = CounterDao.class)
+public class CounterDaoImpl extends GenericDaoBase<CounterVO, Long> implements CounterDao {
+ final SearchBuilder<CounterVO> AllFieldsSearch;
+
+ protected CounterDaoImpl() {
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.LIKE);
+ AllFieldsSearch.and("source", AllFieldsSearch.entity().getSource(), Op.EQ);
+ AllFieldsSearch.done();
+ }
+
+ @Override
+ public List<CounterVO> listCounters(Long id, String name, String source, String keyword, Filter filter) {
+ SearchCriteria<CounterVO> sc = AllFieldsSearch.create();
+
+ if (keyword != null) {
+ SearchCriteria<CounterVO> ssc = createSearchCriteria();
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ }
+
+ if (name != null) {
+ sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
+ }
+
+ if (id != null) {
+ sc.addAnd("id", SearchCriteria.Op.EQ, id);
+ }
+
+ if (source != null) {
+ sc.addAnd("source", SearchCriteria.Op.EQ, source);
+ }
+ return listBy(sc, filter);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDao.java b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDao.java
new file mode 100644
index 0000000..dc1ec89
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDao.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 com.cloud.network.dao.AccountGuestVlanMapVO;
+import com.cloud.utils.db.GenericDao;
+
+import java.util.List;
+
+public interface AccountGuestVlanMapDao extends GenericDao<AccountGuestVlanMapVO, Long> {
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByAccount(long accountId);
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByVlan(long guestVlanId);
+
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByPhysicalNetwork(long physicalNetworkId);
+
+ public int removeByAccountId(long accountId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
new file mode 100644
index 0000000..e7a7b34
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapDaoImpl.java
@@ -0,0 +1,83 @@
+// 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.network.dao.AccountGuestVlanMapVO;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+
+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;
+
+@Component
+@Local(value={AccountGuestVlanMapDao.class})
+@DB(txn=false)
+public class AccountGuestVlanMapDaoImpl extends GenericDaoBase<AccountGuestVlanMapVO, Long> implements AccountGuestVlanMapDao {
+
+ protected SearchBuilder<AccountGuestVlanMapVO> AccountSearch;
+ protected SearchBuilder<AccountGuestVlanMapVO> GuestVlanSearch;
+ protected SearchBuilder<AccountGuestVlanMapVO> PhysicalNetworkSearch;
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByAccount(long accountId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = AccountSearch.create();
+ sc.setParameters("accountId", accountId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByVlan(long guestVlanId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = GuestVlanSearch.create();
+ sc.setParameters("guestVlanId", guestVlanId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<AccountGuestVlanMapVO> listAccountGuestVlanMapsByPhysicalNetwork(long physicalNetworkId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = GuestVlanSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public int removeByAccountId(long accountId) {
+ SearchCriteria<AccountGuestVlanMapVO> sc = AccountSearch.create();
+ sc.setParameters("accountId", accountId);
+ return expunge(sc);
+ }
+
+ public AccountGuestVlanMapDaoImpl() {
+ super();
+ AccountSearch = createSearchBuilder();
+ AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+ AccountSearch.done();
+
+ GuestVlanSearch = createSearchBuilder();
+ GuestVlanSearch.and("guestVlanId", GuestVlanSearch.entity().getId(), SearchCriteria.Op.EQ);
+ GuestVlanSearch.done();
+
+ PhysicalNetworkSearch = createSearchBuilder();
+ PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getId(), SearchCriteria.Op.EQ);
+ PhysicalNetworkSearch.done();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapVO.java b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
new file mode 100644
index 0000000..17c941a
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/AccountGuestVlanMapVO.java
@@ -0,0 +1,94 @@
+// 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.network.GuestVlan;
+
+import javax.persistence.*;
+import java.util.UUID;
+
+@Entity
+@Table(name="account_vnet_map")
+public class AccountGuestVlanMapVO implements GuestVlan {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="account_id")
+ private long accountId;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name="vnet_range")
+ private String guestVlanRange;
+
+ @Column(name="physical_network_id")
+ private long physicalNetworkId;
+
+ public AccountGuestVlanMapVO(long accountId,long physicalNetworkId) {
+ this.accountId = accountId;
+ this.physicalNetworkId = physicalNetworkId;
+ this.guestVlanRange = null;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public AccountGuestVlanMapVO() {
+
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public String getGuestVlanRange() {
+ return guestVlanRange;
+ }
+
+
+ public void setGuestVlanRange(String guestVlanRange) {
+ this.guestVlanRange = guestVlanRange;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ @Override
+ public long getPhysicalNetworkId() {
+ return this.physicalNetworkId;
+ }
+
+ public void setPhysicalNetworkId(long physicalNetworkId) {
+ this.physicalNetworkId = physicalNetworkId;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDao.java b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDao.java
new file mode 100644
index 0000000..bb3ebef
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDao.java
@@ -0,0 +1,58 @@
+// 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.dao.ExternalFirewallDeviceVO.FirewallDeviceAllocationState;
+import com.cloud.network.dao.ExternalFirewallDeviceVO.FirewallDeviceState;
+import com.cloud.utils.db.GenericDao;
+
+public interface ExternalFirewallDeviceDao extends GenericDao<ExternalFirewallDeviceVO, Long> {
+
+ /**
+ * list all the firewall devices added in to this physical network?
+ * @param physicalNetworkId physical Network Id
+ * @return list of ExternalFirewallDeviceVO for the devices added in to this physical network.
+ */
+ List<ExternalFirewallDeviceVO> listByPhysicalNetwork(long physicalNetworkId);
+
+ /**
+ * list the firewall devices added in to this physical network of certain provider type?
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ */
+ List<ExternalFirewallDeviceVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String provider_name);
+
+ /**
+ * list the firewall devices added in to this physical network by their allocation state
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ * @param allocationState firewall device allocation state
+ * @return list of ExternalFirewallDeviceVO for the devices in the physical network with a device allocation state
+ */
+ List<ExternalFirewallDeviceVO> listByProviderAndDeviceAllocationState(long physicalNetworkId, String provider_name, FirewallDeviceAllocationState allocationState);
+
+ /**
+ * list the load balancer devices added in to this physical network by the device status (enabled/disabled)
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ * @param state firewall device status
+ * @return list of ExternalFirewallDeviceVO for the devices in the physical network with a device state
+ */
+ List<ExternalFirewallDeviceVO> listByProviderAndDeviceStaus(long physicalNetworkId, String provider_name, FirewallDeviceState state);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDaoImpl.java b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDaoImpl.java
new file mode 100644
index 0000000..01f8861
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceDaoImpl.java
@@ -0,0 +1,96 @@
+// 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.dao.ExternalFirewallDeviceVO.FirewallDeviceAllocationState;
+import com.cloud.network.dao.ExternalFirewallDeviceVO.FirewallDeviceState;
+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=ExternalFirewallDeviceDao.class) @DB(txn=false)
+public class ExternalFirewallDeviceDaoImpl extends GenericDaoBase<ExternalFirewallDeviceVO, Long> implements ExternalFirewallDeviceDao {
+ final SearchBuilder<ExternalFirewallDeviceVO> physicalNetworkServiceProviderSearch;
+ final SearchBuilder<ExternalFirewallDeviceVO> physicalNetworkIdSearch;
+ final SearchBuilder<ExternalFirewallDeviceVO> allocationStateSearch;
+ final SearchBuilder<ExternalFirewallDeviceVO> deviceStatusSearch;
+
+ protected ExternalFirewallDeviceDaoImpl() {
+ physicalNetworkIdSearch = createSearchBuilder();
+ physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ physicalNetworkIdSearch.done();
+
+ physicalNetworkServiceProviderSearch = createSearchBuilder();
+ physicalNetworkServiceProviderSearch.and("physicalNetworkId", physicalNetworkServiceProviderSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ physicalNetworkServiceProviderSearch.and("networkServiceProviderName", physicalNetworkServiceProviderSearch.entity().getProviderName(), Op.EQ);
+ physicalNetworkServiceProviderSearch.done();
+
+ allocationStateSearch = createSearchBuilder();
+ allocationStateSearch.and("physicalNetworkId", allocationStateSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ allocationStateSearch.and("providerName", allocationStateSearch.entity().getProviderName(), Op.EQ);
+ allocationStateSearch.and("allocationState", allocationStateSearch.entity().getAllocationState(), Op.EQ);
+ allocationStateSearch.done();
+
+ deviceStatusSearch = createSearchBuilder();
+ deviceStatusSearch.and("physicalNetworkId", deviceStatusSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ deviceStatusSearch.and("providerName", deviceStatusSearch.entity().getProviderName(), Op.EQ);
+ deviceStatusSearch.and("deviceState", deviceStatusSearch.entity().getDeviceState(), Op.EQ);
+ deviceStatusSearch.done();
+ }
+
+ @Override
+ public List<ExternalFirewallDeviceVO> listByPhysicalNetwork(long physicalNetworkId) {
+ SearchCriteria<ExternalFirewallDeviceVO> sc = physicalNetworkIdSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalFirewallDeviceVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String providerName) {
+ SearchCriteria<ExternalFirewallDeviceVO> sc = physicalNetworkServiceProviderSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("networkServiceProviderName", providerName);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalFirewallDeviceVO> listByProviderAndDeviceAllocationState(long physicalNetworkId, String providerName, FirewallDeviceAllocationState allocationState) {
+ SearchCriteria<ExternalFirewallDeviceVO> sc = allocationStateSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", providerName);
+ sc.setParameters("allocationState", allocationState);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalFirewallDeviceVO> listByProviderAndDeviceStaus(long physicalNetworkId, String providerName, FirewallDeviceState state) {
+ SearchCriteria<ExternalFirewallDeviceVO> sc = deviceStatusSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", providerName);
+ sc.setParameters("deviceState", state);
+ return search(sc, null);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceVO.java b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceVO.java
new file mode 100644
index 0000000..31750b4
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalFirewallDeviceVO.java
@@ -0,0 +1,161 @@
+// 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.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+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;
+
+/**
+ * ExternalFirewallDeviceVO contains information of a external firewall device (Juniper SRX) added into a deployment
+ */
+
+@Entity
+@Table(name="external_firewall_devices")
+public class ExternalFirewallDeviceVO implements InternalIdentity, Identity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name = "host_id")
+ private long hostId;
+
+ @Column(name = "physical_network_id")
+ private long physicalNetworkId;
+
+ @Column(name = "provider_name")
+ private String providerName;
+
+ @Column(name = "device_name")
+ private String deviceName;
+
+ @Column(name="device_state")
+ @Enumerated(value=EnumType.STRING)
+ FirewallDeviceState deviceState;
+
+ @Column(name="is_dedicated")
+ private boolean isDedicatedDevice;
+
+ @Column(name = "capacity")
+ private long capacity;
+
+ @Column(name = "allocation_state")
+ @Enumerated(value=EnumType.STRING)
+ private FirewallDeviceAllocationState allocationState;
+
+ //keeping it enum for future possible states Maintenance, Shutdown
+ public enum FirewallDeviceState {
+ Enabled,
+ Disabled
+ }
+
+ public enum FirewallDeviceAllocationState {
+ Free,
+ Allocated
+ }
+
+ public ExternalFirewallDeviceVO(long hostId, long physicalNetworkId, String provider_name, String device_name, long capacity, boolean dedicated) {
+ this.physicalNetworkId = physicalNetworkId;
+ this.providerName = provider_name;
+ this.deviceName = device_name;
+ this.hostId = hostId;
+ this.deviceState = FirewallDeviceState.Disabled;
+ this.allocationState = FirewallDeviceAllocationState.Free;
+ this.capacity = capacity;
+ this.isDedicatedDevice = dedicated;
+ this.deviceState = FirewallDeviceState.Enabled;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public ExternalFirewallDeviceVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public String getProviderName() {
+ return providerName;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ public long getHostId() {
+ return hostId;
+ }
+
+ public long getCapacity() {
+ return capacity;
+ }
+
+ public void setCapacity(long capacity) {
+ this.capacity = capacity;
+ }
+
+ public FirewallDeviceState getDeviceState() {
+ return deviceState;
+ }
+
+ public void setDeviceState(FirewallDeviceState state) {
+ this.deviceState = state;
+ }
+
+ public FirewallDeviceAllocationState getAllocationState() {
+ return allocationState;
+ }
+
+ public void setAllocationState(FirewallDeviceAllocationState allocationState) {
+ this.allocationState = allocationState;
+ }
+
+ public boolean getIsDedicatedDevice() {
+ return isDedicatedDevice;
+ }
+
+ public void setIsDedicatedDevice(boolean isDedicated) {
+ isDedicatedDevice = isDedicated;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDao.java b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDao.java
new file mode 100644
index 0000000..b7baa7e
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDao.java
@@ -0,0 +1,74 @@
+// 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.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState;
+import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
+import com.cloud.utils.db.GenericDao;
+
+import java.util.List;
+
+public interface ExternalLoadBalancerDeviceDao extends GenericDao<ExternalLoadBalancerDeviceVO, Long> {
+
+ /**
+ * list all the load balancer devices added in to this physical network?
+ * @param physicalNetworkId physical Network Id
+ * @return list of ExternalLoadBalancerDeviceVO for the devices in the physical network.
+ */
+ List<ExternalLoadBalancerDeviceVO> listByPhysicalNetwork(long physicalNetworkId);
+
+ /**
+ * list the load balancer devices added in to this physical network of certain provider type?
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ */
+ List<ExternalLoadBalancerDeviceVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String provider_name);
+
+ /**
+ * list the load balancer devices added in to this physical network by their allocation state
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ * @param allocationState load balancer device allocation state
+ * @return list of ExternalLoadBalancerDeviceVO for the devices in the physical network with a device allocation state
+ */
+ List<ExternalLoadBalancerDeviceVO> listByProviderAndDeviceAllocationState(long physicalNetworkId, String provider_name, LBDeviceAllocationState allocationState);
+
+ /**
+ * list the load balancer devices added in to this physical network by the device status (enabled/disabled)
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ * @param state load balancer device status
+ * @return list of ExternalLoadBalancerDeviceVO for the devices in the physical network with a device state
+ */
+ List<ExternalLoadBalancerDeviceVO> listByProviderAndDeviceStaus(long physicalNetworkId, String provider_name, LBDeviceState state);
+
+ /**
+ * list the load balancer devices added in to this physical network by the managed type (external/cloudstack managed)
+ * @param physicalNetworkId physical Network Id
+ * @param provider_name netwrok service provider name
+ * @param managed managed type
+ * @return list of ExternalLoadBalancerDeviceVO for the devices in to this physical network of a managed type
+ */
+ List<ExternalLoadBalancerDeviceVO> listByProviderAndManagedType(long physicalNetworkId, String provider_name, boolean managed);
+
+ /**
+ * Find the external load balancer device that is provisioned as GSLB service provider in the pyshical network
+ * @param physicalNetworkId physical Network Id
+ * @return ExternalLoadBalancerDeviceVO for the device acting as GSLB provider in the physical network
+ */
+ ExternalLoadBalancerDeviceVO findGslbServiceProvider(long physicalNetworkId, String providerName);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDaoImpl.java b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDaoImpl.java
new file mode 100644
index 0000000..ea6437d
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceDaoImpl.java
@@ -0,0 +1,127 @@
+// 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.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState;
+import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
+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;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value=ExternalLoadBalancerDeviceDao.class) @DB(txn=false)
+public class ExternalLoadBalancerDeviceDaoImpl extends GenericDaoBase<ExternalLoadBalancerDeviceVO, Long> implements ExternalLoadBalancerDeviceDao {
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> physicalNetworkIdSearch;
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> physicalNetworkServiceProviderSearch;
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> allocationStateSearch;
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> deviceStatusSearch;
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> deviceManagedTypeSearch;
+ final SearchBuilder<ExternalLoadBalancerDeviceVO> gslbProviderSearch;
+
+ public ExternalLoadBalancerDeviceDaoImpl() {
+ super();
+
+ physicalNetworkIdSearch = createSearchBuilder();
+ physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ physicalNetworkIdSearch.done();
+
+ physicalNetworkServiceProviderSearch = createSearchBuilder();
+ physicalNetworkServiceProviderSearch.and("physicalNetworkId", physicalNetworkServiceProviderSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ physicalNetworkServiceProviderSearch.and("providerName", physicalNetworkServiceProviderSearch.entity().getProviderName(), Op.EQ);
+ physicalNetworkServiceProviderSearch.done();
+
+ allocationStateSearch = createSearchBuilder();
+ allocationStateSearch.and("physicalNetworkId", allocationStateSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ allocationStateSearch.and("providerName", allocationStateSearch.entity().getProviderName(), Op.EQ);
+ allocationStateSearch.and("allocationState", allocationStateSearch.entity().getAllocationState(), Op.EQ);
+ allocationStateSearch.done();
+
+ deviceStatusSearch = createSearchBuilder();
+ deviceStatusSearch.and("physicalNetworkId", deviceStatusSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ deviceStatusSearch.and("providerName", deviceStatusSearch.entity().getProviderName(), Op.EQ);
+ deviceStatusSearch.and("deviceState", deviceStatusSearch.entity().getState(), Op.EQ);
+ deviceStatusSearch.done();
+
+ deviceManagedTypeSearch = createSearchBuilder();
+ deviceManagedTypeSearch.and("physicalNetworkId", deviceManagedTypeSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ deviceManagedTypeSearch.and("providerName", deviceManagedTypeSearch.entity().getProviderName(), Op.EQ);
+ deviceManagedTypeSearch.and("managedType", deviceManagedTypeSearch.entity().getIsManagedDevice(), Op.EQ);
+ deviceManagedTypeSearch.done();
+
+ gslbProviderSearch = createSearchBuilder();
+ gslbProviderSearch.and("physicalNetworkId", gslbProviderSearch.entity().getPhysicalNetworkId(), Op.EQ);
+ gslbProviderSearch.and("providerName", gslbProviderSearch.entity().getProviderName(), Op.EQ);
+ gslbProviderSearch.and("gslbProvider", gslbProviderSearch.entity().getGslbProvider(), Op.EQ);
+
+ }
+
+ public List<ExternalLoadBalancerDeviceVO> listByPhysicalNetwork(long physicalNetworkId) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = physicalNetworkIdSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalLoadBalancerDeviceVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String provider_name) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = physicalNetworkServiceProviderSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", provider_name);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalLoadBalancerDeviceVO> listByProviderAndDeviceAllocationState(long physicalNetworkId, String provider_name, LBDeviceAllocationState state) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = allocationStateSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", provider_name);
+ sc.setParameters("allocationState", state);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalLoadBalancerDeviceVO> listByProviderAndDeviceStaus(long physicalNetworkId, String providerName, LBDeviceState state) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = deviceStatusSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", providerName);
+ sc.setParameters("deviceState", state);
+ return search(sc, null);
+ }
+
+ @Override
+ public List<ExternalLoadBalancerDeviceVO> listByProviderAndManagedType(long physicalNetworkId, String providerName, boolean managed) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = deviceManagedTypeSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", providerName);
+ sc.setParameters("managedType", managed);
+ return search(sc, null);
+ }
+
+ @Override
+ public ExternalLoadBalancerDeviceVO findGslbServiceProvider(long physicalNetworkId, String providerName) {
+ SearchCriteria<ExternalLoadBalancerDeviceVO> sc = gslbProviderSearch.create();
+ sc.setParameters("physicalNetworkId", physicalNetworkId);
+ sc.setParameters("providerName", providerName);
+ sc.setParameters("gslbProvider", true);
+ return findOneBy(sc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceVO.java b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceVO.java
new file mode 100644
index 0000000..04714a6
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/ExternalLoadBalancerDeviceVO.java
@@ -0,0 +1,227 @@
+// 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.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
+
+import javax.persistence.*;
+import java.util.UUID;
+
+/**
+ * ExternalLoadBalancerDeviceVO contains information on external load balancer devices (F5/Netscaler VPX,MPX,SDX) added into a deployment
+ */
+
+@Entity
+@Table(name="external_load_balancer_devices")
+public class ExternalLoadBalancerDeviceVO implements InternalIdentity, Identity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name = "host_id")
+ private long hostId;
+
+ @Column(name = "physical_network_id")
+ private long physicalNetworkId;
+
+ @Column(name = "provider_name")
+ private String providerName;
+
+ @Column(name = "device_name")
+ private String deviceName;
+
+ @Column(name="device_state")
+ @Enumerated(value=EnumType.STRING)
+ private LBDeviceState state;
+
+ @Column(name = "allocation_state")
+ @Enumerated(value=EnumType.STRING)
+ private LBDeviceAllocationState allocationState;
+
+ @Column(name="is_managed")
+ private boolean isManagedDevice;
+
+ @Column(name="is_dedicated")
+ private boolean isDedicatedDevice;
+
+ @Column(name="is_gslb_provider")
+ private boolean gslbProvider;
+
+ @Column(name="gslb_site_publicip")
+ private String gslbSitePublicIP;
+
+ @Column(name="gslb_site_privateip")
+ private String gslbSitePrivateIP;
+
+ @Column(name = "parent_host_id")
+ private long parentHostId;
+
+ @Column(name = "capacity")
+ private long capacity;
+
+ //keeping it enum for future possible states Maintenance, Shutdown
+ public enum LBDeviceState {
+ Enabled,
+ Disabled
+ }
+
+ public enum LBDeviceAllocationState {
+ Free, // In this state no networks are using this device for load balancing
+ Shared, // In this state one or more networks will be using this device for load balancing
+ Dedicated, // In this state this device is dedicated for a single network
+ Provider // This state is set only for device that can dynamically provision LB appliances
+ }
+
+ public ExternalLoadBalancerDeviceVO(long hostId, long physicalNetworkId, String provider_name, String device_name,
+ long capacity, boolean dedicated, boolean gslbProvider) {
+ this.physicalNetworkId = physicalNetworkId;
+ this.providerName = provider_name;
+ this.deviceName = device_name;
+ this.hostId = hostId;
+ this.state = LBDeviceState.Disabled;
+ this.allocationState = LBDeviceAllocationState.Free;
+ this.capacity = capacity;
+ this.isDedicatedDevice = dedicated;
+ this.isManagedDevice = false;
+ this.state = LBDeviceState.Enabled;
+ this.uuid = UUID.randomUUID().toString();
+ this.gslbProvider = gslbProvider;
+ this.gslbSitePublicIP = null;
+ this.gslbSitePrivateIP = null;
+ if (device_name.equalsIgnoreCase(ExternalNetworkDeviceManager.NetworkDevice.NetscalerSDXLoadBalancer.getName())) {
+ this.allocationState = LBDeviceAllocationState.Provider;
+ }
+ }
+
+ public ExternalLoadBalancerDeviceVO(long hostId, long physicalNetworkId, String provider_name, String device_name,
+ long capacity, boolean dedicated, boolean managed, long parentHostId) {
+ this(hostId, physicalNetworkId, provider_name, device_name, capacity, dedicated, false);
+ this.isManagedDevice = managed;
+ this.parentHostId = parentHostId;
+ }
+
+ public ExternalLoadBalancerDeviceVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public String getProviderName() {
+ return providerName;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ public long getHostId() {
+ return hostId;
+ }
+
+ public long getParentHostId() {
+ return parentHostId;
+ }
+
+ public void setParentHostId(long parentHostId) {
+ this.parentHostId = parentHostId;
+ }
+
+ public long getCapacity() {
+ return capacity;
+ }
+
+ public void setCapacity(long capacity) {
+ this.capacity = capacity;
+ }
+
+ public LBDeviceState getState() {
+ return state;
+ }
+
+ public void setState(LBDeviceState state) {
+ this.state = state;
+ }
+
+ public LBDeviceAllocationState getAllocationState() {
+ return allocationState;
+ }
+
+ public void setAllocationState(LBDeviceAllocationState allocationState) {
+ this.allocationState = allocationState;
+ }
+
+ public boolean getIsManagedDevice() {
+ return isManagedDevice;
+ }
+
+ public void setIsManagedDevice(boolean managed) {
+ this.isManagedDevice = managed;
+ }
+
+ public boolean getIsDedicatedDevice() {
+ return isDedicatedDevice;
+ }
+
+ public void setIsDedicatedDevice(boolean isDedicated) {
+ isDedicatedDevice = isDedicated;
+ }
+
+ public boolean getGslbProvider() {
+ return gslbProvider;
+ }
+
+ public void setGslbProvider(boolean gslbProvider) {
+ gslbProvider = gslbProvider;
+ }
+
+ public void setGslbSitePublicIP(String gslbSitePublicIP) {
+ this.gslbSitePublicIP = gslbSitePublicIP;
+ }
+
+ public String getGslbSitePublicIP() {
+ return gslbSitePublicIP;
+ }
+
+ public void setGslbSitePrivateIP(String gslbSitePrivateIP) {
+ this.gslbSitePrivateIP = gslbSitePrivateIP;
+ }
+
+ public String getGslbSitePrivateIP() {
+ return gslbSitePrivateIP;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDao.java b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDao.java
new file mode 100644
index 0000000..d020ea7
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDao.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 java.util.List;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface FirewallRulesCidrsDao extends GenericDao<FirewallRulesCidrsVO, Long> {
+
+ void persist(long firewallRuleId, List<String> sourceCidrs);
+
+ List<String> getSourceCidrs(long firewallRuleId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java
new file mode 100644
index 0000000..b007e19
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.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.ArrayList;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+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.Transaction;
+
+@Component
+@Local(value=FirewallRulesCidrsDao.class)
+public class FirewallRulesCidrsDaoImpl extends GenericDaoBase<FirewallRulesCidrsVO, Long> implements FirewallRulesCidrsDao {
+ private static final Logger s_logger = Logger.getLogger(FirewallRulesCidrsDaoImpl.class);
+ protected final SearchBuilder<FirewallRulesCidrsVO> CidrsSearch;
+
+ protected FirewallRulesCidrsDaoImpl() {
+ CidrsSearch = createSearchBuilder();
+ CidrsSearch.and("firewallRuleId", CidrsSearch.entity().getFirewallRuleId(), SearchCriteria.Op.EQ);
+ CidrsSearch.done();
+ }
+
+ @Override @DB
+ public List<String> getSourceCidrs(long firewallRuleId) {
+ SearchCriteria<FirewallRulesCidrsVO> sc = CidrsSearch.create();
+ sc.setParameters("firewallRuleId", firewallRuleId);
+
+ List<FirewallRulesCidrsVO> results = search(sc, null);
+ List<String> cidrs = new ArrayList<String>(results.size());
+ for (FirewallRulesCidrsVO result : results) {
+ cidrs.add(result.getCidr());
+ }
+
+ return cidrs;
+ }
+
+ @Override @DB
+ public void persist(long firewallRuleId, List<String> sourceCidrs) {
+ Transaction txn = Transaction.currentTxn();
+
+ txn.start();
+ for (String tag : sourceCidrs) {
+ FirewallRulesCidrsVO vo = new FirewallRulesCidrsVO(firewallRuleId, tag);
+ persist(vo);
+ }
+ txn.commit();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsVO.java b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsVO.java
new file mode 100644
index 0000000..75b8919
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/FirewallRulesCidrsVO.java
@@ -0,0 +1,65 @@
+// 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=("firewall_rules_cidrs"))
+public class FirewallRulesCidrsVO implements InternalIdentity {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private Long id;
+
+ @Column(name="firewall_rule_id")
+ private long firewallRuleId;
+
+ @Column(name="source_cidr")
+ private String sourceCidrList;
+
+ public FirewallRulesCidrsVO() { }
+
+ public FirewallRulesCidrsVO(long firewallRuleId, String sourceCidrList) {
+ this.firewallRuleId = firewallRuleId;
+ this.sourceCidrList = sourceCidrList;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getFirewallRuleId() {
+ return firewallRuleId;
+ }
+
+ public String getCidr() {
+ return sourceCidrList;
+ }
+
+ public String getSourceCidrList() {
+ return sourceCidrList;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/FirewallRulesDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/FirewallRulesDao.java b/engine/schema/src/com/cloud/network/dao/FirewallRulesDao.java
new file mode 100644
index 0000000..6b9b3bb
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/FirewallRulesDao.java
@@ -0,0 +1,64 @@
+// 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.FirewallRule;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.utils.db.GenericDao;
+
+/*
+ * Data Access Object for user_ip_address and ip_forwarding tables
+ */
+public interface FirewallRulesDao extends GenericDao<FirewallRuleVO, Long> {
+
+ List<FirewallRuleVO> listByIpAndPurposeAndNotRevoked(long ipAddressId, FirewallRule.Purpose purpose);
+
+ List<FirewallRuleVO> listByNetworkAndPurposeAndNotRevoked(long networkId, FirewallRule.Purpose purpose);
+
+ boolean setStateToAdd(FirewallRuleVO rule);
+
+ boolean revoke(FirewallRuleVO rule);
+
+ boolean releasePorts(long ipAddressId, String protocol, FirewallRule.Purpose purpose, int[] ports);
+
+ List<FirewallRuleVO> listByIpAndPurpose(long ipAddressId, FirewallRule.Purpose purpose);
+
+ List<FirewallRuleVO> listByNetworkAndPurpose(long networkId, FirewallRule.Purpose purpose);
+
+ List<FirewallRuleVO> listStaticNatByVmId(long vmId);
+
+ List<FirewallRuleVO> listByIpPurposeAndProtocolAndNotRevoked(long ipAddressId, Integer startPort, Integer endPort, String protocol, FirewallRule.Purpose purpose);
+
+ FirewallRuleVO findByRelatedId(long ruleId);
+
+ List<FirewallRuleVO> listSystemRules();
+
+ List<FirewallRuleVO> listByIp(long ipAddressId);
+
+ List<FirewallRuleVO> listByIpAndNotRevoked(long ipAddressId);
+
+ long countRulesByIpId(long sourceIpId);
+
+ List<FirewallRuleVO> listByNetworkPurposeTrafficTypeAndNotRevoked(long networkId, FirewallRule.Purpose purpose, FirewallRule.TrafficType trafficType);
+ List<FirewallRuleVO> listByNetworkPurposeTrafficType(long networkId, FirewallRule.Purpose purpose, FirewallRule.TrafficType trafficType);
+
+ List<FirewallRuleVO> listByIpAndPurposeWithState(Long addressId, FirewallRule.Purpose purpose, FirewallRule.State state);
+
+ void loadSourceCidrs(FirewallRuleVO rule);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/FirewallRulesDaoImpl.java b/engine/schema/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
new file mode 100644
index 0000000..45a8068
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/FirewallRulesDaoImpl.java
@@ -0,0 +1,352 @@
+// 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;
+import com.cloud.network.rules.FirewallRule.FirewallRuleType;
+import com.cloud.network.rules.FirewallRule.Purpose;
+import com.cloud.network.rules.FirewallRule.State;
+import com.cloud.network.rules.FirewallRule.TrafficType;
+import com.cloud.network.rules.FirewallRuleVO;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.tags.dao.ResourceTagsDaoImpl;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = FirewallRulesDao.class)
+@DB(txn = false)
+public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> implements FirewallRulesDao {
+
+ protected final SearchBuilder<FirewallRuleVO> AllFieldsSearch;
+ protected final SearchBuilder<FirewallRuleVO> NotRevokedSearch;
+ protected final SearchBuilder<FirewallRuleVO> ReleaseSearch;
+ protected SearchBuilder<FirewallRuleVO> VmSearch;
+ protected final SearchBuilder<FirewallRuleVO> SystemRuleSearch;
+ protected final GenericSearchBuilder<FirewallRuleVO, Long> RulesByIpCount;
+
+ @Inject protected FirewallRulesCidrsDao _firewallRulesCidrsDao;
+ @Inject ResourceTagDao _tagsDao;
+ @Inject IPAddressDao _ipDao;
+
+ protected FirewallRulesDaoImpl() {
+ super();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("ipId", AllFieldsSearch.entity().getSourceIpAddressId(), Op.EQ);
+ AllFieldsSearch.and("protocol", AllFieldsSearch.entity().getProtocol(), Op.EQ);
+ AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+ AllFieldsSearch.and("purpose", AllFieldsSearch.entity().getPurpose(), Op.EQ);
+ AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
+ AllFieldsSearch.and("domain", AllFieldsSearch.entity().getDomainId(), Op.EQ);
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
+ AllFieldsSearch.and("related", AllFieldsSearch.entity().getRelated(), Op.EQ);
+ AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), Op.EQ);
+ AllFieldsSearch.done();
+
+ NotRevokedSearch = createSearchBuilder();
+ NotRevokedSearch.and("ipId", NotRevokedSearch.entity().getSourceIpAddressId(), Op.EQ);
+ NotRevokedSearch.and("state", NotRevokedSearch.entity().getState(), Op.NEQ);
+ NotRevokedSearch.and("purpose", NotRevokedSearch.entity().getPurpose(), Op.EQ);
+ NotRevokedSearch.and("protocol", NotRevokedSearch.entity().getProtocol(), Op.EQ);
+ NotRevokedSearch.and("sourcePortStart", NotRevokedSearch.entity().getSourcePortStart(), Op.EQ);
+ NotRevokedSearch.and("sourcePortEnd", NotRevokedSearch.entity().getSourcePortEnd(), Op.EQ);
+ NotRevokedSearch.and("networkId", NotRevokedSearch.entity().getNetworkId(), Op.EQ);
+ NotRevokedSearch.and("trafficType", NotRevokedSearch.entity().getTrafficType(), Op.EQ);
+ NotRevokedSearch.done();
+
+ ReleaseSearch = createSearchBuilder();
+ ReleaseSearch.and("protocol", ReleaseSearch.entity().getProtocol(), Op.EQ);
+ ReleaseSearch.and("ipId", ReleaseSearch.entity().getSourceIpAddressId(), Op.EQ);
+ ReleaseSearch.and("purpose", ReleaseSearch.entity().getPurpose(), Op.EQ);
+ ReleaseSearch.and("ports", ReleaseSearch.entity().getSourcePortStart(), Op.IN);
+ ReleaseSearch.done();
+
+ SystemRuleSearch = createSearchBuilder();
+ SystemRuleSearch.and("type", SystemRuleSearch.entity().getType(), Op.EQ);
+ SystemRuleSearch.and("ipId", SystemRuleSearch.entity().getSourceIpAddressId(), Op.NULL);
+ SystemRuleSearch.done();
+
+ RulesByIpCount = createSearchBuilder(Long.class);
+ RulesByIpCount.select(null, Func.COUNT, RulesByIpCount.entity().getId());
+ RulesByIpCount.and("ipAddressId", RulesByIpCount.entity().getSourceIpAddressId(), Op.EQ);
+ RulesByIpCount.done();
+ }
+
+ @Override
+ public List<FirewallRuleVO> listSystemRules() {
+ SearchCriteria<FirewallRuleVO> sc = SystemRuleSearch.create();
+ sc.setParameters("type", FirewallRuleType.System.toString());
+ return listBy(sc);
+ }
+
+ @Override
+ public boolean releasePorts(long ipId, String protocol, FirewallRule.Purpose purpose, int[] ports) {
+ SearchCriteria<FirewallRuleVO> sc = ReleaseSearch.create();
+ sc.setParameters("protocol", protocol);
+ sc.setParameters("ipId", ipId);
+ sc.setParameters("purpose", purpose);
+ sc.setParameters("ports", ports);
+
+ int results = remove(sc);
+ return results == ports.length;
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIpAndPurpose(long ipId, FirewallRule.Purpose purpose) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ipId", ipId);
+ sc.setParameters("purpose", purpose);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIpAndPurposeAndNotRevoked(long ipId, FirewallRule.Purpose purpose) {
+ SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
+ sc.setParameters("ipId", ipId);
+ sc.setParameters("state", State.Revoke);
+
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByNetworkAndPurposeAndNotRevoked(long networkId, FirewallRule.Purpose purpose) {
+ SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
+ sc.setParameters("networkId", networkId);
+ sc.setParameters("state", State.Revoke);
+
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByNetworkAndPurpose(long networkId, FirewallRule.Purpose purpose) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("purpose", purpose);
+ sc.setParameters("networkId", networkId);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByNetworkPurposeTrafficTypeAndNotRevoked(long networkId, FirewallRule.Purpose purpose, TrafficType trafficType) {
+ SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
+ sc.setParameters("networkId", networkId);
+ sc.setParameters("state", State.Revoke);
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+ sc.setParameters("trafficType", trafficType);
+
+ return listBy(sc);
+ }
+
+
+ @Override
+ public boolean setStateToAdd(FirewallRuleVO rule) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("id", rule.getId());
+ sc.setParameters("state", State.Staged);
+
+ rule.setState(State.Add);
+
+ return update(rule, sc) > 0;
+ }
+
+ @Override
+ public boolean revoke(FirewallRuleVO rule) {
+ rule.setState(State.Revoke);
+ return update(rule.getId(), rule);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listStaticNatByVmId(long vmId) {
+ if (VmSearch == null) {
+ SearchBuilder<IPAddressVO> IpSearch = _ipDao.createSearchBuilder();
+ IpSearch.and("associatedWithVmId", IpSearch.entity().getAssociatedWithVmId(), SearchCriteria.Op.EQ);
+ IpSearch.and("oneToOneNat", IpSearch.entity().isOneToOneNat(), SearchCriteria.Op.NNULL);
+
+ VmSearch = createSearchBuilder();
+ VmSearch.and("purpose", VmSearch.entity().getPurpose(), Op.EQ);
+ VmSearch.join("ipSearch", IpSearch, VmSearch.entity().getSourceIpAddressId(), IpSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+ VmSearch.done();
+ }
+
+ SearchCriteria<FirewallRuleVO> sc = VmSearch.create();
+ sc.setParameters("purpose", Purpose.StaticNat);
+ sc.setJoinParameters("ipSearch", "associatedWithVmId", vmId);
+
+ return listBy(sc);
+ }
+
+ @Override
+ @DB
+ public FirewallRuleVO persist(FirewallRuleVO firewallRule) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+
+ FirewallRuleVO dbfirewallRule = super.persist(firewallRule);
+ saveSourceCidrs(firewallRule, firewallRule.getSourceCidrList());
+ loadSourceCidrs(dbfirewallRule);
+
+ txn.commit();
+ return dbfirewallRule;
+ }
+
+ public void saveSourceCidrs(FirewallRuleVO firewallRule, List<String> cidrList) {
+ if (cidrList == null) {
+ return;
+ }
+ _firewallRulesCidrsDao.persist(firewallRule.getId(), cidrList);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIpPurposeAndProtocolAndNotRevoked(long ipAddressId, Integer startPort, Integer endPort, String protocol, FirewallRule.Purpose purpose) {
+ SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
+ sc.setParameters("ipId", ipAddressId);
+ sc.setParameters("state", State.Revoke);
+
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+
+ if (protocol != null) {
+ sc.setParameters("protocol", protocol);
+ }
+
+ sc.setParameters("sourcePortStart", startPort);
+
+ sc.setParameters("sourcePortEnd", endPort);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public FirewallRuleVO findByRelatedId(long ruleId) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("related", ruleId);
+ sc.setParameters("purpose", Purpose.Firewall);
+
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIp(long ipId) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ipId", ipId);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIpAndNotRevoked(long ipId) {
+ SearchCriteria<FirewallRuleVO> sc = NotRevokedSearch.create();
+ sc.setParameters("ipId", ipId);
+ sc.setParameters("state", State.Revoke);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public long countRulesByIpId(long sourceIpId) {
+ SearchCriteria<Long> sc = RulesByIpCount.create();
+ sc.setParameters("ipAddressId", sourceIpId);
+ return customSearch(sc, null).get(0);
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByNetworkPurposeTrafficType(long networkId, Purpose purpose, TrafficType trafficType) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkId", networkId);
+
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+
+ sc.setParameters("trafficType", trafficType);
+
+ return listBy(sc);
+ }
+
+ @Override
+ @DB
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ FirewallRuleVO entry = findById(id);
+ if (entry != null) {
+ if (entry.getPurpose() == Purpose.LoadBalancing) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.LoadBalancer);
+ } else if (entry.getPurpose() == Purpose.PortForwarding) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.PortForwardingRule);
+ } else if (entry.getPurpose() == Purpose.Firewall) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.FirewallRule);
+ } else if (entry.getPurpose() == Purpose.NetworkACL) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.NetworkACL);
+ }
+ }
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+
+ @Override
+ public List<FirewallRuleVO> listByIpAndPurposeWithState(Long ipId, Purpose purpose, State state) {
+ SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ipId", ipId);
+
+ if (state != null) {
+ sc.setParameters("state", state);
+ }
+
+ if (purpose != null) {
+ sc.setParameters("purpose", purpose);
+ }
+
+ return listBy(sc);
+ }
+
+ @Override
+ public void loadSourceCidrs(FirewallRuleVO rule) {
+ List<String> sourceCidrs = _firewallRulesCidrsDao.getSourceCidrs(rule.getId());
+ rule.setSourceCidrList(sourceCidrs);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java
new file mode 100755
index 0000000..3d588fa
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.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 com.cloud.dc.Vlan.VlanType;
+import com.cloud.utils.db.GenericDao;
+import com.cloud.utils.net.Ip;
+
+public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
+
+ IPAddressVO markAsUnavailable(long ipAddressId);
+
+ void unassignIpAddress(long ipAddressId);
+
+ List<IPAddressVO> listByAccount(long accountId);
+
+ List<IPAddressVO> listByVlanId(long vlanId);
+
+ List<IPAddressVO> listByDcIdIpAddress(long dcId, String ipAddress);
+
+ List<IPAddressVO> listByDcId(long dcId);
+
+ List<IPAddressVO> listByAssociatedNetwork(long networkId, Boolean isSourceNat);
+
+ List<IPAddressVO> listStaticNatPublicIps(long networkId);
+
+ int countIPs(long dcId, long vlanDbId, boolean onlyCountAllocated);
+
+ int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask);
+
+ long countAllocatedIPsForAccount(long accountId);
+
+ boolean mark(long dcId, Ip ip);
+
+ int countIPsForNetwork(long dcId, boolean onlyCountAllocated, VlanType vlanType);
+
+ IPAddressVO findByAssociatedVmId(long vmId);
+
+ IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress);
+
+ public IPAddressVO findByIpAndDcId(long dcId, String ipAddress);
+
+ List<IPAddressVO> listByPhysicalNetworkId(long physicalNetworkId);
+
+ List<IPAddressVO> listByAssociatedVpc(long vpcId, Boolean isSourceNat);
+
+ long countFreePublicIPs();
+
+ long countFreeIPsInNetwork(long networkId);
+ IPAddressVO findByVmIp(String vmIp);
+
+ IPAddressVO findByAssociatedVmIdAndVmIp(long vmId, String vmIp);
+
+ IPAddressVO findByIpAndNetworkId(long networkId, String ipAddress);
+}