bug 12686: added search by zoneId to the listNetworkOfferings

This commit is contained in:
Alena Prokharchyk 2012-01-04 12:31:30 -08:00
parent d16c535514
commit d4e0fbda83
9 changed files with 80 additions and 13 deletions

View File

@ -81,7 +81,9 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
private List<String> supportedServices;
@Parameter(name=ApiConstants.SOURCE_NAT_SUPPORTED, type=CommandType.BOOLEAN, description="true if need to list only netwok offerings where source nat is supported, false otherwise")
private Boolean sourceNatSupported;
private Boolean sourceNatSupported;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////

View File

@ -84,7 +84,7 @@ public interface NetworkService {
Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
Map<String, Set<String>> listNetworkOfferingServices(long networkOfferingId);
Map<String, Set<String>> listNetworkOfferingServicesAndProviders(long networkOfferingId);
PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List<String> isolationMethods, String broadcastDomainRange, Long domainId, List<String> tags);

View File

@ -699,7 +699,7 @@ public class ApiDBUtils {
}
public static Map<String, Set<String>> listNetworkOfferingServices(long networkOfferingId) {
return _networkMgr.listNetworkOfferingServices(networkOfferingId);
return _networkMgr.listNetworkOfferingServicesAndProviders(networkOfferingId);
}
public static List<Service> getElementServices(Provider provider) {

View File

@ -103,12 +103,12 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.IPAddressVO;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.BroadcastDomainType;
@ -163,6 +163,8 @@ import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.VMInstanceDao;
import edu.emory.mathcs.backport.java.util.Arrays;
@Local(value = { ConfigurationManager.class, ConfigurationService.class })
public class ConfigurationManagerImpl implements ConfigurationManager, ConfigurationService {
public static final Logger s_logger = Logger.getLogger(ConfigurationManagerImpl.class.getName());
@ -3200,6 +3202,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (zoneId != null) {
zone = getZone(zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId);
}
}
Object keyword = cmd.getKeyword();
@ -3288,21 +3293,22 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
//filter by supported services
boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null);
boolean checkIfProvidersAreEnabled = (zoneId != null);
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled);
if (parseOfferings) {
List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
Service[] suppportedServices = null;
Service[] supportedServices = null;
if (listBySupportedServices) {
suppportedServices = new Service[supportedServicesStr.size()];
supportedServices = new Service[supportedServicesStr.size()];
int i = 0;
for (String supportedServiceStr : supportedServicesStr) {
Service service = Service.getService(supportedServiceStr);
if (service == null) {
throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
} else {
suppportedServices[i] = service;
supportedServices[i] = service;
}
i++;
}
@ -3310,9 +3316,20 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
for (NetworkOfferingVO offering : offerings) {
boolean addOffering = true;
List<Service> checkForProviders = new ArrayList<Service>();
if (listBySupportedServices) {
addOffering = addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), suppportedServices);
addOffering = addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices);
}
if (checkIfProvidersAreEnabled) {
if (supportedServices != null && supportedServices.length > 0) {
checkForProviders = Arrays.asList(supportedServices);
} else {
checkForProviders = _networkMgr.listNetworkOfferingServices(offering.getId());
}
addOffering = addOffering && _networkMgr.areServicesEnabledInZone(zoneId, offering.getId(), offering.getTags(), checkForProviders);
}
if (sourceNatSupported != null) {

View File

@ -260,4 +260,8 @@ public interface NetworkManager extends NetworkService {
HypervisorType hypervisorType);
boolean canAddDefaultSecurityGroup();
List<Service> listNetworkOfferingServices(long networkOfferingId);
boolean areServicesEnabledInZone(long zoneId, long networkOfferingId, String tags, List<Service> services);
}

View File

@ -3883,7 +3883,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public Map<String, Set<String>> listNetworkOfferingServices(long networkOfferingId) {
public Map<String, Set<String>> listNetworkOfferingServicesAndProviders(long networkOfferingId) {
Map<String, Set<String>> serviceProviderMap = new HashMap<String, Set<String>>();
List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
@ -3952,8 +3952,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
protected boolean canUpgradeProviders(long oldNetworkOfferingId, long newNetworkOfferingId) {
//list of services and providers should be the same
Map<String, Set<String>> newServices = listNetworkOfferingServices(newNetworkOfferingId);
Map<String, Set<String>> oldServices = listNetworkOfferingServices(oldNetworkOfferingId);
Map<String, Set<String>> newServices = listNetworkOfferingServicesAndProviders(newNetworkOfferingId);
Map<String, Set<String>> oldServices = listNetworkOfferingServicesAndProviders(oldNetworkOfferingId);
if (newServices.size() < oldServices.size()) {
s_logger.debug("Network offering downgrade is not allowed: number of supported services for the new offering " + newNetworkOfferingId + " is less than the old offering " + oldNetworkOfferingId);
@ -5429,4 +5429,33 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
String defaultAdding = _configDao.getValue(Config.SecurityGroupDefaultAdding.key());
return (defaultAdding != null && defaultAdding.equalsIgnoreCase("true"));
}
@Override
public List<Service> listNetworkOfferingServices(long networkOfferingId) {
List<Service> services = new ArrayList<Service>();
List<String> servicesStr = _ntwkOfferingSrvcDao.listServicesForNetworkOffering(networkOfferingId);
for (String serviceStr : servicesStr) {
services.add(Service.getService(serviceStr));
}
return services;
}
@Override
public boolean areServicesEnabledInZone(long zoneId, long networkOfferingId, String tags, List<Service> services) {
long physicalNtwkId = findPhysicalNetworkId(zoneId, tags);
boolean result = true;
List<String> checkedProvider = new ArrayList<String>();
for (Service service : services) {
//get all the providers, and check if each provider is enabled
List<String> providerNames = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(networkOfferingId, service);
for (String providerName : providerNames) {
if (!checkedProvider.contains(providerName)) {
result = result && isProviderEnabledInPhysicalNetwork(physicalNtwkId, providerName);
}
}
}
return result;
}
}

View File

@ -35,6 +35,7 @@ public interface NetworkOfferingServiceMapDao extends GenericDao<NetworkOffering
void deleteByOfferingId(long networkOfferingId);
List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service);
boolean isProviderForNetworkOffering(long networkOfferingId, Provider provider);
List<String> listServicesForNetworkOffering(long networkOfferingId);
}

View File

@ -39,6 +39,7 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
final SearchBuilder<NetworkOfferingServiceMapVO> AllFieldsSearch;
final SearchBuilder<NetworkOfferingServiceMapVO> MultipleServicesSearch;
final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ProvidersSearch;
final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ServicesSearch;
protected NetworkOfferingServiceMapDaoImpl() {
super();
@ -59,6 +60,11 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
ProvidersSearch.and("service", ProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
ProvidersSearch.select(null, Func.DISTINCT, ProvidersSearch.entity().getProvider());
ProvidersSearch.done();
ServicesSearch = createSearchBuilder(String.class);
ServicesSearch.and("networkOfferingId", ServicesSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
ServicesSearch.select(null, Func.DISTINCT, ServicesSearch.entity().getService());
ServicesSearch.done();
}
@Override
@ -127,4 +133,12 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
}
return false;
}
@Override
public List<String> listServicesForNetworkOffering(long networkOfferingId) {
SearchCriteria<String> sc = ServicesSearch.create();;
sc.setParameters("networkOfferingId", networkOfferingId);
return customSearch(sc, null);
}
}

View File

@ -429,7 +429,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
}
@Override
public Map<String, Set<String>> listNetworkOfferingServices(long networkOfferingId) {
public Map<String, Set<String>> listNetworkOfferingServicesAndProviders(long networkOfferingId) {
return null;
}