You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/07/11 21:05:47 UTC
[1/2] git commit: VPC: added State to vpc_gateways
Updated Branches:
refs/heads/vpc 37ab2dd49 -> 7cb4ab5e6
VPC: added State to vpc_gateways
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7cb4ab5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7cb4ab5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7cb4ab5e
Branch: refs/heads/vpc
Commit: 7cb4ab5e606b6939274a055d2eaf59ae2a6742d6
Parents: d2e491a
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Wed Jul 11 11:46:26 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Jul 11 12:05:42 2012 -0700
----------------------------------------------------------------------
.../cloud/api/commands/ListPrivateGatewaysCmd.java | 7 +
.../cloud/api/response/PrivateGatewayResponse.java | 7 +
api/src/com/cloud/network/vpc/VpcGateway.java | 11 ++
server/src/com/cloud/api/ApiResponseHelper.java | 1 +
.../router/VirtualNetworkApplianceManagerImpl.java | 2 +-
.../VpcVirtualNetworkApplianceManagerImpl.java | 1 +
.../cloud/network/vpc/PrivateGatewayProfile.java | 5 +
server/src/com/cloud/network/vpc/VpcGatewayVO.java | 14 ++
.../src/com/cloud/network/vpc/VpcManagerImpl.java | 97 +++++++++++----
setup/db/create-schema.sql | 1 +
10 files changed, 118 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
index bc4cc1f..32767ca 100644
--- a/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
+++ b/api/src/com/cloud/api/commands/ListPrivateGatewaysCmd.java
@@ -49,6 +49,9 @@ public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCm
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list gateways by vpc")
private Long vpcId;
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list gateways by state")
+ private String state;
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -69,6 +72,10 @@ public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCm
public Long getId() {
return id;
}
+
+ public String getState() {
+ return state;
+ }
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/api/src/com/cloud/api/response/PrivateGatewayResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/PrivateGatewayResponse.java b/api/src/com/cloud/api/response/PrivateGatewayResponse.java
index c94b589..fccc7c4 100644
--- a/api/src/com/cloud/api/response/PrivateGatewayResponse.java
+++ b/api/src/com/cloud/api/response/PrivateGatewayResponse.java
@@ -64,6 +64,9 @@ public class PrivateGatewayResponse extends BaseResponse implements ControlledEn
@Param(description = "the domain associated with the private gateway")
private String domainName;
+ @SerializedName(ApiConstants.STATE) @Param(description="State of the gateway, can be Creating, Ready, Deleting")
+ private String state;
+
public void setId(Long id) {
this.id.setValue(id);
@@ -125,5 +128,9 @@ public class PrivateGatewayResponse extends BaseResponse implements ControlledEn
public void setProjectName(String projectName) {
this.projectName = projectName;
}
+
+ public void setState(String state) {
+ this.state = state;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/api/src/com/cloud/network/vpc/VpcGateway.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/vpc/VpcGateway.java b/api/src/com/cloud/network/vpc/VpcGateway.java
index 30e613c..a437cbe 100644
--- a/api/src/com/cloud/network/vpc/VpcGateway.java
+++ b/api/src/com/cloud/network/vpc/VpcGateway.java
@@ -22,6 +22,12 @@ public interface VpcGateway extends Identity, ControlledEntity {
Vpn
}
+ public enum State {
+ Creating,
+ Ready,
+ Deleting
+ }
+
long getId();
/**
@@ -63,4 +69,9 @@ public interface VpcGateway extends Identity, ControlledEntity {
* @return
*/
String getVlanTag();
+
+ /**
+ * @return
+ */
+ State getState();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/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 a97f9bf..b64b528 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3736,6 +3736,7 @@ public class ApiResponseHelper implements ResponseGenerator {
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
+ response.setState(result.getState().toString());
response.setObjectName("privategateway");
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index ec74333..544ca73 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -1240,7 +1240,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
Network network = _networkDao.acquireInLockTable(guestNetwork.getId());
if (network == null) {
throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
- }
+ }
try {
//Check if providers are supported in the physical networks
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 541fc61..9751a18 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -823,6 +823,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
createVpcAssociatePublicIPCommands(router, sourceNat, cmds);
}
+ //add VPC router to guest networks
for (Nic nic : guestNics.keySet()) {
//plug guest nic
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, nic.getNetworkId()));
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
index b98c5ae..0959b04 100644
--- a/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
+++ b/server/src/com/cloud/network/vpc/PrivateGatewayProfile.java
@@ -91,4 +91,9 @@ public class PrivateGatewayProfile implements PrivateGateway{
public long getDomainId() {
return vpcGateway.getDomainId();
}
+
+ @Override
+ public State getState() {
+ return vpcGateway.getState();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/server/src/com/cloud/network/vpc/VpcGatewayVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcGatewayVO.java b/server/src/com/cloud/network/vpc/VpcGatewayVO.java
index 320984d..59f754d 100644
--- a/server/src/com/cloud/network/vpc/VpcGatewayVO.java
+++ b/server/src/com/cloud/network/vpc/VpcGatewayVO.java
@@ -76,6 +76,10 @@ public class VpcGatewayVO implements VpcGateway{
@Column(name = "domain_id")
long domainId;
+ @Column(name="state")
+ @Enumerated(value=EnumType.STRING)
+ State state;
+
protected VpcGatewayVO(){
this.uuid = UUID.randomUUID().toString();
}
@@ -106,6 +110,7 @@ public class VpcGatewayVO implements VpcGateway{
this.uuid = UUID.randomUUID().toString();
this.accountId = accountId;
this.domainId = domainId;
+ this.state = State.Creating;
}
@Override
@@ -174,4 +179,13 @@ public class VpcGatewayVO implements VpcGateway{
public long getDomainId() {
return domainId;
}
+
+ @Override
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 8f5db9a..43a8ab4 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -1132,43 +1132,71 @@ public class VpcManagerImpl implements VpcManager, Manager{
@Override
+ @DB
public PrivateGateway applyVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
- PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
- if (getVpcElement().createPrivateGateway(gateway)) {
- s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
- return gateway;
- } else {
- s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
- return null;
+ VpcGatewayVO vo = _vpcGatewayDao.acquireInLockTable(gatewayId);
+ if (vo == null) {
+ throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
+ }
+
+ try {
+ PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
+ if (getVpcElement().createPrivateGateway(gateway)) {
+ s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
+ if (vo.getState() != VpcGateway.State.Ready) {
+ vo.setState(VpcGateway.State.Ready);
+ _vpcGatewayDao.update(vo.getId(), vo);
+ s_logger.debug("Marke gateway " + gateway + " with state " + VpcGateway.State.Ready);
+ }
+ return getVpcPrivateGateway(gatewayId);
+ } else {
+ s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
+ return null;
+ }
+ } finally {
+ if (vo != null) {
+ _vpcGatewayDao.releaseFromLockTable(gatewayId);
+ }
}
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_PRIVATE_GATEWAY_DELETE, eventDescription = "deleting private gateway")
+ @DB
public boolean deleteVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
- VpcGatewayVO gatewayVO = _vpcGatewayDao.findById(gatewayId);
+ VpcGatewayVO gatewayVO = _vpcGatewayDao.acquireInLockTable(gatewayId);
if (gatewayVO == null || gatewayVO.getType() != VpcGateway.Type.Private) {
- throw new InvalidParameterValueException("Can't find private gateway by id specified");
- }
-
- //don't allow to remove gateway when there are static routes associated with it
- long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
- if (routeCount > 0) {
- throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount +
- " static routes applied. Remove the routes first");
- }
-
- //1) delete the gateway on the backend
- PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
- if (getVpcElement().deletePrivateGateway(gateway)) {
- s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
- } else {
- s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
- return false;
+ throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
}
- //2) Delete private gateway from the DB
- return deletePrivateGatewayFromTheDB(gateway);
+ try {
+ gatewayVO.setState(VpcGateway.State.Deleting);
+ _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO);
+ s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting);
+ //don't allow to remove gateway when there are static routes associated with it
+ long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId());
+ if (routeCount > 0) {
+ throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount +
+ " static routes applied. Remove the routes first");
+ }
+
+ //1) delete the gateway on the backend
+ PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
+ if (getVpcElement().deletePrivateGateway(gateway)) {
+ s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
+ } else {
+ s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
+ return false;
+ }
+
+ //2) Delete private gateway from the DB
+ return deletePrivateGatewayFromTheDB(gateway);
+
+ } finally {
+ if (gatewayVO != null) {
+ _vpcGatewayDao.releaseFromLockTable(gatewayId);
+ }
+ }
}
@DB
@@ -1219,6 +1247,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
String accountName = cmd.getAccountName();
Account caller = UserContext.current().getCaller();
List<Long> permittedAccounts = new ArrayList<Long>();
+ String state = cmd.getState();
Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
@@ -1249,6 +1278,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
sc.addAnd("ip4Address", Op.EQ, ipAddress);
}
+ if (state != null) {
+ sc.addAnd("state", Op.EQ, state);
+ }
+
if (vpcId != null) {
sc.addAnd("vpcId", Op.EQ, vpcId);
}
@@ -1339,6 +1372,12 @@ public class VpcManagerImpl implements VpcManager, Manager{
if (route == null) {
throw new InvalidParameterValueException("Unable to find static route by id");
}
+
+ VpcGateway gateway = _vpcGatewayDao.findById(route.getVpcGatewayId());
+
+ if (gateway.getState() != VpcGateway.State.Ready) {
+ throw new InvalidParameterValueException("Gateway is not in the " + VpcGateway.State.Ready + " state: " + gateway.getState());
+ }
_accountMgr.checkAccess(caller, null, false, route);
@@ -1378,6 +1417,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
throw new InvalidParameterValueException("Invalid gateway id is given");
}
+ if (gateway.getState() != VpcGateway.State.Ready) {
+ throw new InvalidParameterValueException("Gateway is not in the " + VpcGateway.State.Ready + " state: " + gateway.getState());
+ }
+
Vpc vpc = getActiveVpc(gateway.getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't add static route to VPC that is being deleted");
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7cb4ab5e/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 388d13f..7cd030d 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -2260,6 +2260,7 @@ CREATE TABLE `cloud`.`vpc_gateways` (
`created` datetime COMMENT 'date created',
`account_id` bigint unsigned NOT NULL COMMENT 'owner id',
`domain_id` bigint unsigned NOT NULL COMMENT 'domain id',
+ `state` varchar(32) NOT NULL COMMENT 'what state the vpc gateway in',
`removed` datetime COMMENT 'date removed if not null',
PRIMARY KEY (`id`),
CONSTRAINT `fk_vpc_gateways__network_id` FOREIGN KEY `fk_vpc_gateways__network_id`(`network_id`) REFERENCES `networks`(`id`),