Search in sources :

Example 56 with Service

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

the class NetworkModelImpl method start.

@Override
public boolean start() {
    // Need to do this in start() since _networkElements are not completely configured until then.
    for (final NetworkElement element : networkElements) {
        final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
        final Provider implementedProvider = element.getProvider();
        if (implementedProvider != null) {
            if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) {
                s_logger.error("Cannot start NetworkModel: Provider <-> NetworkElement must be a one-to-one map, " + "multiple NetworkElements found for Provider: " + implementedProvider.getName());
                continue;
            }
            s_logger.info("Add provider <-> element map entry. " + implementedProvider.getName() + "-" + element.getName() + "-" + element.getClass().getSimpleName());
            s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName());
        }
        if (capabilities != null && implementedProvider != null) {
            for (final Service service : capabilities.keySet()) {
                if (s_serviceToImplementedProvidersMap.containsKey(service)) {
                    final List<Provider> providers = s_serviceToImplementedProvidersMap.get(service);
                    providers.add(implementedProvider);
                } else {
                    final List<Provider> providers = new ArrayList<>();
                    providers.add(implementedProvider);
                    s_serviceToImplementedProvidersMap.put(service, providers);
                }
            }
        }
    }
    s_logger.info("Started Network Model");
    return true;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 57 with Service

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

the class ConfigurationManagerImpl method validateConnectivityServiceCapablities.

void validateConnectivityServiceCapablities(final Set<Provider> providers, final Map<Capability, String> connectivityServiceCapabilityMap) {
    if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
        for (final Map.Entry<Capability, String> entry : connectivityServiceCapabilityMap.entrySet()) {
            final Capability capability = entry.getKey();
            if (capability == Capability.StretchedL2Subnet) {
                final String value = entry.getValue().toLowerCase();
                if (!(value.contains("true") ^ value.contains("false"))) {
                    throw new InvalidParameterValueException("Invalid value (" + value + ") for " + capability + " should be true/false");
                }
            } else {
                throw new InvalidParameterValueException("Capability " + capability.getName() + " can not be " + " specified with connectivity service.");
            }
        }
        // validate connectivity service provider actually supports specified capabilities
        if (providers != null && !providers.isEmpty()) {
            for (final Provider provider : providers) {
                final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
                final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
                if (capabilities != null && !capabilities.isEmpty()) {
                    final Map<Capability, String> connectivityCapabilities = capabilities.get(Service.Connectivity);
                    if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(Capability.StretchedL2Subnet)) {
                        throw new InvalidParameterValueException("Provider: " + provider.getName() + " does not support " + Capability.StretchedL2Subnet.getName());
                    }
                }
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Map(java.util.Map) HashMap(java.util.HashMap) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 58 with Service

use of com.cloud.legacymodel.network.Network.Service 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;
    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 GuestType offType : 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.legacymodel.network.Network.Service) GuestType(com.cloud.model.enumeration.GuestType) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) TrafficType(com.cloud.model.enumeration.TrafficType) HashSet(java.util.HashSet) Availability(com.cloud.offering.NetworkOffering.Availability) Capability(com.cloud.legacymodel.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) Detail(com.cloud.offering.NetworkOffering.Detail) Provider(com.cloud.legacymodel.network.Network.Provider) Provider(com.cloud.legacymodel.network.Network.Provider) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail) ActionEvent(com.cloud.event.ActionEvent)

Example 59 with Service

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

the class ConfigurationManagerImpl method searchForNetworkOfferings.

@Override
public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(final ListNetworkOfferingsCmd cmd) {
    Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
    isAscending = isAscending == null ? Boolean.TRUE : isAscending;
    final Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending, null, null);
    final Account caller = CallContext.current().getCallingAccount();
    final SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
    final Long id = cmd.getId();
    final Object name = cmd.getNetworkOfferingName();
    final Object displayText = cmd.getDisplayText();
    final Object trafficType = cmd.getTrafficType();
    final Object isDefault = cmd.getIsDefault();
    final Object specifyVlan = cmd.getSpecifyVlan();
    final Object availability = cmd.getAvailability();
    final Object state = cmd.getState();
    final Long zoneId = cmd.getZoneId();
    DataCenter zone = null;
    final Long networkId = cmd.getNetworkId();
    final String guestIpType = cmd.getGuestIpType();
    final List<String> supportedServicesStr = cmd.getSupportedServices();
    final Object specifyIpRanges = cmd.getSpecifyIpRanges();
    final String tags = cmd.getTags();
    final Boolean isTagged = cmd.isTagged();
    final Boolean forVpc = cmd.getForVpc();
    if (zoneId != null) {
        zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId);
        }
    }
    final Object keyword = cmd.getKeyword();
    if (keyword != null) {
        final SearchCriteria<NetworkOfferingVO> ssc = _networkOfferingDao.createSearchCriteria();
        ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
    }
    if (guestIpType != null) {
        sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType);
    }
    if (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (trafficType != null) {
        sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType);
    }
    if (isDefault != null) {
        sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
    }
    // only root admin can list network offering with specifyVlan = true
    if (specifyVlan != null) {
        sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan);
    }
    if (availability != null) {
        sc.addAnd("availability", SearchCriteria.Op.EQ, availability);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (specifyIpRanges != null) {
        sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
    }
    if (zone != null) {
        if (zone.getNetworkType() == NetworkType.Basic) {
            // basic zone, and shouldn't display networkOfferings
            return new Pair<>(new ArrayList<>(), 0);
        }
    }
    // Don't return system network offerings to the user except for private gateway offerings
    if (keyword == null || !keyword.equals("private")) {
        sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
    }
    // if networkId is specified, list offerings available for upgrade only
    // (for this network)
    Network network = null;
    if (networkId != null) {
        // check if network exists and the caller can operate with it
        network = _networkModel.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find the network by id=" + networkId);
        }
        // Don't allow to update system network
        final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
        if (offering.isSystemOnly()) {
            throw new InvalidParameterValueException("Can't update system networks");
        }
        _accountMgr.checkAccess(caller, null, true, network);
        final List<Long> offeringIds = _networkModel.listNetworkOfferingsForUpgrade(networkId);
        if (!offeringIds.isEmpty()) {
            sc.addAnd("id", SearchCriteria.Op.IN, offeringIds.toArray());
        } else {
            return new Pair<>(new ArrayList<>(), 0);
        }
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (tags != null) {
        sc.addAnd("tags", SearchCriteria.Op.EQ, tags);
    }
    if (isTagged != null) {
        if (isTagged) {
            sc.addAnd("tags", SearchCriteria.Op.NNULL);
        } else {
            sc.addAnd("tags", SearchCriteria.Op.NULL);
        }
    }
    final List<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);
    final Boolean sourceNatSupported = cmd.getSourceNatSupported();
    final List<String> pNtwkTags = new ArrayList<>();
    boolean checkForTags = false;
    if (zone != null) {
        final List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
        if (pNtwks.size() > 1) {
            checkForTags = true;
            // go through tags
            for (final PhysicalNetworkVO pNtwk : pNtwks) {
                final List<String> pNtwkTag = pNtwk.getTags();
                if (pNtwkTag == null || pNtwkTag.isEmpty()) {
                    throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + zoneId);
                }
                pNtwkTags.addAll(pNtwkTag);
            }
        }
    }
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    final boolean checkIfProvidersAreEnabled = zoneId != null;
    final boolean parseOfferings = listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null;
    if (parseOfferings) {
        final List<NetworkOfferingVO> supportedOfferings = new ArrayList<>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = new Service[supportedServicesStr.size()];
            int i = 0;
            for (final String supportedServiceStr : supportedServicesStr) {
                final Service service = Service.getService(supportedServiceStr);
                if (service == null) {
                    throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
                } else {
                    supportedServices[i] = service;
                }
                i++;
            }
        }
        for (final NetworkOfferingVO offering : offerings) {
            boolean addOffering = true;
            final List<Service> checkForProviders;
            if (checkForTags) {
                if (!pNtwkTags.contains(offering.getTags())) {
                    continue;
                }
            }
            if (listBySupportedServices) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices);
            }
            if (checkIfProvidersAreEnabled) {
                if (supportedServices != null && supportedServices.length > 0) {
                    checkForProviders = Arrays.asList(supportedServices);
                } else {
                    checkForProviders = _networkModel.listNetworkOfferingServices(offering.getId());
                }
                addOffering = addOffering && _networkModel.areServicesEnabledInZone(zoneId, offering, checkForProviders);
            }
            if (sourceNatSupported != null) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported;
            }
            if (forVpc != null) {
                addOffering = addOffering && isOfferingForVpc(offering) == forVpc.booleanValue();
            } else if (network != null) {
                addOffering = addOffering && isOfferingForVpc(offering) == (network.getVpcId() != null);
            }
            if (addOffering) {
                supportedOfferings.add(offering);
            }
        }
        // Now apply pagination
        final List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<? extends NetworkOffering> wPagination = StringUtils.applyPagination(offerings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<>(offerings, offerings.size());
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.legacymodel.utils.Pair) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(com.cloud.affinity.AffinityGroupService) DataCenter(com.cloud.legacymodel.dc.DataCenter) Filter(com.cloud.utils.db.Filter) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 60 with Service

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

the class UserVmManagerTest method testUpdateVmNicIpFailure1.

// vm is running in network with dhcp support
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure1() throws Exception {
    final UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
    final Class<?> _class = cmd.getClass();
    final Field virtualmachineIdField = _class.getDeclaredField("nicId");
    virtualmachineIdField.setAccessible(true);
    virtualmachineIdField.set(cmd, 1L);
    final Field accountNameField = _class.getDeclaredField("ipAddr");
    accountNameField.setAccessible(true);
    accountNameField.set(cmd, "10.10.10.10");
    final NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachineType.User);
    when(_nicDao.findById(anyLong())).thenReturn(nic);
    when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
    when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
    when(_networkMock.getState()).thenReturn(Network.State.Implemented);
    doReturn(9L).when(_networkMock).getNetworkOfferingId();
    when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
    doReturn(10L).when(_networkOfferingMock).getId();
    final List<Service> services = new ArrayList<>();
    services.add(Service.Dhcp);
    when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
    when(_vmMock.getState()).thenReturn(State.Running);
    _userVmMgr.updateNicIpForVirtualMachine(cmd);
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) OrchestrationService(com.cloud.engine.service.api.OrchestrationService) VolumeOrchestrationService(com.cloud.engine.orchestration.service.VolumeOrchestrationService) UpdateVmNicIpCmd(com.cloud.api.command.user.vm.UpdateVmNicIpCmd) Test(org.junit.Test)

Aggregations

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