Changes to updateNetwork command:

* update network with new networkOfferingId only after the network is shutdown
* fixed NPE happenining when updateNetwork with the networkOffering w/o soucrceNat service in Advance zone
This commit is contained in:
Alena Prokharchyk 2011-11-11 14:04:10 -08:00
parent cdfac9a5e1
commit 9ca379fc61
3 changed files with 37 additions and 31 deletions

View File

@ -25,6 +25,7 @@ import com.cloud.api.IdentityProxy;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@SuppressWarnings("unused")
public class PhysicalNetworkResponse extends BaseResponse{
@SerializedName(ApiConstants.ID) @Param(description="the uuid of the physical network")

View File

@ -2610,7 +2610,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
_accountMgr.checkAccess(callerAccount, null, network);
boolean success = restartNetwork(networkId, callerAccount, callerUser, null, cleanup);
boolean success = restartNetwork(networkId, callerAccount, callerUser, cleanup);
if (success) {
s_logger.debug("Network id=" + networkId + " is restarted successfully.");
@ -2641,7 +2641,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
private boolean restartNetwork(long networkId, Account callerAccount, User callerUser, Long newNetworkOfferingId, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
private boolean restartNetwork(long networkId, Account callerAccount, User callerUser, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
NetworkVO network = _networksDao.findById(networkId);
@ -2656,13 +2656,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return false;
}
//Only after network was shutdown properly, change the network offering
if (newNetworkOfferingId != null) {
s_logger.debug("Updating network " + network + " with the new network offering id=" + newNetworkOfferingId + " as a part of network restart");
network.setNetworkOfferingId(newNetworkOfferingId);
_networksDao.update(networkId, network, finalizeServicesAndProvidersForNetwork(_configMgr.getNetworkOffering(newNetworkOfferingId), network.getPhysicalNetworkId()));
}
//implement the network elements and rules again
DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
@ -3332,31 +3325,43 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//have to restart the network
restartNetwork = true;
}
//1) Shutdown all the elements and cleanup all the rules
ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
if (restartNetwork) {
s_logger.debug("Shutting down elements and resources for network id=" + networkId + " as a part of network update");
_networksDao.update(networkId, network);
boolean success = true;
if (restartNetwork && (network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
//network offering id will be updated in the restartNetowrk call aftet the network elements are shutdown properly
s_logger.info("Restarting network " + network + " as a part of update network call");
try {
success = restartNetwork(networkId, callerAccount, callerUser, networkOfferingId, true);
} catch (Exception e) {
success = false;
if (!shutdownNetworkElementsAndResources(context, true, network)) {
s_logger.warn("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState());
throw new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState());
}
if (success) {
s_logger.debug("Successully restarted the network " + network + " as a part of updateNetwork call");
} else {
s_logger.warn("Failed to restart the network " + network + " as a part of updateNetwork call");
}
} else if (networkOfferingId != null) {
network.setNetworkOfferingId(networkOfferingId);
_networksDao.update(networkId, network, finalizeServicesAndProvidersForNetwork(_configMgr.getNetworkOffering(networkOfferingId), network.getPhysicalNetworkId()));
}
return network;
//2) Only after all the elements and rules are shutdown properly, update the network VO
if (networkOfferingId != null) {
network.setNetworkOfferingId(networkOfferingId);
_networksDao.update(networkId, network, finalizeServicesAndProvidersForNetwork(_configMgr.getNetworkOffering(networkOfferingId), network.getPhysicalNetworkId()));
} else {
_networksDao.update(networkId, network);
}
//get updated network
network = _networksDao.findById(networkId);
//3) Implement the elements and rules again
if (restartNetwork) {
DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
s_logger.debug("Implementing the network " + network + " elements and resources as a part of network update");
try {
implementNetworkElementsAndResources(dest, context, network, _networkOfferingDao.findById(network.getNetworkOfferingId()));
} catch (Exception ex) {
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network update due to ", ex);
throw new CloudRuntimeException("Failed to implement network " + network + " elements and resources as a part of network update");
}
}
return getNetwork(network.getId());
}
@Override

View File

@ -1156,8 +1156,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (publicNetwork) {
routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER);
} else {
Long podId = dest.getPod().getId();
if (isPodBased) {
Long podId = dest.getPod().getId();
routers = _routerDao.listByNetworkAndPodAndRole(guestNetwork.getId(), podId, Role.VIRTUAL_ROUTER);
plan = new DataCenterDeployment(dcId, podId, null, null, null, null);
} else {