Search in sources :

Example 1 with UnsupportedServiceException

use of com.cloud.legacymodel.exceptions.UnsupportedServiceException in project cosmic by MissionCriticalCloud.

the class ResourceCountDaoImpl method persist.

@Override
public ResourceCountVO persist(final ResourceCountVO resourceCountVO) {
    final ResourceOwnerType ownerType = resourceCountVO.getResourceOwnerType();
    final ResourceType resourceType = resourceCountVO.getType();
    if (!resourceType.supportsOwner(ownerType)) {
        throw new UnsupportedServiceException("Resource type " + resourceType + " is not supported for owner of type " + ownerType.getName());
    }
    return super.persist(resourceCountVO);
}
Also used : UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ResourceOwnerType(com.cloud.legacymodel.configuration.Resource.ResourceOwnerType) ResourceType(com.cloud.legacymodel.configuration.Resource.ResourceType)

Example 2 with UnsupportedServiceException

use of com.cloud.legacymodel.exceptions.UnsupportedServiceException in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method finalizeServicesAndProvidersForNetwork.

@Override
public Map<String, String> finalizeServicesAndProvidersForNetwork(final NetworkOffering offering, final Long physicalNetworkId) {
    final Map<String, String> svcProviders = new HashMap<>();
    final Map<String, List<String>> providerSvcs = new HashMap<>();
    final List<NetworkOfferingServiceMapVO> servicesMap = _ntwkOfferingSrvcDao.listByNetworkOfferingId(offering.getId());
    final boolean checkPhysicalNetwork = physicalNetworkId != null;
    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<>());
        }
        l.add(service);
    }
    return svcProviders;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with UnsupportedServiceException

use of com.cloud.legacymodel.exceptions.UnsupportedServiceException in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method canProviderSupportServices.

@Override
public void canProviderSupportServices(final Map<Provider, Set<Service>> providersMap) {
    for (final Provider provider : providersMap.keySet()) {
        // check if services can be turned off
        final NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element == null) {
            throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'");
        }
        final Set<Service> enabledServices = new HashSet<>();
        enabledServices.addAll(providersMap.get(provider));
        if (enabledServices != null && !enabledServices.isEmpty()) {
            if (!element.canEnableIndividualServices()) {
                final Set<Service> requiredServices = new HashSet<>();
                requiredServices.addAll(element.getCapabilities().keySet());
                if (requiredServices.contains(Network.Service.Gateway)) {
                    requiredServices.remove(Network.Service.Gateway);
                }
                if (requiredServices.contains(Network.Service.Firewall)) {
                    requiredServices.remove(Network.Service.Firewall);
                }
                if (enabledServices.contains(Network.Service.Firewall)) {
                    enabledServices.remove(Network.Service.Firewall);
                }
                // exclude gateway service
                if (enabledServices.size() != requiredServices.size()) {
                    final StringBuilder servicesSet = new StringBuilder();
                    for (final Service requiredService : requiredServices) {
                        // 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());
                    throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services: " + servicesSet.toString() + "  for Service Provider " + provider.getName());
                }
            }
            final List<String> serviceList = new ArrayList<>();
            for (final Service service : enabledServices) {
                // check if the service is provided by this Provider
                if (!element.getCapabilities().containsKey(service)) {
                    throw new UnsupportedServiceException(provider.getName() + " Provider cannot provide service " + service.getName());
                }
                serviceList.add(service.getName());
            }
            if (!element.verifyServicesCombination(enabledServices)) {
                throw new UnsupportedServiceException("Provider " + provider.getName() + " doesn't support services combination: " + serviceList);
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) HashSet(java.util.HashSet)

Example 4 with UnsupportedServiceException

use of com.cloud.legacymodel.exceptions.UnsupportedServiceException in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method getNetworkOfferingServiceCapabilities.

@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(final NetworkOffering offering, final 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<>();
    // get the Provider for this Service for this offering
    final 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
    final 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?
    final NetworkElement element = _networkModel.getElementImplementingProvider(provider);
    if (element != null) {
        final 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.legacymodel.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with UnsupportedServiceException

use of com.cloud.legacymodel.exceptions.UnsupportedServiceException in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getNetworkOfferingServiceCapabilities.

@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(final NetworkOffering offering, final 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<>();
    // get the Provider for this Service for this offering
    final 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
    final 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?
    final NetworkElement element = getElementImplementingProvider(provider);
    if (element != null) {
        final 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.legacymodel.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

UnsupportedServiceException (com.cloud.legacymodel.exceptions.UnsupportedServiceException)7 Service (com.cloud.legacymodel.network.Network.Service)5 NetworkElement (com.cloud.network.element.NetworkElement)5 HashMap (java.util.HashMap)5 Capability (com.cloud.legacymodel.network.Network.Capability)4 Map (java.util.Map)4 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 Provider (com.cloud.legacymodel.network.Network.Provider)2 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)2 ArrayList (java.util.ArrayList)2 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)1 ResourceOwnerType (com.cloud.legacymodel.configuration.Resource.ResourceOwnerType)1 ResourceType (com.cloud.legacymodel.configuration.Resource.ResourceType)1 LoadBalancingRulesService (com.cloud.network.lb.LoadBalancingRulesService)1 NetworkOfferingServiceMapVO (com.cloud.offerings.NetworkOfferingServiceMapVO)1 ResourceLimitService (com.cloud.user.ResourceLimitService)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1