diff --git a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java index de97c2939db..de13cd7b3e4 100644 --- a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java @@ -2000,12 +2000,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C Account caller = CallContext.current().getCallingAccount(); // Verify network id - NetworkVO network = _networksDao.findById(networkId); - if (network == null) { - // see NetworkVO.java - - throwInvalidIdException("unable to find network with specified id", String.valueOf(networkId), "networkId"); - } + NetworkVO network = getNetworkVO(networkId, "Unable to find a network with the specified ID."); // don't allow to delete system network if (isNetworkSystem(network)) { @@ -2035,10 +2030,20 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C @Override @ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true) public boolean restartNetwork(Long networkId, boolean cleanup, boolean makeRedundant, User user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + NetworkVO network = getNetworkVO(networkId, "Network with specified id doesn't exist"); + return restartNetwork(network, cleanup, makeRedundant, user); + } + + private NetworkVO getNetworkVO(Long networkId, String errMsgFormat) { NetworkVO network = _networksDao.findById(networkId); if (network == null) { - throwInvalidIdException("Network with specified id doesn't exist", networkId.toString(), "networkId"); + throwInvalidIdException(errMsgFormat, networkId.toString(), "networkId"); } + return network; + } + + @ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true) + public boolean restartNetwork(NetworkVO network, boolean cleanup, boolean makeRedundant, User user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // Don't allow to restart network if it's not in Implemented/Setup state if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) { @@ -2064,11 +2069,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C cleanup = true; } - boolean success = _networkMgr.restartNetwork(networkId, callerAccount, user, cleanup); + long id = network.getId(); + boolean success = _networkMgr.restartNetwork(id, callerAccount, user, cleanup); if (success) { - s_logger.debug("Network id=" + networkId + " is restarted successfully."); + s_logger.debug(String.format("Network id=%d is restarted successfully.",id)); } else { - s_logger.warn("Network id=" + networkId + " failed to restart."); + s_logger.warn(String.format("Network id=%d failed to restart.",id)); } return success; @@ -2078,11 +2084,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C @ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true) public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // This method restarts all network elements belonging to the network and re-applies all the rules - Long networkId = cmd.getNetworkId(); + NetworkVO network = getNetworkVO(cmd.getNetworkId(), "Network [%s] to restart was not found."); boolean cleanup = cmd.getCleanup(); + if (network.getVpcId() != null && cleanup) { + throwInvalidIdException("Cannot restart a VPC tier with cleanup, please restart the whole VPC.", network.getUuid(), "network tier"); + } boolean makeRedundant = cmd.getMakeRedundant(); User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); - return restartNetwork(networkId, cleanup, makeRedundant, callerUser); + return restartNetwork(network, cleanup, makeRedundant, callerUser); } @Override @@ -2219,11 +2228,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C boolean restartNetwork = false; // verify input parameters - final NetworkVO network = _networksDao.findById(networkId); - if (network == null) { - // see NetworkVO.java - throwInvalidIdException("Specified network id doesn't exist in the system", String.valueOf(networkId), "networkId"); - } + final NetworkVO network = getNetworkVO(networkId, "Specified network id doesn't exist in the system"); //perform below validation if the network is vpc network if (network.getVpcId() != null && networkOfferingId != null) { diff --git a/ui/src/config/section/network.js b/ui/src/config/section/network.js index 95c24159bb0..43992e81ced 100644 --- a/ui/src/config/section/network.js +++ b/ui/src/config/section/network.js @@ -99,7 +99,7 @@ export default { label: 'label.restart.network', message: 'message.restart.network', dataView: true, - args: ['cleanup'], + args: (record) => record.vpcid == null ? ['cleanup'] : [], // if it is a tier in a VPC and so it has a vpc do not allow "cleanup show: (record) => record.type !== 'L2', groupAction: true, popup: true,