Search in sources :

Example 1 with Service

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

the class NetworkOrchestrator method getServiceProvidersMap.

private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId) {
    final Map<Service, Set<Provider>> map = new HashMap<>();
    final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (final NetworkServiceMapVO nsm : nsms) {
        Set<Provider> providers = map.get(Service.getService(nsm.getService()));
        if (providers == null) {
            providers = new HashSet<>();
        }
        providers.add(Provider.getProvider(nsm.getProvider()));
        map.put(Service.getService(nsm.getService()), providers);
    }
    return map;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) VpcVirtualNetworkApplianceService(com.cloud.network.VpcVirtualNetworkApplianceService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 2 with Service

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

the class ConfigurationManagerImpl method createNetworkOffering.

@Override
@DB
public NetworkOfferingVO createNetworkOffering(final String name, final String displayText, final TrafficType trafficType, String tags, final boolean specifyVlan, final Availability availability, final Integer networkRate, final Map<Service, Set<Provider>> serviceProviderMap, final boolean isDefault, final GuestType type, final boolean systemOnly, final Long serviceOfferingId, final Long secondaryServiceOfferingId, final boolean conserveMode, final Map<Service, Map<Capability, String>> serviceCapabilityMap, final boolean specifyIpRanges, final boolean isPersistent, final Map<NetworkOffering.Detail, String> details, final boolean egressDefaultPolicy, final Integer maxconn, final boolean enableKeepAlive) {
    final String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
    final int multicastRate = multicastRateStr == null ? 10 : Integer.parseInt(multicastRateStr);
    tags = StringUtils.cleanupTags(tags);
    // specifyVlan should always be true for Shared network offerings
    if (!specifyVlan && type == GuestType.Shared) {
        throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type);
    }
    // Nat service
    if (specifyIpRanges) {
        if (type == GuestType.Isolated) {
            if (serviceProviderMap.containsKey(Service.SourceNat)) {
                throw new InvalidParameterValueException("SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service");
            }
        }
    } else {
        if (type == GuestType.Shared) {
            throw new InvalidParameterValueException("SpecifyIpRanges should always be true for Shared network offerings");
        }
    }
    // isPersistent should always be false for Shared network Offerings
    if (isPersistent && type == GuestType.Shared) {
        throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type);
    }
    // validate availability value
    if (availability == NetworkOffering.Availability.Required) {
        final boolean canOffBeRequired = type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat);
        if (!canOffBeRequired) {
            throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
        }
        // only one network offering in the system can be Required
        final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
        if (!offerings.isEmpty()) {
            throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
        }
    }
    boolean dedicatedLb = false;
    boolean elasticLb = false;
    boolean sharedSourceNat = false;
    boolean redundantRouter = false;
    boolean elasticIp = false;
    boolean associatePublicIp = false;
    boolean inline = false;
    boolean publicLb = false;
    boolean strechedL2Subnet = false;
    if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) {
        final Map<Capability, String> lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb);
        if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
            final String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
            if (isolationCapability != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.SupportedLBIsolation, isolationCapability);
                dedicatedLb = isolationCapability.contains("dedicated");
            } else {
                dedicatedLb = true;
            }
            final String param = lbServiceCapabilityMap.get(Capability.ElasticLb);
            if (param != null) {
                elasticLb = param.contains("true");
            }
            final String inlineMode = lbServiceCapabilityMap.get(Capability.InlineMode);
            if (inlineMode != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.InlineMode, inlineMode);
                inline = inlineMode.contains("true");
            } else {
                inline = false;
            }
            final String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes);
            if (serviceProviderMap.containsKey(Service.Lb)) {
                if (publicLbStr != null) {
                    _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr);
                    publicLb = publicLbStr.contains("public");
                }
            }
        }
        final Map<Capability, String> sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat);
        if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
            final String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes);
            if (sourceNatType != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType);
                sharedSourceNat = sourceNatType.contains("perzone");
            }
            final String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter);
            if (param != null) {
                _networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param);
                redundantRouter = param.contains("true");
            }
        }
        final Map<Capability, String> staticNatServiceCapabilityMap = serviceCapabilityMap.get(Service.StaticNat);
        if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
            final String param = staticNatServiceCapabilityMap.get(Capability.ElasticIp);
            if (param != null) {
                elasticIp = param.contains("true");
                final String associatePublicIP = staticNatServiceCapabilityMap.get(Capability.AssociatePublicIP);
                if (associatePublicIP != null) {
                    associatePublicIp = associatePublicIP.contains("true");
                }
            }
        }
        final Map<Capability, String> connectivityServiceCapabilityMap = serviceCapabilityMap.get(Service.Connectivity);
        if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
            final String value = connectivityServiceCapabilityMap.get(Capability.StretchedL2Subnet);
            if ("true".equalsIgnoreCase(value)) {
                strechedL2Subnet = true;
            }
        }
    }
    if (serviceProviderMap != null && serviceProviderMap.containsKey(Service.Lb) && !publicLb) {
        // if not specified, default public lb to true
        publicLb = true;
    }
    final NetworkOfferingVO offeringFinal = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, egressDefaultPolicy, strechedL2Subnet);
    if (serviceOfferingId != null) {
        offeringFinal.setServiceOfferingId(serviceOfferingId);
    }
    if (secondaryServiceOfferingId != null) {
        offeringFinal.setSecondaryServiceOfferingId(secondaryServiceOfferingId);
    }
    // validate the details
    if (details != null) {
        validateNtwkOffDetails(details, serviceProviderMap);
    }
    return Transaction.execute(new TransactionCallback<NetworkOfferingVO>() {

        @Override
        public NetworkOfferingVO doInTransaction(final TransactionStatus status) {
            NetworkOfferingVO offering = offeringFinal;
            // 1) create network offering object
            s_logger.debug("Adding network offering " + offering);
            offering.setConcurrentConnections(maxconn);
            offering.setKeepAliveEnabled(enableKeepAlive);
            offering = _networkOfferingDao.persist(offering, details);
            // 2) populate services and providers
            if (serviceProviderMap != null) {
                for (final Network.Service service : serviceProviderMap.keySet()) {
                    final Set<Provider> providers = serviceProviderMap.get(service);
                    if (providers != null && !providers.isEmpty()) {
                        boolean vpcOff = false;
                        for (final Network.Provider provider : providers) {
                            if (provider == Provider.VPCVirtualRouter) {
                                vpcOff = true;
                            }
                            final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, provider);
                            _ntwkOffServiceMapDao.persist(offService);
                            s_logger.trace("Added service for the network offering: " + offService + " with provider " + provider.getName());
                        }
                        if (vpcOff) {
                            final List<Service> supportedSvcs = new ArrayList<>();
                            supportedSvcs.addAll(serviceProviderMap.keySet());
                            _vpcMgr.validateNtwkOffForVpc(offering, supportedSvcs);
                        }
                    } else {
                        final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, null);
                        _ntwkOffServiceMapDao.persist(offService);
                        s_logger.trace("Added service for the network offering: " + offService + " with null provider");
                    }
                }
            }
            return offering;
        }
    });
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) Set(java.util.Set) HashSet(java.util.HashSet) Capability(com.cloud.legacymodel.network.Network.Capability) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Provider(com.cloud.legacymodel.network.Network.Provider) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 3 with Service

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

the class NetworkModelImpl method listSupportedNetworkServiceProviders.

@Override
public List<? extends Provider> listSupportedNetworkServiceProviders(final String serviceName) {
    Network.Service service = null;
    if (serviceName != null) {
        service = Network.Service.getService(serviceName);
        if (service == null) {
            throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
        }
    }
    final Set<Provider> supportedProviders = new HashSet<>();
    if (service != null) {
        final List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
        if (providers != null && !providers.isEmpty()) {
            supportedProviders.addAll(providers);
        }
    } else {
        for (final List<Provider> pList : s_serviceToImplementedProvidersMap.values()) {
            supportedProviders.addAll(pList);
        }
    }
    return new ArrayList<>(supportedProviders);
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Network(com.cloud.legacymodel.network.Network) 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 4 with Service

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

the class NetworkModelImpl method getNetworkOfferingServiceProvidersMap.

@Override
public Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(final long networkOfferingId) {
    final Map<Service, Set<Provider>> serviceProviderMap = new HashMap<>();
    final List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
    for (final NetworkOfferingServiceMapVO instance : map) {
        final String service = instance.getService();
        Set<Provider> providers;
        providers = serviceProviderMap.get(Service.getService(service));
        if (providers == null) {
            providers = new HashSet<>();
        }
        providers.add(Provider.getProvider(instance.getProvider()));
        serviceProviderMap.put(Service.getService(service), providers);
    }
    return serviceProviderMap;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 5 with Service

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

the class NetworkModelImpl method getIpToServices.

@Override
public Map<PublicIpAddress, Set<Service>> getIpToServices(final List<? extends PublicIpAddress> publicIps, final boolean postApplyRules, final boolean includingFirewall) {
    final Map<PublicIpAddress, Set<Service>> ipToServices = new HashMap<>();
    if (publicIps != null && !publicIps.isEmpty()) {
        final Set<Long> networkSNAT = new HashSet<>();
        for (final PublicIpAddress ip : publicIps) {
            Set<Service> services = ipToServices.get(ip);
            if (services == null) {
                services = new HashSet<>();
            }
            if (ip.isSourceNat()) {
                if (!networkSNAT.contains(ip.getAssociatedWithNetworkId())) {
                    services.add(Service.SourceNat);
                    networkSNAT.add(ip.getAssociatedWithNetworkId());
                } else {
                    final CloudRuntimeException ex = new CloudRuntimeException("Multiple generic soure NAT IPs provided for network");
                    // see the IPAddressVO.java class.
                    final 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<>();
                }
                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<>();
                    }
                    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 (postApplyRules) {
                        // association with the provider
                        if (ip.isSourceNat()) {
                            s_logger.debug("Not releasing ip " + ip.getAddress().addr() + " as it is in use for SourceNat");
                        } else {
                            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 : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) IPAddressVO(com.cloud.network.dao.IPAddressVO) HashSet(java.util.HashSet)

Aggregations

Service (com.cloud.legacymodel.network.Network.Service)62 HashMap (java.util.HashMap)31 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)29 Provider (com.cloud.legacymodel.network.Network.Provider)29 ArrayList (java.util.ArrayList)29 HashSet (java.util.HashSet)29 ResourceLimitService (com.cloud.user.ResourceLimitService)27 Set (java.util.Set)24 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)18 Map (java.util.Map)15 Network (com.cloud.legacymodel.network.Network)14 NetworkElement (com.cloud.network.element.NetworkElement)14 NetworkService (com.cloud.network.NetworkService)13 SortedSet (java.util.SortedSet)12 Capability (com.cloud.legacymodel.network.Network.Capability)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 Test (org.junit.Test)11 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)10 ExecutorService (java.util.concurrent.ExecutorService)10 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)9