mirror of https://github.com/apache/cloudstack.git
bug 11307: Add cleanup parameter to restartNetwork command
Default set it to true. When cleanup=false, restartNetwork would only re-implement the network, but don't destroy current existed routers.
This commit is contained in:
parent
e330e97f4b
commit
684a603a6e
|
|
@ -48,6 +48,9 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
|
|||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The id of the network to restart.")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.CLEANUP, type=CommandType.BOOLEAN, required=false, description="If cleanup old network elements")
|
||||
private Boolean cleanup;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -61,6 +64,13 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
|
|||
return network.getId();
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getCleanup() {
|
||||
if (cleanup != null) {
|
||||
return cleanup;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -79,7 +89,7 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
|
||||
boolean result = _networkService.restartNetwork(this);
|
||||
boolean result = _networkService.restartNetwork(this, getCleanup());
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public interface NetworkService {
|
|||
|
||||
boolean deleteNetwork(long networkId);
|
||||
|
||||
boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
|
||||
int getActiveNicsInNetwork(long networkId);
|
||||
|
||||
|
|
|
|||
|
|
@ -101,11 +101,12 @@ public interface NetworkElement extends Adapter {
|
|||
* The network is being restarted.
|
||||
* @param network
|
||||
* @param context
|
||||
* @param cleanup If need to clean up old network elements
|
||||
* @return
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
|
||||
/**
|
||||
* The network is being destroyed.
|
||||
|
|
|
|||
|
|
@ -1213,7 +1213,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
// reapply all the firewall/staticNat/lb rules
|
||||
s_logger.debug("Applying network rules as a part of network " + network + " implement...");
|
||||
if (!restartNetwork(networkId, false, context.getAccount())) {
|
||||
if (!restartNetwork(networkId, false, true, context.getAccount())) {
|
||||
s_logger.warn("Failed to reapply network rules as a part of network " + network + " implement");
|
||||
throw new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
|
@ -2360,7 +2360,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
|
||||
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
// This method restarts all network elements belonging to the network and re-applies all the rules
|
||||
Long networkId = cmd.getNetworkId();
|
||||
|
||||
|
|
@ -2383,7 +2383,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
boolean success = true;
|
||||
|
||||
// Restart network - network elements restart is required
|
||||
success = restartNetwork(networkId, true, callerAccount);
|
||||
success = restartNetwork(networkId, true, cleanup, callerAccount);
|
||||
|
||||
if (success) {
|
||||
s_logger.debug("Network id=" + networkId + " is restarted successfully.");
|
||||
|
|
@ -2414,7 +2414,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
private boolean restartNetwork(long networkId, boolean restartElements, Account caller) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
private boolean restartNetwork(long networkId, boolean restartElements, boolean cleanup, Account caller) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
boolean success = true;
|
||||
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
|
|
@ -2427,7 +2427,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
for (NetworkElement element : _networkElements) {
|
||||
// stop and start the network element
|
||||
try {
|
||||
boolean supported = element.restart(network, context);
|
||||
boolean supported = element.restart(network, context, cleanup);
|
||||
if (!supported) {
|
||||
s_logger.trace("Network element(s) " + element.getName() + " doesn't support network id" + networkId + " restart");
|
||||
}
|
||||
|
|
@ -3101,7 +3101,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
s_logger.info("Restarting network " + network + " as a part of update network call");
|
||||
|
||||
try {
|
||||
success = restartNetwork(networkId, true, caller);
|
||||
success = restartNetwork(networkId, true, true, caller);
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class BareMetalElement extends AdapterBase implements NetworkElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
InsufficientCapacityException {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
|
||||
s_logger.trace("Cloudzones element doesn't handle network restart for the network " + network);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, null);
|
||||
NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class ElasticLoadBalancerElement extends AdapterBase implements NetworkEl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
// TODO restart all loadbalancer vms by calling the ElasticLoadBalancerManager
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class ExternalDhcpElement extends AdapterBase implements NetworkElement,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
InsufficientCapacityException {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ public class ExternalFirewallElement extends AdapterBase implements NetworkEleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public class NetscalerExternalLoadBalancerElement extends AdapterBase implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class OvsElement extends AdapterBase implements NetworkElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context)
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
InsufficientCapacityException {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean restart(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
public boolean restart(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
if (!canHandle(network.getGuestType(), dc)) {
|
||||
s_logger.trace("Virtual router element doesn't handle network restart for the network " + network);
|
||||
|
|
@ -160,12 +160,14 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
|
|||
if (host_id == null || host_id == 0) {
|
||||
host_id = (router.getHostId() != null ? router.getHostId() : router.getLastHostId());
|
||||
}
|
||||
/* FIXME it's not completely safe to ignore these failure, but we would try to push on now */
|
||||
if (router.getState() != State.Stopped || _routerMgr.stopRouter(router.getId(), false) == null) {
|
||||
s_logger.warn("Failed to stop virtual router element " + router + " as a part of network " + network + " restart");
|
||||
}
|
||||
if (!_routerMgr.destroyRouter(router.getId())) {
|
||||
s_logger.warn("Failed to destroy virtual router element " + router + " as a part of network " + network + " restart");
|
||||
if (cleanup) {
|
||||
/* FIXME it's not completely safe to ignore these failure, but we would try to push on now */
|
||||
if (router.getState() != State.Stopped || _routerMgr.stopRouter(router.getId(), false) == null) {
|
||||
s_logger.warn("Failed to stop virtual router element " + router + " as a part of network " + network + " restart");
|
||||
}
|
||||
if (!_routerMgr.destroyRouter(router.getId())) {
|
||||
s_logger.warn("Failed to destroy virtual router element " + router + " as a part of network " + network + " restart");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (host_id == null || host_id == 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue