use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class NetworkModelTest method testCapabilityForProvider.
@Test
public void testCapabilityForProvider() {
NetworkModelImpl modelImpl = spy(NetworkModelImpl.class);
Set<Provider> providers = new HashSet<>();
providers.add(Provider.NuageVsp);
NetworkElement nuageVspElement = mock(NetworkElement.class);
HashMap<Network.Service, Map<Network.Capability, String>> nuageVspCap = new HashMap<Network.Service, Map<Network.Capability, String>>();
HashMap<Network.Capability, String> nuageVspConnectivity = new HashMap<Network.Capability, String>();
nuageVspConnectivity.put(Network.Capability.NoVlan, "FindMe");
nuageVspConnectivity.put(Network.Capability.PublicAccess, "");
nuageVspCap.put(Network.Service.Connectivity, nuageVspConnectivity);
when(nuageVspElement.getName()).thenReturn("NuageVsp");
doReturn(nuageVspCap).when(nuageVspElement).getCapabilities();
doReturn(nuageVspElement).when(modelImpl).getElementImplementingProvider("NuageVsp");
try {
modelImpl.checkCapabilityForProvider(providers, Network.Service.UserData, null, null);
Assert.fail();
} catch (UnsupportedServiceException e) {
Assert.assertEquals(e.getMessage(), "Service " + Network.Service.UserData.getName() + " is not supported by the element=NuageVsp implementing Provider=" + Provider.NuageVsp.getName());
}
try {
modelImpl.checkCapabilityForProvider(providers, Network.Service.Connectivity, Network.Capability.ElasticIp, null);
Assert.fail();
} catch (UnsupportedServiceException e) {
Assert.assertEquals(e.getMessage(), "Service " + Network.Service.Connectivity.getName() + " doesn't have capability " + Network.Capability.ElasticIp.getName() + " for element=NuageVsp implementing Provider=" + Provider.NuageVsp.getName());
}
try {
modelImpl.checkCapabilityForProvider(providers, Network.Service.Connectivity, Network.Capability.PublicAccess, "NonExistingVal");
Assert.fail();
} catch (UnsupportedServiceException e) {
Assert.assertEquals(e.getMessage(), "Service Connectivity doesn't have capability PublicAccess for element=NuageVsp implementing Provider=NuageVsp");
}
modelImpl.checkCapabilityForProvider(providers, Network.Service.Connectivity, Network.Capability.NoVlan, "FindMe");
NetworkElement nuageVspElement2 = mock(NetworkElement.class);
doReturn(null).when(nuageVspElement).getCapabilities();
try {
modelImpl.checkCapabilityForProvider(providers, Network.Service.Connectivity, Network.Capability.PublicAccess, "");
Assert.fail();
} catch (UnsupportedServiceException e) {
Assert.assertEquals(e.getMessage(), "Service Connectivity is not supported by the element=NuageVsp implementing Provider=NuageVsp");
}
}
use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class NetworkOrchestrator method finalizeServicesAndProvidersForNetwork.
@Override
public Map<String, String> finalizeServicesAndProvidersForNetwork(final NetworkOffering offering, final Long physicalNetworkId) {
final Map<String, String> svcProviders = new HashMap<String, String>();
final Map<String, List<String>> providerSvcs = new HashMap<String, List<String>>();
final List<NetworkOfferingServiceMapVO> servicesMap = _ntwkOfferingSrvcDao.listByNetworkOfferingId(offering.getId());
final boolean checkPhysicalNetwork = physicalNetworkId != null ? true : false;
for (final NetworkOfferingServiceMapVO serviceMap : servicesMap) {
if (svcProviders.containsKey(serviceMap.getService())) {
// provider load, etc
continue;
}
final String service = serviceMap.getService();
String provider = serviceMap.getProvider();
if (provider == null) {
provider = _networkModel.getDefaultUniqueProviderForService(service).getName();
}
// check that provider is supported
if (checkPhysicalNetwork) {
if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) {
throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " + "support service " + service + " in physical network id=" + physicalNetworkId);
}
}
svcProviders.put(service, provider);
List<String> l = providerSvcs.get(provider);
if (l == null) {
providerSvcs.put(provider, l = new ArrayList<String>());
}
l.add(service);
}
return svcProviders;
}
use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class NetworkServiceImpl method getNetworkOfferingServiceCapabilities.
@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
// TBD: We should be sending networkOfferingId and not the offering object itself.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
}
Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
// get the Provider for this Service for this offering
List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
if (providers.isEmpty()) {
// TBD: We should be sending networkOfferingId and not the offering object itself.
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 = _networkModel.getElementImplementingProvider(provider);
if (element != null) {
Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
;
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
// TBD: We should be sending providerId and not the offering object itself.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
}
serviceCapabilities = elementCapabilities.get(service);
}
return serviceCapabilities;
}
use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class NetworkModelImpl method getNetworkOfferingServiceCapabilities.
@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
// TBD: We should be sending networkOfferingId and not the offering object itself.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
}
Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
// get the Provider for this Service for this offering
List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
if (providers.isEmpty()) {
// TBD: We should be sending networkOfferingId and not the offering object itself.
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);
if (element != null) {
Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
;
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
// TBD: We should be sending providerId and not the offering object itself.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
}
serviceCapabilities = elementCapabilities.get(service);
}
return serviceCapabilities;
}
use of com.cloud.exception.UnsupportedServiceException in project cloudstack by apache.
the class NetworkModelImpl method getNetworkServiceCapabilities.
@Override
public Map<Capability, String> getNetworkServiceCapabilities(long networkId, Service service) {
if (!areServicesSupportedInNetwork(networkId, service)) {
// addProxyObject with hardcoded tablename. Or we should probably look up the correct dao proxy object.
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId);
}
Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
// get the Provider for this Service for this offering
String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(networkId, service);
NetworkElement element = getElementImplementingProvider(provider);
if (element != null) {
Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
;
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
}
serviceCapabilities = elementCapabilities.get(service);
}
return serviceCapabilities;
}
Aggregations