Do not restart VPC tiers with cleanup (#5873)

* do not restart VPC tiers with cleanup

* no option for cleanup for VPC tiers

* Update server/src/main/java/com/cloud/network/NetworkServiceImpl.java

* paramNames

* remove superfluent parameter

Co-authored-by: Daan Hoogland <dahn@onecht.net>
Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
This commit is contained in:
dahn 2022-01-31 13:29:26 +01:00 committed by GitHub
parent 5f07e4daaf
commit c1bba2a308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 18 deletions

View File

@ -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) {

View File

@ -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,