Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5F4A6C60D for ; Tue, 26 Jun 2012 04:01:17 +0000 (UTC) Received: (qmail 24573 invoked by uid 500); 26 Jun 2012 04:01:17 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 24500 invoked by uid 500); 26 Jun 2012 04:01:17 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 23943 invoked by uid 99); 26 Jun 2012 04:01:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jun 2012 04:01:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 928E7742E; Tue, 26 Jun 2012 04:01:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: alena1108@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [9/16] git commit: VPC: listPrivateGateways API implementation Message-Id: <20120626040113.928E7742E@tyr.zones.apache.org> Date: Tue, 26 Jun 2012 04:01:13 +0000 (UTC) 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 Authored: Mon Jun 25 10:11:55 2012 -0700 Committer: Alena Prokharchyk 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 gateways = _vpcService.listPrivateGateway(this); + ListResponse response = new ListResponse(); + List projectResponses = new ArrayList(); + 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 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 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 sb = _vpcGatewayDao.createSearchBuilder(); + + if (vlan != null) { + SearchBuilder 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 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 vos = _vpcGatewayDao.search(sc, searchFilter); + List privateGtws = new ArrayList(vos.size()); + for (VpcGateway vo : vos) { + privateGtws.add(getPrivateGatewayProfile(vo)); + } + + return privateGtws; + } }