mirror of https://github.com/apache/cloudstack.git
VPC: added State to vpc_gateways
This commit is contained in:
parent
d2e491a377
commit
7cb4ab5e60
|
|
@ -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///////////////////
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -91,4 +91,9 @@ public class PrivateGatewayProfile implements PrivateGateway{
|
|||
public long getDomainId() {
|
||||
return vpcGateway.getDomainId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return vpcGateway.getState();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
throw new ConcurrentOperationException("Unable to lock gateway " + gatewayId);
|
||||
}
|
||||
|
||||
//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);
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -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`),
|
||||
|
|
|
|||
Loading…
Reference in New Issue