Skip to content

Commit a8cbba9

Browse files
author
Sheng Yang
committed
S2S VPN: CS-15820: Remove account information of vpn gateway and vpn connection
The owner would be always same as VPC owner. Conflicts: api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java setup/db/db/schema-304to305.sql
1 parent 70d704c commit a8cbba9

4 files changed

Lines changed: 14 additions & 55 deletions

File tree

‎api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java‎

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.cloud.exception.ResourceUnavailableException;
3434
import com.cloud.network.IpAddress;
3535
import com.cloud.network.Site2SiteVpnConnection;
36+
import com.cloud.network.Site2SiteVpnGateway;
37+
import com.cloud.network.vpc.Vpc;
3638
import com.cloud.user.Account;
3739
import com.cloud.user.UserContext;
3840

@@ -53,14 +55,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
5355
@Parameter(name=ApiConstants.S2S_CUSTOMER_GATEWAY_ID, type=CommandType.LONG, required=true, description="id of the customer gateway")
5456
private Long customerGatewayId;
5557

56-
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. Must be used with the domainId parameter.")
57-
private String accountName;
58-
59-
@IdentityMapper(entityTableName="domain")
60-
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the connection. " +
61-
"If used with the account parameter returns the connection associated with the account for the specified domain.")
62-
private Long domainId;
63-
6458
/////////////////////////////////////////////////////
6559
/////////////////// Accessors ///////////////////////
6660
/////////////////////////////////////////////////////
@@ -77,14 +71,6 @@ public Long getCustomerGatewayId() {
7771
return customerGatewayId;
7872
}
7973

80-
public String getAccountName() {
81-
return accountName;
82-
}
83-
84-
public Long getDomainId() {
85-
return domainId;
86-
}
87-
8874
/////////////////////////////////////////////////////
8975
/////////////// API Implementation///////////////////
9076
/////////////////////////////////////////////////////
@@ -97,11 +83,8 @@ public String getCommandName() {
9783

9884
@Override
9985
public long getEntityOwnerId() {
100-
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
101-
if (accountId == null) {
102-
accountId = UserContext.current().getCaller().getId();
103-
}
104-
return accountId;
86+
Vpc vpc = _vpcService.getVpc(getVpnGateway().getVpcId());
87+
return vpc.getAccountId();
10588
}
10689

10790
@Override
@@ -155,14 +138,10 @@ public String getSyncObjType() {
155138

156139
@Override
157140
public Long getSyncObjId() {
158-
return getIp().getVpcId();
141+
return getVpnGateway().getVpcId();
159142
}
160143

161-
private IpAddress getIp() {
162-
IpAddress ip = _s2sVpnService.getVpnGatewayIp(vpnGatewayId);
163-
if (ip == null) {
164-
throw new InvalidParameterValueException("Unable to find ip address by vpn gateway id " + vpnGatewayId);
165-
}
166-
return ip;
144+
private Site2SiteVpnGateway getVpnGateway() {
145+
return _s2sVpnService.getVpnGateway(vpnGatewayId);
167146
}
168147
}

‎api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import com.cloud.api.response.Site2SiteVpnGatewayResponse;
2929
import com.cloud.event.EventTypes;
3030
import com.cloud.network.Site2SiteVpnGateway;
31+
import com.cloud.network.vpc.Vpc;
3132
import com.cloud.user.Account;
3233
import com.cloud.user.UserContext;
3334

3435
@Implementation(description="Creates site to site vpn local gateway", responseObject=Site2SiteVpnGatewayResponse.class)
3536
public class CreateVpnGatewayCmd extends BaseAsyncCmd {
3637
public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName());
37-
38+
3839
private static final String s_name = "createvpngatewayresponse";
3940

4041
/////////////////////////////////////////////////////
@@ -44,14 +45,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
4445
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn gateway")
4546
private Long vpcId;
4647

47-
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. Must be used with the domainId parameter.")
48-
private String accountName;
49-
50-
@IdentityMapper(entityTableName="domain")
51-
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the connection. " +
52-
"If used with the account parameter returns the connection associated with the account for the specified domain.")
53-
private Long domainId;
54-
5548
/////////////////////////////////////////////////////
5649
/////////////////// Accessors ///////////////////////
5750
/////////////////////////////////////////////////////
@@ -64,14 +57,6 @@ public Long getVpcId() {
6457
return vpcId;
6558
}
6659

67-
public String getAccountName() {
68-
return accountName;
69-
}
70-
71-
public Long getDomainId() {
72-
return domainId;
73-
}
74-
7560
/////////////////////////////////////////////////////
7661
/////////////// API Implementation///////////////////
7762
/////////////////////////////////////////////////////
@@ -84,11 +69,8 @@ public String getCommandName() {
8469

8570
@Override
8671
public long getEntityOwnerId() {
87-
Long accountId = finalyzeAccountId(accountName, domainId, null, true);
88-
if (accountId == null) {
89-
accountId = UserContext.current().getCaller().getId();
90-
}
91-
return accountId;
72+
Vpc vpc = _vpcService.getVpc(vpcId);
73+
return vpc.getAccountId();
9274
}
9375

9476
@Override

‎api/src/com/cloud/network/vpn/Site2SiteVpnService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface Site2SiteVpnService {
4040
Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd);
4141
Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCmd cmd);
4242
Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException;
43-
IpAddress getVpnGatewayIp(Long vpnGatewayId);
43+
Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId);
4444
Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException;
4545
boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd deleteVpnCustomerGatewayCmd);
4646
boolean deleteVpnGateway(DeleteVpnGatewayCmd deleteVpnGatewayCmd);

‎server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,8 @@ public Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavail
265265
}
266266

267267
@Override
268-
public IpAddress getVpnGatewayIp(Long vpnGatewayId) {
269-
Site2SiteVpnGatewayVO gateway = _vpnGatewayDao.findById(vpnGatewayId);
270-
IpAddress ip = _networkMgr.getIp(gateway.getAddrId());
271-
return ip;
268+
public Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId) {
269+
return _vpnGatewayDao.findById(vpnGatewayId);
272270
}
273271

274272
@Override

0 commit comments

Comments
 (0)