mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Re-create serviceProvider map when network is updated
This commit is contained in:
parent
9c09c35fa5
commit
3aff7f00ff
@ -1108,7 +1108,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
|
||||
NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isDefault,
|
||||
(domainId != null), predefined.getNetworkDomain(), offering.getGuestType(), isShared, plan.getDataCenterId(), plan.getPhysicalNetworkId());
|
||||
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, getServicesAndProvidersForNetwork(offering)));
|
||||
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
|
||||
|
||||
if (domainId != null) {
|
||||
_networksDao.addDomainToNetwork(id, domainId);
|
||||
@ -1737,9 +1737,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
isDomainSpecific = true;
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME - need to check if all providers are supported by the physical network
|
||||
//FIXME - need to check that the traffic type is supported
|
||||
|
||||
Account owner = null;
|
||||
if (cmd.getAccountName() != null && cmd.getDomainId() != null) {
|
||||
@ -1865,7 +1862,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
|
||||
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
|
||||
DataCenterVO zone = _dcDao.findById(zoneId);
|
||||
|
||||
|
||||
// allow isDefault to be set only for Shared network
|
||||
if (networkOffering.getGuestType() == Network.GuestType.Isolated) {
|
||||
if (isDefault != null && !isDefault) {
|
||||
@ -2630,7 +2627,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
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);
|
||||
_networksDao.update(networkId, network, finalizeServicesAndProvidersForNetwork(_configMgr.getNetworkOffering(newNetworkOfferingId), network.getPhysicalNetworkId()));
|
||||
}
|
||||
|
||||
//implement the network elements and rules again
|
||||
@ -3324,10 +3321,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
//have to restart the network
|
||||
restartNetwork = true;
|
||||
}
|
||||
|
||||
_networksDao.update(networkId, network);
|
||||
|
||||
_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 {
|
||||
@ -3341,6 +3340,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
} 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;
|
||||
@ -4851,16 +4853,29 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getServicesAndProvidersForNetwork(NetworkOffering offering) {
|
||||
public Map<String, String> finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId) {
|
||||
Map<String, String> svcProviders = new HashMap<String, String>();
|
||||
List<NetworkOfferingServiceMapVO> servicesMap = _ntwkOfferingSrvcDao.listByNetworkOfferingId(offering.getId());
|
||||
|
||||
boolean checkPhysicalNetwork = (physicalNetworkId != null) ? true : false;
|
||||
|
||||
for (NetworkOfferingServiceMapVO serviceMap : servicesMap) {
|
||||
if (svcProviders.containsKey(serviceMap.getService())) {
|
||||
//FIXME - right now we pick up the first provider from the list, need to add more logic based on provider load, etc
|
||||
continue;
|
||||
}
|
||||
svcProviders.put(serviceMap.getService(), serviceMap.getProvider());
|
||||
}
|
||||
|
||||
String service = serviceMap.getService();
|
||||
String provider = serviceMap.getProvider();
|
||||
|
||||
//check that provider is supported
|
||||
if (checkPhysicalNetwork) {
|
||||
if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) {
|
||||
throw new UnsupportedServiceException("Provider " + provider + " doesn't support service " + service + " in physical network id=" + physicalNetworkId);
|
||||
}
|
||||
}
|
||||
|
||||
svcProviders.put(service, provider);
|
||||
}
|
||||
|
||||
return svcProviders;
|
||||
|
||||
@ -46,7 +46,7 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
|
||||
@Override
|
||||
@Deprecated
|
||||
NetworkVO persist(NetworkVO vo);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the next available mac address in this network configuration.
|
||||
*
|
||||
@ -85,4 +85,8 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
|
||||
List<NetworkVO> listBy(long accountId, long dataCenterId, Network.GuestType type, TrafficType trafficType);
|
||||
|
||||
List<NetworkVO> listByPhysicalNetworkAndProvider(long physicalNetworkId, String providerName);
|
||||
|
||||
void persistNetworkServiceProviders(long networkId, Map<String, String> serviceProviderMap);
|
||||
|
||||
boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap);
|
||||
}
|
||||
|
||||
@ -198,14 +198,39 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
|
||||
NetworkOpVO op = new NetworkOpVO(network.getId(), gc);
|
||||
_opDao.persist(op);
|
||||
//4) add services/providers for the network
|
||||
for (String service : serviceProviderMap.keySet()) {
|
||||
NetworkServiceMapVO serviceMap = new NetworkServiceMapVO(newNetwork.getId(), Service.getService(service), Provider.getProvider(serviceProviderMap.get(service)));
|
||||
_ntwkSvcMap.persist(serviceMap);
|
||||
}
|
||||
persistNetworkServiceProviders(newNetwork.getId(), serviceProviderMap);
|
||||
|
||||
txn.commit();
|
||||
return newNetwork;
|
||||
}
|
||||
|
||||
|
||||
@Override @DB
|
||||
public boolean update(Long networkId, NetworkVO network, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
super.update(networkId, network);
|
||||
if (serviceProviderMap != null) {
|
||||
_ntwkSvcMap.deleteByNetworkId(networkId);
|
||||
persistNetworkServiceProviders(networkId, serviceProviderMap);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void persistNetworkServiceProviders(long networkId, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
for (String service : serviceProviderMap.keySet()) {
|
||||
NetworkServiceMapVO serviceMap = new NetworkServiceMapVO(networkId, Service.getService(service), Provider.getProvider(serviceProviderMap.get(service)));
|
||||
_ntwkSvcMap.persist(serviceMap);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
protected void addAccountToNetwork(long networkId, long accountId, boolean isOwner) {
|
||||
NetworkAccountVO account = new NetworkAccountVO(networkId, accountId, isOwner);
|
||||
|
||||
@ -17,4 +17,5 @@ public interface NetworkServiceMapDao extends GenericDao<NetworkServiceMapVO, Lo
|
||||
boolean isProviderSupportedInNetwork(long networkId, Service service, Provider provider);
|
||||
List<NetworkServiceMapVO> getServicesInNetwork(long networkId);
|
||||
String getProviderForServiceInNetwork(long networkid, Service service);
|
||||
void deleteByNetworkId(long networkId);
|
||||
}
|
||||
|
||||
@ -128,8 +128,8 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
protected void deleteByNetworkId(long networkId) {
|
||||
@Override
|
||||
public void deleteByNetworkId(long networkId) {
|
||||
SearchCriteria<NetworkServiceMapVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("networkId", networkId);
|
||||
remove(sc);
|
||||
|
||||
@ -25,4 +25,5 @@ public interface PhysicalNetworkServiceProviderDao extends GenericDao<PhysicalNe
|
||||
List<PhysicalNetworkServiceProviderVO> listBy(long physicalNetworkId);
|
||||
PhysicalNetworkServiceProviderVO findByServiceProvider(long physicalNetworkId, String providerType);
|
||||
void deleteProviders(long physicalNetworkId);
|
||||
boolean isServiceProviderEnabled(long physicalNetworkId, String providerType, String serviceType);
|
||||
}
|
||||
|
||||
@ -21,6 +21,8 @@ import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
@ -31,6 +33,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
|
||||
public class PhysicalNetworkServiceProviderDaoImpl extends GenericDaoBase<PhysicalNetworkServiceProviderVO, Long> implements PhysicalNetworkServiceProviderDao {
|
||||
final SearchBuilder<PhysicalNetworkServiceProviderVO> physicalNetworkSearch;
|
||||
final SearchBuilder<PhysicalNetworkServiceProviderVO> physicalNetworkServiceProviderSearch;
|
||||
final SearchBuilder<PhysicalNetworkServiceProviderVO> AllFieldsSearch;
|
||||
|
||||
protected PhysicalNetworkServiceProviderDaoImpl() {
|
||||
super();
|
||||
@ -42,6 +45,23 @@ public class PhysicalNetworkServiceProviderDaoImpl extends GenericDaoBase<Physic
|
||||
physicalNetworkServiceProviderSearch.and("physicalNetworkId", physicalNetworkServiceProviderSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
physicalNetworkServiceProviderSearch.and("serviceProvderType", physicalNetworkServiceProviderSearch.entity().getProviderName(), Op.EQ);
|
||||
physicalNetworkServiceProviderSearch.done();
|
||||
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.and("serviceProvderType", AllFieldsSearch.entity().getProviderName(), Op.EQ);
|
||||
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
|
||||
AllFieldsSearch.and("vpnService", AllFieldsSearch.entity().isVpnServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("dhcpService", AllFieldsSearch.entity().isDhcpServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("dnsService", AllFieldsSearch.entity().isDnsServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("gatewayService", AllFieldsSearch.entity().isGatewayServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("firewallService", AllFieldsSearch.entity().isFirewallServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("sourceNatService", AllFieldsSearch.entity().isSourcenatServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("lbService", AllFieldsSearch.entity().isLbServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("staticNatService", AllFieldsSearch.entity().isStaticnatServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("pfService", AllFieldsSearch.entity().isPortForwardingServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("userDataService", AllFieldsSearch.entity().isUserdataServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.and("securityGroupService", AllFieldsSearch.entity().isSecuritygroupServiceProvided(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,4 +86,44 @@ public class PhysicalNetworkServiceProviderDaoImpl extends GenericDaoBase<Physic
|
||||
remove(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isServiceProviderEnabled(long physicalNetworkId, String providerType, String serviceType) {
|
||||
SearchCriteria<PhysicalNetworkServiceProviderVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("physicalNetworkId", physicalNetworkId);
|
||||
sc.setParameters("serviceProvderType", providerType);
|
||||
sc.setParameters("state", PhysicalNetworkServiceProvider.State.Enabled.toString());
|
||||
|
||||
if (serviceType.equalsIgnoreCase(Service.Dhcp.getName())) {
|
||||
sc.setParameters("dhcpService", true);
|
||||
} else if (serviceType.equalsIgnoreCase(Service.Dns.getName())) {
|
||||
sc.setParameters("dnsService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.Firewall.getName())) {
|
||||
sc.setParameters("firewallService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.Gateway.getName())) {
|
||||
sc.setParameters("gatewayService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.Lb.getName())) {
|
||||
sc.setParameters("lbService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.PortForwarding.getName())) {
|
||||
sc.setParameters("pfService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.SecurityGroup.getName())) {
|
||||
sc.setParameters("securityGroupService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.SourceNat.getName())) {
|
||||
sc.setParameters("sourceNatService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.StaticNat.getName())) {
|
||||
sc.setParameters("staticNatService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.UserData.getName())) {
|
||||
sc.setParameters("userDataService", true);
|
||||
}else if (serviceType.equalsIgnoreCase(Service.Vpn.getName())) {
|
||||
sc.setParameters("vpnService", true);
|
||||
}
|
||||
|
||||
PhysicalNetworkServiceProviderVO map = findOneBy(sc);
|
||||
|
||||
if (map != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user