Skip to content

Commit c1bba2a

Browse files
DaanHooglandDaan HooglandGutoVeronezi
authored
Do not restart VPC tiers with cleanup (apache#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>
1 parent 5f07e4d commit c1bba2a

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,12 +2000,7 @@ public boolean deleteNetwork(long networkId, boolean forced) {
20002000
Account caller = CallContext.current().getCallingAccount();
20012001

20022002
// Verify network id
2003-
NetworkVO network = _networksDao.findById(networkId);
2004-
if (network == null) {
2005-
// see NetworkVO.java
2006-
2007-
throwInvalidIdException("unable to find network with specified id", String.valueOf(networkId), "networkId");
2008-
}
2003+
NetworkVO network = getNetworkVO(networkId, "Unable to find a network with the specified ID.");
20092004

20102005
// don't allow to delete system network
20112006
if (isNetworkSystem(network)) {
@@ -2035,10 +2030,20 @@ public boolean deleteNetwork(long networkId, boolean forced) {
20352030
@Override
20362031
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
20372032
public boolean restartNetwork(Long networkId, boolean cleanup, boolean makeRedundant, User user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
2033+
NetworkVO network = getNetworkVO(networkId, "Network with specified id doesn't exist");
2034+
return restartNetwork(network, cleanup, makeRedundant, user);
2035+
}
2036+
2037+
private NetworkVO getNetworkVO(Long networkId, String errMsgFormat) {
20382038
NetworkVO network = _networksDao.findById(networkId);
20392039
if (network == null) {
2040-
throwInvalidIdException("Network with specified id doesn't exist", networkId.toString(), "networkId");
2040+
throwInvalidIdException(errMsgFormat, networkId.toString(), "networkId");
20412041
}
2042+
return network;
2043+
}
2044+
2045+
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
2046+
public boolean restartNetwork(NetworkVO network, boolean cleanup, boolean makeRedundant, User user) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
20422047

20432048
// Don't allow to restart network if it's not in Implemented/Setup state
20442049
if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
@@ -2064,11 +2069,12 @@ public boolean restartNetwork(Long networkId, boolean cleanup, boolean makeRedun
20642069
cleanup = true;
20652070
}
20662071

2067-
boolean success = _networkMgr.restartNetwork(networkId, callerAccount, user, cleanup);
2072+
long id = network.getId();
2073+
boolean success = _networkMgr.restartNetwork(id, callerAccount, user, cleanup);
20682074
if (success) {
2069-
s_logger.debug("Network id=" + networkId + " is restarted successfully.");
2075+
s_logger.debug(String.format("Network id=%d is restarted successfully.",id));
20702076
} else {
2071-
s_logger.warn("Network id=" + networkId + " failed to restart.");
2077+
s_logger.warn(String.format("Network id=%d failed to restart.",id));
20722078
}
20732079

20742080
return success;
@@ -2078,11 +2084,14 @@ public boolean restartNetwork(Long networkId, boolean cleanup, boolean makeRedun
20782084
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
20792085
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
20802086
// This method restarts all network elements belonging to the network and re-applies all the rules
2081-
Long networkId = cmd.getNetworkId();
2087+
NetworkVO network = getNetworkVO(cmd.getNetworkId(), "Network [%s] to restart was not found.");
20822088
boolean cleanup = cmd.getCleanup();
2089+
if (network.getVpcId() != null && cleanup) {
2090+
throwInvalidIdException("Cannot restart a VPC tier with cleanup, please restart the whole VPC.", network.getUuid(), "network tier");
2091+
}
20832092
boolean makeRedundant = cmd.getMakeRedundant();
20842093
User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
2085-
return restartNetwork(networkId, cleanup, makeRedundant, callerUser);
2094+
return restartNetwork(network, cleanup, makeRedundant, callerUser);
20862095
}
20872096

20882097
@Override
@@ -2219,11 +2228,7 @@ public Network updateGuestNetwork(final UpdateNetworkCmd cmd) {
22192228
boolean restartNetwork = false;
22202229

22212230
// verify input parameters
2222-
final NetworkVO network = _networksDao.findById(networkId);
2223-
if (network == null) {
2224-
// see NetworkVO.java
2225-
throwInvalidIdException("Specified network id doesn't exist in the system", String.valueOf(networkId), "networkId");
2226-
}
2231+
final NetworkVO network = getNetworkVO(networkId, "Specified network id doesn't exist in the system");
22272232

22282233
//perform below validation if the network is vpc network
22292234
if (network.getVpcId() != null && networkOfferingId != null) {

ui/src/config/section/network.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default {
9999
label: 'label.restart.network',
100100
message: 'message.restart.network',
101101
dataView: true,
102-
args: ['cleanup'],
102+
args: (record) => record.vpcid == null ? ['cleanup'] : [], // if it is a tier in a VPC and so it has a vpc do not allow "cleanup
103103
show: (record) => record.type !== 'L2',
104104
groupAction: true,
105105
popup: true,

0 commit comments

Comments
 (0)