Search in sources :

Example 11 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method getNetworkCapabilities.

@Override
public Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId) {
    Map<Service, Map<Capability, String>> networkCapabilities = new HashMap<Service, Map<Capability, String>>();
    // list all services of this networkOffering
    List<NetworkServiceMapVO> servicesMap = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (NetworkServiceMapVO instance : servicesMap) {
        Service service = Service.getService(instance.getService());
        NetworkElement element = getElementImplementingProvider(instance.getProvider());
        if (element != null) {
            Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
            if (elementCapabilities != null) {
                networkCapabilities.put(service, elementCapabilities.get(service));
            }
        }
    }
    return networkCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method getServiceProvidersMap.

Map<Service, Set<Provider>> getServiceProvidersMap(long networkId) {
    Map<Service, Set<Provider>> map = new HashMap<Service, Set<Provider>>();
    List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (NetworkServiceMapVO nsm : nsms) {
        Set<Provider> providers = map.get(Service.getService(nsm.getService()));
        if (providers == null) {
            providers = new HashSet<Provider>();
        }
        providers.add(Provider.getProvider(nsm.getProvider()));
        map.put(Service.getService(nsm.getService()), providers);
    }
    return map;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 13 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method start.

@Override
public boolean start() {
    // Need to do this in start() since _networkElements are not completely configured until then.
    for (NetworkElement element : networkElements) {
        Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
        Provider implementedProvider = element.getProvider();
        if (implementedProvider != null) {
            if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) {
                s_logger.error("Cannot start NetworkModel: Provider <-> NetworkElement must be a one-to-one map, " + "multiple NetworkElements found for Provider: " + implementedProvider.getName());
                continue;
            }
            s_logger.info("Add provider <-> element map entry. " + implementedProvider.getName() + "-" + element.getName() + "-" + element.getClass().getSimpleName());
            s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName());
        }
        if (capabilities != null && implementedProvider != null) {
            for (Service service : capabilities.keySet()) {
                if (s_serviceToImplementedProvidersMap.containsKey(service)) {
                    List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
                    providers.add(implementedProvider);
                } else {
                    List<Provider> providers = new ArrayList<Provider>();
                    providers.add(implementedProvider);
                    s_serviceToImplementedProvidersMap.put(service, providers);
                }
            }
        }
    }
    s_logger.info("Started Network Model");
    return true;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 14 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method canIpUsedForService.

public boolean canIpUsedForService(PublicIp publicIp, Service service, Long networkId) {
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = getIpToServices(ipList, false, true);
    Set<Service> services = ipToServices.get(publicIp);
    if (services == null || services.isEmpty()) {
        return true;
    }
    if (networkId == null) {
        networkId = publicIp.getAssociatedWithNetworkId();
    }
    // We only support one provider for one service now
    Map<Service, Set<Provider>> serviceToProviders = getServiceProvidersMap(networkId);
    // Since IP already has service to bind with, the oldProvider can't be null
    Set<Provider> newProviders = serviceToProviders.get(service);
    if (newProviders == null || newProviders.isEmpty()) {
        throw new InvalidParameterException("There is no new provider for IP " + publicIp.getAddress() + " of service " + service.getName() + "!");
    }
    Provider newProvider = (Provider) newProviders.toArray()[0];
    Set<Provider> oldProviders = serviceToProviders.get(services.toArray()[0]);
    Provider oldProvider = (Provider) oldProviders.toArray()[0];
    Network network = _networksDao.findById(networkId);
    NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
    NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
    if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester) {
        IpDeployer oldIpDeployer = ((IpDeployingRequester) oldElement).getIpDeployer(network);
        IpDeployer newIpDeployer = ((IpDeployingRequester) newElement).getIpDeployer(network);
    // FIXME: I ignored this check
    } else {
        throw new InvalidParameterException("Ip cannot be applied for new provider!");
    }
    return true;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) InvalidParameterException(java.security.InvalidParameterException) NetworkElement(com.cloud.network.element.NetworkElement) IpDeployer(com.cloud.network.element.IpDeployer)

Example 15 with Service

use of com.cloud.network.Network.Service 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) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Service (com.cloud.network.Network.Service)76 HashMap (java.util.HashMap)40 ArrayList (java.util.ArrayList)37 Provider (com.cloud.network.Network.Provider)36 HashSet (java.util.HashSet)36 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)31 Set (java.util.Set)30 ResourceLimitService (com.cloud.user.ResourceLimitService)28 Map (java.util.Map)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 Network (com.cloud.network.Network)18 Capability (com.cloud.network.Network.Capability)17 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)15 NetworkElement (com.cloud.network.element.NetworkElement)14 Test (org.junit.Test)13 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)12 NetworkService (com.cloud.network.NetworkService)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 NetworkOffering (com.cloud.offering.NetworkOffering)10 Account (com.cloud.user.Account)10