mirror of https://github.com/apache/cloudstack.git
bug 10605: updateNetworks api command - restart the network if networkDomain is updated.
updateNetwork command is async now
This commit is contained in:
parent
efa431ed1b
commit
a2531b60f9
|
|
@ -23,11 +23,13 @@ import java.util.List;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.NetworkResponse;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
|
@ -35,7 +37,7 @@ import com.cloud.network.Network;
|
|||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Updates a network", responseObject=NetworkResponse.class)
|
||||
public class UpdateNetworkCmd extends BaseCmd {
|
||||
public class UpdateNetworkCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName());
|
||||
|
||||
private static final String s_name = "updatenetworkresponse";
|
||||
|
|
@ -120,4 +122,13 @@ public class UpdateNetworkCmd extends BaseCmd {
|
|||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
|
||||
}
|
||||
}
|
||||
|
||||
public String getEventDescription() {
|
||||
return "Updating network: " + getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return EventTypes.EVENT_NETWORK_UPDATE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2919,8 +2919,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = false)
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = true)
|
||||
public Network updateNetwork(long networkId, String name, String displayText, List<String> tags, Account caller, String domainSuffix, long networkOfferingId) {
|
||||
boolean restartNetwork = false;
|
||||
|
||||
// verify input parameters
|
||||
NetworkVO network = _networksDao.findById(networkId);
|
||||
|
|
@ -2932,6 +2933,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
throw new InvalidParameterException("Unable to support more than one tag on network yet");
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, network);
|
||||
|
||||
// Don't allow to update system network - make an exception for the Guest network in Basic zone
|
||||
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
|
||||
if (offering.isSystemOnly() && network.getTrafficType() != TrafficType.Guest) {
|
||||
|
|
@ -2954,17 +2957,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
throw new InvalidParameterValueException("Domain name change is not supported for network id=" + network.getNetworkOfferingId() + " in zone id=" + network.getDataCenterId());
|
||||
}
|
||||
|
||||
//restart network if it has active network elements
|
||||
List<DomainRouterVO> routers = _routerDao.listActive(networkId);
|
||||
if (!routers.isEmpty()) {
|
||||
throw new CloudRuntimeException("Unable to update network id=" + networkId + " with new network domain as the network has running network elements");
|
||||
restartNetwork = true;
|
||||
}
|
||||
|
||||
|
||||
network.setNetworkDomain(domainSuffix);
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller, network);
|
||||
|
||||
if (name != null) {
|
||||
network.setName(name);
|
||||
}
|
||||
|
|
@ -2988,34 +2989,30 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
network.setNetworkOfferingId(networkOfferingId);
|
||||
}
|
||||
|
||||
_networksDao.update(networkId, network);
|
||||
|
||||
if ((networkOfferingId != 0) && (networkOfferingId != oldNetworkOfferingId)) {
|
||||
s_logger.info("Try to restart the network since the networkofferingID is changed");
|
||||
// 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)) {
|
||||
s_logger.warn("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup);
|
||||
}
|
||||
restartNetwork = true;
|
||||
}
|
||||
|
||||
boolean success = _networksDao.update(networkId, network);
|
||||
|
||||
if (success && restartNetwork && (network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
|
||||
s_logger.info("Restarting network " + network + " as a part of update network call");
|
||||
|
||||
boolean success = true;
|
||||
try {
|
||||
// Restart network - network elements restart is required
|
||||
success = restartNetwork(networkId, true, caller);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Fail to restart the network: " + e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
s_logger.debug("Network id=" + networkId + " is restarted successfully.");
|
||||
s_logger.debug("Successully restarted the network " + network + " as a part of updateNetwork call");
|
||||
} else {
|
||||
s_logger.warn("Network id=" + networkId + " failed to restart.");
|
||||
s_logger.warn("Failed to restart the network " + network + " as a part of updateNetwork call");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return network;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue