incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [5/13] git commit: S2S VPN: Add domain and account for VPN
Date Mon, 23 Jul 2012 21:57:40 GMT
S2S VPN: Add domain and account for VPN

Admin can add VPN connection for others

Conflicts:

	api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java
	server/src/com/cloud/api/ApiResponseHelper.java
	setup/db/create-schema.sql


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/67147524
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/67147524
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/67147524

Branch: refs/heads/vpc
Commit: 671475242cef6b77dda4050afde14db38b3e624e
Parents: 230ce1d
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Tue Jul 10 14:58:04 2012 -0700
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Mon Jul 23 14:40:26 2012 -0700

----------------------------------------------------------------------
 .../cloud/api/commands/CreateVpnConnectionCmd.java |   50 +++++++++++----
 .../api/commands/CreateVpnCustomerGatewayCmd.java  |   30 ++++++++-
 .../cloud/api/commands/CreateVpnGatewayCmd.java    |   16 +++++
 .../cloud/api/commands/ListVpnConnectionsCmd.java  |    8 +++
 .../com/cloud/api/commands/ListVpnGatewaysCmd.java |    9 +++-
 .../response/Site2SiteCustomerGatewayResponse.java |   43 ++++++++++++-
 .../response/Site2SiteVpnConnectionResponse.java   |   42 ++++++++++++-
 .../api/response/Site2SiteVpnGatewayResponse.java  |   43 ++++++++++++-
 .../cloud/network/Site2SiteCustomerGateway.java    |    4 +-
 .../com/cloud/network/Site2SiteVpnConnection.java  |    4 +-
 api/src/com/cloud/network/Site2SiteVpnGateway.java |    4 +-
 server/src/com/cloud/api/ApiResponseHelper.java    |    9 +++
 .../cloud/network/Site2SiteCustomerGatewayVO.java  |   20 ++++++-
 .../cloud/network/Site2SiteVpnConnectionVO.java    |   20 ++++++-
 .../com/cloud/network/Site2SiteVpnGatewayVO.java   |   20 ++++++-
 .../network/dao/Site2SiteVpnConnectionDao.java     |    3 +
 .../network/dao/Site2SiteVpnConnectionDaoImpl.java |   27 ++++++++
 .../cloud/network/vpn/Site2SiteVpnManagerImpl.java |   34 +++++++++--
 setup/db/create-schema.sql                         |   12 ++++
 19 files changed, 368 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java
index e10f316..91bc94d 100644
--- a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java
+++ b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java
@@ -53,6 +53,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 ///////////////////////
     /////////////////////////////////////////////////////
@@ -68,7 +76,15 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
     public Long getCustomerGatewayId() {
         return customerGatewayId;
     }
-    
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -79,21 +95,29 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
         return s_name;
     }
 
-	@Override
-	public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
+    @Override
+    public long getEntityOwnerId() {
+        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 for account " + getEntityOwnerId();
     }
 
-	@Override
-	public String getEventDescription() {
-		return "Create site-to-site VPN connection";
-	}
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_S2S_CONNECTION_CREATE;
+    }
 
-	@Override
-	public String getEventType() {
-		return EventTypes.EVENT_S2S_CONNECTION_CREATE;
-	}
-	
     @Override
     public void create() {
         try {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
index ca028d7..7d47eee 100644
--- a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
+++ b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
@@ -21,6 +21,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;
@@ -28,6 +29,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 {
@@ -56,6 +58,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 ///////////////////////
     /////////////////////////////////////////////////////
@@ -88,6 +98,14 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd {
         return lifetime;
     }
 
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -100,12 +118,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

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java
index fce74c6..1210fe2 100644
--- a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java
+++ b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java
@@ -44,6 +44,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 ///////////////////////
     /////////////////////////////////////////////////////
@@ -56,6 +64,14 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd {
         return publicIpId;
     }
 
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java b/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java
index 32769bf..512f945 100644
--- a/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java
+++ b/api/src/com/cloud/api/commands/ListVpnConnectionsCmd.java
@@ -43,6 +43,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 ///////////////////////
@@ -53,6 +57,10 @@ public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd
         return id;
     }
 
+    public Long getVpcId() {
+        return vpcId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java b/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java
index a147788..63b212b 100644
--- a/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java
+++ b/api/src/com/cloud/api/commands/ListVpnGatewaysCmd.java
@@ -44,15 +44,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///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
index 637ba91..829a9f6 100644
--- a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
+++ b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
@@ -24,7 +24,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");
 
@@ -40,6 +40,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;
 
@@ -66,4 +81,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;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java b/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java
index fcbe56b..44f7c20 100644
--- a/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java
+++ b/api/src/com/cloud/api/response/Site2SiteVpnConnectionResponse.java
@@ -24,7 +24,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");
 
@@ -58,6 +58,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;
 
@@ -116,4 +131,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;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java b/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java
index b3bdfa3..f085144 100644
--- a/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java
+++ b/api/src/com/cloud/api/response/Site2SiteVpnGatewayResponse.java
@@ -24,13 +24,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;
 
@@ -45,4 +60,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;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/network/Site2SiteCustomerGateway.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Site2SiteCustomerGateway.java b/api/src/com/cloud/network/Site2SiteCustomerGateway.java
index 0dbda65..423d8d1 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();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/network/Site2SiteVpnConnection.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Site2SiteVpnConnection.java b/api/src/com/cloud/network/Site2SiteVpnConnection.java
index d5a615f..d613203 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,

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/api/src/com/cloud/network/Site2SiteVpnGateway.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Site2SiteVpnGateway.java b/api/src/com/cloud/network/Site2SiteVpnGateway.java
index 19ec742..2e4aa37 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();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 50fb8dc..9319b22 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3773,6 +3773,8 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setRemoved(result.getRemoved());
         response.setObjectName("vpngateway");
         
+        populateAccount(response, result.getAccountId());
+        populateDomain(response, result.getDomainId());
         return response;
     }
 
@@ -3785,6 +3787,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;
     }
 
@@ -3815,6 +3821,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());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java
index d0d8b2b..8e0afca 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;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java b/server/src/com/cloud/network/Site2SiteVpnConnectionVO.java
index 4362b22..f38e2d8 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;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java b/server/src/com/cloud/network/Site2SiteVpnGatewayVO.java
index 5c94866..84a3bf2 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;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDao.java
index 61204a5..26cdc47 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,
Long> {
     Site2SiteVpnConnectionVO findByCustomerGatewayId(long id);
     Site2SiteVpnConnectionVO findByVpnGatewayId(long id);
+    List<Site2SiteVpnConnectionVO> listByVpcId(long vpcId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java b/server/src/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java
index 8659d27..113b438 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<Site2SiteVpnConnectionVO,
Long> 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<Site2SiteVpnConnectionVO> AllFieldsSearch;
+    private final SearchBuilder<Site2SiteVpnConnectionVO> VpcSearch;
+    private final SearchBuilder<Site2SiteVpnGatewayVO> VpnGatewaySearch;
+    private final SearchBuilder<IPAddressVO> 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<Site2SiteVpnCo
         sc.setParameters("vpnGatewayId", id);
         return findOneBy(sc);
     }
+
+    @Override
+    public List<Site2SiteVpnConnectionVO> listByVpcId(long vpcId) {
+        SearchCriteria<Site2SiteVpnConnectionVO> sc = VpcSearch.create();
+        sc.setJoinParameters("addrSearch", "vpcId", vpcId);
+        return listBy(sc);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index ac017d3..39aa2fb 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<Site2SiteVpnGateway> searchForVpnGateways(ListVpnGatewaysCmd cmd) {
         Long id = cmd.getId();
+        Long vpcId = cmd.getVpcId();
+        
         List<Site2SiteVpnGateway> results = new ArrayList<Site2SiteVpnGateway>();
         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<Site2SiteVpnConnection> searchForVpnConnections(ListVpnConnectionsCmd
cmd) {
         Long id = cmd.getId();
+        Long vpcId = cmd.getVpcId();
+        
         List<Site2SiteVpnConnection> results = new ArrayList<Site2SiteVpnConnection>();
         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;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/67147524/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 8227028..9972bb4 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -2140,9 +2140,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;
 
@@ -2155,8 +2159,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;
 
@@ -2166,11 +2174,15 @@ 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;
 


Mime
View raw message