Search in sources :

Example 16 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cloudstack by apache.

the class NetworkModelImpl method getNetworkOfferingServiceProvidersMap.

@Override
public Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(long networkOfferingId) {
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Service, Set<Provider>>();
    List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
    for (NetworkOfferingServiceMapVO instance : map) {
        String service = instance.getService();
        Set<Provider> providers;
        providers = serviceProviderMap.get(Service.getService(service));
        if (providers == null) {
            providers = new HashSet<Provider>();
        }
        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) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 17 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cloudstack by apache.

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 boolean conserveMode, final Map<Service, Map<Capability, String>> serviceCapabilityMap, final boolean specifyIpRanges, final boolean isPersistent, final Map<Detail, String> details, final boolean egressDefaultPolicy, final Integer maxconn, final boolean enableKeepAlive, Boolean forVpc, final List<Long> domainIds, final List<Long> zoneIds, final boolean enableOffering) {
    String servicePackageUuid;
    String spDescription = null;
    if (details == null) {
        servicePackageUuid = null;
    } else {
        servicePackageUuid = details.get(NetworkOffering.Detail.servicepackageuuid);
        spDescription = details.get(NetworkOffering.Detail.servicepackagedescription);
    }
    final String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
    final int multicastRate = multicastRateStr == null ? 10 : Integer.parseInt(multicastRateStr);
    tags = com.cloud.utils.StringUtils.cleanupTags(tags);
    // specifyVlan should always be true for Shared network offerings
    if (!specifyVlan && type == GuestType.Shared) {
        Set<Provider> connectivityProviders = serviceProviderMap != null ? serviceProviderMap.get(Service.Connectivity) : null;
        if (CollectionUtils.isEmpty(connectivityProviders) || !_networkModel.providerSupportsCapability(connectivityProviders, Service.Connectivity, Capability.NoVlan)) {
            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 internalLb = false;
    boolean strechedL2Subnet = false;
    boolean publicAccess = 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);
                    internalLb = publicLbStr.contains("internal");
                    publicLb = publicLbStr.contains("public");
                }
            }
        }
        // both be set to true for the same network offering
        if (publicLb && internalLb) {
            throw new InvalidParameterValueException("Public lb and internal lb can't be enabled at the same time on the offering");
        }
        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()) {
            if (connectivityServiceCapabilityMap.containsKey(Capability.StretchedL2Subnet)) {
                final String value = connectivityServiceCapabilityMap.get(Capability.StretchedL2Subnet);
                if ("true".equalsIgnoreCase(value)) {
                    strechedL2Subnet = true;
                }
            }
            if (connectivityServiceCapabilityMap.containsKey(Capability.PublicAccess)) {
                final String value = connectivityServiceCapabilityMap.get(Capability.PublicAccess);
                if ("true".equalsIgnoreCase(value)) {
                    publicAccess = true;
                }
            }
        }
    }
    if (serviceProviderMap != null && serviceProviderMap.containsKey(Service.Lb) && !internalLb && !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, internalLb, forVpc, egressDefaultPolicy, strechedL2Subnet, publicAccess);
    if (serviceOfferingId != null) {
        offeringFinal.setServiceOfferingId(serviceOfferingId);
    }
    if (enableOffering) {
        offeringFinal.setState(NetworkOffering.State.Enabled);
    }
    // Set Service package id
    offeringFinal.setServicePackage(servicePackageUuid);
    // validate the details
    if (details != null) {
        validateNtwkOffDetails(details, serviceProviderMap);
    }
    boolean vpcOff = false;
    boolean nsOff = false;
    if (serviceProviderMap != null && spDescription != null) {
        for (final Network.Service service : serviceProviderMap.keySet()) {
            final Set<Provider> providers = serviceProviderMap.get(service);
            if (providers != null && !providers.isEmpty()) {
                for (final Network.Provider provider : providers) {
                    if (provider == Provider.VPCVirtualRouter) {
                        vpcOff = true;
                    }
                    if (provider == Provider.Netscaler) {
                        nsOff = true;
                    }
                }
            }
        }
        if (vpcOff && nsOff) {
            if (!(spDescription.equalsIgnoreCase("A NetScalerVPX is dedicated per network.") || spDescription.contains("dedicated NetScaler"))) {
                throw new InvalidParameterValueException("Only NetScaler Service Package with Dedicated Device Mode is Supported in VPC Type Guest Network");
            }
        }
    }
    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<Service>();
                            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");
                    }
                }
                if (offering != null) {
                    // Filter child domains when both parent and child domains are present
                    List<Long> filteredDomainIds = filterChildSubDomains(domainIds);
                    List<NetworkOfferingDetailsVO> detailsVO = new ArrayList<>();
                    for (Long domainId : filteredDomainIds) {
                        detailsVO.add(new NetworkOfferingDetailsVO(offering.getId(), Detail.domainid, String.valueOf(domainId), false));
                    }
                    if (CollectionUtils.isNotEmpty(zoneIds)) {
                        for (Long zoneId : zoneIds) {
                            detailsVO.add(new NetworkOfferingDetailsVO(offering.getId(), Detail.zoneid, String.valueOf(zoneId), false));
                        }
                    }
                    if (!detailsVO.isEmpty()) {
                        networkOfferingDetailsDao.saveDetails(detailsVO);
                    }
                }
            }
            return offering;
        }
    });
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) HashSet(java.util.HashSet) Set(java.util.Set) Capability(com.cloud.network.Network.Capability) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) QueryService(org.apache.cloudstack.query.QueryService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(org.apache.cloudstack.affinity.AffinityGroupService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) Service(com.cloud.network.Network.Service) Provider(com.cloud.network.Network.Provider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Provider(com.cloud.network.Network.Provider) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) NetworkOfferingDetailsVO(com.cloud.offerings.NetworkOfferingDetailsVO) DB(com.cloud.utils.db.DB)

Example 18 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cloudstack by apache.

the class ConfigurationServerImpl method createDefaultNetworkOfferings.

@DB
protected void createDefaultNetworkOfferings() {
    NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemPublicNetwork, TrafficType.Public, true);
    publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
    NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemManagementNetwork, TrafficType.Management, false);
    managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
    NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemControlNetwork, TrafficType.Control, false);
    controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
    NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemStorageNetwork, TrafficType.Storage, true);
    storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
    NetworkOfferingVO privateGatewayNetworkOffering = new NetworkOfferingVO(NetworkOffering.SystemPrivateGatewayNetworkOffering, GuestType.Isolated);
    privateGatewayNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(privateGatewayNetworkOffering);
    // populate providers
    final Map<Network.Service, Network.Provider> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    defaultSharedNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
    defaultSharedNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
    defaultSharedNetworkOfferingProviders.put(Service.UserData, Provider.VirtualRouter);
    final Map<Network.Service, Network.Provider> defaultIsolatedNetworkOfferingProviders = defaultSharedNetworkOfferingProviders;
    final Map<Network.Service, Network.Provider> defaultSharedSGNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    defaultSharedSGNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
    defaultSharedSGNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
    defaultSharedSGNetworkOfferingProviders.put(Service.UserData, Provider.VirtualRouter);
    defaultSharedSGNetworkOfferingProviders.put(Service.SecurityGroup, Provider.SecurityGroupProvider);
    final Map<Network.Service, Network.Provider> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dhcp, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dns, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.UserData, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Firewall, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Gateway, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Lb, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.SourceNat, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.StaticNat, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.PortForwarding, Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Vpn, Provider.VirtualRouter);
    final Map<Network.Service, Network.Provider> netscalerServiceProviders = new HashMap<Network.Service, Network.Provider>();
    netscalerServiceProviders.put(Service.Dhcp, Provider.VirtualRouter);
    netscalerServiceProviders.put(Service.Dns, Provider.VirtualRouter);
    netscalerServiceProviders.put(Service.UserData, Provider.VirtualRouter);
    netscalerServiceProviders.put(Service.SecurityGroup, Provider.SecurityGroupProvider);
    netscalerServiceProviders.put(Service.StaticNat, Provider.Netscaler);
    netscalerServiceProviders.put(Service.Lb, Provider.Netscaler);
    // The only one diff between 1 and 2 network offerings is that the first one has SG enabled. In Basic zone only
    // first network offering has to be enabled, in Advance zone - the second one
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // Offering #1
            NetworkOfferingVO defaultSharedSGNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false, false);
            defaultSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled);
            defaultSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedSGNetworkOffering);
            for (Service service : defaultSharedSGNetworkOfferingProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultSharedSGNetworkOffering.getId(), service, defaultSharedSGNetworkOfferingProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #2
            NetworkOfferingVO defaultSharedNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false, false);
            defaultSharedNetworkOffering.setState(NetworkOffering.State.Enabled);
            defaultSharedNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedNetworkOffering);
            for (Service service : defaultSharedNetworkOfferingProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultSharedNetworkOffering.getId(), service, defaultSharedNetworkOfferingProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #3
            NetworkOfferingVO defaultIsolatedSourceNatEnabledNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Required, null, Network.GuestType.Isolated, true, false, false, false, true, false);
            defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
            defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering);
            for (Service service : defaultIsolatedSourceNatEnabledNetworkOfferingProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultIsolatedSourceNatEnabledNetworkOffering.getId(), service, defaultIsolatedSourceNatEnabledNetworkOfferingProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #4
            NetworkOfferingVO defaultIsolatedEnabledNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, true, true, false, false, false, false);
            defaultIsolatedEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
            defaultIsolatedEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedEnabledNetworkOffering);
            for (Service service : defaultIsolatedNetworkOfferingProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultIsolatedEnabledNetworkOffering.getId(), service, defaultIsolatedNetworkOfferingProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #5
            NetworkOfferingVO defaultNetscalerNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, false, true, null, null, true, Availability.Optional, null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false, false, false, false, false);
            defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled);
            defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering);
            for (Service service : netscalerServiceProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultNetscalerNetworkOffering.getId(), service, netscalerServiceProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #6
            NetworkOfferingVO defaultNetworkOfferingForVpcNetworks = new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated Vpc networks with Source Nat service enabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, true, true);
            defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled);
            defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks);
            Map<Network.Service, Network.Provider> defaultVpcNetworkOfferingProviders = new HashMap<Network.Service, Network.Provider>();
            defaultVpcNetworkOfferingProviders.put(Service.Dhcp, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.Dns, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.UserData, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.NetworkACL, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.Gateway, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.Lb, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.SourceNat, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.StaticNat, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.PortForwarding, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProviders.put(Service.Vpn, Provider.VPCVirtualRouter);
            for (Map.Entry<Service, Provider> entry : defaultVpcNetworkOfferingProviders.entrySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworks.getId(), entry.getKey(), entry.getValue());
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // Offering #7
            NetworkOfferingVO defaultNetworkOfferingForVpcNetworksNoLB = new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, "Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false, true);
            defaultNetworkOfferingForVpcNetworksNoLB.setState(NetworkOffering.State.Enabled);
            defaultNetworkOfferingForVpcNetworksNoLB = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworksNoLB);
            Map<Network.Service, Network.Provider> defaultVpcNetworkOfferingProvidersNoLB = new HashMap<Network.Service, Network.Provider>();
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.Dhcp, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.Dns, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.UserData, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.NetworkACL, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.Gateway, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.SourceNat, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.StaticNat, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.PortForwarding, Provider.VPCVirtualRouter);
            defaultVpcNetworkOfferingProvidersNoLB.put(Service.Vpn, Provider.VPCVirtualRouter);
            for (Map.Entry<Service, Provider> entry : defaultVpcNetworkOfferingProvidersNoLB.entrySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(defaultNetworkOfferingForVpcNetworksNoLB.getId(), entry.getKey(), entry.getValue());
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            // offering #8 - network offering with internal lb service
            NetworkOfferingVO internalLbOff = new NetworkOfferingVO(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, "Offering for Isolated Vpc networks with Internal LB support", TrafficType.Guest, false, false, null, null, true, Availability.Optional, null, Network.GuestType.Isolated, false, false, false, true, false, true);
            internalLbOff.setState(NetworkOffering.State.Enabled);
            internalLbOff = _networkOfferingDao.persistDefaultNetworkOffering(internalLbOff);
            Map<Network.Service, Network.Provider> internalLbOffProviders = new HashMap<Network.Service, Network.Provider>();
            internalLbOffProviders.put(Service.Dhcp, Provider.VPCVirtualRouter);
            internalLbOffProviders.put(Service.Dns, Provider.VPCVirtualRouter);
            internalLbOffProviders.put(Service.UserData, Provider.VPCVirtualRouter);
            internalLbOffProviders.put(Service.NetworkACL, Provider.VPCVirtualRouter);
            internalLbOffProviders.put(Service.Gateway, Provider.VPCVirtualRouter);
            internalLbOffProviders.put(Service.Lb, Provider.InternalLbVm);
            internalLbOffProviders.put(Service.SourceNat, Provider.VPCVirtualRouter);
            for (Service service : internalLbOffProviders.keySet()) {
                NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(internalLbOff.getId(), service, internalLbOffProviders.get(service));
                _ntwkOfferingServiceMapDao.persist(offService);
                s_logger.trace("Added service for the network offering: " + offService);
            }
            _networkOfferingDao.persistDefaultL2NetworkOfferings();
        }
    });
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) Provider(com.cloud.network.Network.Provider) Network(com.cloud.network.Network) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Map(java.util.Map) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Example 19 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cloudstack by apache.

the class ConfigurationServerImpl method getServicesAndProvidersForNetwork.

public Map<String, String> getServicesAndProvidersForNetwork(long networkOfferingId) {
    Map<String, String> svcProviders = new HashMap<String, String>();
    List<NetworkOfferingServiceMapVO> servicesMap = _ntwkOfferingServiceMapDao.listByNetworkOfferingId(networkOfferingId);
    for (NetworkOfferingServiceMapVO serviceMap : servicesMap) {
        if (svcProviders.containsKey(serviceMap.getService())) {
            continue;
        }
        svcProviders.put(serviceMap.getService(), serviceMap.getProvider());
    }
    return svcProviders;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) HashMap(java.util.HashMap)

Example 20 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method createPublicLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description, int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd, Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
    Account lbOwner = _accountMgr.getAccount(lbOwnerId);
    if (srcPortStart != srcPortEnd) {
        throw new InvalidParameterValueException("Port ranges are not supported by the load balancer");
    }
    IPAddressVO ipVO = null;
    if (ipAddrId != null) {
        ipVO = _ipAddressDao.findById(ipAddrId);
    }
    Network network = _networkModel.getNetwork(networkId);
    // FIXME: breaking the dependency on ELB manager. This breaks
    // functionality of ELB using virtual router
    // Bug CS-15411 opened to document this
    // LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb,
    // lbOwner, lb.getNetworkId());
    LoadBalancer result = null;
    IpAddress systemIp = null;
    NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (srcPortStart == DNS_PORT && ipVO.isSourceNat()) {
        List<NetworkOfferingServiceMapVO> offeringServices = _networkOfferingServiceDao.listByNetworkOfferingId(network.getNetworkOfferingId());
        for (NetworkOfferingServiceMapVO serviceMapVo : offeringServices) {
            if (serviceMapVo.getService().equals(Service.Dns.getName())) {
                throw new InvalidParameterValueException("Error adding load balancer rule, cannot add port 53 with network service offering having DNS service and Source NAT.");
            }
        }
    }
    if (off.isElasticLb() && ipVO == null && network.getVpcId() == null) {
        systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false);
        if (systemIp != null) {
            ipVO = _ipAddressDao.findById(systemIp.getId());
        }
    }
    // Validate ip address
    if (ipVO == null) {
        throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP");
    } else if (ipVO.isOneToOneNat()) {
        throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
    }
    boolean performedIpAssoc = false;
    try {
        if (ipVO.getAssociatedWithNetworkId() == null) {
            boolean assignToVpcNtwk = network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
            if (assignToVpcNtwk) {
                // set networkId just for verification purposes
                _networkModel.checkIpForService(ipVO, Service.Lb, networkId);
                s_logger.debug("The ip is not associated with the VPC network id=" + networkId + " so assigning");
                ipVO = _ipAddrMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
                performedIpAssoc = true;
            }
        } else {
            _networkModel.checkIpForService(ipVO, Service.Lb, null);
        }
        if (ipVO.getAssociatedWithNetworkId() == null) {
            throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
        }
        result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, CallContext.current(), lbProtocol, forDisplay);
    } catch (Exception ex) {
        s_logger.warn("Failed to create load balancer due to ", ex);
        if (ex instanceof NetworkRuleConflictException) {
            throw (NetworkRuleConflictException) ex;
        }
        if (ex instanceof InvalidParameterValueException) {
            throw (InvalidParameterValueException) ex;
        }
    } finally {
        if (result == null && systemIp != null) {
            s_logger.debug("Releasing system IP address " + systemIp + " as corresponding lb rule failed to create");
            _ipAddrMgr.handleSystemIpRelease(systemIp);
        }
        // release ip address if ipassoc was perfored
        if (performedIpAssoc) {
            ipVO = _ipAddressDao.findById(ipVO.getId());
            _vpcMgr.unassignIPFromVpcNetwork(ipVO.getId(), networkId);
        }
    }
    if (result == null) {
        throw new CloudRuntimeException("Failed to create load balancer rule: " + name);
    }
    return result;
}
Also used : Account(com.cloud.user.Account) NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) NetworkOffering(com.cloud.offering.NetworkOffering) LoadBalancer(com.cloud.network.rules.LoadBalancer) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) IPAddressVO(com.cloud.network.dao.IPAddressVO) IpAddress(com.cloud.network.IpAddress) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

NetworkOfferingServiceMapVO (com.cloud.offerings.NetworkOfferingServiceMapVO)21 Service (com.cloud.network.Network.Service)11 HashMap (java.util.HashMap)9 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)8 Network (com.cloud.network.Network)6 Provider (com.cloud.network.Network.Provider)6 NetworkService (com.cloud.network.NetworkService)6 DB (com.cloud.utils.db.DB)6 ResourceLimitService (com.cloud.user.ResourceLimitService)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Set (java.util.Set)5 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 PhysicalNetwork (com.cloud.network.PhysicalNetwork)4 TransactionStatus (com.cloud.utils.db.TransactionStatus)4 Capability (com.cloud.network.Network.Capability)3 NetworkOffering (com.cloud.offering.NetworkOffering)3 ManagementService (com.cloud.server.ManagementService)3