Search in sources :

Example 6 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 7 with UnsupportedServiceException

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

the class NetworkModelImpl method checkCapabilityForProvider.

@Override
public void checkCapabilityForProvider(final Set<Provider> providers, final Service service, final Capability cap, final String capValue) {
    for (final Provider provider : providers) {
        final NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element != null) {
            final 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.getName());
            }
            final Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
            if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capabilities for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            final String value = serviceCapabilities.get(cap);
            if (value == null || value.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            if (!value.toLowerCase().contains(capValue.toLowerCase())) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't support value " + capValue + " for capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
        } else {
            throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

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