Return redundantRouter/sourceNatSupported capabilities as a part of listSupportedNetworkServices

This commit is contained in:
Alena Prokharchyk 2011-12-06 15:36:02 -08:00
parent 9c6a56a61b
commit e89c8725ed
6 changed files with 31 additions and 13 deletions

View File

@ -194,6 +194,8 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
if (svc.equalsIgnoreCase(service.getName())) {
capabilityMap.put(capability, capabilityValue);
} else {
//throw new InvalidParameterValueException("Service is not equal ")
}
}
}

View File

@ -51,10 +51,10 @@ public interface Network extends ControlledEntity {
public static final Service Dhcp = new Service("Dhcp");
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
public static final Service Gateway = new Service("Gateway");
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.SupportedSourceNatTypes, Capability.TrafficStatistics);
public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.TrafficStatistics);
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps, Capability.SupportedStickinessMethods);
public static final Service UserData = new Service("UserData");
public static final Service SourceNat = new Service("SourceNat");
public static final Service SourceNat = new Service("SourceNat", Capability.SupportedSourceNatTypes, Capability.RedundantRouter);
public static final Service StaticNat = new Service("StaticNat");
public static final Service PortForwarding = new Service("PortForwarding");
public static final Service SecurityGroup = new Service("SecurityGroup");
@ -118,7 +118,6 @@ public interface Network extends ControlledEntity {
public static final Provider ExternalDhcpServer = new Provider("ExternalDhcpServer", true);
public static final Provider ExternalGateWay = new Provider("ExternalGateWay", true);
public static final Provider ElasticLoadBalancerVm = new Provider("ElasticLoadBalancerVm", false);
public static final Provider RedundantVirtualRouter = new Provider("RedundantVirtualRouter", false);
public static final Provider SecurityGroupProvider = new Provider("SecurityGroupProvider", false);
public static final Provider None = new Provider("None", false);

View File

@ -2849,7 +2849,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
//get the Provider for this Service for this offering
String provider = _ntwkOfferingSrvcDao.getProviderForServiceForNetworkOffering(offering.getId(), service);
List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
if (providers.isEmpty()) {
throw new InvalidParameterValueException("Service " + service.getName() + " is not supported by the network offering " + offering);
}
//FIXME - in post 3.0 we are going to support multiple providers for the same service per network offering, so we have to calculate capabilities for all of them
String provider = providers.get(0);
//FIXME we return the capabilities of the first provider of the service - what if we have multiple providers for same Service?
NetworkElement element = getElementImplementingProvider(provider);
@ -5104,6 +5110,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if(enabledServices.size() != element.getCapabilities().keySet().size()){
StringBuilder servicesSet = new StringBuilder();
for (Service requiredService: element.getCapabilities().keySet()) {
//skip gateway service as we don't allow setting it via API
if (requiredService == Service.Gateway) {
continue;
}
servicesSet.append(requiredService.getName() + ", ");
}
servicesSet.delete(servicesSet.toString().length() -2, servicesSet.toString().length());

View File

@ -57,7 +57,7 @@ public class NetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceMapVO
DistinctProvidersSearch = createSearchBuilder(String.class);
DistinctProvidersSearch.and("networkId", DistinctProvidersSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
DistinctProvidersSearch.select(null, Func.DISTINCT, DistinctProvidersSearch.entity().getProvider());
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
DistinctProvidersSearch.done();
}

View File

@ -32,7 +32,7 @@ public interface NetworkOfferingServiceMapDao extends GenericDao<NetworkOffering
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
List<NetworkOfferingServiceMapVO> listByNetworkOfferingId(long networkOfferingId);
void deleteByOfferingId(long networkOfferingId);
String getProviderForServiceForNetworkOffering(long networkOfferingId, Service service);
List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service);
}

View File

@ -23,17 +23,21 @@ import java.util.List;
import javax.ejb.Local;
import com.cloud.exception.UnsupportedServiceException;
import com.cloud.network.NetworkServiceMapVO;
import com.cloud.network.Network.Service;
import com.cloud.offerings.NetworkOfferingServiceMapVO;
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=NetworkOfferingServiceMapDao.class) @DB(txn=false)
public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOfferingServiceMapVO, Long> implements NetworkOfferingServiceMapDao {
final SearchBuilder<NetworkOfferingServiceMapVO> AllFieldsSearch;
final SearchBuilder<NetworkOfferingServiceMapVO> MultipleServicesSearch;
final GenericSearchBuilder<NetworkOfferingServiceMapVO, String> ProvidersSearch;
protected NetworkOfferingServiceMapDaoImpl() {
super();
@ -48,6 +52,12 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
MultipleServicesSearch.done();
ProvidersSearch = createSearchBuilder(String.class);
ProvidersSearch.and("networkOfferingId", ProvidersSearch.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ);
ProvidersSearch.and("service", ProvidersSearch.entity().getService(), SearchCriteria.Op.EQ);
ProvidersSearch.select(null, Func.DISTINCT, ProvidersSearch.entity().getProvider());
ProvidersSearch.done();
}
@Override
@ -95,15 +105,12 @@ public class NetworkOfferingServiceMapDaoImpl extends GenericDaoBase<NetworkOffe
}
@Override
public String getProviderForServiceForNetworkOffering(long networkOfferingId, Service service) {
SearchCriteria<NetworkOfferingServiceMapVO> sc = AllFieldsSearch.create();
public List<String> listProvidersForServiceForNetworkOffering(long networkOfferingId, Service service) {
SearchCriteria<String> sc = ProvidersSearch.create();;
sc.setParameters("networkOfferingId", networkOfferingId);
sc.setParameters("service", service.getName());
NetworkOfferingServiceMapVO ntwkSvc = findOneBy(sc);
if (ntwkSvc == null) {
throw new UnsupportedServiceException("Service " + service + " is not supported by network offering id=" + networkOfferingId);
}
return ntwkSvc.getProvider();
return customSearch(sc, null);
}
}