Search in sources :

Example 1 with Availability

use of com.cloud.offering.NetworkOffering.Availability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method createNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering")
public NetworkOffering createNetworkOffering(final CreateNetworkOfferingCmd cmd) {
    final String name = cmd.getNetworkOfferingName();
    final String displayText = cmd.getDisplayText();
    final String tags = cmd.getTags();
    final String trafficTypeString = cmd.getTraffictype();
    final boolean specifyVlan = cmd.getSpecifyVlan();
    final boolean conserveMode = cmd.getConserveMode();
    final String availabilityStr = cmd.getAvailability();
    Integer networkRate = cmd.getNetworkRate();
    TrafficType trafficType = null;
    Availability availability = null;
    Network.GuestType guestType = null;
    final boolean specifyIpRanges = cmd.getSpecifyIpRanges();
    final boolean isPersistent = cmd.getIsPersistent();
    final Map<String, String> detailsStr = cmd.getDetails();
    final Boolean egressDefaultPolicy = cmd.getEgressDefaultPolicy();
    Integer maxconn = null;
    boolean enableKeepAlive = false;
    // Verify traffic type
    for (final TrafficType tType : TrafficType.values()) {
        if (tType.name().equalsIgnoreCase(trafficTypeString)) {
            trafficType = tType;
            break;
        }
    }
    if (trafficType == null) {
        throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
    }
    // Only GUEST traffic type is supported in Acton
    if (trafficType != TrafficType.Guest) {
        throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release");
    }
    // Verify offering type
    for (final Network.GuestType offType : Network.GuestType.values()) {
        if (offType.name().equalsIgnoreCase(cmd.getGuestIpType())) {
            guestType = offType;
            break;
        }
    }
    if (guestType == null) {
        throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values");
    }
    // Verify availability
    for (final Availability avlb : Availability.values()) {
        if (avlb.name().equalsIgnoreCase(availabilityStr)) {
            availability = avlb;
        }
    }
    if (availability == null) {
        throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
    }
    if (networkRate != null && networkRate < 0) {
        networkRate = 0;
    }
    final Long serviceOfferingId = cmd.getServiceOfferingId();
    final Long secondaryServiceOfferingId = cmd.getSecondaryServiceOfferingId();
    if (serviceOfferingId != null) {
        checkServiceOffering(serviceOfferingId);
    }
    if (secondaryServiceOfferingId != null) {
        checkServiceOffering(secondaryServiceOfferingId);
    }
    // configure service provider map
    final Map<Network.Service, Set<Network.Provider>> serviceProviderMap = new HashMap<>();
    final Set<Network.Provider> defaultProviders = new HashSet<>();
    // populate the services first
    for (final String serviceName : cmd.getSupportedServices()) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || service == Service.Gateway) {
            throw new InvalidParameterValueException("Invalid service " + serviceName);
        }
        serviceProviderMap.put(service, defaultProviders);
    }
    // add gateway provider (if sourceNat provider is enabled)
    final Set<Provider> sourceNatServiceProviders = serviceProviderMap.get(Service.SourceNat);
    if (sourceNatServiceProviders != null && !sourceNatServiceProviders.isEmpty()) {
        serviceProviderMap.put(Service.Gateway, sourceNatServiceProviders);
    }
    // populate providers
    final Map<Provider, Set<Service>> providerCombinationToVerify = new HashMap<>();
    final Map<String, List<String>> svcPrv = cmd.getServiceProviders();
    Provider firewallProvider = null;
    Provider dhcpProvider = null;
    Boolean IsVrUserdataProvider = false;
    if (svcPrv != null) {
        for (final String serviceStr : svcPrv.keySet()) {
            final Network.Service service = Network.Service.getService(serviceStr);
            if (serviceProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<>();
                // the service is LB
                if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) {
                    throw new InvalidParameterValueException("In the current release only one provider can be " + "specified for the service if the service is not LB");
                }
                for (final String prvNameStr : svcPrv.get(serviceStr)) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    if ((service == Service.PortForwarding || service == Service.StaticNat) && provider == Provider.VirtualRouter) {
                        firewallProvider = Provider.VirtualRouter;
                    }
                    if (service == Service.Dhcp) {
                        dhcpProvider = provider;
                    }
                    if (service == Service.UserData && provider == Provider.VirtualRouter) {
                        IsVrUserdataProvider = true;
                    }
                    providers.add(provider);
                    final Set<Service> serviceSet;
                    if (providerCombinationToVerify.get(provider) == null) {
                        serviceSet = new HashSet<>();
                    } else {
                        serviceSet = providerCombinationToVerify.get(provider);
                    }
                    serviceSet.add(service);
                    providerCombinationToVerify.put(provider, serviceSet);
                }
                serviceProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    // dhcp provider and userdata provider should be same because vm will be contacting dhcp server for user data.
    if (dhcpProvider == null && IsVrUserdataProvider) {
        s_logger.debug("User data provider VR can't be selected without VR as dhcp provider. In this case VM fails to contact the DHCP server for userdata");
        throw new InvalidParameterValueException("Without VR as dhcp provider, User data can't selected for VR. Please select VR as DHCP provider ");
    }
    // validate providers combination here
    _networkModel.canProviderSupportServices(providerCombinationToVerify);
    // validate the LB service capabilities specified in the network
    // offering
    final Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
    if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
    }
    validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
    if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        maxconn = cmd.getMaxconnections();
        if (maxconn == null) {
            maxconn = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyMaxConn.key()));
        }
    }
    if (cmd.getKeepAliveEnabled() != null && cmd.getKeepAliveEnabled()) {
        enableKeepAlive = true;
    }
    // validate the Source NAT service capabilities specified in the network
    // offering
    final Map<Capability, String> sourceNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.SourceNat);
    if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering.");
    }
    validateSourceNatServiceCapablities(sourceNatServiceCapabilityMap);
    // validate the Static Nat service capabilities specified in the network
    // offering
    final Map<Capability, String> staticNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.StaticNat);
    if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering.");
    }
    validateStaticNatServiceCapablities(staticNatServiceCapabilityMap);
    // validate the 'Connectivity' service capabilities specified in the network offering, if 'Connectivity' service
    // is in the supported services of network offering
    final Map<Capability, String> connectivityServiceCapabilityMap = cmd.getServiceCapabilities(Service.Connectivity);
    if (!serviceProviderMap.containsKey(Service.Connectivity) && connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for 'Connectivity' service can be specified " + "only when Connectivity service is enabled for network offering.");
    }
    validateConnectivityServiceCapablities(serviceProviderMap.get(Service.Connectivity), connectivityServiceCapabilityMap);
    final Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<>();
    serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap);
    serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.Connectivity, connectivityServiceCapabilityMap);
    // combination
    if (firewallProvider != null) {
        s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName());
        final Set<Provider> firewallProviderSet = new HashSet<>();
        firewallProviderSet.add(firewallProvider);
        serviceProviderMap.put(Service.Firewall, firewallProviderSet);
        if (!firewallProvider.getName().equals(Provider.VirtualRouter.getName()) && !egressDefaultPolicy) {
            throw new InvalidParameterValueException("Firewall egress with default policy " + egressDefaultPolicy + " is not supported by the provider " + firewallProvider.getName());
        }
    }
    final Map<NetworkOffering.Detail, String> details = new HashMap<>();
    if (detailsStr != null) {
        for (final String detailStr : detailsStr.keySet()) {
            NetworkOffering.Detail offDetail = null;
            for (final NetworkOffering.Detail supportedDetail : NetworkOffering.Detail.values()) {
                if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
                    offDetail = supportedDetail;
                    break;
                }
            }
            if (offDetail == null) {
                throw new InvalidParameterValueException("Unsupported detail " + detailStr);
            }
            details.put(offDetail, detailsStr.get(detailStr));
        }
    }
    final NetworkOffering offering = createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId, secondaryServiceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details, egressDefaultPolicy, maxconn, enableKeepAlive);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) List(java.util.List) TrafficType(com.cloud.network.Networks.TrafficType) HashSet(java.util.HashSet) Availability(com.cloud.offering.NetworkOffering.Availability) Capability(com.cloud.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Detail(com.cloud.offering.NetworkOffering.Detail) Provider(com.cloud.network.Network.Provider) Provider(com.cloud.network.Network.Provider) GuestType(com.cloud.network.Network.GuestType) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail) ActionEvent(com.cloud.event.ActionEvent)

Example 2 with Availability

use of com.cloud.offering.NetworkOffering.Availability in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method updateNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_EDIT, eventDescription = "updating network offering")
public NetworkOffering updateNetworkOffering(final UpdateNetworkOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getNetworkOfferingName();
    final String availabilityStr = cmd.getAvailability();
    final Integer sortKey = cmd.getSortKey();
    final Integer maxconn = cmd.getMaxconnections();
    Availability availability = null;
    final String state = cmd.getState();
    CallContext.current().setEventDetails(" Id: " + id);
    // Verify input parameters
    final NetworkOfferingVO offeringToUpdate = _networkOfferingDao.findById(id);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("unable to find network offering " + id);
    }
    // Don't allow to update system network offering
    if (offeringToUpdate.isSystemOnly()) {
        throw new InvalidParameterValueException("Can't update system network offerings");
    }
    final NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
    if (name != null) {
        offering.setName(name);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        offering.setSortKey(sortKey);
    }
    if (state != null) {
        boolean validState = false;
        for (final NetworkOffering.State st : NetworkOffering.State.values()) {
            if (st.name().equalsIgnoreCase(state)) {
                validState = true;
                offering.setState(st);
            }
        }
        if (!validState) {
            throw new InvalidParameterValueException("Incorrect state value: " + state);
        }
    }
    // Verify availability
    if (availabilityStr != null) {
        for (final Availability avlb : Availability.values()) {
            if (avlb.name().equalsIgnoreCase(availabilityStr)) {
                availability = avlb;
            }
        }
        if (availability == null) {
            throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
        } else {
            if (availability == NetworkOffering.Availability.Required) {
                final boolean canOffBeRequired = offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), 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() && offerings.get(0).getId() != offeringToUpdate.getId()) {
                    throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
                }
            }
            offering.setAvailability(availability);
        }
    }
    if (_ntwkOffServiceMapDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Lb)) {
        if (maxconn != null) {
            offering.setConcurrentConnections(maxconn);
        }
    }
    if (_networkOfferingDao.update(id, offering)) {
        return _networkOfferingDao.findById(id);
    } else {
        return null;
    }
}
Also used : Availability(com.cloud.offering.NetworkOffering.Availability) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 3 with Availability

use of com.cloud.offering.NetworkOffering.Availability in project cloudstack by apache.

the class ConfigurationManagerImpl method createNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_CREATE, eventDescription = "creating network offering")
public NetworkOffering createNetworkOffering(final CreateNetworkOfferingCmd cmd) {
    final String name = cmd.getNetworkOfferingName();
    final String displayText = cmd.getDisplayText();
    final String tags = cmd.getTags();
    final String trafficTypeString = cmd.getTraffictype();
    final boolean specifyVlan = cmd.getSpecifyVlan();
    final boolean conserveMode = cmd.getConserveMode();
    final String availabilityStr = cmd.getAvailability();
    Integer networkRate = cmd.getNetworkRate();
    TrafficType trafficType = null;
    Availability availability = null;
    Network.GuestType guestType = null;
    final boolean specifyIpRanges = cmd.getSpecifyIpRanges();
    final boolean isPersistent = cmd.getIsPersistent();
    final Map<String, String> detailsStr = cmd.getDetails();
    final Boolean egressDefaultPolicy = cmd.getEgressDefaultPolicy();
    Boolean forVpc = cmd.getForVpc();
    Integer maxconn = null;
    boolean enableKeepAlive = false;
    String servicePackageuuid = cmd.getServicePackageId();
    final List<Long> domainIds = cmd.getDomainIds();
    final List<Long> zoneIds = cmd.getZoneIds();
    final boolean enable = cmd.getEnable();
    // check if valid domain
    if (CollectionUtils.isNotEmpty(domainIds)) {
        for (final Long domainId : domainIds) {
            if (_domainDao.findById(domainId) == null) {
                throw new InvalidParameterValueException("Please specify a valid domain id");
            }
        }
    }
    // check if valid zone
    if (CollectionUtils.isNotEmpty(zoneIds)) {
        for (Long zoneId : zoneIds) {
            if (_zoneDao.findById(zoneId) == null)
                throw new InvalidParameterValueException("Please specify a valid zone id");
        }
    }
    // Verify traffic type
    for (final TrafficType tType : TrafficType.values()) {
        if (tType.name().equalsIgnoreCase(trafficTypeString)) {
            trafficType = tType;
            break;
        }
    }
    if (trafficType == null) {
        throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
    }
    // Only GUEST traffic type is supported in Acton
    if (trafficType != TrafficType.Guest) {
        throw new InvalidParameterValueException("Only traffic type " + TrafficType.Guest + " is supported in the current release");
    }
    // Verify offering type
    for (final Network.GuestType offType : Network.GuestType.values()) {
        if (offType.name().equalsIgnoreCase(cmd.getGuestIpType())) {
            guestType = offType;
            break;
        }
    }
    if (guestType == null) {
        throw new InvalidParameterValueException("Invalid \"type\" parameter is given; can have Shared and Isolated values");
    }
    // Verify availability
    for (final Availability avlb : Availability.values()) {
        if (avlb.name().equalsIgnoreCase(availabilityStr)) {
            availability = avlb;
        }
    }
    if (availability == null) {
        throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
    }
    if (networkRate != null && networkRate < 0) {
        networkRate = 0;
    }
    final Long serviceOfferingId = cmd.getServiceOfferingId();
    if (serviceOfferingId != null) {
        final ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOfferingId);
        if (offering == null) {
            throw new InvalidParameterValueException("Cannot find specified service offering: " + serviceOfferingId);
        }
        if (!VirtualMachine.Type.DomainRouter.toString().equalsIgnoreCase(offering.getSystemVmType())) {
            throw new InvalidParameterValueException("The specified service offering " + serviceOfferingId + " cannot be used by virtual router!");
        }
    }
    // configure service provider map
    final Map<Network.Service, Set<Network.Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    final Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
    // populate the services first
    for (final String serviceName : cmd.getSupportedServices()) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || service == Service.Gateway) {
            throw new InvalidParameterValueException("Invalid service " + serviceName);
        }
        if (forVpc == null) {
            if (service == Service.SecurityGroup || service == Service.Firewall) {
                forVpc = false;
            } else if (service == Service.NetworkACL) {
                forVpc = true;
            }
        }
        if (service == Service.SecurityGroup) {
            // allow security group service for Shared networks only
            if (guestType != GuestType.Shared) {
                throw new InvalidParameterValueException("Security group service is supported for network offerings with guest ip type " + GuestType.Shared);
            }
            final Set<Network.Provider> sgProviders = new HashSet<Network.Provider>();
            sgProviders.add(Provider.SecurityGroupProvider);
            serviceProviderMap.put(Network.Service.SecurityGroup, sgProviders);
            continue;
        }
        serviceProviderMap.put(service, defaultProviders);
    }
    // add gateway provider (if sourceNat provider is enabled)
    final Set<Provider> sourceNatServiceProviders = serviceProviderMap.get(Service.SourceNat);
    if (sourceNatServiceProviders != null && !sourceNatServiceProviders.isEmpty()) {
        serviceProviderMap.put(Service.Gateway, sourceNatServiceProviders);
    }
    // populate providers
    final Map<Provider, Set<Service>> providerCombinationToVerify = new HashMap<Provider, Set<Service>>();
    final Map<String, List<String>> svcPrv = cmd.getServiceProviders();
    Provider firewallProvider = null;
    Provider dhcpProvider = null;
    Boolean IsVrUserdataProvider = false;
    if (svcPrv != null) {
        for (final String serviceStr : svcPrv.keySet()) {
            final Network.Service service = Network.Service.getService(serviceStr);
            if (serviceProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<Provider>();
                // the service is LB
                if (!serviceStr.equalsIgnoreCase(Service.Lb.getName()) && svcPrv.get(serviceStr) != null && svcPrv.get(serviceStr).size() > 1) {
                    throw new InvalidParameterValueException("In the current release only one provider can be " + "specified for the service if the service is not LB");
                }
                for (final String prvNameStr : svcPrv.get(serviceStr)) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    if (provider == Provider.JuniperSRX || provider == Provider.CiscoVnmc) {
                        firewallProvider = provider;
                    }
                    if (provider == Provider.PaloAlto) {
                        firewallProvider = Provider.PaloAlto;
                    }
                    if ((service == Service.PortForwarding || service == Service.StaticNat) && provider == Provider.VirtualRouter) {
                        firewallProvider = Provider.VirtualRouter;
                    }
                    if (forVpc == null && VPC_ONLY_PROVIDERS.contains(provider)) {
                        forVpc = true;
                    }
                    if (service == Service.Dhcp) {
                        dhcpProvider = provider;
                    }
                    if (service == Service.UserData && provider == Provider.VirtualRouter) {
                        IsVrUserdataProvider = true;
                    }
                    providers.add(provider);
                    Set<Service> serviceSet = null;
                    if (providerCombinationToVerify.get(provider) == null) {
                        serviceSet = new HashSet<Service>();
                    } else {
                        serviceSet = providerCombinationToVerify.get(provider);
                    }
                    serviceSet.add(service);
                    providerCombinationToVerify.put(provider, serviceSet);
                }
                serviceProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceStr + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    // dhcp provider and userdata provider should be same because vm will be contacting dhcp server for user data.
    if (dhcpProvider == null && IsVrUserdataProvider) {
        s_logger.debug("User data provider VR can't be selected without VR as dhcp provider. In this case VM fails to contact the DHCP server for userdata");
        throw new InvalidParameterValueException("Without VR as dhcp provider, User data can't selected for VR. Please select VR as DHCP provider ");
    }
    // validate providers combination here
    _networkModel.canProviderSupportServices(providerCombinationToVerify);
    // validate the LB service capabilities specified in the network
    // offering
    final Map<Capability, String> lbServiceCapabilityMap = cmd.getServiceCapabilities(Service.Lb);
    if (!serviceProviderMap.containsKey(Service.Lb) && lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for LB service can be specifed only when LB service is enabled for network offering.");
    }
    validateLoadBalancerServiceCapabilities(lbServiceCapabilityMap);
    if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
        maxconn = cmd.getMaxconnections();
        if (maxconn == null) {
            maxconn = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyMaxConn.key()));
        }
    }
    if (cmd.getKeepAliveEnabled() != null && cmd.getKeepAliveEnabled()) {
        enableKeepAlive = true;
    }
    // validate the Source NAT service capabilities specified in the network
    // offering
    final Map<Capability, String> sourceNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.SourceNat);
    if (!serviceProviderMap.containsKey(Service.SourceNat) && sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for source NAT service can be specifed only when source NAT service is enabled for network offering.");
    }
    validateSourceNatServiceCapablities(sourceNatServiceCapabilityMap);
    // validate the Static Nat service capabilities specified in the network
    // offering
    final Map<Capability, String> staticNatServiceCapabilityMap = cmd.getServiceCapabilities(Service.StaticNat);
    if (!serviceProviderMap.containsKey(Service.StaticNat) && sourceNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for static NAT service can be specifed only when static NAT service is enabled for network offering.");
    }
    validateStaticNatServiceCapablities(staticNatServiceCapabilityMap);
    // validate the 'Connectivity' service capabilities specified in the network offering, if 'Connectivity' service
    // is in the supported services of network offering
    final Map<Capability, String> connectivityServiceCapabilityMap = cmd.getServiceCapabilities(Service.Connectivity);
    if (!serviceProviderMap.containsKey(Service.Connectivity) && connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
        throw new InvalidParameterValueException("Capabilities for 'Connectivity' service can be specified " + "only when Connectivity service is enabled for network offering.");
    }
    validateConnectivityServiceCapablities(guestType, serviceProviderMap.get(Service.Connectivity), connectivityServiceCapabilityMap);
    final Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<Service, Map<Capability, String>>();
    serviceCapabilityMap.put(Service.Lb, lbServiceCapabilityMap);
    serviceCapabilityMap.put(Service.SourceNat, sourceNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.StaticNat, staticNatServiceCapabilityMap);
    serviceCapabilityMap.put(Service.Connectivity, connectivityServiceCapabilityMap);
    // combination
    if (firewallProvider != null) {
        s_logger.debug("Adding Firewall service with provider " + firewallProvider.getName());
        final Set<Provider> firewallProviderSet = new HashSet<Provider>();
        firewallProviderSet.add(firewallProvider);
        serviceProviderMap.put(Service.Firewall, firewallProviderSet);
        if (!(firewallProvider.getName().equals(Provider.JuniperSRX.getName()) || firewallProvider.getName().equals(Provider.PaloAlto.getName()) || firewallProvider.getName().equals(Provider.VirtualRouter.getName())) && egressDefaultPolicy == false) {
            throw new InvalidParameterValueException("Firewall egress with default policy " + egressDefaultPolicy + " is not supported by the provider " + firewallProvider.getName());
        }
    }
    final Map<NetworkOffering.Detail, String> details = new HashMap<NetworkOffering.Detail, String>();
    if (detailsStr != null) {
        for (final String detailStr : detailsStr.keySet()) {
            NetworkOffering.Detail offDetail = null;
            for (final NetworkOffering.Detail supportedDetail : NetworkOffering.Detail.values()) {
                if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
                    offDetail = supportedDetail;
                    break;
                }
            }
            if (offDetail == null) {
                throw new InvalidParameterValueException("Unsupported detail " + detailStr);
            }
            details.put(offDetail, detailsStr.get(detailStr));
        }
    }
    if (forVpc == null) {
        forVpc = false;
    }
    final NetworkOfferingVO offering = createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false, serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details, egressDefaultPolicy, maxconn, enableKeepAlive, forVpc, domainIds, zoneIds, enable);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) Service(com.cloud.network.Network.Service) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) List(java.util.List) TrafficType(com.cloud.network.Networks.TrafficType) HashSet(java.util.HashSet) Availability(com.cloud.offering.NetworkOffering.Availability) Capability(com.cloud.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) 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) Detail(com.cloud.offering.NetworkOffering.Detail) Provider(com.cloud.network.Network.Provider) Provider(com.cloud.network.Network.Provider) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) GuestType(com.cloud.network.Network.GuestType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail) ActionEvent(com.cloud.event.ActionEvent)

Example 4 with Availability

use of com.cloud.offering.NetworkOffering.Availability in project cloudstack by apache.

the class ConfigurationManagerImpl method updateNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_EDIT, eventDescription = "updating network offering")
public NetworkOffering updateNetworkOffering(final UpdateNetworkOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getNetworkOfferingName();
    final String availabilityStr = cmd.getAvailability();
    final Integer sortKey = cmd.getSortKey();
    final Integer maxconn = cmd.getMaxconnections();
    Availability availability = null;
    final String state = cmd.getState();
    final String tags = cmd.getTags();
    final List<Long> domainIds = cmd.getDomainIds();
    final List<Long> zoneIds = cmd.getZoneIds();
    CallContext.current().setEventDetails(" Id: " + id);
    // Verify input parameters
    final NetworkOfferingVO offeringToUpdate = _networkOfferingDao.findById(id);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("unable to find network offering " + id);
    }
    List<Long> existingDomainIds = networkOfferingDetailsDao.findDomainIds(id);
    Collections.sort(existingDomainIds);
    List<Long> existingZoneIds = networkOfferingDetailsDao.findZoneIds(id);
    Collections.sort(existingZoneIds);
    // Don't allow to update system network offering
    if (offeringToUpdate.isSystemOnly()) {
        throw new InvalidParameterValueException("Can't update system network offerings");
    }
    // check if valid domain
    if (CollectionUtils.isNotEmpty(domainIds)) {
        for (final Long domainId : domainIds) {
            if (_domainDao.findById(domainId) == null) {
                throw new InvalidParameterValueException("Please specify a valid domain id");
            }
        }
    }
    // check if valid zone
    if (CollectionUtils.isNotEmpty(zoneIds)) {
        for (Long zoneId : zoneIds) {
            if (_zoneDao.findById(zoneId) == null)
                throw new InvalidParameterValueException("Please specify a valid zone id");
        }
    }
    // Filter child domains when both parent and child domains are present
    List<Long> filteredDomainIds = filterChildSubDomains(domainIds);
    Collections.sort(filteredDomainIds);
    List<Long> filteredZoneIds = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(zoneIds)) {
        filteredZoneIds.addAll(zoneIds);
    }
    Collections.sort(filteredZoneIds);
    final NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
    boolean updateNeeded = name != null || displayText != null || sortKey != null || state != null || tags != null || availabilityStr != null || maxconn != null;
    if (updateNeeded) {
        if (name != null) {
            offering.setName(name);
        }
        if (displayText != null) {
            offering.setDisplayText(displayText);
        }
        if (sortKey != null) {
            offering.setSortKey(sortKey);
        }
        if (state != null) {
            boolean validState = false;
            for (final NetworkOffering.State st : NetworkOffering.State.values()) {
                if (st.name().equalsIgnoreCase(state)) {
                    validState = true;
                    offering.setState(st);
                }
            }
            if (!validState) {
                throw new InvalidParameterValueException("Incorrect state value: " + state);
            }
        }
        if (tags != null) {
            List<DataCenterVO> dataCenters = _zoneDao.listAll();
            TrafficType trafficType = offeringToUpdate.getTrafficType();
            String oldTags = offeringToUpdate.getTags();
            for (DataCenterVO dataCenter : dataCenters) {
                long zoneId = dataCenter.getId();
                long newPhysicalNetworkId = _networkModel.findPhysicalNetworkId(zoneId, tags, trafficType);
                if (oldTags != null) {
                    long oldPhysicalNetworkId = _networkModel.findPhysicalNetworkId(zoneId, oldTags, trafficType);
                    if (newPhysicalNetworkId != oldPhysicalNetworkId) {
                        throw new InvalidParameterValueException("New tags: selects different physical network for zone " + zoneId);
                    }
                }
            }
            offering.setTags(tags);
        }
        // Verify availability
        if (availabilityStr != null) {
            for (final Availability avlb : Availability.values()) {
                if (avlb.name().equalsIgnoreCase(availabilityStr)) {
                    availability = avlb;
                }
            }
            if (availability == null) {
                throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
            } else {
                if (availability == NetworkOffering.Availability.Required) {
                    final boolean canOffBeRequired = offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), 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() && offerings.get(0).getId() != offeringToUpdate.getId()) {
                        throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
                    }
                }
                offering.setAvailability(availability);
            }
        }
        if (_ntwkOffServiceMapDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Lb)) {
            if (maxconn != null) {
                offering.setConcurrentConnections(maxconn);
            }
        }
        if (!_networkOfferingDao.update(id, offering)) {
            return null;
        }
    }
    List<NetworkOfferingDetailsVO> detailsVO = new ArrayList<>();
    if (!filteredDomainIds.equals(existingDomainIds) || !filteredZoneIds.equals(existingZoneIds)) {
        SearchBuilder<NetworkOfferingDetailsVO> sb = networkOfferingDetailsDao.createSearchBuilder();
        sb.and("offeringId", sb.entity().getResourceId(), SearchCriteria.Op.EQ);
        sb.and("detailName", sb.entity().getName(), SearchCriteria.Op.EQ);
        sb.done();
        SearchCriteria<NetworkOfferingDetailsVO> sc = sb.create();
        sc.setParameters("offeringId", String.valueOf(id));
        if (!filteredDomainIds.equals(existingDomainIds)) {
            sc.setParameters("detailName", ApiConstants.DOMAIN_ID);
            networkOfferingDetailsDao.remove(sc);
            for (Long domainId : filteredDomainIds) {
                detailsVO.add(new NetworkOfferingDetailsVO(id, Detail.domainid, String.valueOf(domainId), false));
            }
        }
        if (!filteredZoneIds.equals(existingZoneIds)) {
            sc.setParameters("detailName", ApiConstants.ZONE_ID);
            networkOfferingDetailsDao.remove(sc);
            for (Long zoneId : filteredZoneIds) {
                detailsVO.add(new NetworkOfferingDetailsVO(id, Detail.zoneid, String.valueOf(zoneId), false));
            }
        }
    }
    if (!detailsVO.isEmpty()) {
        for (NetworkOfferingDetailsVO detailVO : detailsVO) {
            networkOfferingDetailsDao.persist(detailVO);
        }
    }
    return _networkOfferingDao.findById(id);
}
Also used : Availability(com.cloud.offering.NetworkOffering.Availability) DataCenterVO(com.cloud.dc.DataCenterVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) TrafficType(com.cloud.network.Networks.TrafficType) NetworkOfferingDetailsVO(com.cloud.offerings.NetworkOfferingDetailsVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)4 NetworkOffering (com.cloud.offering.NetworkOffering)4 Availability (com.cloud.offering.NetworkOffering.Availability)4 TrafficType (com.cloud.network.Networks.TrafficType)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 ArrayList (java.util.ArrayList)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Network (com.cloud.network.Network)2 Capability (com.cloud.network.Network.Capability)2 GuestType (com.cloud.network.Network.GuestType)2 Provider (com.cloud.network.Network.Provider)2 Service (com.cloud.network.Network.Service)2 NetworkService (com.cloud.network.NetworkService)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 Detail (com.cloud.offering.NetworkOffering.Detail)2 ManagementService (com.cloud.server.ManagementService)2 ResourceLimitService (com.cloud.user.ResourceLimitService)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2