Search in sources :

Example 1 with UnsupportedServiceException

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");
    }
}
Also used : HashMap(java.util.HashMap) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with UnsupportedServiceException

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;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with UnsupportedServiceException

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;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) AccountService(com.cloud.user.AccountService) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with UnsupportedServiceException

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;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with UnsupportedServiceException

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;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)22 NetworkElement (com.cloud.network.element.NetworkElement)12 HashMap (java.util.HashMap)12 Service (com.cloud.network.Network.Service)11 Map (java.util.Map)10 Capability (com.cloud.network.Network.Capability)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 Provider (com.cloud.network.Network.Provider)7 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)6 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)6 ArrayList (java.util.ArrayList)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 HashSet (java.util.HashSet)3 ResourceOwnerType (com.cloud.configuration.Resource.ResourceOwnerType)2 ResourceType (com.cloud.configuration.Resource.ResourceType)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 NetworkOfferingServiceMapVO (com.cloud.offerings.NetworkOfferingServiceMapVO)2 ResourceLimitService (com.cloud.user.ResourceLimitService)2