Call implement() and shutdown() methods for providers only when the provider serves a service for the network

This commit is contained in:
Alena Prokharchyk 2011-11-17 13:52:05 -08:00
parent cb6c1424ef
commit 0bb325ac12
8 changed files with 79 additions and 32 deletions

View File

@ -27,7 +27,6 @@ import java.util.List;
import java.util.Set;
import com.cloud.acl.ControlledEntity;
import com.cloud.acl.ControlledEntity.ACLType;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;

View File

@ -77,9 +77,9 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNatRule;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.ResourceManager;
@ -99,9 +99,9 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.net.UrlUtil;
import com.cloud.vm.NicVO;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.Nic.State;
import com.cloud.vm.NicVO;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;

View File

@ -227,7 +227,7 @@ public interface NetworkManager extends NetworkService {
boolean isProviderEnabled(PhysicalNetworkServiceProvider provider);
boolean isProviderAvailable(long physicalNetowrkId, String providerName);
boolean isProviderExistAndEnabled(long physicalNetowrkId, String providerName);
boolean isServiceEnabledInNetwork(long physicalNetworkId, long networkId, Service service);

View File

@ -1409,12 +1409,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
assignSourceNatIpAddress(owner, network, context.getCaller().getId());
}
}
//get providers to implement
List<Provider> providersToImplement = getNetworkProviders(network.getId());
for (NetworkElement element : _networkElements) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to implemenet " + network);
}
element.implement(network, offering, dest, context);
if (providersToImplement.contains(element.getProvider())) {
if (!isProviderExistAndEnabled(getPhysicalNetworkId(network), "VirtualRouter")) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or not enabled in physical network id=" + network.getPhysicalNetworkId());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to implemenet " + network);
}
if (!element.implement(network, offering, dest, context)) {
throw new CloudRuntimeException("Failed to implement provider " + element.getProvider().getName() + " for network " + network);
}
}
}
// reapply all the firewall/staticNat/lb rules
@ -2408,24 +2417,34 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
//2) Shutdown all the network elements
//get providers to implement
List<Provider> providersToImplement = getNetworkProviders(network.getId());
boolean success = true;
for (NetworkElement element : _networkElements) {
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending network shutdown to " + element.getName());
if (providersToImplement.contains(element.getProvider())) {
try {
if (!isProviderExistAndEnabled(getPhysicalNetworkId(network), "VirtualRouter")) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName() + " either doesn't exist or not enabled in the physical network " + getPhysicalNetworkId(network));
success = false;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending network shutdown to " + element.getName());
}
if (!element.shutdown(network, context, cleanupElements)) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName());
success = false;
}
} catch (ResourceUnavailableException e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
} catch (ConcurrentOperationException e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
} catch (Exception e) {
s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
success = false;
}
element.shutdown(network, context, cleanupElements);
} catch (ResourceUnavailableException e) {
s_logger.warn("Unable to complete shutdown of the network due to element: " + element.getName(), e);
success = false;
} catch (ConcurrentOperationException e) {
s_logger.warn("Unable to complete shutdown of the network due to element: " + element.getName(), e);
success = false;
} catch (Exception e) {
s_logger.warn("Unable to complete shutdown of the network due to element: " + element.getName(), e);
success = false;
}
}
}
return success;
}
@ -4855,8 +4874,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public boolean isProviderAvailable(long physicalNetowrkId, String providerName) {
public boolean isProviderExistAndEnabled(long physicalNetowrkId, String providerName) {
PhysicalNetworkServiceProviderVO ntwkSvcProvider = _pNSPDao.findByServiceProvider(physicalNetowrkId, providerName);
if (ntwkSvcProvider == null) {
s_logger.warn("Unable to find provider " + providerName + " in physical network id=" + physicalNetowrkId);
return false;
}
return isProviderEnabled(ntwkSvcProvider);
}
@ -4871,7 +4894,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//get provider for the service and check if all of them are supported
String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(networkId, service);
if (!isProviderAvailable(physicalNetworkId, provider)) {
if (!isProviderExistAndEnabled(physicalNetworkId, provider)) {
s_logger.debug("Provider " + provider + " is not enabled in physical network id=" + physicalNetworkId);
return false;
}
@ -4991,4 +5014,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
public boolean getAllowSubdomainAccessGlobal() {
return _allowSubdomainNetworkAccess;
}
public List<Provider> getNetworkProviders(long networkId) {
List<String> providerNames = _ntwkSrvcDao.getDistinctProviders(networkId);
List<Provider> providers = new ArrayList<Provider>();
for (String providerName : providerNames) {
providers.add(Network.Provider.getProvider(providerName));
}
return providers;
}
}

View File

@ -18,4 +18,5 @@ public interface NetworkServiceMapDao extends GenericDao<NetworkServiceMapVO, Lo
List<NetworkServiceMapVO> getServicesInNetwork(long networkId);
String getProviderForServiceInNetwork(long networkid, Service service);
void deleteByNetworkId(long networkId);
List<String> getDistinctProviders(long networkId);
}

View File

@ -29,13 +29,16 @@ import com.cloud.network.Network.Service;
import com.cloud.network.NetworkServiceMapVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
@Local(value=NetworkServiceMapDao.class) @DB(txn=false)
public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO, Long> implements NetworkServiceMapDao {
final SearchBuilder<NetworkServiceMapVO> AllFieldsSearch;
final SearchBuilder<NetworkServiceMapVO> MultipleServicesSearch;
final GenericSearchBuilder<NetworkServiceMapVO, String> DistinctProvidersSearch;
protected NetworkServiceMapDaoImpl() {
super();
@ -50,6 +53,12 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
MultipleServicesSearch.done();
DistinctProvidersSearch = createSearchBuilder(String.class);
DistinctProvidersSearch.and("networkId", DistinctProvidersSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.select(null, Func.DISTINCT, DistinctProvidersSearch.entity().getProvider());
DistinctProvidersSearch.done();
}
@Override
@ -135,4 +144,12 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
remove(sc);
}
@Override
public List<String> getDistinctProviders(long networkId) {
SearchCriteria<String> sc = DistinctProvidersSearch.create();
sc.setParameters("networkId", networkId);
List<String> results = customSearch(sc, null);
return results;
}
}

View File

@ -104,7 +104,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
@Inject VirtualRouterProviderDao _vrProviderDao;
protected boolean canHandle(Network network, Service service) {
if (!_networkMgr.isProviderAvailable(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) {
if (!_networkMgr.isProviderExistAndEnabled(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) {
return false;
}
@ -120,9 +120,6 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
if (offering.isSystemOnly()) {
return false;
}
if (!_networkMgr.isProviderAvailable(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) {
return false;
}
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramNetwork, true);
@ -139,7 +136,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
if (offering.isSystemOnly()) {
return false;
}
if (!_networkMgr.isProviderAvailable(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) {
if (!_networkMgr.isProviderExistAndEnabled(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) {
return false;
}

View File

@ -626,7 +626,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
}
@Override
public boolean isProviderAvailable(long physicalNetowrkId, String providerName) {
public boolean isProviderExistAndEnabled(long physicalNetowrkId, String providerName) {
// TODO Auto-generated method stub
return false;
}