You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/06/26 06:01:13 UTC
[9/16] git commit: VPC: listPrivateGateways API implementation
VPC: listPrivateGateways API implementation
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/dc04e0b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/dc04e0b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/dc04e0b2
Branch: refs/heads/vpc
Commit: dc04e0b2e5f4e367cb44fefb0507f6e2597efb35
Parents: 11de5d4
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Mon Jun 25 10:11:55 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Mon Jun 25 20:57:09 2012 -0700
----------------------------------------------------------------------
.../cloud/api/commands/ListPrivateGatewaysCmd.java | 89 +++++++++++++++
api/src/com/cloud/network/vpc/VpcService.java | 7 +
client/tomcatconf/commands.properties.in | 2 +-
.../src/com/cloud/network/vpc/VpcManagerImpl.java | 48 ++++++++
4 files changed, 145 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dc04e0b2/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
new file mode 100644
index 0000000..5d9266e
--- /dev/null
+++ b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
@@ -0,0 +1,89 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License. Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+//
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.api.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseListCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Parameter;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.PrivateGatewayResponse;
+import com.cloud.network.vpc.PrivateGateway;
+
+/**
+ * @author Alena Prokharchyk
+ */
+public class ListPrivateGatewaysCmd extends BaseListCmd{
+ public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName());
+
+ private static final String s_name = "listprivategatewaysresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list gateways by ip address")
+ private String ipAddress;
+
+ @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="list gateways by vlan")
+ private String vlan;
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list gateways by vpc")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public String getVlan() {
+ return vlan;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ List<PrivateGateway> gateways = _vpcService.listPrivateGateway(this);
+ ListResponse<PrivateGatewayResponse> response = new ListResponse<PrivateGatewayResponse>();
+ List<PrivateGatewayResponse> projectResponses = new ArrayList<PrivateGatewayResponse>();
+ for (PrivateGateway gateway : gateways) {
+ PrivateGatewayResponse gatewayResponse = _responseGenerator.createPrivateGatewayResponseResponse(gateway);
+ projectResponses.add(gatewayResponse);
+ }
+ response.setResponses(projectResponses);
+ response.setResponseName(getCommandName());
+
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dc04e0b2/api/src/com/cloud/network/vpc/VpcService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpc/VpcService.java b/api/src/com/cloud/network/vpc/VpcService.java
index e8c9e86..926ad0f 100644
--- a/api/src/com/cloud/network/vpc/VpcService.java
+++ b/api/src/com/cloud/network/vpc/VpcService.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import com.cloud.api.commands.ListPrivateGatewaysCmd;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
@@ -171,4 +172,10 @@ public interface VpcService {
*/
boolean deleteVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
+ /**
+ * @param listPrivateGatewaysCmd
+ * @return
+ */
+ public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd);
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dc04e0b2/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 137a4a0..748101e 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -353,7 +353,7 @@ listVPCOfferings=com.cloud.api.commands.ListVPCOfferingsCmd;15
#### Private gateway commands
createPrivateGateway=com.cloud.api.commands.CreatePrivateGatewayCmd;1
-#listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
+listPrivateGateways=com.cloud.api.commands.ListPrivateGatewaysCmd;1
deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;1
####
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/dc04e0b2/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 02fdce9..d3605a1 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -24,6 +24,7 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
+import com.cloud.api.commands.ListPrivateGatewaysCmd;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
@@ -43,6 +44,8 @@ import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkVO;
+import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.dao.IPAddressDao;
@@ -66,8 +69,10 @@ import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
@@ -930,6 +935,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
if (gateway == null || gateway.getType() != VpcGateway.Type.Private) {
return null;
}
+ return getPrivateGatewayProfile(gateway);
+ }
+
+ protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) {
Network network = _ntwkMgr.getNetwork(gateway.getNetworkId());
String vlanTag = network.getBroadcastUri().getHost();
String netmask = NetUtils.getCidrNetmask(network.getCidr());
@@ -1050,4 +1059,43 @@ public class VpcManagerImpl implements VpcManager, Manager{
txn.commit();
return true;
}
+
+ @Override
+ public List<PrivateGateway> listPrivateGateway(ListPrivateGatewaysCmd cmd) {
+ String ipAddress = cmd.getIpAddress();
+ String vlan = cmd.getVlan();
+ Long vpcId = cmd.getVpcId();
+
+ Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
+ SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
+
+ if (vlan != null) {
+ SearchBuilder<NetworkVO> ntwkSearch = _ntwkDao.createSearchBuilder();
+ ntwkSearch.and("vlan", ntwkSearch.entity().getBroadcastUri(), SearchCriteria.Op.EQ);
+ sb.join("networkSearch", ntwkSearch, sb.entity().getNetworkId(), ntwkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+
+ SearchCriteria<VpcGatewayVO> sc = sb.create();
+
+ if (ipAddress != null) {
+ sc.addAnd("ip4Address", Op.EQ, ipAddress);
+ }
+
+ if (vpcId != null) {
+ sc.addAnd("vpcId", Op.EQ, vpcId);
+ }
+
+ if (vlan != null) {
+ sc.setJoinParameters("networkSearch", "vlan", BroadcastDomainType.Vlan.toUri(vlan));
+ }
+
+ List<VpcGatewayVO> vos = _vpcGatewayDao.search(sc, searchFilter);
+ List<PrivateGateway> privateGtws = new ArrayList<PrivateGateway>(vos.size());
+ for (VpcGateway vo : vos) {
+ privateGtws.add(getPrivateGatewayProfile(vo));
+ }
+
+ return privateGtws;
+ }
}