Search in sources :

Example 31 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getProviderToIpList.

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(final Network network, final Map<PublicIpAddress, Set<Service>> ipToServices) {
    final NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (final PublicIpAddress ip : ipToServices.keySet()) {
            final Set<Service> services = new HashSet<>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }
        }
    }
    final Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<>();
    for (final PublicIpAddress ip : ipToServices.keySet()) {
        for (final Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    final Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    final Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<>();
    for (final Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        final Set<Service> services = providerToServices.get(provider);
        final ArrayList<PublicIpAddress> ipList = new ArrayList<>();
        final Set<PublicIpAddress> ipSet = new HashSet<>();
        for (final Service service : services) {
            final Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        final Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) 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 32 with Provider

use of com.cloud.legacymodel.network.Network.Provider 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 33 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method canIpsUseOffering.

private boolean canIpsUseOffering(final List<PublicIp> publicIps, final long offeringId) {
    final Map<PublicIp, Set<Service>> ipToServices = getIpToServices(publicIps, false, true);
    final Map<Service, Set<Provider>> serviceToProviders = _networkModel.getNetworkOfferingServiceProvidersMap(offeringId);
    final NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
    // For inline mode checking, using firewall provider for LB instead, because public ip would apply on firewall provider
    if (offering.isInline()) {
        Provider firewallProvider = null;
        if (serviceToProviders.containsKey(Service.Firewall)) {
            firewallProvider = (Provider) serviceToProviders.get(Service.Firewall).toArray()[0];
        }
        final Set<Provider> p = new HashSet<>();
        p.add(firewallProvider);
        serviceToProviders.remove(Service.Lb);
        serviceToProviders.put(Service.Lb, p);
    }
    for (final PublicIp ip : ipToServices.keySet()) {
        final Set<Service> services = ipToServices.get(ip);
        Provider provider = null;
        for (final Service service : services) {
            final Set<Provider> curProviders = serviceToProviders.get(service);
            if (curProviders == null || curProviders.isEmpty()) {
                continue;
            }
            final Provider curProvider = (Provider) curProviders.toArray()[0];
            if (provider == null) {
                provider = curProvider;
                continue;
            }
            // We don't support multiple providers for one service now
            if (!provider.equals(curProvider)) {
                throw new InvalidParameterException("There would be multiple providers for IP " + ip.getAddress() + " with the new network offering!");
            }
        }
    }
    return true;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ResultSet(java.sql.ResultSet) Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) PublicIp(com.cloud.network.addr.PublicIp) 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) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.legacymodel.network.Network.Provider) HashSet(java.util.HashSet)

Example 34 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method addProviderToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(final Long physicalNetworkId, final String providerName, final Long destinationPhysicalNetworkId, final List<String> enabledServices) {
    // verify input parameters
    final PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
        throw ex;
    }
    // verify input parameters
    if (destinationPhysicalNetworkId != null) {
        final PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
        if (destNetwork == null) {
            final InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
            ex.addProxyObject(destinationPhysicalNetworkId.toString(), "destinationPhysicalNetworkId");
            throw ex;
        }
    }
    if (providerName != null) {
        final Provider provider = Network.Provider.getProvider(providerName);
        if (provider == null) {
            throw new InvalidParameterValueException("Invalid Network Service Provider=" + providerName);
        }
    }
    if (_pNSPDao.findByServiceProvider(physicalNetworkId, providerName) != null) {
        // TBD: send uuid instead of physicalNetworkId.
        throw new CloudRuntimeException("The '" + providerName + "' provider already exists on physical network : " + physicalNetworkId);
    }
    // check if services can be turned off
    final NetworkElement element = _networkModel.getElementImplementingProvider(providerName);
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + providerName + "'");
    }
    List<Service> services = new ArrayList<>();
    if (enabledServices != null) {
        if (!element.canEnableIndividualServices()) {
            if (enabledServices.size() != element.getCapabilities().keySet().size()) {
                throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services for this Service Provider '" + providerName + "'");
            }
        }
        // validate Services
        boolean addGatewayService = false;
        for (final String serviceName : enabledServices) {
            final Network.Service service = Network.Service.getService(serviceName);
            if (service == null || service == Service.Gateway) {
                throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
            } else if (service == Service.SourceNat) {
                addGatewayService = true;
            }
            // check if the service is provided by this Provider
            if (!element.getCapabilities().containsKey(service)) {
                throw new InvalidParameterValueException(providerName + " Provider cannot provide this Service specified=" + serviceName);
            }
            services.add(service);
        }
        if (addGatewayService) {
            services.add(Service.Gateway);
        }
    } else {
        // enable all the default services supported by this element.
        services = new ArrayList<>(element.getCapabilities().keySet());
    }
    try {
        // Create the new physical network in the database
        PhysicalNetworkServiceProviderVO nsp = new PhysicalNetworkServiceProviderVO(physicalNetworkId, providerName);
        // set enabled services
        nsp.setEnabledServices(services);
        if (destinationPhysicalNetworkId != null) {
            nsp.setDestinationPhysicalNetworkId(destinationPhysicalNetworkId);
        }
        nsp = _pNSPDao.persist(nsp);
        return nsp;
    } catch (final Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a provider to physical network");
    }
}
Also used : ArrayList(java.util.ArrayList) 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) Service(com.cloud.legacymodel.network.Network.Service) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) SQLException(java.sql.SQLException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) UnknownHostException(java.net.UnknownHostException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Provider(com.cloud.legacymodel.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) Network(com.cloud.legacymodel.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 35 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method createVpcOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create = true)
public VpcOffering createVpcOffering(final String name, final String displayText, final List<String> supportedServices, final Map<String, List<String>> serviceProviders, final Map serviceCapabilitystList, final Long serviceOfferingId, final Long secondaryServiceOfferingId) {
    final Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<>();
    final Set<Network.Provider> defaultProviders = new HashSet<>();
    defaultProviders.add(Provider.VPCVirtualRouter);
    // Just here for 4.1, replaced by commit 836ce6c1 in newer versions
    final Set<Network.Provider> sdnProviders = new HashSet<>();
    sdnProviders.add(Provider.NiciraNvp);
    boolean firewallSvs = false;
    // populate the services first
    for (final String serviceName : supportedServices) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || nonSupportedServices.contains(service)) {
            throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC");
        }
        if (service == Service.Connectivity) {
            s_logger.debug("Applying Connectivity workaround, setting provider to NiciraNvp");
            svcProviderMap.put(service, sdnProviders);
        } else {
            svcProviderMap.put(service, defaultProviders);
        }
        if (service == Service.NetworkACL) {
            firewallSvs = true;
        }
    }
    if (!firewallSvs) {
        s_logger.debug("Automatically adding network ACL service to the list of VPC services");
        svcProviderMap.put(Service.NetworkACL, defaultProviders);
    }
    if (serviceProviders != null) {
        for (final Entry<String, List<String>> serviceEntry : serviceProviders.entrySet()) {
            final Network.Service service = Network.Service.getService(serviceEntry.getKey());
            if (svcProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<>();
                for (final String prvNameStr : serviceEntry.getValue()) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    providers.add(provider);
                }
                svcProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceEntry.getKey() + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    validateConnectivtyServiceCapabilities(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList);
    final boolean redundantRouter = isVpcOfferingRedundantRouter(serviceCapabilitystList);
    final VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, serviceOfferingId, secondaryServiceOfferingId, redundantRouter);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Service(com.cloud.legacymodel.network.Network.Service) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Provider(com.cloud.legacymodel.network.Network.Provider) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

Provider (com.cloud.legacymodel.network.Network.Provider)55 Service (com.cloud.legacymodel.network.Network.Service)29 HashSet (java.util.HashSet)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)22 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArrayList (java.util.ArrayList)21 NetworkElement (com.cloud.network.element.NetworkElement)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)14 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)14 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)13 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)12 ResourceLimitService (com.cloud.user.ResourceLimitService)12 Network (com.cloud.legacymodel.network.Network)11 VpcProvider (com.cloud.network.element.VpcProvider)10 NicProfile (com.cloud.vm.NicProfile)10 SortedSet (java.util.SortedSet)10 NetworkVO (com.cloud.network.dao.NetworkVO)8