From 263ae863111919eba4febb6184d776691ed3e45c Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Thu, 2 Aug 2012 16:31:00 -0700 Subject: [PATCH] S2S VPN: CS-15820: Remove account information of vpn gateway and vpn connection The owner would be always same as VPC owner. --- .../api/commands/CreateVpnConnectionCmd.java | 35 ++++--------------- .../api/commands/CreateVpnGatewayCmd.java | 26 +++----------- .../network/vpn/Site2SiteVpnService.java | 2 +- .../network/vpn/Site2SiteVpnManagerImpl.java | 10 +++--- setup/db/db/schema-304to305.sql | 2 +- 5 files changed, 17 insertions(+), 58 deletions(-) diff --git a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java index f1033a0ec13..18692acc19a 100644 --- a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java @@ -29,6 +29,8 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; import com.cloud.network.Site2SiteVpnConnection; +import com.cloud.network.Site2SiteVpnGateway; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -49,14 +51,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.S2S_CUSTOMER_GATEWAY_ID, type=CommandType.LONG, required=true, description="id of the customer gateway") private Long customerGatewayId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. Must be used with the domainId parameter.") - private String accountName; - - @IdentityMapper(entityTableName="domain") - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the connection. " + - "If used with the account parameter returns the connection associated with the account for the specified domain.") - private Long domainId; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -74,14 +68,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { return customerGatewayId; } - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -94,11 +80,8 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Long accountId = finalyzeAccountId(accountName, domainId, null, true); - if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); - } - return accountId; + Vpc vpc = _vpcService.getVpc(getVpnGateway().getVpcId()); + return vpc.getAccountId(); } @Override @@ -152,14 +135,10 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public Long getSyncObjId() { - return getIp().getVpcId(); + return getVpnGateway().getVpcId(); } - private IpAddress getIp() { - IpAddress ip = _s2sVpnService.getVpnGatewayIp(vpnGatewayId); - if (ip == null) { - throw new InvalidParameterValueException("Unable to find ip address by vpn gateway id " + vpnGatewayId, null); - } - return ip; + private Site2SiteVpnGateway getVpnGateway() { + return _s2sVpnService.getVpnGateway(vpnGatewayId); } } diff --git a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java index 1582459a425..5a147fcc8f0 100644 --- a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java @@ -24,13 +24,14 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.Site2SiteVpnGatewayResponse; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnGateway; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.user.UserContext; @Implementation(description="Creates site to site vpn local gateway", responseObject=Site2SiteVpnGatewayResponse.class) public class CreateVpnGatewayCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName()); - + private static final String s_name = "createvpngatewayresponse"; ///////////////////////////////////////////////////// @@ -40,14 +41,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn gateway") private Long vpcId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. Must be used with the domainId parameter.") - private String accountName; - - @IdentityMapper(entityTableName="domain") - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the connection. " + - "If used with the account parameter returns the connection associated with the account for the specified domain.") - private Long domainId; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -60,14 +53,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { return vpcId; } - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -80,11 +65,8 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Long accountId = finalyzeAccountId(accountName, domainId, null, true); - if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); - } - return accountId; + Vpc vpc = _vpcService.getVpc(vpcId); + return vpc.getAccountId(); } @Override diff --git a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java index 9a97d976f64..20ab4222056 100644 --- a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java +++ b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java @@ -36,7 +36,7 @@ public interface Site2SiteVpnService { Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd); Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCmd cmd); Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException; - IpAddress getVpnGatewayIp(Long vpnGatewayId); + Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId); Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException; boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd deleteVpnCustomerGatewayCmd); boolean deleteVpnGateway(DeleteVpnGatewayCmd deleteVpnGatewayCmd); diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index 579a6393a3d..45bfeb5ec18 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -175,7 +175,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { // Default value of lifetime is 1 day espLifetime = (long) 3600; } - if (espLifetime > 3600) { + if (espLifetime > 86400) { throw new InvalidParameterValueException("The ESP lifetime " + espLifetime + " of vpn connection is invalid!", null); } @@ -278,10 +278,8 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { } @Override - public IpAddress getVpnGatewayIp(Long vpnGatewayId) { - Site2SiteVpnGatewayVO gateway = _vpnGatewayDao.findById(vpnGatewayId); - IpAddress ip = _networkMgr.getIp(gateway.getAddrId()); - return ip; + public Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId) { + return _vpnGatewayDao.findById(vpnGatewayId); } @Override @@ -398,7 +396,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { // Default value of lifetime is 1 day espLifetime = (long) 3600; } - if (espLifetime > 3600) { + if (espLifetime > 86400) { throw new InvalidParameterValueException("The ESP lifetime " + espLifetime + " of vpn connection is invalid!", null); } diff --git a/setup/db/db/schema-304to305.sql b/setup/db/db/schema-304to305.sql index 219d50f555d..950768a4f6d 100755 --- a/setup/db/db/schema-304to305.sql +++ b/setup/db/db/schema-304to305.sql @@ -313,7 +313,7 @@ CREATE TABLE `cloud`.`s2s_customer_gateway` ( `ike_policy` varchar(30) NOT NULL, `esp_policy` varchar(30) NOT NULL, `ike_lifetime` int NOT NULL DEFAULT 86400, - `esp_lifetime` int NOT NULL DEFAULT 86400, + `esp_lifetime` int NOT NULL DEFAULT 3600, `dpd` int(1) NOT NULL DEFAULT 0, `domain_id` bigint unsigned NOT NULL, `account_id` bigint unsigned NOT NULL,