Search in sources :

Example 6 with NetworkElement

use of com.cloud.network.element.NetworkElement 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 7 with NetworkElement

use of com.cloud.network.element.NetworkElement in project cloudstack by apache.

the class NetworkModelImpl method getElementImplementingProvider.

@Override
public NetworkElement getElementImplementingProvider(String providerName) {
    String elementName = s_providerToNetworkElementMap.get(providerName);
    NetworkElement element = AdapterBase.getAdapterByName(networkElements, elementName);
    return element;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement)

Example 8 with NetworkElement

use of com.cloud.network.element.NetworkElement 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 9 with NetworkElement

use of com.cloud.network.element.NetworkElement 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 10 with NetworkElement

use of com.cloud.network.element.NetworkElement 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

NetworkElement (com.cloud.network.element.NetworkElement)36 Provider (com.cloud.network.Network.Provider)23 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)17 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)15 Service (com.cloud.network.Network.Service)14 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)13 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 Capability (com.cloud.network.Network.Capability)8 NetworkVO (com.cloud.network.dao.NetworkVO)8 NetworkGuru (com.cloud.network.guru.NetworkGuru)8 ArrayList (java.util.ArrayList)8 NicProfile (com.cloud.vm.NicProfile)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6