You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/05/07 01:35:17 UTC
[37/56] [abbrv] [partial] Moved most of the VOs and DAOs from server
package into engine-schema as well
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDao.java b/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDao.java
new file mode 100644
index 0000000..02df92e
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDao.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.vpc.dao;
+
+import java.util.List;
+
+import com.cloud.network.vpc.PrivateIpVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface PrivateIpDao extends GenericDao<PrivateIpVO, Long>{
+
+ /**
+ * @param dcId
+ * @param networkId
+ * @param requestedIp TODO
+ * @return
+ */
+ PrivateIpVO allocateIpAddress(long dcId, long networkId, String requestedIp);
+
+ /**
+ * @param ipAddress
+ * @param networkId
+ */
+ void releaseIpAddress(String ipAddress, long networkId);
+
+ /**
+ * @param networkId
+ * @param ip4Address
+ * @return
+ */
+ PrivateIpVO findByIpAndSourceNetworkId(long networkId, String ip4Address);
+
+ /**
+ * @param networkId
+ * @return
+ */
+ List<PrivateIpVO> listByNetworkId(long networkId);
+
+ /**
+ * @param ntwkId
+ * @return
+ */
+ int countAllocatedByNetworkId(long ntwkId);
+
+ /**
+ * @param networkId
+ */
+ void deleteByNetworkId(long networkId);
+
+ int countByNetworkId(long ntwkId);
+
+ /**
+ * @param vpcId
+ * @param ip4Address
+ * @return
+ */
+ PrivateIpVO findByIpAndVpcId(long vpcId, String ip4Address);
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java
new file mode 100644
index 0000000..ecab3bb
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java
@@ -0,0 +1,156 @@
+// 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.vpc.dao;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.vpc.PrivateIpVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = PrivateIpDao.class)
+@DB(txn = false)
+public class PrivateIpDaoImpl extends GenericDaoBase<PrivateIpVO, Long> implements PrivateIpDao {
+ private static final Logger s_logger = Logger.getLogger(PrivateIpDaoImpl.class);
+
+ private final SearchBuilder<PrivateIpVO> AllFieldsSearch;
+ private final GenericSearchBuilder<PrivateIpVO, Integer> CountAllocatedByNetworkId;
+ private final GenericSearchBuilder<PrivateIpVO, Integer> CountByNetworkId;
+
+
+ protected PrivateIpDaoImpl() {
+ super();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.done();
+
+ CountAllocatedByNetworkId = createSearchBuilder(Integer.class);
+ CountAllocatedByNetworkId.select(null, Func.COUNT, CountAllocatedByNetworkId.entity().getId());
+ CountAllocatedByNetworkId.and("networkId", CountAllocatedByNetworkId.entity().getNetworkId(), Op.EQ);
+ CountAllocatedByNetworkId.and("taken", CountAllocatedByNetworkId.entity().getTakenAt(), Op.NNULL);
+ CountAllocatedByNetworkId.done();
+
+ CountByNetworkId = createSearchBuilder(Integer.class);
+ CountByNetworkId.select(null, Func.COUNT, CountByNetworkId.entity().getId());
+ CountByNetworkId.and("networkId", CountByNetworkId.entity().getNetworkId(), Op.EQ);
+ CountByNetworkId.done();
+ }
+
+ @Override
+ public PrivateIpVO allocateIpAddress(long dcId, long networkId, String requestedIp) {
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkId", networkId);
+ sc.setParameters("taken", (Date)null);
+
+ if (requestedIp != null) {
+ sc.setParameters("ipAddress", requestedIp);
+ }
+
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ PrivateIpVO vo = lockOneRandomRow(sc, true);
+ if (vo == null) {
+ txn.rollback();
+ return null;
+ }
+ vo.setTakenAt(new Date());
+ update(vo.getId(), vo);
+ txn.commit();
+ return vo;
+ }
+
+ @Override
+ public void releaseIpAddress(String ipAddress, long networkId) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId);
+ }
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ip", ipAddress);
+ sc.setParameters("networkId", networkId);
+
+ PrivateIpVO vo = createForUpdate();
+
+ vo.setTakenAt(null);
+ update(vo, sc);
+ }
+
+
+ @Override
+ public PrivateIpVO findByIpAndSourceNetworkId(long networkId, String ip4Address) {
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ip", ip4Address);
+ sc.setParameters("networkId", networkId);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public PrivateIpVO findByIpAndVpcId(long vpcId, String ip4Address) {
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ip", ip4Address);
+ sc.setParameters("vpcId", vpcId);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<PrivateIpVO> listByNetworkId(long networkId) {
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkId", networkId);
+ return listBy(sc);
+ }
+
+ @Override
+ public int countAllocatedByNetworkId(long ntwkId) {
+ SearchCriteria<Integer> sc = CountAllocatedByNetworkId.create();
+ sc.setParameters("networkId", ntwkId);
+ List<Integer> results = customSearch(sc, null);
+ return results.get(0);
+ }
+
+
+ @Override
+ public void deleteByNetworkId(long networkId) {
+ SearchCriteria<PrivateIpVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkId", networkId);
+ remove(sc);
+ }
+
+ @Override
+ public int countByNetworkId(long ntwkId) {
+ SearchCriteria<Integer> sc = CountByNetworkId.create();
+ sc.setParameters("networkId", ntwkId);
+ List<Integer> results = customSearch(sc, null);
+ return results.get(0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDao.java b/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDao.java
new file mode 100644
index 0000000..a8fbc09
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDao.java
@@ -0,0 +1,35 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.vpc.dao;
+
+import java.util.List;
+
+import com.cloud.network.vpc.StaticRoute;
+import com.cloud.network.vpc.StaticRouteVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface StaticRouteDao extends GenericDao<StaticRouteVO, Long>{
+
+ boolean setStateToAdd(StaticRouteVO rule);
+
+ List<? extends StaticRoute> listByGatewayIdAndNotRevoked(long gatewayId);
+
+ List<StaticRouteVO> listByVpcId(long vpcId);
+
+ long countRoutesByGateway(long gatewayId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDaoImpl.java
new file mode 100644
index 0000000..fac35a9
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/StaticRouteDaoImpl.java
@@ -0,0 +1,119 @@
+// 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.vpc.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.vpc.StaticRoute;
+import com.cloud.network.vpc.StaticRouteVO;
+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.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 = StaticRouteDao.class)
+@DB(txn = false)
+public class StaticRouteDaoImpl extends GenericDaoBase<StaticRouteVO, Long> implements StaticRouteDao{
+ protected final SearchBuilder<StaticRouteVO> AllFieldsSearch;
+ protected final SearchBuilder<StaticRouteVO> NotRevokedSearch;
+ protected final GenericSearchBuilder<StaticRouteVO, Long> RoutesByGatewayCount;
+ @Inject ResourceTagDao _tagsDao;
+
+ protected StaticRouteDaoImpl() {
+ super();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("gatewayId", AllFieldsSearch.entity().getVpcGatewayId(), Op.EQ);
+ AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
+ AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.done();
+
+ NotRevokedSearch = createSearchBuilder();
+ NotRevokedSearch.and("gatewayId", NotRevokedSearch.entity().getVpcGatewayId(), Op.EQ);
+ NotRevokedSearch.and("state", NotRevokedSearch.entity().getState(), Op.NEQ);
+ NotRevokedSearch.done();
+
+ RoutesByGatewayCount = createSearchBuilder(Long.class);
+ RoutesByGatewayCount.select(null, Func.COUNT, RoutesByGatewayCount.entity().getId());
+ RoutesByGatewayCount.and("gatewayId", RoutesByGatewayCount.entity().getVpcGatewayId(), Op.EQ);
+ RoutesByGatewayCount.done();
+ }
+
+
+ @Override
+ public boolean setStateToAdd(StaticRouteVO rule) {
+ SearchCriteria<StaticRouteVO> sc = AllFieldsSearch.create();
+ sc.setParameters("id", rule.getId());
+ sc.setParameters("state", StaticRoute.State.Staged);
+
+ rule.setState(StaticRoute.State.Add);
+
+ return update(rule, sc) > 0;
+ }
+
+
+ @Override
+ public List<? extends StaticRoute> listByGatewayIdAndNotRevoked(long gatewayId) {
+ SearchCriteria<StaticRouteVO> sc = NotRevokedSearch.create();
+ sc.setParameters("gatewayId", gatewayId);
+ sc.setParameters("state", StaticRoute.State.Revoke);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<StaticRouteVO> listByVpcId(long vpcId) {
+ SearchCriteria<StaticRouteVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcId", vpcId);
+ return listBy(sc);
+ }
+
+ @Override
+ public long countRoutesByGateway(long gatewayId) {
+ SearchCriteria<Long> sc = RoutesByGatewayCount.create();
+ sc.setParameters("gatewayId", gatewayId);
+ return customSearch(sc, null).get(0);
+ }
+
+ @Override
+ @DB
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ StaticRouteVO entry = findById(id);
+ if (entry != null) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.StaticRoute);
+ }
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
new file mode 100644
index 0000000..5a33217
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcDao.java
@@ -0,0 +1,47 @@
+// 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.vpc.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.VpcVO;
+import com.cloud.utils.db.GenericDao;
+
+
+public interface VpcDao extends GenericDao<VpcVO, Long>{
+
+ /**
+ * @param offId
+ * @return
+ */
+ int getVpcCountByOfferingId(long offId);
+
+ Vpc getActiveVpcById(long vpcId);
+
+ List<? extends Vpc> listByAccountId(long accountId);
+
+ List<VpcVO> listInactiveVpcs();
+
+ long countByAccountId(long accountId);
+
+ VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap);
+
+ void persistVpcServiceProviders(long vpcId,
+ Map<String, String> serviceProviderMap);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
new file mode 100644
index 0000000..6560b90
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcDaoImpl.java
@@ -0,0 +1,152 @@
+// 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.vpc.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import com.cloud.network.Network;
+import com.cloud.network.vpc.VpcServiceMapVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.VpcVO;
+import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.tags.dao.ResourceTagDao;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = VpcDao.class)
+@DB(txn = false)
+public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
+ final GenericSearchBuilder<VpcVO, Integer> CountByOfferingId;
+ final SearchBuilder<VpcVO> AllFieldsSearch;
+ final GenericSearchBuilder<VpcVO, Long> CountByAccountId;
+
+ @Inject ResourceTagDao _tagsDao;
+ @Inject VpcServiceMapDao _vpcSvcMap;
+
+ protected VpcDaoImpl() {
+ super();
+
+ CountByOfferingId = createSearchBuilder(Integer.class);
+ CountByOfferingId.select(null, Func.COUNT, CountByOfferingId.entity().getId());
+ CountByOfferingId.and("offeringId", CountByOfferingId.entity().getVpcOfferingId(), Op.EQ);
+ CountByOfferingId.and("removed", CountByOfferingId.entity().getRemoved(), Op.NULL);
+ CountByOfferingId.done();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+ AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ);
+ AllFieldsSearch.done();
+
+ CountByAccountId = createSearchBuilder(Long.class);
+ CountByAccountId.select(null, Func.COUNT, CountByAccountId.entity().getId());
+ CountByAccountId.and("offeringId", CountByAccountId.entity().getAccountId(), Op.EQ);
+ CountByAccountId.and("removed", CountByAccountId.entity().getRemoved(), Op.NULL);
+ CountByAccountId.done();
+ }
+
+
+ @Override
+ public int getVpcCountByOfferingId(long offId) {
+ SearchCriteria<Integer> sc = CountByOfferingId.create();
+ sc.setParameters("offeringId", offId);
+ List<Integer> results = customSearch(sc, null);
+ return results.get(0);
+ }
+
+ @Override
+ public Vpc getActiveVpcById(long vpcId) {
+ SearchCriteria<VpcVO> sc = AllFieldsSearch.create();
+ sc.setParameters("id", vpcId);
+ sc.setParameters("state", Vpc.State.Enabled);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<? extends Vpc> listByAccountId(long accountId) {
+ SearchCriteria<VpcVO> sc = AllFieldsSearch.create();
+ sc.setParameters("accountId", accountId);
+ return listBy(sc, null);
+ }
+
+ @Override
+ public List<VpcVO> listInactiveVpcs() {
+ SearchCriteria<VpcVO> sc = AllFieldsSearch.create();
+ sc.setParameters("state", Vpc.State.Inactive);
+ return listBy(sc, null);
+ }
+
+ @Override
+ @DB
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ VpcVO entry = findById(id);
+ if (entry != null) {
+ _tagsDao.removeByIdAndType(id, TaggedResourceType.Vpc);
+ }
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+
+ @Override
+ public long countByAccountId(long accountId) {
+ SearchCriteria<Long> sc = CountByAccountId.create();
+ sc.setParameters("accountId", accountId);
+ List<Long> results = customSearch(sc, null);
+ return results.get(0);
+ }
+
+ @Override
+ @DB
+ public VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ VpcVO newVpc = super.persist(vpc);
+ persistVpcServiceProviders(vpc.getId(), serviceProviderMap);
+ txn.commit();
+ return newVpc;
+ }
+
+ @Override
+ @DB
+ public void persistVpcServiceProviders(long vpcId, Map<String, String> serviceProviderMap) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ for (String service : serviceProviderMap.keySet()) {
+ VpcServiceMapVO serviceMap = new VpcServiceMapVO(vpcId, Network.Service.getService(service), Network.Provider.getProvider(serviceProviderMap.get(service)));
+ _vpcSvcMap.persist(serviceMap);
+ }
+ txn.commit();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java
new file mode 100644
index 0000000..600d67f
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.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.vpc.dao;
+
+import com.cloud.network.vpc.VpcGatewayVO;
+import com.cloud.utils.db.GenericDao;
+
+
+public interface VpcGatewayDao extends GenericDao<VpcGatewayVO, Long>{
+ VpcGatewayVO getPrivateGatewayForVpc(long vpcId);
+ VpcGatewayVO getVpnGatewayForVpc(long vpcId);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java
new file mode 100644
index 0000000..a1cd934
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.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.vpc.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.vpc.VpcGateway;
+import com.cloud.network.vpc.VpcGatewayVO;
+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 = VpcGatewayDao.class)
+@DB(txn = false)
+public class VpcGatewayDaoImpl extends GenericDaoBase<VpcGatewayVO, Long> implements VpcGatewayDao{
+ protected final SearchBuilder<VpcGatewayVO> AllFieldsSearch;
+
+ protected VpcGatewayDaoImpl() {
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.done();
+ }
+
+
+ @Override
+ public VpcGatewayVO getPrivateGatewayForVpc(long vpcId) {
+ SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcId", vpcId);
+ sc.setParameters("type", VpcGateway.Type.Private);
+
+ return findOneBy(sc);
+ }
+
+ @Override
+ public VpcGatewayVO getVpnGatewayForVpc(long vpcId) {
+ SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcId", vpcId);
+ sc.setParameters("type", VpcGateway.Type.Vpn);
+
+ return findOneBy(sc);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDao.java
new file mode 100644
index 0000000..8138ac6
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDao.java
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.vpc.dao;
+
+import com.cloud.network.vpc.VpcOfferingVO;
+import com.cloud.utils.db.GenericDao;
+
+
+public interface VpcOfferingDao extends GenericDao<VpcOfferingVO, Long>{
+ /**
+ * Returns the VPC offering that matches the unique name.
+ *
+ * @param uniqueName
+ * name
+ * @return VpcOfferingVO
+ */
+ VpcOfferingVO findByUniqueName(String uniqueName);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java
new file mode 100644
index 0000000..2cda547
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.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.vpc.dao;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.vpc.VpcOfferingVO;
+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 com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = VpcOfferingDao.class)
+@DB(txn = false)
+public class VpcOfferingDaoImpl extends GenericDaoBase<VpcOfferingVO, Long> implements VpcOfferingDao{
+ final SearchBuilder<VpcOfferingVO> AllFieldsSearch;
+
+ protected VpcOfferingDaoImpl() {
+ super();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
+ AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
+ AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ);
+ AllFieldsSearch.and("uName", AllFieldsSearch.entity().getUniqueName(), Op.EQ);
+ AllFieldsSearch.and("displayText", AllFieldsSearch.entity().getDisplayText(), Op.EQ);
+ AllFieldsSearch.and("svcOffId", AllFieldsSearch.entity().getServiceOfferingId(), Op.EQ);
+ AllFieldsSearch.done();
+
+ }
+
+ @Override
+ @DB
+ public boolean remove(Long vpcOffId) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ VpcOfferingVO offering = findById(vpcOffId);
+ offering.setUniqueName(null);
+ update(vpcOffId, offering);
+ boolean result = super.remove(vpcOffId);
+ txn.commit();
+ return result;
+ }
+
+
+ @Override
+ public VpcOfferingVO findByUniqueName(String uniqueName) {
+ SearchCriteria<VpcOfferingVO> sc = AllFieldsSearch.create();
+ sc.setParameters("uName", uniqueName);
+ return findOneBy(sc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDao.java
new file mode 100644
index 0000000..b298c1e
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDao.java
@@ -0,0 +1,41 @@
+// 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.vpc.dao;
+
+import java.util.List;
+
+import com.cloud.network.Network.Service;
+import com.cloud.network.vpc.VpcOfferingServiceMapVO;
+import com.cloud.utils.db.GenericDao;
+
+
+public interface VpcOfferingServiceMapDao extends GenericDao<VpcOfferingServiceMapVO, Long>{
+
+ List<VpcOfferingServiceMapVO> listByVpcOffId(long vpcOffId);
+
+ /**
+ * @param networkOfferingId
+ * @param services
+ * @return
+ */
+ boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service[] services);
+
+ List<String> listServicesForVpcOffering(long vpcOfferingId);
+
+ VpcOfferingServiceMapVO findByServiceProviderAndOfferingId(String service, String provider, long vpcOfferingId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDaoImpl.java
new file mode 100644
index 0000000..4b5f1b9
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcOfferingServiceMapDaoImpl.java
@@ -0,0 +1,119 @@
+// 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.vpc.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network.Service;
+import com.cloud.network.vpc.VpcOfferingServiceMapVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+
+@Component
+@Local(value = VpcOfferingServiceMapDao.class)
+@DB(txn = false)
+public class VpcOfferingServiceMapDaoImpl extends GenericDaoBase<VpcOfferingServiceMapVO, Long> implements VpcOfferingServiceMapDao{
+ final SearchBuilder<VpcOfferingServiceMapVO> AllFieldsSearch;
+ final SearchBuilder<VpcOfferingServiceMapVO> MultipleServicesSearch;
+ final GenericSearchBuilder<VpcOfferingServiceMapVO, String> ServicesSearch;
+
+
+ protected VpcOfferingServiceMapDaoImpl() {
+ super();
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("vpcOffId", AllFieldsSearch.entity().getVpcOfferingId(), 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("vpcOffId", MultipleServicesSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ);
+ MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
+ MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+ MultipleServicesSearch.done();
+
+ ServicesSearch = createSearchBuilder(String.class);
+ ServicesSearch.and("offeringId", ServicesSearch.entity().getVpcOfferingId(), SearchCriteria.Op.EQ);
+ ServicesSearch.select(null, Func.DISTINCT, ServicesSearch.entity().getService());
+ ServicesSearch.done();
+ }
+
+ @Override
+ public List<VpcOfferingServiceMapVO> listByVpcOffId(long vpcOffId) {
+ SearchCriteria<VpcOfferingServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcOffId", vpcOffId);
+ return listBy(sc);
+ }
+
+
+ @Override
+ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
+ SearchCriteria<VpcOfferingServiceMapVO> sc = MultipleServicesSearch.create();
+ sc.setParameters("vpcOffId", networkOfferingId);
+
+ 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<VpcOfferingServiceMapVO> offeringServices = listBy(sc);
+
+ if (services != null) {
+ if (offeringServices.size() == services.length) {
+ return true;
+ }
+ } else if (!offeringServices.isEmpty()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public List<String> listServicesForVpcOffering(long offId) {
+ SearchCriteria<String> sc = ServicesSearch.create();;
+ sc.setParameters("offeringId", offId);
+ return customSearch(sc, null);
+ }
+
+
+ @Override
+ public VpcOfferingServiceMapVO findByServiceProviderAndOfferingId(String service, String provider, long vpcOfferingId) {
+ SearchCriteria<VpcOfferingServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcOffId", vpcOfferingId);
+ sc.setParameters("service", service);
+ sc.setParameters("provider", provider);
+
+ return findOneBy(sc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java
new file mode 100644
index 0000000..8c4537e
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java
@@ -0,0 +1,40 @@
+// 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.vpc.dao;
+
+import java.util.List;
+
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.dao.NetworkServiceMapVO;
+import com.cloud.network.vpc.VpcServiceMapVO;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * VpcServiceMapDao deals with searches and operations done on the
+ * vpc_service_map table.
+ *
+ */
+public interface VpcServiceMapDao extends GenericDao<VpcServiceMapVO, Long>{
+ boolean areServicesSupportedInVpc(long vpcId, Service... services);
+ boolean canProviderSupportServiceInVpc(long vpcId, Service service, Provider provider);
+ List<NetworkServiceMapVO> getServicesInVpc(long vpcId);
+ String getProviderForServiceInVpc(long vpcId, Service service);
+ void deleteByVpcId(long vpcId);
+ List<String> getDistinctProviders(long vpcId);
+ String isProviderForVpc(long vpcId, Provider provider);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java
new file mode 100644
index 0000000..a992181
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java
@@ -0,0 +1,115 @@
+// 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.vpc.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import com.cloud.exception.UnsupportedServiceException;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.dao.NetworkServiceMapVO;
+import com.cloud.network.vpc.VpcServiceMapVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import org.springframework.stereotype.Component;
+
+@Component
+@Local(value=VpcServiceMapDao.class) @DB(txn=false)
+public class VpcServiceMapDaoImpl extends GenericDaoBase<VpcServiceMapVO, Long> implements VpcServiceMapDao {
+ final SearchBuilder<VpcServiceMapVO> AllFieldsSearch;
+ final SearchBuilder<VpcServiceMapVO> MultipleServicesSearch;
+ final GenericSearchBuilder<VpcServiceMapVO, String> DistinctProvidersSearch;
+
+ protected VpcServiceMapDaoImpl(){
+ super();
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), 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("vpcId", MultipleServicesSearch.entity().getVpcId(), 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("vpcId", DistinctProvidersSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
+ DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+ DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
+ DistinctProvidersSearch.done();
+ }
+
+ @Override
+ public boolean areServicesSupportedInVpc(long vpcId, Service... services) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean canProviderSupportServiceInVpc(long vpcId, Service service,
+ Provider provider) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public List<NetworkServiceMapVO> getServicesInVpc(long vpcId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getProviderForServiceInVpc(long vpcId, Service service) {
+ SearchCriteria<VpcServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("vpcId", vpcId);
+ sc.setParameters("service", service.getName());
+ VpcServiceMapVO ntwkSvc = findOneBy(sc);
+ if (ntwkSvc == null) {
+ throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the vpc id=" + vpcId);
+ }
+
+ return ntwkSvc.getProvider();
+ }
+
+ @Override
+ public void deleteByVpcId(long vpcId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public List<String> getDistinctProviders(long vpcId) {
+ SearchCriteria<String> sc = DistinctProvidersSearch.create();
+ sc.setParameters("vpcId", vpcId);
+ List<String> results = customSearch(sc, null);
+ return results;
+ }
+
+ @Override
+ public String isProviderForVpc(long vpcId, Provider provider) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.java
new file mode 100644
index 0000000..f249405
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingServiceMapVO.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.offerings;
+
+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.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="ntwk_offering_service_map")
+public class NetworkOfferingServiceMapVO implements InternalIdentity {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="network_offering_id")
+ long networkOfferingId;
+
+ @Column(name="service")
+ String service;
+
+ @Column(name="provider")
+ String provider;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ public long getId() {
+ return id;
+ }
+
+ public long getNetworkOfferingId() {
+ return networkOfferingId;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public NetworkOfferingServiceMapVO() {
+ }
+
+ public NetworkOfferingServiceMapVO(long networkOfferingId, Service service, Provider provider) {
+ this.networkOfferingId = networkOfferingId;
+ this.service = service.getName();
+ if (provider != null) {
+ this.provider = provider.getName();
+ }
+ }
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[Network Offering Service[");
+ return buf.append(networkOfferingId).append("-").append(service).append("-").append(provider).append("]").toString();
+ }
+}
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
new file mode 100755
index 0000000..c015989
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java
@@ -0,0 +1,391 @@
+// 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.offerings;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.utils.db.GenericDao;
+
+import javax.persistence.*;
+import java.util.Date;
+import java.util.UUID;
+
+@Entity
+@Table(name = "network_offerings")
+public class NetworkOfferingVO implements NetworkOffering {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ long id;
+
+ @Column(name = "name")
+ String name;
+
+ @Column(name = "unique_name")
+ private String uniqueName;
+
+ @Column(name = "display_text")
+ String displayText;
+
+ @Column(name = "nw_rate")
+ Integer rateMbps;
+
+ @Column(name = "mc_rate")
+ Integer multicastRateMbps;
+
+ @Column(name = "traffic_type")
+ @Enumerated(value = EnumType.STRING)
+ TrafficType trafficType;
+
+ @Column(name = "specify_vlan")
+ boolean specifyVlan;
+
+ @Column(name = "system_only")
+ boolean systemOnly;
+
+ @Column(name = "service_offering_id")
+ Long serviceOfferingId;
+
+ @Column(name = "tags", length = 4096)
+ String tags;
+
+ @Column(name = "default")
+ boolean isDefault;
+
+ @Column(name = "availability")
+ @Enumerated(value = EnumType.STRING)
+ Availability availability;
+
+ @Column(name = "state")
+ @Enumerated(value = EnumType.STRING)
+ State state = State.Disabled;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ Date created;
+
+ @Column(name = "guest_type")
+ @Enumerated(value = EnumType.STRING)
+ Network.GuestType guestType;
+
+ @Column(name = "dedicated_lb_service")
+ boolean dedicatedLB;
+
+ @Column(name = "shared_source_nat_service")
+ boolean sharedSourceNat;
+
+ @Column(name = "specify_ip_ranges")
+ boolean specifyIpRanges = false;
+
+ @Column(name = "sort_key")
+ int sortKey;
+
+ @Column(name = "uuid")
+ String uuid;
+
+ @Column(name = "redundant_router_service")
+ boolean redundantRouter;
+
+ @Column(name = "conserve_mode")
+ boolean conserveMode;
+
+ @Column(name = "elastic_ip_service")
+ boolean elasticIp;
+
+ @Column(name = "eip_associate_public_ip")
+ boolean eipAssociatePublicIp;
+
+ @Column(name = "elastic_lb_service")
+ boolean elasticLb;
+
+ @Column(name = "inline")
+ boolean inline;
+
+ @Column(name = "is_persistent")
+ boolean isPersistent;
+
+ @Override
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public TrafficType getTrafficType() {
+ return trafficType;
+ }
+
+ @Override
+ public Integer getMulticastRateMbps() {
+ return multicastRateMbps;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Integer getRateMbps() {
+ return rateMbps;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ @Override
+ public boolean isSystemOnly() {
+ return systemOnly;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ @Override
+ public String getTags() {
+ return tags;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDisplayText(String displayText) {
+ this.displayText = displayText;
+ }
+
+ public void setRateMbps(Integer rateMbps) {
+ this.rateMbps = rateMbps;
+ }
+
+ public void setMulticastRateMbps(Integer multicastRateMbps) {
+ this.multicastRateMbps = multicastRateMbps;
+ }
+
+ @Override
+ public boolean isDefault() {
+ return isDefault;
+ }
+
+ @Override
+ public boolean getSpecifyVlan() {
+ return specifyVlan;
+ }
+
+ @Override
+ public Availability getAvailability() {
+ return availability;
+ }
+
+ public void setAvailability(Availability availability) {
+ this.availability = availability;
+ }
+
+ @Override
+ public String getUniqueName() {
+ return uniqueName;
+ }
+
+ @Override
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ @Override
+ public Network.GuestType getGuestType() {
+ return guestType;
+ }
+
+ public void setServiceOfferingId(Long serviceOfferingId) {
+ this.serviceOfferingId = serviceOfferingId;
+ }
+
+ @Override
+ public Long getServiceOfferingId() {
+ return serviceOfferingId;
+ }
+
+ @Override
+ public boolean getDedicatedLB() {
+ return dedicatedLB;
+ }
+
+ public void setDedicatedLB(boolean dedicatedLB) {
+ this.dedicatedLB = dedicatedLB;
+ }
+
+ @Override
+ public boolean getSharedSourceNat() {
+ return sharedSourceNat;
+ }
+
+ public void setSharedSourceNat(boolean sharedSourceNat) {
+ this.sharedSourceNat = sharedSourceNat;
+ }
+
+ @Override
+ public boolean getRedundantRouter() {
+ return redundantRouter;
+ }
+
+ public void setRedundantRouter(boolean redundantRouter) {
+ this.redundantRouter = redundantRouter;
+ }
+
+ public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
+ Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent) {
+ this.name = name;
+ this.displayText = displayText;
+ this.rateMbps = rateMbps;
+ this.multicastRateMbps = multicastRateMbps;
+ this.trafficType = trafficType;
+ this.systemOnly = systemOnly;
+ this.specifyVlan = specifyVlan;
+ this.isDefault = isDefault;
+ this.availability = availability;
+ this.uniqueName = name;
+ this.uuid = UUID.randomUUID().toString();
+ this.tags = tags;
+ this.guestType = guestType;
+ this.conserveMode = conserveMode;
+ this.dedicatedLB = true;
+ this.sharedSourceNat = false;
+ this.redundantRouter = false;
+ this.elasticIp = false;
+ this.eipAssociatePublicIp = true;
+ this.elasticLb = false;
+ this.inline = false;
+ this.specifyIpRanges = specifyIpRanges;
+ this.isPersistent=isPersistent;
+ }
+
+ public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
+ Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb,
+ boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP) {
+ this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent);
+ this.dedicatedLB = dedicatedLb;
+ this.sharedSourceNat = sharedSourceNat;
+ this.redundantRouter = redundantRouter;
+ this.elasticIp = elasticIp;
+ this.elasticLb = elasticLb;
+ this.inline = inline;
+ this.eipAssociatePublicIp = associatePublicIP;
+ }
+
+ public NetworkOfferingVO() {
+ }
+
+ /**
+ * Network Offering for all system vms.
+ *
+ * @param name
+ * @param trafficType
+ * @param specifyIpRanges
+ * TODO
+ */
+ public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
+ this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false);
+ this.state = State.Enabled;
+ }
+
+ public NetworkOfferingVO(String name, Network.GuestType guestType) {
+ this(name, "System Offering for " + name, TrafficType.Guest, true, true, 0, 0, true, Availability.Optional,
+ null, Network.GuestType.Isolated, true, false, false);
+ this.state = State.Enabled;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[Network Offering [");
+ return buf.append(id).append("-").append(trafficType).append("-").append(name).append("]").toString();
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public void setSortKey(int key) {
+ sortKey = key;
+ }
+
+ public int getSortKey() {
+ return sortKey;
+ }
+
+ public void setUniqueName(String uniqueName) {
+ this.uniqueName = uniqueName;
+ }
+
+ @Override
+ public boolean isConserveMode() {
+ return conserveMode;
+ }
+
+ @Override
+ public boolean getElasticIp() {
+ return elasticIp;
+ }
+
+ @Override
+ public boolean getAssociatePublicIP() {
+ return eipAssociatePublicIp;
+ }
+
+ @Override
+ public boolean getElasticLb() {
+ return elasticLb;
+ }
+
+ @Override
+ public boolean getSpecifyIpRanges() {
+ return specifyIpRanges;
+ }
+
+ @Override
+ public boolean isInline() {
+ return inline;
+ }
+
+ public void setIsPersistent(Boolean isPersistent) {
+ this.isPersistent = isPersistent;
+ }
+
+ public boolean getIsPersistent() {
+ return isPersistent;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
new file mode 100644
index 0000000..405d348
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.offerings.dao;
+
+import java.util.List;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Availability;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * NetworkOfferingDao deals with searches and operations done on the
+ * network_offering table.
+ *
+ */
+public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long> {
+ /**
+ * Returns the network offering that matches the name.
+ *
+ * @param uniqueName
+ * name
+ * @return NetworkOfferingVO
+ */
+ NetworkOfferingVO findByUniqueName(String uniqueName);
+
+ /**
+ * If not, then it persists it into the database.
+ *
+ * @param offering
+ * network offering to persist if not in the database.
+ * @return NetworkOfferingVO backed by a row in the database
+ */
+ NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering);
+
+ List<NetworkOfferingVO> listSystemNetworkOfferings();
+
+ List<NetworkOfferingVO> listByAvailability(Availability availability, boolean isSystem);
+
+ List<Long> getOfferingIdsToUpgradeFrom(NetworkOffering originalOffering);
+
+ List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
new file mode 100644
index 0000000..d1e4424
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java
@@ -0,0 +1,169 @@
+// 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.offerings.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.persistence.EntityExistsException;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Availability;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value = NetworkOfferingDao.class)
+@DB(txn = false)
+public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
+ final SearchBuilder<NetworkOfferingVO> NameSearch;
+ final SearchBuilder<NetworkOfferingVO> SystemOfferingSearch;
+ final SearchBuilder<NetworkOfferingVO> AvailabilitySearch;
+ final SearchBuilder<NetworkOfferingVO> AllFieldsSearch;
+ private final GenericSearchBuilder<NetworkOfferingVO, Long> UpgradeSearch;
+
+ protected NetworkOfferingDaoImpl() {
+ super();
+
+ NameSearch = createSearchBuilder();
+ NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+ NameSearch.and("uniqueName", NameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
+ NameSearch.done();
+
+ SystemOfferingSearch = createSearchBuilder();
+ SystemOfferingSearch.and("system", SystemOfferingSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+ SystemOfferingSearch.done();
+
+ AvailabilitySearch = createSearchBuilder();
+ AvailabilitySearch.and("availability", AvailabilitySearch.entity().getAvailability(), SearchCriteria.Op.EQ);
+ AvailabilitySearch.and("isSystem", AvailabilitySearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+ AvailabilitySearch.done();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("isSystem", AllFieldsSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.done();
+
+ UpgradeSearch = createSearchBuilder(Long.class);
+ UpgradeSearch.selectField(UpgradeSearch.entity().getId());
+ UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().getId(), Op.NEQ);
+ UpgradeSearch.and("physicalNetworkId", UpgradeSearch.entity().isSystemOnly(), Op.EQ);
+ UpgradeSearch.and("trafficType", UpgradeSearch.entity().getTrafficType(), Op.EQ);
+ UpgradeSearch.and("guestType", UpgradeSearch.entity().getGuestType(), Op.EQ);
+ UpgradeSearch.and("state", UpgradeSearch.entity().getState(), Op.EQ);
+ UpgradeSearch.done();
+ }
+
+ @Override
+ public NetworkOfferingVO findByUniqueName(String uniqueName) {
+ SearchCriteria<NetworkOfferingVO> sc = NameSearch.create();
+
+ sc.setParameters("uniqueName", uniqueName);
+
+ return findOneBy(sc);
+
+ }
+
+ @Override
+ public NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering) {
+ assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
+ NetworkOfferingVO vo = findByUniqueName(offering.getUniqueName());
+ if (vo != null) {
+ return vo;
+ }
+ try {
+ vo = persist(offering);
+ return vo;
+ } catch (EntityExistsException e) {
+ // Assume it's conflict on unique name from two different management servers.
+ return findByUniqueName(offering.getName());
+ }
+ }
+
+ @Override
+ public List<NetworkOfferingVO> listSystemNetworkOfferings() {
+ SearchCriteria<NetworkOfferingVO> sc = SystemOfferingSearch.create();
+ sc.setParameters("system", true);
+ return this.listIncludingRemovedBy(sc, null);
+ }
+
+ @Override
+ public List<NetworkOfferingVO> listByAvailability(Availability availability, boolean isSystem) {
+ SearchCriteria<NetworkOfferingVO> sc = AvailabilitySearch.create();
+ sc.setParameters("availability", availability);
+ sc.setParameters("isSystem", isSystem);
+ return listBy(sc, null);
+ }
+
+ @Override
+ @DB
+ public boolean remove(Long networkOfferingId) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ NetworkOfferingVO offering = findById(networkOfferingId);
+ offering.setUniqueName(null);
+ update(networkOfferingId, offering);
+ boolean result = super.remove(networkOfferingId);
+ txn.commit();
+ return result;
+ }
+
+ @Override
+ public List<Long> getOfferingIdsToUpgradeFrom(NetworkOffering originalOffering) {
+ SearchCriteria<Long> sc = UpgradeSearch.create();
+ // exclude original offering
+ sc.addAnd("id", SearchCriteria.Op.NEQ, originalOffering.getId());
+
+ // list only non-system offerings
+ sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
+
+ // Type of the network should be the same
+ sc.addAnd("guestType", SearchCriteria.Op.EQ, originalOffering.getGuestType());
+
+ // Traffic types should be the same
+ sc.addAnd("trafficType", SearchCriteria.Op.EQ, originalOffering.getTrafficType());
+
+ sc.addAnd("state", SearchCriteria.Op.EQ, NetworkOffering.State.Enabled);
+
+ //specify Vlan should be the same
+ sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, originalOffering.getSpecifyVlan());
+
+ return customSearch(sc, null);
+ }
+
+ @Override
+ public List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type) {
+ SearchCriteria<NetworkOfferingVO> sc = AllFieldsSearch.create();
+ sc.setParameters("trafficType", trafficType);
+ sc.setParameters("guestType", type);
+ sc.setParameters("state", state);
+ return listBy(sc, null);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
new file mode 100644
index 0000000..42ab0eb
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDao.java
@@ -0,0 +1,50 @@
+// 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.offerings.dao;
+
+import java.util.List;
+
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.offerings.NetworkOfferingServiceMapVO;
+import com.cloud.utils.db.GenericDao;
+
+/**
+ * NetworkOfferingServiceDao deals with searches and operations done on the
+ * ntwk_offering_service_map table.
+ *
+ */
+public interface NetworkOfferingServiceMapDao extends GenericDao<NetworkOfferingServiceMapVO, Long> {
+ boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
+
+ List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId);
+
+ void deleteByOfferingId(long networkOfferingId);
+
+ List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service);
+
+ boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider);
+
+ List<String> listServicesForNetworkOffering(long networkOfferingId);
+
+ List<String> getDistinctProviders(long offId);
+}
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
new file mode 100644
index 0000000..7282443
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingServiceMapDaoImpl.java
@@ -0,0 +1,171 @@
+// 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.offerings.dao;
+
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.offerings.NetworkOfferingServiceMapVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+
+@Component
+@Local(value=NetworkOfferingServiceMapDao.class) @DB(txn=false)
+public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOfferingServiceMapVO, Long> implements NetworkOfferingServiceMapDao {
+
+ final SearchBuilder<NetworkOfferingServiceMapVO> AllFieldsSearch;
+ final SearchBuilder<NetworkOfferingServiceMapVO> MultipleServicesSearch;
+ final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ProvidersSearch;
+ final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ServicesSearch;
+ final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> DistinctProvidersSearch;
+
+
+ protected NetworkOfferingServiceMapDaoImpl() {
+ super();
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("networkOfferingId", AllFieldsSearch.entity().getNetworkOfferingId(), 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("networkOfferingId", MultipleServicesSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+ MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
+ MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+ MultipleServicesSearch.done();
+
+ ProvidersSearch = createSearchBuilder(String.class);
+ ProvidersSearch.and("networkOfferingId", ProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+ ProvidersSearch.and("service", ProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
+ ProvidersSearch.select(null, Func.DISTINCT, ProvidersSearch.entity().getProvider());
+ ProvidersSearch.done();
+
+ ServicesSearch = createSearchBuilder(String.class);
+ ServicesSearch.and("networkOfferingId", ServicesSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+ ServicesSearch.select(null, Func.DISTINCT, ServicesSearch.entity().getService());
+ ServicesSearch.done();
+
+ DistinctProvidersSearch = createSearchBuilder(String.class);
+ DistinctProvidersSearch.and("offId", DistinctProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
+ DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
+ DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
+ DistinctProvidersSearch.done();
+ }
+
+ @Override
+ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
+ SearchCriteria<NetworkOfferingServiceMapVO> sc = MultipleServicesSearch.create();
+ sc.setParameters("networkOfferingId", networkOfferingId);
+
+ 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<NetworkOfferingServiceMapVO> offeringServices = listBy(sc);
+
+ if (services != null) {
+ if (offeringServices.size() == services.length) {
+ return true;
+ }
+ } else if (!offeringServices.isEmpty()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId) {
+ SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkOfferingId", networkOfferingId);
+ return listBy(sc);
+ }
+
+ @Override
+ public void deleteByOfferingId(long networkOfferingId) {
+ SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkOfferingId", networkOfferingId);
+ remove(sc);
+ }
+
+ @Override
+ public List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service) {
+ SearchCriteria<String> sc = ProvidersSearch.create();;
+
+ sc.setParameters("networkOfferingId", networkOfferingId);
+ sc.setParameters("service", service.getName());
+
+ return customSearch(sc, null);
+ }
+
+ @Override
+ public boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider) {
+ SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();;
+
+ sc.setParameters("networkOfferingId", networkOfferingId);
+ sc.setParameters("provider", provider.getName());
+
+ if (findOneBy(sc) != null) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> listServicesForNetworkOffering(long networkOfferingId) {
+ SearchCriteria<String> sc = ServicesSearch.create();;
+ sc.setParameters("networkOfferingId", networkOfferingId);
+ return customSearch(sc, null);
+ }
+
+ @Override
+ public NetworkOfferingServiceMapVO persist(
+ NetworkOfferingServiceMapVO entity) {
+ SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
+ sc.setParameters("networkOfferingId", entity.getNetworkOfferingId());
+ sc.setParameters("service", entity.getService());
+ sc.setParameters("provider", entity.getProvider());
+ NetworkOfferingServiceMapVO mappingInDb = findOneBy(sc);
+ return mappingInDb!=null? mappingInDb : super.persist(entity);
+ }
+
+ @Override
+ public List<String> getDistinctProviders(long offId) {
+ SearchCriteria<String> sc = DistinctProvidersSearch.create();
+ sc.setParameters("offId", offId);
+ List<String> results = customSearch(sc, null);
+ return results;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/572e71e5/engine/schema/src/com/cloud/projects/ProjectAccountVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/projects/ProjectAccountVO.java b/engine/schema/src/com/cloud/projects/ProjectAccountVO.java
new file mode 100644
index 0000000..8c4f1ba
--- /dev/null
+++ b/engine/schema/src/com/cloud/projects/ProjectAccountVO.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.projects;
+
+import java.util.Date;
+
+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.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="project_account")
+@SuppressWarnings("unused")
+public class ProjectAccountVO implements ProjectAccount, InternalIdentity {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="project_id")
+ private long projectId;
+
+ @Column(name="account_id")
+ private long accountId;
+
+ @Column(name="account_role")
+ @Enumerated(value=EnumType.STRING)
+ private Role accountRole = Role.Regular;
+
+ @Column(name="project_account_id")
+ long projectAccountId;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ private Date created;
+
+
+ protected ProjectAccountVO(){
+ }
+
+ public ProjectAccountVO(Project project, long accountId, Role accountRole) {
+ this.accountId = accountId;
+ this.accountRole = accountRole;
+ this.projectId = project.getId();
+ this.projectAccountId = project.getProjectAccountId();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getProjectId() {
+ return projectId;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public Role getAccountRole() {
+ return accountRole;
+ }
+
+ @Override
+ public long getProjectAccountId() {
+ return projectAccountId;
+ }
+
+ public void setAccountRole(Role accountRole) {
+ this.accountRole = accountRole;
+ }
+}