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/11 11:59:31 UTC
[06/51] [partial] merge master
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java b/engine/schema/src/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java
new file mode 100644
index 0000000..746b66f
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java
@@ -0,0 +1,200 @@
+// 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.security.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLTransactionRollbackException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.network.security.VmRulesetLogVO;
+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={VmRulesetLogDao.class})
+public class VmRulesetLogDaoImpl extends GenericDaoBase<VmRulesetLogVO, Long> implements VmRulesetLogDao {
+ protected static Logger s_logger = Logger.getLogger(VmRulesetLogDaoImpl.class);
+ private SearchBuilder<VmRulesetLogVO> VmIdSearch;
+ private String INSERT_OR_UPDATE = "INSERT INTO op_vm_ruleset_log (instance_id, created, logsequence) " +
+ " VALUES(?, now(), 1) ON DUPLICATE KEY UPDATE logsequence=logsequence+1";
+ private static HashMap<Integer, String> cachedPrepStmtStrings = new HashMap<Integer, String>();
+ final static private int cacheStringSizes [] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};
+
+ static {
+ //prepare the cache.
+ for (int size: cacheStringSizes) {
+ cachedPrepStmtStrings.put(size, createPrepStatementString(size));
+ }
+ }
+
+
+ private static String createPrepStatementString(int numItems) {
+ StringBuilder builder = new StringBuilder("INSERT INTO op_vm_ruleset_log (instance_id, created, logsequence) VALUES ");
+ for (int i=0; i < numItems-1; i++) {
+ builder.append("(?, now(), 1), ");
+ }
+ builder.append("(?, now(), 1) ");
+ builder.append(" ON DUPLICATE KEY UPDATE logsequence=logsequence+1");
+ return builder.toString();
+ }
+
+ protected VmRulesetLogDaoImpl() {
+ VmIdSearch = createSearchBuilder();
+ VmIdSearch.and("vmId", VmIdSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
+
+ VmIdSearch.done();
+
+ }
+
+ @Override
+ public VmRulesetLogVO findByVmId(long vmId) {
+ SearchCriteria<VmRulesetLogVO> sc = VmIdSearch.create();
+ sc.setParameters("vmId", vmId);
+ return findOneIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public int createOrUpdate(Set<Long> workItems) {
+ //return createOrUpdateUsingBatch(workItems);
+ return createOrUpdateUsingMultiInsert(workItems);
+ }
+
+ private int executeWithRetryOnDeadlock(Transaction txn, String pstmt, List<Long> vmIds) throws SQLException {
+
+ int numUpdated = 0;
+ final int maxTries = 3;
+ for (int i=0; i < maxTries; i++) {
+ try {
+ PreparedStatement stmtInsert = txn.prepareAutoCloseStatement(pstmt);
+ int argIndex = 1;
+ for (Long vmId: vmIds) {
+ stmtInsert.setLong(argIndex++, vmId);
+ }
+ numUpdated = stmtInsert.executeUpdate();
+ i = maxTries;
+ } catch (SQLTransactionRollbackException e1) {
+ if (i < maxTries-1) {
+ int delayMs = (i+1)*1000;
+ s_logger.debug("Caught a deadlock exception while inserting security group rule log, retrying in " + delayMs);
+ try {
+ Thread.sleep(delayMs);
+ } catch(InterruptedException ie) {
+
+ }
+ }
+ else
+ s_logger.warn("Caught another deadlock exception while retrying inserting security group rule log, giving up");
+
+ }
+ }
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("Inserted or updated " + numUpdated + " rows");
+ }
+ return numUpdated;
+ }
+
+ protected int createOrUpdateUsingMultiInsert(Set<Long> workItems) {
+ Transaction txn = Transaction.currentTxn();
+
+ int size = workItems.size();
+ int count = 0;
+ Iterator<Long> workIter = workItems.iterator();
+ int remaining = size;
+ try {
+ for (int stmtSize : cacheStringSizes) {
+ int numStmts = remaining / stmtSize;
+ if (numStmts > 0) {
+ String pstmt = cachedPrepStmtStrings.get(stmtSize);
+ for (int i=0; i < numStmts; i++) {
+ List<Long> vmIds = new ArrayList<Long>();
+ for (int argIndex=1; argIndex <= stmtSize; argIndex++) {
+ Long vmId = workIter.next();
+ vmIds.add(vmId);
+ }
+ int numUpdated = executeWithRetryOnDeadlock(txn, pstmt, vmIds);
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("Inserted or updated " + numUpdated + " rows");
+ }
+ if (numUpdated > 0)
+ count += stmtSize;
+ }
+ remaining = remaining - numStmts * stmtSize;
+ }
+
+ }
+ } catch (SQLException sqe) {
+ s_logger.warn("Failed to execute multi insert ", sqe);
+ }
+
+ return count;
+ }
+
+ protected int createOrUpdateUsingBatch(Set<Long> workItems) {
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement stmtInsert = null;
+ int [] queryResult = null;
+ int count=0;
+ boolean success = true;
+ try {
+ stmtInsert = txn.prepareAutoCloseStatement(INSERT_OR_UPDATE);
+
+ txn.start();
+ for (Long vmId: workItems) {
+ stmtInsert.setLong(1, vmId);
+ stmtInsert.addBatch();
+ count++;
+ if (count % 16 ==0) {
+ queryResult = stmtInsert.executeBatch();
+ stmtInsert.clearBatch();
+ }
+ }
+ queryResult = stmtInsert.executeBatch();
+
+ txn.commit();
+ if (s_logger.isTraceEnabled())
+ s_logger.trace("Updated or inserted " + workItems.size() + " log items");
+ } catch (SQLException e) {
+ s_logger.warn("Failed to execute batch update statement for ruleset log: ", e);
+ txn.rollback();
+ success = false;
+ }
+ if (!success && queryResult != null) {
+ Long [] arrayItems = new Long[workItems.size()];
+ workItems.toArray(arrayItems);
+ for (int i=0; i < queryResult.length; i++) {
+ if (queryResult[i] < 0 ) {
+ s_logger.debug("Batch query update failed for vm " + arrayItems[i]);
+ }
+ }
+ }
+ return count;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/PrivateIpVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/PrivateIpVO.java b/engine/schema/src/com/cloud/network/vpc/PrivateIpVO.java
new file mode 100644
index 0000000..952a0c2
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/PrivateIpVO.java
@@ -0,0 +1,103 @@
+// 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;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+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 javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+
+@Entity
+@Table(name="private_ip_address")
+public class PrivateIpVO implements InternalIdentity {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="ip_address", updatable=false, nullable=false)
+ String ipAddress;
+
+ @Column(name="mac_address")
+ private long macAddress;
+
+ @Column(name="taken")
+ @Temporal(value=TemporalType.TIMESTAMP)
+ private Date takenAt;
+
+ @Column(name="network_id", updatable=false, nullable=false)
+ private long networkId;
+
+ @Column(name="vpc_id")
+ private Long vpcId;
+
+ @Column(name="source_nat")
+ private boolean sourceNat;
+
+ public PrivateIpVO() {
+ }
+
+ public PrivateIpVO(String ipAddress, long networkId, long macAddress, long vpcId, boolean sourceNat) {
+ this.ipAddress = ipAddress;
+ this.networkId = networkId;
+ this.macAddress = macAddress;
+ this.vpcId = vpcId;
+ this.sourceNat = sourceNat;
+ }
+
+ public void setTakenAt(Date takenDate) {
+ this.takenAt = takenDate;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
+ public long getNetworkId() {
+ return networkId;
+ }
+
+ public Date getTakenAt() {
+ return takenAt;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getMacAddress() {
+ return macAddress;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+ public boolean getSourceNat() {
+ return sourceNat;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java b/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
new file mode 100644
index 0000000..eb4c61b
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/StaticRouteVO.java
@@ -0,0 +1,141 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+
+@Entity
+@Table(name="static_routes")
+public class StaticRouteVO implements StaticRoute {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="uuid")
+ String uuid;
+
+ @Column(name="vpc_gateway_id", updatable=false)
+ long vpcGatewayId;
+
+ @Column(name="cidr")
+ private String cidr;
+
+ @Enumerated(value=EnumType.STRING)
+ @Column(name="state")
+ State state;
+
+ @Column(name="vpc_id")
+ private Long vpcId;
+
+ @Column(name = "account_id")
+ long accountId;
+
+ @Column(name = "domain_id")
+ long domainId;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ protected StaticRouteVO(){
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ /**
+ * @param vpcGatewayId
+ * @param cidr
+ * @param vpcId
+ * @param accountId TODO
+ * @param domainId TODO
+ */
+ public StaticRouteVO(long vpcGatewayId, String cidr, Long vpcId, long accountId, long domainId) {
+ super();
+ this.vpcGatewayId = vpcGatewayId;
+ this.cidr = cidr;
+ this.state = State.Staged;
+ this.vpcId = vpcId;
+ this.accountId = accountId;
+ this.domainId = domainId;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ @Override
+ public long getVpcGatewayId() {
+ return vpcGatewayId;
+ }
+
+ @Override
+ public String getCidr() {
+ return cidr;
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ @Override
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public long getDomainId() {
+ return domainId;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("StaticRoute[");
+ buf.append(uuid).append("|").append(cidr).append("|").append(vpcGatewayId).append("]");
+ return buf.toString();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java b/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
new file mode 100644
index 0000000..e8dcb46
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/VpcGatewayVO.java
@@ -0,0 +1,206 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+
+
+@Entity
+@Table(name="vpc_gateways")
+public class VpcGatewayVO implements VpcGateway {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name = "ip4_address")
+ String ip4Address;
+
+ @Column(name="gateway")
+ String gateway;
+
+ @Column(name="netmask")
+ String netmask;
+
+ @Column(name="vlan_tag")
+ String vlanTag;
+
+ @Column(name = "type")
+ @Enumerated(value = EnumType.STRING)
+ VpcGateway.Type type;
+
+ @Column(name="vpc_id")
+ Long vpcId;
+
+ @Column(name="zone_id")
+ long zoneId;
+
+ @Column(name="network_id")
+ Long networkId;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ @Column(name=GenericDao.REMOVED_COLUMN)
+ Date removed;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name = "account_id")
+ long accountId;
+
+ @Column(name = "domain_id")
+ long domainId;
+
+ @Column(name="state")
+ @Enumerated(value=EnumType.STRING)
+ State state;
+
+ @Column(name="source_nat")
+ boolean sourceNat;
+
+ protected VpcGatewayVO(){
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ /**
+ * @param ip4Address
+ * @param type
+ * @param vpcId
+ * @param zoneId
+ * @param networkId
+ * @param vlanTag TODO
+ * @param gateway TODO
+ * @param netmask TODO
+ * @param accountId TODO
+ * @param domainId TODO
+ * @param account_id
+ * @param sourceNat
+ */
+ public VpcGatewayVO(String ip4Address, Type type, Long vpcId, long zoneId, Long networkId, String vlanTag,
+ String gateway, String netmask, long accountId, long domainId, boolean sourceNat) {
+ this.ip4Address = ip4Address;
+ this.type = type;
+ this.vpcId = vpcId;
+ this.zoneId = zoneId;
+ this.networkId = networkId;
+ this.vlanTag = vlanTag;
+ this.gateway = gateway;
+ this.netmask = netmask;
+ this.uuid = UUID.randomUUID().toString();
+ this.accountId = accountId;
+ this.domainId = domainId;
+ this.state = State.Creating;
+ this.sourceNat = sourceNat;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getIp4Address() {
+ return ip4Address;
+ }
+
+ @Override
+ public VpcGateway.Type getType() {
+ return type;
+ }
+
+ @Override
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ @Override
+ public long getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public Long getNetworkId() {
+ return networkId;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("VpcGateway[");
+ buf.append(id).append("|").append(ip4Address.toString()).append("|").append(vpcId).append("]");
+ return buf.toString();
+ }
+
+ @Override
+ public String getGateway() {
+ return gateway;
+ }
+
+ @Override
+ public String getNetmask() {
+ return netmask;
+ }
+
+ @Override
+ public String getVlanTag() {
+ return vlanTag;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public long getDomainId() {
+ return domainId;
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public boolean getSourceNat() {
+ return this.sourceNat;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java b/engine/schema/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java
new file mode 100644
index 0000000..9dbb32f
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/VpcOfferingServiceMapVO.java
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.vpc;
+
+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="vpc_offering_service_map")
+public class VpcOfferingServiceMapVO implements InternalIdentity {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="vpc_offering_id")
+ long vpcOfferingId;
+
+ @Column(name="service")
+ String service;
+
+ @Column(name="provider")
+ String provider;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ public long getId() {
+ return id;
+ }
+
+ public long getVpcOfferingId() {
+ return vpcOfferingId;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public VpcOfferingServiceMapVO() {
+ }
+
+ public VpcOfferingServiceMapVO(long vpcOfferingId, Service service, Provider provider) {
+ this.vpcOfferingId = vpcOfferingId;
+ this.service = service.getName();
+ if (provider != null) {
+ this.provider = provider.getName();
+ }
+ }
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[VPC Offering Service[");
+ return buf.append(vpcOfferingId).append("-").append(service).append("-").append(provider).append("]").toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/VpcOfferingVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcOfferingVO.java b/engine/schema/src/com/cloud/network/vpc/VpcOfferingVO.java
new file mode 100644
index 0000000..9d5becf
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/VpcOfferingVO.java
@@ -0,0 +1,151 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+
+@Entity
+@Table(name="vpc_offerings")
+public class VpcOfferingVO implements VpcOffering {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ long id;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name = "name")
+ String name;
+
+ @Column(name = "unique_name")
+ String uniqueName;
+
+ @Column(name = "display_text")
+ String displayText;
+
+ @Column(name = "state")
+ @Enumerated(value = EnumType.STRING)
+ State state = State.Disabled;
+
+ @Column(name = "default")
+ boolean isDefault = false;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ Date removed;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ Date created;
+
+ @Column(name = "service_offering_id")
+ Long serviceOfferingId;
+
+ public VpcOfferingVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public VpcOfferingVO(String name, String displayText, Long serviceOfferingId) {
+ this.name = name;
+ this.displayText = displayText;
+ this.uniqueName = name;
+ this.serviceOfferingId = serviceOfferingId;
+ this.uuid = UUID.randomUUID().toString();
+ this.state = State.Disabled;
+ }
+
+ public VpcOfferingVO(String name, String displayText, boolean isDefault, Long serviceOfferingId) {
+ this(name, displayText, serviceOfferingId);
+ this.isDefault = isDefault;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public String getUniqueName() {
+ return uniqueName;
+ }
+
+ @Override
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ @Override
+ public boolean isDefault() {
+ return isDefault;
+ }
+
+ public void setUniqueName(String uniqueName) {
+ this.uniqueName = uniqueName;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[VPC Offering [");
+ return buf.append(id).append("-").append(name).append("]").toString();
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public void setDisplayText(String displayText) {
+ this.displayText = displayText;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public Long getServiceOfferingId() {
+ return serviceOfferingId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/VpcServiceMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcServiceMapVO.java b/engine/schema/src/com/cloud/network/vpc/VpcServiceMapVO.java
new file mode 100644
index 0000000..6f22909
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/VpcServiceMapVO.java
@@ -0,0 +1,90 @@
+// 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;
+
+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;
+
+@Entity
+@Table(name="vpc_service_map")
+public class VpcServiceMapVO {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="vpc_id")
+ long vpcId;
+
+ @Column(name="service")
+ String service;
+
+ @Column(name="provider")
+ String provider;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ public long getId() {
+ return id;
+ }
+
+ public long getVpcId() {
+ return vpcId;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public VpcServiceMapVO() {
+ }
+
+ public VpcServiceMapVO(long vpcId, Service service, Provider provider) {
+ this.vpcId = vpcId;
+ this.service = service.getName();
+ this.provider = provider.getName();
+ }
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[VPC Service[");
+ return buf.append(vpcId).append("-").append(service).append("-").append(provider).append("]").toString();
+ }
+}
+
+
+
+
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/network/vpc/VpcVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/vpc/VpcVO.java b/engine/schema/src/com/cloud/network/vpc/VpcVO.java
new file mode 100644
index 0000000..7b784eb
--- /dev/null
+++ b/engine/schema/src/com/cloud/network/vpc/VpcVO.java
@@ -0,0 +1,181 @@
+// 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;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name="vpc")
+public class VpcVO implements Vpc {
+ @Id
+ @Column(name="id")
+ long id;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name="name")
+ private String name;
+
+ @Column(name = "display_text")
+ String displayText;
+
+ @Column(name="zone_id")
+ long zoneId;
+
+ @Column(name="cidr")
+ private String cidr = null;
+
+ @Column(name="domain_id")
+ Long domainId = null;
+
+ @Column(name="account_id")
+ Long accountId = null;
+
+ @Column(name="state")
+ @Enumerated(value=EnumType.STRING)
+ State state;
+
+ @Column(name="vpc_offering_id")
+ long vpcOfferingId;
+
+ @Column(name=GenericDao.REMOVED_COLUMN)
+ Date removed;
+
+ @Column(name=GenericDao.CREATED_COLUMN)
+ Date created;
+
+ @Column(name="network_domain")
+ String networkDomain;
+
+ @Column(name="restart_required")
+ boolean restartRequired = false;
+
+ public VpcVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public VpcVO(long zoneId, String name, String displayText, long accountId, long domainId, long vpcOffId, String cidr,
+ String networkDomain) {
+ this.zoneId = zoneId;
+ this.name = name;
+ this.displayText = displayText;
+ this.accountId = accountId;
+ this.domainId = domainId;
+ this.cidr = cidr;
+ this.uuid = UUID.randomUUID().toString();
+ this.state = State.Enabled;
+ this.networkDomain = networkDomain;
+ this.vpcOfferingId = vpcOffId;
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public long getZoneId() {
+ return zoneId;
+ }
+
+ @Override
+ public String getCidr() {
+ return cidr;
+ }
+
+ @Override
+ public long getDomainId() {
+ return domainId;
+ }
+
+ @Override
+ public long getAccountId() {
+ return accountId;
+ }
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ @Override
+ public long getVpcOfferingId() {
+ return vpcOfferingId;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ @Override
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDisplayText(String displayText) {
+ this.displayText = displayText;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder("[VPC [");
+ return buf.append(id).append("-").append(name).append("]").toString();
+ }
+
+ @Override
+ public String getNetworkDomain() {
+ return networkDomain;
+ }
+
+ public void setRestartRequired(boolean restartRequired) {
+ this.restartRequired = restartRequired;
+ }
+
+ @Override
+ public boolean isRestartRequired() {
+ return restartRequired;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/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/c11dbad9/engine/schema/src/com/cloud/offerings/NetworkOfferingDetailsVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingDetailsVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingDetailsVO.java
new file mode 100644
index 0000000..6cd5abc
--- /dev/null
+++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingDetailsVO.java
@@ -0,0 +1,90 @@
+// 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 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 org.apache.cloudstack.api.InternalIdentity;
+
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offering.NetworkOffering.Detail;
+
+@Entity
+@Table(name="network_offering_details")
+public class NetworkOfferingDetailsVO implements InternalIdentity {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="network_offering_id")
+ private long offeringId;
+
+ @Enumerated(value=EnumType.STRING)
+ @Column(name="name")
+ private NetworkOffering.Detail name;
+
+ @Column(name="value", length=1024)
+ private String value;
+
+ public NetworkOfferingDetailsVO() {}
+
+ public NetworkOfferingDetailsVO(long offeringId, Detail detailName, String value) {
+ this.offeringId = offeringId;
+ this.name = detailName;
+ this.value = value;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getOfferingId() {
+ return offeringId;
+ }
+
+ public NetworkOffering.Detail getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public void setOfferingId(long offeringId) {
+ this.offeringId = offeringId;
+ }
+
+ public void setName(NetworkOffering.Detail name) {
+ this.name = name;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}