diff --git a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java index 9ec62226280..3c2465affc6 100644 --- a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java @@ -30,6 +30,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; import com.cloud.network.Site2SiteVpnConnection; import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Create site to site vpn connection", responseObject=Site2SiteVpnConnectionResponse.class) public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @@ -48,6 +49,14 @@ 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 /////////////////////// ///////////////////////////////////////////////////// @@ -65,6 +74,14 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { return customerGatewayId; } + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -77,12 +94,20 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; + Long accountId = finalyzeAccountId(accountName, domainId, null, true); + if (accountId == null) { + accountId = UserContext.current().getCaller().getId(); + } + + if (accountId == null) { + accountId = Account.ACCOUNT_ID_SYSTEM; + } + return accountId; } @Override public String getEventDescription() { - return "Create site-to-site VPN connection"; + return "Create site-to-site VPN connection for account " + getEntityOwnerId(); } @Override diff --git a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java index 696457ca47f..ab0adccb5ec 100644 --- a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java @@ -17,6 +17,7 @@ import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseCmd; +import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; import com.cloud.api.ServerApiException; @@ -24,6 +25,7 @@ import com.cloud.api.response.Site2SiteCustomerGatewayResponse; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteCustomerGateway; import com.cloud.user.Account; +import com.cloud.user.UserContext; @Implementation(description="Creates site to site vpn customer gateway", responseObject=Site2SiteCustomerGatewayResponse.class) public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { @@ -52,6 +54,14 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.LIFETIME, type=CommandType.LONG, required=false, description="Lifetime of vpn connection to the customer gateway, in seconds") private Long lifetime; + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the gateway. 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 gateway. " + + "If used with the account parameter returns the gateway associated with the account for the specified domain.") + private Long domainId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -84,6 +94,14 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { return lifetime; } + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -96,12 +114,20 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; + Long accountId = finalyzeAccountId(accountName, domainId, null, true); + if (accountId == null) { + accountId = UserContext.current().getCaller().getId(); + } + + if (accountId == null) { + accountId = Account.ACCOUNT_ID_SYSTEM; + } + return accountId; } @Override public String getEventDescription() { - return "Create site-to-site VPN customer gateway"; + return "Create site-to-site VPN customer gateway for account " + getEntityOwnerId(); } @Override diff --git a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java index defb60ac312..95401102742 100644 --- a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java @@ -40,6 +40,14 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn gateway") private Long publicIpId; + @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 /////////////////////// ///////////////////////////////////////////////////// @@ -52,6 +60,14 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { return publicIpId; } + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java b/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java index a7cd2eb6d85..06484a1afba 100644 --- a/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java +++ b/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java @@ -39,6 +39,10 @@ public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd @IdentityMapper(entityTableName="s2s_vpn_connection") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the vpn connection") private Long id; + + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="id of vpc") + private Long vpcId; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -49,6 +53,10 @@ public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd return id; } + public Long getVpcId() { + return vpcId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java b/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java index 543110e8971..1cf215126fe 100644 --- a/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java +++ b/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java @@ -40,15 +40,22 @@ public class ListVpnGatewaysCmd extends BaseListProjectAndAccountResourcesCmd { @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the vpn gateway") private Long id; + @IdentityMapper(entityTableName="vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="id of vpc") + private Long vpcId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public Long getId() { return id; } + public Long getVpcId() { + return vpcId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java index 06d359c4c0c..0b39ef97f6c 100644 --- a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java +++ b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java @@ -20,7 +20,7 @@ import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") -public class Site2SiteCustomerGatewayResponse extends BaseResponse { +public class Site2SiteCustomerGatewayResponse extends BaseResponse implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description="the vpn gateway ID") private IdentityProxy id = new IdentityProxy("s2s_customer_gateway"); @@ -36,6 +36,21 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse { @SerializedName(ApiConstants.IPSEC_PSK) @Param(description="IPsec preshared-key of customer gateway") private String ipsecPsk; + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id") + private IdentityProxy projectId = new IdentityProxy("projects"); + + @SerializedName(ApiConstants.PROJECT) @Param(description="the project name") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the owner") + private IdentityProxy domainId = new IdentityProxy("domain"); + + @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the owner") + private String domain; + @SerializedName(ApiConstants.REMOVED) @Param(description="the date and time the host was removed") private Date removed; @@ -62,4 +77,30 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse { public void setRemoved(Date removed) { this.removed = removed; } + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(Long projectId) { + this.projectId.setValue(projectId); + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(Long domainId) { + this.domainId.setValue(domainId); + } + + @Override + public void setDomainName(String domainName) { + this.domain = domainName; + } + } diff --git a/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java b/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java index 833d012692a..a167711690b 100644 --- a/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java +++ b/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java @@ -20,7 +20,7 @@ import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") -public class Site2SiteVpnConnectionResponse extends BaseResponse { +public class Site2SiteVpnConnectionResponse extends BaseResponse implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description="the vpn gateway ID") private IdentityProxy id = new IdentityProxy("s2s_vpn_connection"); @@ -54,6 +54,21 @@ public class Site2SiteVpnConnectionResponse extends BaseResponse { @SerializedName(ApiConstants.STATE) @Param(description="State of vpn connection") private String state; + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id") + private IdentityProxy projectId = new IdentityProxy("projects"); + + @SerializedName(ApiConstants.PROJECT) @Param(description="the project name") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the owner") + private IdentityProxy domainId = new IdentityProxy("domain"); + + @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the owner") + private String domain; + @SerializedName(ApiConstants.CREATED) @Param(description="the date and time the host was created") private Date created; @@ -112,4 +127,29 @@ public class Site2SiteVpnConnectionResponse extends BaseResponse { this.removed = removed; } + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(Long projectId) { + this.projectId.setValue(projectId); + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(Long domainId) { + this.domainId.setValue(domainId); + } + + @Override + public void setDomainName(String domainName) { + this.domain = domainName; + } + } diff --git a/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java b/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java index 529288c18d5..c6e60a829d0 100644 --- a/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java +++ b/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java @@ -20,13 +20,28 @@ import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") -public class Site2SiteVpnGatewayResponse extends BaseResponse { +public class Site2SiteVpnGatewayResponse extends BaseResponse implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description="the vpn gateway ID") private IdentityProxy id = new IdentityProxy("s2s_vpn_gateway"); @SerializedName(ApiConstants.PUBLIC_IP) @Param(description="the public IP address") private String ip; + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id") + private IdentityProxy projectId = new IdentityProxy("projects"); + + @SerializedName(ApiConstants.PROJECT) @Param(description="the project name") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the owner") + private IdentityProxy domainId = new IdentityProxy("domain"); + + @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain name of the owner") + private String domain; + @SerializedName(ApiConstants.REMOVED) @Param(description="the date and time the host was removed") private Date removed; @@ -41,4 +56,30 @@ public class Site2SiteVpnGatewayResponse extends BaseResponse { public void setRemoved(Date removed) { this.removed = removed; } + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(Long projectId) { + this.projectId.setValue(projectId); + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(Long domainId) { + this.domainId.setValue(domainId); + } + + @Override + public void setDomainName(String domainName) { + this.domain = domainName; + } + } diff --git a/api/src/com/cloud/network/Site2SiteCustomerGateway.java b/api/src/com/cloud/network/Site2SiteCustomerGateway.java index 0dbda6523c5..423d8d1f533 100644 --- a/api/src/com/cloud/network/Site2SiteCustomerGateway.java +++ b/api/src/com/cloud/network/Site2SiteCustomerGateway.java @@ -2,7 +2,9 @@ package com.cloud.network; import java.util.Date; -public interface Site2SiteCustomerGateway { +import com.cloud.acl.ControlledEntity; + +public interface Site2SiteCustomerGateway extends ControlledEntity { public long getId(); public String getGatewayIp(); public String getGuestCidrList(); diff --git a/api/src/com/cloud/network/Site2SiteVpnConnection.java b/api/src/com/cloud/network/Site2SiteVpnConnection.java index d5a615ff0b0..d613203e90d 100644 --- a/api/src/com/cloud/network/Site2SiteVpnConnection.java +++ b/api/src/com/cloud/network/Site2SiteVpnConnection.java @@ -2,7 +2,9 @@ package com.cloud.network; import java.util.Date; -public interface Site2SiteVpnConnection { +import com.cloud.acl.ControlledEntity; + +public interface Site2SiteVpnConnection extends ControlledEntity { enum State { Pending, Connected, diff --git a/api/src/com/cloud/network/Site2SiteVpnGateway.java b/api/src/com/cloud/network/Site2SiteVpnGateway.java index 19ec7425641..2e4aa379841 100644 --- a/api/src/com/cloud/network/Site2SiteVpnGateway.java +++ b/api/src/com/cloud/network/Site2SiteVpnGateway.java @@ -2,7 +2,9 @@ package com.cloud.network; import java.util.Date; -public interface Site2SiteVpnGateway { +import com.cloud.acl.ControlledEntity; + +public interface Site2SiteVpnGateway extends ControlledEntity { public long getId(); public long getAddrId(); public Date getRemoved(); diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 91d3319964b..b4c0e1c01ca 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -3806,6 +3806,10 @@ public class ApiResponseHelper implements ResponseGenerator { response.setIp(ApiDBUtils.findIpAddressById(result.getAddrId()).getAddress().toString()); response.setRemoved(result.getRemoved()); response.setObjectName("vpngateway"); + + populateAccount(response, result.getAccountId()); + populateDomain(response, result.getDomainId()); + return response; } @@ -3818,6 +3822,10 @@ public class ApiResponseHelper implements ResponseGenerator { response.setIpsecPsk(result.getIpsecPsk()); response.setRemoved(result.getRemoved()); response.setObjectName("vpncustomergateway"); + + populateAccount(response, result.getAccountId()); + populateDomain(response, result.getDomainId()); + return response; } @@ -3848,6 +3856,9 @@ public class ApiResponseHelper implements ResponseGenerator { response.setLifetime(customerGateway.getLifetime()); } + populateAccount(response, result.getAccountId()); + populateDomain(response, result.getDomainId()); + response.setState(result.getState().toString()); response.setCreated(result.getCreated()); response.setRemoved(result.getRemoved()); diff --git a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java index d0d8b2b69fd..8e0afca7d3f 100644 --- a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java +++ b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java @@ -41,12 +41,18 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { @Column(name="lifetime") private long lifetime; + @Column(name="domain_id") + private Long domainId; + + @Column(name="account_id") + private Long accountId; + @Column(name=GenericDao.REMOVED_COLUMN) private Date removed; public Site2SiteCustomerGatewayVO() { } - public Site2SiteCustomerGatewayVO(String gatewayIp, String guestCidrList, String ipsecPsk, String ikePolicy, String espPolicy, long lifetime) { + public Site2SiteCustomerGatewayVO(long accountId, long domainId, String gatewayIp, String guestCidrList, String ipsecPsk, String ikePolicy, String espPolicy, long lifetime) { this.gatewayIp = gatewayIp; this.guestCidrList = guestCidrList; this.ipsecPsk = ipsecPsk; @@ -54,6 +60,8 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { this.espPolicy = espPolicy; this.lifetime = lifetime; this.uuid = UUID.randomUUID().toString(); + this.accountId = accountId; + this.domainId = domainId; } @Override @@ -124,4 +132,14 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { public String getUuid() { return uuid; } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } } diff --git a/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java b/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java index 4362b2210a3..f38e2d8644b 100644 --- a/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java +++ b/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java @@ -32,6 +32,12 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection { @Column(name="state") private State state; + @Column(name="domain_id") + private Long domainId; + + @Column(name="account_id") + private Long accountId; + @Column(name=GenericDao.CREATED_COLUMN) private Date created; @@ -40,11 +46,13 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection { public Site2SiteVpnConnectionVO() { } - public Site2SiteVpnConnectionVO(long vpnGatewayId, long customerGatewayId) { + public Site2SiteVpnConnectionVO(long accountId, long domainId, long vpnGatewayId, long customerGatewayId) { this.uuid = UUID.randomUUID().toString(); this.setVpnGatewayId(vpnGatewayId); this.setCustomerGatewayId(customerGatewayId); this.setState(State.Pending); + this.accountId = accountId; + this.domainId = domainId; } @Override @@ -100,4 +108,14 @@ public class Site2SiteVpnConnectionVO implements Site2SiteVpnConnection { public String getUuid() { return uuid; } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } } diff --git a/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java b/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java index 5c9486637c4..84a3bf22a0f 100644 --- a/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java +++ b/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java @@ -26,14 +26,22 @@ public class Site2SiteVpnGatewayVO implements Site2SiteVpnGateway { @Column(name="addr_id") private long addrId; + @Column(name="domain_id") + private Long domainId; + + @Column(name="account_id") + private Long accountId; + @Column(name=GenericDao.REMOVED_COLUMN) private Date removed; public Site2SiteVpnGatewayVO() { } - public Site2SiteVpnGatewayVO(long addrId) { + public Site2SiteVpnGatewayVO(long accountId, long domainId, long addrId) { this.uuid = UUID.randomUUID().toString(); this.setAddrId(addrId); + this.accountId = accountId; + this.domainId = domainId; } @Override @@ -62,4 +70,14 @@ public class Site2SiteVpnGatewayVO implements Site2SiteVpnGateway { public String getUuid() { return uuid; } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } } diff --git a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java index 61204a5d9e5..26cdc47102b 100644 --- a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java +++ b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java @@ -1,9 +1,12 @@ package com.cloud.network.dao; +import java.util.List; + import com.cloud.network.Site2SiteVpnConnectionVO; import com.cloud.utils.db.GenericDao; public interface Site2SiteVpnConnectionDao extends GenericDao { Site2SiteVpnConnectionVO findByCustomerGatewayId(long id); Site2SiteVpnConnectionVO findByVpnGatewayId(long id); + List listByVpcId(long vpcId); } diff --git a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java index 8659d2784be..113b43864a0 100644 --- a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java +++ b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java @@ -1,11 +1,17 @@ package com.cloud.network.dao; +import java.util.List; + import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.network.IPAddressVO; import com.cloud.network.Site2SiteVpnConnectionVO; +import com.cloud.network.Site2SiteVpnGatewayVO; +import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @@ -13,13 +19,27 @@ import com.cloud.utils.db.SearchCriteria; public class Site2SiteVpnConnectionDaoImpl extends GenericDaoBase implements Site2SiteVpnConnectionDao { private static final Logger s_logger = Logger.getLogger(Site2SiteVpnConnectionDaoImpl.class); + protected final IPAddressDaoImpl _addrDao = ComponentLocator.inject(IPAddressDaoImpl.class); + protected final Site2SiteVpnGatewayDaoImpl _vpnGatewayDao = ComponentLocator.inject(Site2SiteVpnGatewayDaoImpl.class); + private final SearchBuilder AllFieldsSearch; + private final SearchBuilder VpcSearch; + private final SearchBuilder VpnGatewaySearch; + private final SearchBuilder AddrSearch; protected Site2SiteVpnConnectionDaoImpl() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("customerGatewayId", AllFieldsSearch.entity().getCustomerGatewayId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("vpnGatewayId", AllFieldsSearch.entity().getVpnGatewayId(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); + + VpcSearch = createSearchBuilder(); + AddrSearch = _addrDao.createSearchBuilder(); + AddrSearch.and("vpcId", AddrSearch.entity().getVpcId(), SearchCriteria.Op.EQ); + VpnGatewaySearch = _vpnGatewayDao.createSearchBuilder(); + VpnGatewaySearch.join("addrSearch", AddrSearch, AddrSearch.entity().getId(), VpnGatewaySearch.entity().getAddrId(), JoinType.INNER); + VpcSearch.join("vpnGatewaySearch", VpnGatewaySearch, VpnGatewaySearch.entity().getId(), VpcSearch.entity().getVpnGatewayId(), JoinType.INNER); + VpcSearch.done(); } @Override @@ -35,4 +55,11 @@ public class Site2SiteVpnConnectionDaoImpl extends GenericDaoBase listByVpcId(long vpcId) { + SearchCriteria sc = VpcSearch.create(); + sc.setJoinParameters("addrSearch", "vpcId", vpcId); + return listBy(sc); + } } diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index ac017d3dbfb..39aa2fb719b 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -20,6 +20,7 @@ import com.cloud.api.commands.ListVpnCustomerGatewaysCmd; import com.cloud.api.commands.ListVpnGatewaysCmd; import com.cloud.api.commands.ResetVpnConnectionCmd; import com.cloud.api.commands.UpdateVpnCustomerGatewayCmd; +import com.cloud.domain.Domain; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; @@ -91,7 +92,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager { if (gws != null && gws.size() != 0) { throw new InvalidParameterValueException("The VPN gateway of VPC " + vpcId + " already existed!"); } - Site2SiteVpnGatewayVO gw = new Site2SiteVpnGatewayVO(ipId); + Long accountId = cmd.getEntityOwnerId(); + Long domainId = cmd.getDomainId(); + if (domainId == null) { + domainId = Domain.ROOT_DOMAIN; + } + Site2SiteVpnGatewayVO gw = new Site2SiteVpnGatewayVO(accountId, domainId, ipId); _vpnGatewayDao.persist(gw); return gw; } @@ -126,7 +132,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager { if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) { throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed!"); } - Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(gatewayIp, guestCidrList, ipsecPsk, + Long accountId = cmd.getEntityOwnerId(); + Long domainId = cmd.getDomainId(); + if (domainId == null) { + domainId = Domain.ROOT_DOMAIN; + } + Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(accountId, domainId, gatewayIp, guestCidrList, ipsecPsk, ikePolicy, espPolicy, lifetime); _customerGatewayDao.persist(gw); return gw; @@ -149,7 +160,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager { throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " or vpn gateway id " + vpnGatewayId + " already existed!"); } - Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(vpnGatewayId, customerGatewayId); + Long accountId = cmd.getEntityOwnerId(); + Long domainId = cmd.getDomainId(); + if (domainId == null) { + domainId = Domain.ROOT_DOMAIN; + } + Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(accountId, domainId, vpnGatewayId, customerGatewayId); conn.setState(State.Pending); _vpnConnectionDao.persist(conn); return conn; @@ -320,10 +336,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager { @Override public List searchForVpnGateways(ListVpnGatewaysCmd cmd) { Long id = cmd.getId(); + Long vpcId = cmd.getVpcId(); + List results = new ArrayList(); if (id != null) { results.add(_vpnGatewayDao.findById(cmd.getId())); - } else { + } else if (vpcId != null) { + results.addAll(_vpnGatewayDao.listByVpcId(vpcId)); + } else { //id == null && vpcId == null results.addAll(_vpnGatewayDao.listAll()); } return results; @@ -332,10 +352,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager { @Override public List searchForVpnConnections(ListVpnConnectionsCmd cmd) { Long id = cmd.getId(); + Long vpcId = cmd.getVpcId(); + List results = new ArrayList(); if (id != null) { results.add(_vpnConnectionDao.findById(cmd.getId())); - } else { + } else if (vpcId != null) { + results.addAll(_vpnConnectionDao.listByVpcId(vpcId)); + } else { //id == null && vpcId == null results.addAll(_vpnConnectionDao.listAll()); } return results; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index d7e5fed1520..d11cddb5b85 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2138,9 +2138,13 @@ CREATE TABLE `cloud`.`s2s_vpn_gateway` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40), `addr_id` bigint unsigned NOT NULL, + `domain_id` bigint unsigned NOT NULL, + `account_id` bigint unsigned NOT NULL, `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), CONSTRAINT `fk_s2s_vpn_gateway__addr_id` FOREIGN KEY (`addr_id`) REFERENCES `user_ip_address` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_s2s_vpn_gateway__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_s2s_vpn_gateway__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, CONSTRAINT `uc_s2s_vpn_gateway__uuid` UNIQUE (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2153,8 +2157,12 @@ CREATE TABLE `cloud`.`s2s_customer_gateway` ( `ike_policy` varchar(30) NOT NULL, `esp_policy` varchar(30) NOT NULL, `lifetime` int, + `domain_id` bigint unsigned NOT NULL, + `account_id` bigint unsigned NOT NULL, `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), + CONSTRAINT `fk_s2s_customer_gateway__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_s2s_customer_gateway__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, CONSTRAINT `uc_s2s_customer_gateway__uuid` UNIQUE (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2164,15 +2172,18 @@ CREATE TABLE `cloud`.`s2s_vpn_connection` ( `vpn_gateway_id` bigint unsigned NULL, `customer_gateway_id` bigint unsigned NULL, `state` varchar(32) NOT NULL, + `domain_id` bigint unsigned NOT NULL, + `account_id` bigint unsigned NOT NULL, `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), CONSTRAINT `fk_s2s_vpn_connection__vpn_gateway_id` FOREIGN KEY (`vpn_gateway_id`) REFERENCES `s2s_vpn_gateway` (`id`) ON DELETE CASCADE, CONSTRAINT `fk_s2s_vpn_connection__customer_gateway_id` FOREIGN KEY (`customer_gateway_id`) REFERENCES `s2s_customer_gateway` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_s2s_vpn_connection__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_s2s_vpn_connection__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, CONSTRAINT `uc_s2s_vpn_connection__uuid` UNIQUE (`uuid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `cloud`.`resource_tags` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40),