Search in sources :

Example 61 with Service

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

the class NetworkModelImpl method canProviderSupportServices.

@Override
public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) {
    for (Provider provider : providersMap.keySet()) {
        // check if services can be turned off
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element == null) {
            throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'");
        }
        Set<Service> enabledServices = new HashSet<Service>();
        enabledServices.addAll(providersMap.get(provider));
        if (enabledServices != null && !enabledServices.isEmpty()) {
            if (!element.canEnableIndividualServices()) {
                Set<Service> requiredServices = new HashSet<Service>();
                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()) {
                    StringBuilder servicesSet = new StringBuilder();
                    for (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());
                }
            }
            List<String> serviceList = new ArrayList<String>();
            for (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.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Example 62 with Service

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

the class NetworkModelImpl method listSupportedNetworkServiceProviders.

@Override
public List<? extends Provider> listSupportedNetworkServiceProviders(String serviceName) {
    Network.Service service = null;
    if (serviceName != null) {
        service = Network.Service.getService(serviceName);
        if (service == null) {
            throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
        }
    }
    Set<Provider> supportedProviders = new HashSet<Provider>();
    if (service != null) {
        List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
        if (providers != null && !providers.isEmpty()) {
            supportedProviders.addAll(providers);
        }
    } else {
        for (List<Provider> pList : s_serviceToImplementedProvidersMap.values()) {
            supportedProviders.addAll(pList);
        }
    }
    return new ArrayList<Provider>(supportedProviders);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) HashSet(java.util.HashSet) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 63 with Service

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

the class NetworkServiceImpl method getIpToServices.

/* Get a list of IPs, classify them by service */
protected Map<PublicIp, Set<Service>> getIpToServices(List<PublicIp> publicIps, boolean rulesRevoked, boolean includingFirewall) {
    Map<PublicIp, Set<Service>> ipToServices = new HashMap<PublicIp, Set<Service>>();
    if (publicIps != null && !publicIps.isEmpty()) {
        Set<Long> networkSNAT = new HashSet<Long>();
        for (PublicIp ip : publicIps) {
            Set<Service> services = ipToServices.get(ip);
            if (services == null) {
                services = new HashSet<Service>();
            }
            if (ip.isSourceNat()) {
                if (!networkSNAT.contains(ip.getAssociatedWithNetworkId())) {
                    services.add(Service.SourceNat);
                    networkSNAT.add(ip.getAssociatedWithNetworkId());
                } else {
                    CloudRuntimeException ex = new CloudRuntimeException("Multiple generic soure NAT IPs provided for network");
                    // see the IPAddressVO.java class.
                    IPAddressVO ipAddr = ApiDBUtils.findIpAddressById(ip.getAssociatedWithNetworkId());
                    String ipAddrUuid = ip.getAssociatedWithNetworkId().toString();
                    if (ipAddr != null) {
                        ipAddrUuid = ipAddr.getUuid();
                    }
                    ex.addProxyObject(ipAddrUuid, "networkId");
                    throw ex;
                }
            }
            ipToServices.put(ip, services);
            // provider
            if (ip.getState() == State.Allocating) {
                continue;
            }
            // check if any active rules are applied on the public IP
            Set<Purpose> purposes = getPublicIpPurposeInRules(ip, false, includingFirewall);
            // Firewall rules didn't cover static NAT
            if (ip.isOneToOneNat() && ip.getAssociatedWithVmId() != null) {
                if (purposes == null) {
                    purposes = new HashSet<Purpose>();
                }
                purposes.add(Purpose.StaticNat);
            }
            if (purposes == null || purposes.isEmpty()) {
                // since no active rules are there check if any rules are applied on the public IP but are in
                // revoking state
                purposes = getPublicIpPurposeInRules(ip, true, includingFirewall);
                if (ip.isOneToOneNat()) {
                    if (purposes == null) {
                        purposes = new HashSet<Purpose>();
                    }
                    purposes.add(Purpose.StaticNat);
                }
                if (purposes == null || purposes.isEmpty()) {
                    // IP is not being used for any purpose so skip IPAssoc to network service provider
                    continue;
                } else {
                    if (rulesRevoked) {
                        // no active rules/revoked rules are associated with this public IP, so remove the
                        // association with the provider
                        ip.setState(State.Releasing);
                    } else {
                        if (ip.getState() == State.Releasing) {
                            // rules are not revoked yet, so don't let the network service provider revoke the IP
                            // association
                            // mark IP is allocated so that IP association will not be removed from the provider
                            ip.setState(State.Allocated);
                        }
                    }
                }
            }
            if (purposes.contains(Purpose.StaticNat)) {
                services.add(Service.StaticNat);
            }
            if (purposes.contains(Purpose.LoadBalancing)) {
                services.add(Service.Lb);
            }
            if (purposes.contains(Purpose.PortForwarding)) {
                services.add(Service.PortForwarding);
            }
            if (purposes.contains(Purpose.Vpn)) {
                services.add(Service.Vpn);
            }
            if (purposes.contains(Purpose.Firewall)) {
                services.add(Service.Firewall);
            }
            if (services.isEmpty()) {
                continue;
            }
            ipToServices.put(ip, services);
        }
    }
    return ipToServices;
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PublicIp(com.cloud.network.addr.PublicIp) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Purpose(com.cloud.network.rules.FirewallRule.Purpose) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IPAddressVO(com.cloud.network.dao.IPAddressVO) HashSet(java.util.HashSet)

Example 64 with Service

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

the class NetworkModelImpl method getProviderServicesMap.

Map<Provider, Set<Service>> getProviderServicesMap(long networkId) {
    Map<Provider, Set<Service>> map = new HashMap<Provider, Set<Service>>();
    List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (NetworkServiceMapVO nsm : nsms) {
        Set<Service> services = map.get(Provider.getProvider(nsm.getProvider()));
        if (services == null) {
            services = new HashSet<Service>();
        }
        services.add(Service.getService(nsm.getService()));
        map.put(Provider.getProvider(nsm.getProvider()), services);
    }
    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 65 with Service

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

the class ContrailManagerImpl method locateNetworkOffering.

private NetworkOffering locateNetworkOffering(String offeringName, String offeringDisplayText, Provider provider) {
    List<? extends NetworkOffering> offerList = _configService.listNetworkOfferings(TrafficType.Guest, false);
    for (NetworkOffering offer : offerList) {
        if (offer.getName().equals(offeringName)) {
            if (offer.getState() != NetworkOffering.State.Enabled) {
                return EnableNetworkOffering(offer.getId());
            }
            return offer;
        }
    }
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Service, Set<Provider>>();
    Set<Provider> providerSet = new HashSet<Provider>();
    providerSet.add(provider);
    final Service[] services = { Service.Connectivity, Service.Dhcp, Service.NetworkACL, Service.StaticNat, Service.SourceNat, Service.Lb };
    for (Service svc : services) {
        if (svc == Service.Lb) {
            if (offeringName.equals(vpcRouterOfferingName)) {
                Set<Provider> lbProviderSet = new HashSet<Provider>();
                lbProviderSet.add(Provider.InternalLbVm);
                serviceProviderMap.put(svc, lbProviderSet);
            }
            continue;
        }
        serviceProviderMap.put(svc, providerSet);
    }
    ConfigurationManager configMgr = (ConfigurationManager) _configService;
    NetworkOfferingVO voffer = configMgr.createNetworkOffering(offeringName, offeringDisplayText, TrafficType.Guest, null, false, Availability.Optional, null, serviceProviderMap, true, Network.GuestType.Isolated, false, null, false, null, false, true, null, true, null, false);
    voffer.setState(NetworkOffering.State.Enabled);
    if (offeringName.equals(vpcRouterOfferingName)) {
        voffer.setInternalLb(true);
    }
    long id = voffer.getId();
    _networkOfferingDao.update(id, voffer);
    return _networkOfferingDao.findById(id);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) VpcProvisioningService(com.cloud.network.vpc.VpcProvisioningService) ConfigurationService(com.cloud.configuration.ConfigurationService) Provider(com.cloud.network.Network.Provider) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ConfigurationManager(com.cloud.configuration.ConfigurationManager) HashSet(java.util.HashSet)

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