Skip to content

Commit 88129ad

Browse files
Implement the new VPC restart
- behaves just like network restart: if clean up is checked, all routers destroyed; if 1 router is gone and no clean up, only 1 new router created.
1 parent 9bec4b6 commit 88129ad

7 files changed

Lines changed: 92 additions & 65 deletions

File tree

api/src/com/cloud/network/vpc/VpcService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface VpcService {
4848
* @throws ResourceAllocationException TODO
4949
*/
5050
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain, Boolean displayVpc)
51-
throws ResourceAllocationException;
51+
throws ResourceAllocationException;
5252

5353
/**
5454
* Deletes a VPC
@@ -98,8 +98,8 @@ public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName
9898
* @return
9999
*/
100100
public Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr, String cidr, Long vpcOffId, String state,
101-
String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired,
102-
Map<String, String> tags, Long projectId, Boolean display);
101+
String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired,
102+
Map<String, String> tags, Long projectId, Boolean display);
103103

104104
/**
105105
* Starts VPC which includes starting VPC provider and applying all the neworking rules on the backend
@@ -130,7 +130,7 @@ public Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, Stri
130130
* @return
131131
* @throws InsufficientCapacityException
132132
*/
133-
boolean restartVpc(long id) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
133+
boolean restartVpc(long id, boolean cleanUp) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
134134

135135
/**
136136
* Returns a Private gateway found in the VPC by id
@@ -160,7 +160,7 @@ public Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, Stri
160160
* @throws ResourceAllocationException
161161
*/
162162
public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId, String vlan, String ipAddress, String gateway, String netmask, long gatewayOwnerId,
163-
Long networkOfferingId, Boolean isSoruceNat, Long aclId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
163+
Long networkOfferingId, Boolean isSoruceNat, Long aclId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
164164

165165
/**
166166
* Applies VPC private gateway on the backend, so it becomes functional
@@ -246,7 +246,7 @@ public PrivateGateway createVpcPrivateGateway(long vpcId, Long physicalNetworkId
246246
* @throws ConcurrentOperationException
247247
*/
248248
IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException,
249-
ConcurrentOperationException;
249+
ConcurrentOperationException;
250250

251251
/**
252252
* @param routeId

api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vpc;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
2220
import org.apache.cloudstack.api.ACL;
2321
import org.apache.cloudstack.api.APICommand;
@@ -28,6 +26,7 @@
2826
import org.apache.cloudstack.api.ServerApiException;
2927
import org.apache.cloudstack.api.response.SuccessResponse;
3028
import org.apache.cloudstack.api.response.VpcResponse;
29+
import org.apache.log4j.Logger;
3130

3231
import com.cloud.event.EventTypes;
3332
import com.cloud.exception.ConcurrentOperationException;
@@ -37,7 +36,7 @@
3736
import com.cloud.user.Account;
3837

3938
@APICommand(name = "restartVPC", description = "Restarts a VPC", responseObject = VpcResponse.class, entityType = {Vpc.class},
40-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
39+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4140
public class RestartVPCCmd extends BaseAsyncCmd {
4241
public static final Logger s_logger = Logger.getLogger(RestartVPCCmd.class.getName());
4342
private static final String s_name = "restartvpcresponse";
@@ -49,6 +48,9 @@ public class RestartVPCCmd extends BaseAsyncCmd {
4948
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = VpcResponse.class, required = true, description = "the id of the VPC")
5049
private Long id;
5150

51+
@Parameter(name = ApiConstants.CLEANUP, type = CommandType.BOOLEAN, required = false, description = "If cleanup old network elements")
52+
private Boolean cleanup;
53+
5254
/////////////////////////////////////////////////////
5355
/////////////////// Accessors ///////////////////////
5456
/////////////////////////////////////////////////////
@@ -57,6 +59,13 @@ public Long getId() {
5759
return id;
5860
}
5961

62+
public Boolean getCleanup() {
63+
if (cleanup != null) {
64+
return cleanup;
65+
}
66+
return true;
67+
}
68+
6069
/////////////////////////////////////////////////////
6170
/////////////// API Implementation///////////////////
6271
/////////////////////////////////////////////////////
@@ -67,7 +76,7 @@ public String getCommandName() {
6776

6877
@Override
6978
public long getEntityOwnerId() {
70-
Vpc vpc = _entityMgr.findById(Vpc.class, getId());
79+
final Vpc vpc = _entityMgr.findById(Vpc.class, getId());
7180
if (vpc != null) {
7281
return vpc.getAccountId();
7382
}
@@ -78,20 +87,20 @@ public long getEntityOwnerId() {
7887
@Override
7988
public void execute() {
8089
try {
81-
boolean result = _vpcService.restartVpc(getId());
90+
final boolean result = _vpcService.restartVpc(getId(), getCleanup());
8291
if (result) {
83-
SuccessResponse response = new SuccessResponse(getCommandName());
92+
final SuccessResponse response = new SuccessResponse(getCommandName());
8493
setResponseObject(response);
8594
} else {
8695
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart VPC");
8796
}
88-
} catch (ResourceUnavailableException ex) {
97+
} catch (final ResourceUnavailableException ex) {
8998
s_logger.warn("Exception: ", ex);
9099
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
91-
} catch (ConcurrentOperationException ex) {
100+
} catch (final ConcurrentOperationException ex) {
92101
s_logger.warn("Exception: ", ex);
93102
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
94-
} catch (InsufficientCapacityException ex) {
103+
} catch (final InsufficientCapacityException ex) {
95104
s_logger.info(ex);
96105
s_logger.trace(ex);
97106
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());

api/src/org/apache/cloudstack/api/response/VpcResponse.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,112 +115,112 @@ public class VpcResponse extends BaseResponse implements ControlledEntityRespons
115115
@Param(description = "is VPC uses distributed router for one hop forwarding and host based network ACL's", since = "4.4")
116116
private boolean usesDistributedRouter;
117117

118-
@SerializedName((ApiConstants.REGION_LEVEL_VPC))
118+
@SerializedName(ApiConstants.REGION_LEVEL_VPC)
119119
@Param(description = "true if VPC is region level", since = "4.4")
120120
private Boolean regionLevelVpc;
121121

122122
@SerializedName(ApiConstants.REDUNDANT_VPC_ROUTER)
123-
@Param(description = "if this VPC has redundant router", since = "4.4")
123+
@Param(description = "if this VPC has redundant router", since = "4.6")
124124
private boolean redundantRouter;
125125

126-
public void setId(String id) {
126+
public void setId(final String id) {
127127
this.id = id;
128128
}
129129

130-
public void setName(String name) {
130+
public void setName(final String name) {
131131
this.name = name;
132132
}
133133

134-
public void setDisplayText(String displayText) {
134+
public void setDisplayText(final String displayText) {
135135
this.displayText = displayText;
136136
}
137137

138-
public void setCreated(Date created) {
138+
public void setCreated(final Date created) {
139139
this.created = created;
140140
}
141141

142-
public void setServices(List<ServiceResponse> services) {
142+
public void setServices(final List<ServiceResponse> services) {
143143
this.services = services;
144144
}
145145

146-
public void setState(String state) {
146+
public void setState(final String state) {
147147
this.state = state;
148148
}
149149

150150
@Override
151-
public void setAccountName(String accountName) {
151+
public void setAccountName(final String accountName) {
152152
this.accountName = accountName;
153153
}
154154

155155
@Override
156-
public void setProjectId(String projectId) {
156+
public void setProjectId(final String projectId) {
157157
this.projectId = projectId;
158158
}
159159

160160
@Override
161-
public void setProjectName(String projectName) {
161+
public void setProjectName(final String projectName) {
162162
this.projectName = projectName;
163163
}
164164

165165
@Override
166-
public void setDomainId(String domainId) {
166+
public void setDomainId(final String domainId) {
167167
this.domainId = domainId;
168168
}
169169

170170
@Override
171-
public void setDomainName(String domainName) {
172-
this.domain = domainName;
171+
public void setDomainName(final String domainName) {
172+
domain = domainName;
173173
}
174174

175-
public void setZoneId(String zoneId) {
175+
public void setZoneId(final String zoneId) {
176176
this.zoneId = zoneId;
177177
}
178178

179-
public void setCidr(String cidr) {
179+
public void setCidr(final String cidr) {
180180
this.cidr = cidr;
181181
}
182182

183-
public void setVpcOfferingId(String vpcOfferingId) {
183+
public void setVpcOfferingId(final String vpcOfferingId) {
184184
this.vpcOfferingId = vpcOfferingId;
185185
}
186186

187187
public List<NetworkResponse> getNetworks() {
188188
return networks;
189189
}
190190

191-
public void setNetworks(List<NetworkResponse> networks) {
191+
public void setNetworks(final List<NetworkResponse> networks) {
192192
this.networks = networks;
193193
}
194194

195-
public void setRestartRequired(Boolean restartRequired) {
195+
public void setRestartRequired(final Boolean restartRequired) {
196196
this.restartRequired = restartRequired;
197197
}
198198

199-
public void setNetworkDomain(String networkDomain) {
199+
public void setNetworkDomain(final String networkDomain) {
200200
this.networkDomain = networkDomain;
201201
}
202202

203-
public void setZoneName(String zoneName) {
203+
public void setZoneName(final String zoneName) {
204204
this.zoneName = zoneName;
205205
}
206206

207-
public void setTags(List<ResourceTagResponse> tags) {
207+
public void setTags(final List<ResourceTagResponse> tags) {
208208
this.tags = tags;
209209
}
210210

211-
public void setForDisplay(Boolean forDisplay) {
211+
public void setForDisplay(final Boolean forDisplay) {
212212
this.forDisplay = forDisplay;
213213
}
214214

215-
public void setRegionLevelVpc(Boolean regionLevelVpc) {
215+
public void setRegionLevelVpc(final Boolean regionLevelVpc) {
216216
this.regionLevelVpc = regionLevelVpc;
217217
}
218218

219-
public void setUsesDistributedRouter(Boolean usesDistributedRouter) {
219+
public void setUsesDistributedRouter(final Boolean usesDistributedRouter) {
220220
this.usesDistributedRouter = usesDistributedRouter;
221221
}
222222

223-
public void setRedundantRouter(Boolean redundantRouter) {
223+
public void setRedundantRouter(final Boolean redundantRouter) {
224224
this.redundantRouter = redundantRouter;
225225
}
226226
}

server/src/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ public boolean cleanupVpcResources(final long vpcId, final Account caller, final
14881488

14891489
@Override
14901490
@ActionEvent(eventType = EventTypes.EVENT_VPC_RESTART, eventDescription = "restarting vpc")
1491-
public boolean restartVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
1491+
public boolean restartVpc(final long vpcId, final boolean cleanUp) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
14921492
final Account caller = CallContext.current().getCallingAccount();
14931493

14941494
// Verify input parameters
@@ -1504,11 +1504,15 @@ public boolean restartVpc(final long vpcId) throws ConcurrentOperationException,
15041504
s_logger.debug("Restarting VPC " + vpc);
15051505
boolean restartRequired = false;
15061506
try {
1507-
s_logger.debug("Shutting down VPC " + vpc + " as a part of VPC restart process");
1508-
if (!shutdownVpc(vpcId)) {
1509-
s_logger.warn("Failed to shutdown vpc as a part of VPC " + vpc + " restart process");
1510-
restartRequired = true;
1511-
return false;
1507+
if (cleanUp) {
1508+
s_logger.debug("Shutting down VPC " + vpc + " as a part of VPC restart process");
1509+
if (!shutdownVpc(vpcId)) {
1510+
s_logger.warn("Failed to shutdown vpc as a part of VPC " + vpc + " restart process");
1511+
restartRequired = true;
1512+
return false;
1513+
}
1514+
} else {
1515+
s_logger.info("Will not shutdown vpc as a part of VPC " + vpc + " restart process.");
15121516
}
15131517

15141518
s_logger.debug("Starting VPC " + vpc + " as a part of VPC restart process");

server/src/org/cloud/network/router/deployment/RouterDeploymentDefinition.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
public class RouterDeploymentDefinition {
7272
private static final Logger logger = Logger.getLogger(RouterDeploymentDefinition.class);
7373

74+
protected static final int LIMIT_NUMBER_OF_ROUTERS = 5;
75+
protected static final int MAX_NUMBER_OF_ROUTERS = 2;
76+
7477
protected NetworkDao networkDao;
7578
protected DomainRouterDao routerDao;
7679
protected PhysicalNetworkServiceProviderDao physicalProviderDao;
@@ -280,7 +283,7 @@ protected List<DeployDestination> findDestinations() {
280283

281284
protected int getNumberOfRoutersToDeploy() {
282285
// TODO Are we sure this makes sense? Somebody said 5 was too many?
283-
if (routers.size() >= 5) {
286+
if (routers.size() >= LIMIT_NUMBER_OF_ROUTERS) {
284287
logger.error("Too many redundant routers!");
285288
}
286289

server/src/org/cloud/network/router/deployment/VpcRouterDeploymentDefinition.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ protected List<DeployDestination> findDestinations() {
108108
return destinations;
109109
}
110110

111-
@Override
112-
protected int getNumberOfRoutersToDeploy() {
113-
// Enable redundant Vpc, with the same behavior a Non Vpc Router
114-
// TODO Remove this method unless we need to actually add some behavior
115-
return super.getNumberOfRoutersToDeploy();
116-
}
117-
118111
/**
119112
* @see RouterDeploymentDefinition#prepareDeployment()
120113
*
@@ -125,13 +118,6 @@ protected boolean prepareDeployment() {
125118
return true;
126119
}
127120

128-
@Override
129-
protected void setupPriorityOfRedundantRouter() {
130-
// Implement Redundant Vpc
131-
// TODO Remove this method unless we need to actually add some behavior
132-
super.setupPriorityOfRedundantRouter();
133-
}
134-
135121
@Override
136122
protected void findSourceNatIP() throws InsufficientAddressCapacityException, ConcurrentOperationException {
137123
sourceNatIp = vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
@@ -144,8 +130,8 @@ protected void findOrDeployVirtualRouter() throws ConcurrentOperationException,
144130
// This call will associate any existing router to the "routers" attribute.
145131
// It's needed in order to continue with the VMs deployment.
146132
planDeploymentRouters();
147-
if (!routers.isEmpty()) {
148-
// If routers are found, just return: nothing need to be done here.
133+
if (routers.size() == MAX_NUMBER_OF_ROUTERS) {
134+
// If we have 2 routers already deployed, do nothing and return.
149135
return;
150136
}
151137
}

0 commit comments

Comments
 (0)