Search in sources :

Example 11 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 Network.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<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) {
        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, egressDefaultPolicy, strechedL2Subnet, publicAccess);
    if (serviceOfferingId != null) {
        offeringFinal.setServiceOfferingId(serviceOfferingId);
    }
    // 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<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");
                    }
                }
            }
            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) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(org.apache.cloudstack.affinity.AffinityGroupService) Provider(com.cloud.network.Network.Provider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 12 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method validateNtwkOffForNtwkInVpc.

@DB
@Override
public void validateNtwkOffForNtwkInVpc(final Long networkId, final long newNtwkOffId, final String newCidr, final String newNetworkDomain, final Vpc vpc, final String gateway, final Account networkOwner, final Long aclId) {
    final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId);
    if (guestNtwkOff == null) {
        throw new InvalidParameterValueException("Can't find network offering by id specified");
    }
    if (networkId == null) {
        // 1) Validate attributes that has to be passed in when create new
        // guest network
        validateNewVpcGuestNetwork(newCidr, gateway, networkOwner, vpc, newNetworkDomain);
    }
    // 2) validate network offering attributes
    final List<Service> svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId());
    validateNtwkOffForVpc(guestNtwkOff, svcs);
    // 3) Check services/providers against VPC providers
    final List<NetworkOfferingServiceMapVO> networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId());
    for (final NetworkOfferingServiceMapVO nSvcVO : networkProviders) {
        final String pr = nSvcVO.getProvider();
        final String service = nSvcVO.getService();
        if (_vpcOffServiceDao.findByServiceProviderAndOfferingId(service, pr, vpc.getVpcOfferingId()) == null) {
            throw new InvalidParameterValueException("Service/provider combination " + service + "/" + pr + " is not supported by VPC " + vpc);
        }
    }
    // Internal LB can be supported on multiple VPC tiers
    if (_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.Lb) && guestNtwkOff.getPublicLb()) {
        final List<? extends Network> networks = getVpcNetworks(vpc.getId());
        for (final Network network : networks) {
            if (networkId != null && network.getId() == networkId.longValue()) {
                // skip my own network
                continue;
            } else {
                final NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
                // public lb support
                if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.getPublicLb() && guestNtwkOff.getId() != otherOff.getId()) {
                    throw new InvalidParameterValueException("Public LB service is already supported " + "by network " + network + " in VPC " + vpc);
                }
            }
        }
    }
    // network offering
    if (aclId != null && !_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
        throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
    }
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) DB(com.cloud.utils.db.DB)

Example 13 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cosmic by MissionCriticalCloud.

the class NetworkOfferingServiceMapDaoImpl method areServicesSupportedByNetworkOffering.

@Override
public boolean areServicesSupportedByNetworkOffering(final long networkOfferingId, final Service... services) {
    final SearchCriteria<NetworkOfferingServiceMapVO> sc = MultipleServicesSearch.create();
    sc.setParameters("networkOfferingId", networkOfferingId);
    if (services != null) {
        final String[] servicesStr = new String[services.length];
        int i = 0;
        for (final Service service : services) {
            servicesStr[i] = service.getName();
            i++;
        }
        sc.setParameters("service", (Object[]) servicesStr);
    }
    final List<NetworkOfferingServiceMapVO> offeringServices = listBy(sc);
    if (services != null) {
        if (offeringServices.size() == services.length) {
            return true;
        }
    } else if (!offeringServices.isEmpty()) {
        return true;
    }
    return false;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) Service(com.cloud.network.Network.Service)

Example 14 with NetworkOfferingServiceMapVO

use of com.cloud.offerings.NetworkOfferingServiceMapVO in project cosmic by MissionCriticalCloud.

the class CreateNetworkOfferingTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    final ConfigurationVO configVO = new ConfigurationVO("200", "200", "200", "200", "200", "200");
    Mockito.when(configDao.findByName(Matchers.anyString())).thenReturn(configVO);
    Mockito.when(offDao.persist(Matchers.any(NetworkOfferingVO.class))).thenReturn(new NetworkOfferingVO());
    Mockito.when(offDao.persist(Matchers.any(NetworkOfferingVO.class), Matchers.anyMap())).thenReturn(new NetworkOfferingVO());
    Mockito.when(mapDao.persist(Matchers.any(NetworkOfferingServiceMapVO.class))).thenReturn(new NetworkOfferingServiceMapVO());
    Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    CallContext.register(accountMgr.getSystemUser(), accountMgr.getSystemAccount());
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) ConfigurationVO(com.cloud.framework.config.impl.ConfigurationVO) UserVO(com.cloud.user.UserVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 15 with NetworkOfferingServiceMapVO

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

the class VpcManagerImpl method validateNtwkOffForNtwkInVpc.

@DB
@Override
public void validateNtwkOffForNtwkInVpc(final Long networkId, final long newNtwkOffId, final String newCidr, final String newNetworkDomain, final Vpc vpc, final String gateway, final Account networkOwner, final Long aclId) {
    final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId);
    if (guestNtwkOff == null) {
        throw new InvalidParameterValueException("Can't find network offering by id specified");
    }
    if (networkId == null) {
        // 1) Validate attributes that has to be passed in when create new
        // guest network
        validateNewVpcGuestNetwork(newCidr, gateway, networkOwner, vpc, newNetworkDomain);
    }
    // 2) validate network offering attributes
    final List<Service> svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId());
    validateNtwkOffForVpc(guestNtwkOff, svcs);
    // 3) Check services/providers against VPC providers
    final List<NetworkOfferingServiceMapVO> networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId());
    for (final NetworkOfferingServiceMapVO nSvcVO : networkProviders) {
        final String pr = nSvcVO.getProvider();
        final String service = nSvcVO.getService();
        if (_vpcOffServiceDao.findByServiceProviderAndOfferingId(service, pr, vpc.getVpcOfferingId()) == null) {
            throw new InvalidParameterValueException("Service/provider combination " + service + "/" + pr + " is not supported by VPC " + vpc);
        }
    }
    // Internal LB can be supported on multiple VPC tiers
    if (_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.Lb) && guestNtwkOff.isPublicLb()) {
        final List<? extends Network> networks = getVpcNetworks(vpc.getId());
        for (final Network network : networks) {
            if (networkId != null && network.getId() == networkId.longValue()) {
                // skip my own network
                continue;
            } else {
                final NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
                // public lb support
                if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.isPublicLb() && guestNtwkOff.getId() != otherOff.getId()) {
                    throw new InvalidParameterValueException("Public LB service is already supported " + "by network " + network + " in VPC " + vpc);
                }
            }
        }
    }
    // network offering
    if (aclId != null && !_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
        throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
    }
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) QueryService(org.apache.cloudstack.query.QueryService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NetworkService(com.cloud.network.NetworkService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) DB(com.cloud.utils.db.DB)

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