Search in sources :

Example 46 with Service

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

the class VpcManagerImpl method listVpcOfferings.

@Override
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List<String> supportedServicesStr, final Boolean isDefault, final String keyword, final String state, final Long startIndex, final Long pageSizeVal) {
    final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
    final SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
    if (keyword != null) {
        final SearchCriteria<VpcOfferingVO> ssc = _vpcOffDao.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 (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (isDefault != null) {
        sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    final List<VpcOfferingVO> offerings = _vpcOffDao.search(sc, searchFilter);
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    if (listBySupportedServices) {
        final List<VpcOfferingVO> supportedOfferings = new ArrayList<>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = getServices(supportedServicesStr);
        }
        for (final VpcOfferingVO offering : offerings) {
            if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) {
                supportedOfferings.add(offering);
            }
        }
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<>(wPagination, supportedOfferings.size());
            return listWPagination;
        }
        return new Pair<>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<>(offerings, offerings.size());
    }
}
Also used : ArrayList(java.util.ArrayList) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Filter(com.cloud.utils.db.Filter) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.legacymodel.utils.Pair)

Example 47 with Service

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

the class VpcManagerImpl method createVpcOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create = true)
public VpcOffering createVpcOffering(final String name, final String displayText, final List<String> supportedServices, final Map<String, List<String>> serviceProviders, final Map serviceCapabilitystList, final Long serviceOfferingId, final Long secondaryServiceOfferingId) {
    final Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<>();
    final Set<Network.Provider> defaultProviders = new HashSet<>();
    defaultProviders.add(Provider.VPCVirtualRouter);
    // Just here for 4.1, replaced by commit 836ce6c1 in newer versions
    final Set<Network.Provider> sdnProviders = new HashSet<>();
    sdnProviders.add(Provider.NiciraNvp);
    boolean firewallSvs = false;
    // populate the services first
    for (final String serviceName : supportedServices) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || nonSupportedServices.contains(service)) {
            throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC");
        }
        if (service == Service.Connectivity) {
            s_logger.debug("Applying Connectivity workaround, setting provider to NiciraNvp");
            svcProviderMap.put(service, sdnProviders);
        } else {
            svcProviderMap.put(service, defaultProviders);
        }
        if (service == Service.NetworkACL) {
            firewallSvs = true;
        }
    }
    if (!firewallSvs) {
        s_logger.debug("Automatically adding network ACL service to the list of VPC services");
        svcProviderMap.put(Service.NetworkACL, defaultProviders);
    }
    if (serviceProviders != null) {
        for (final Entry<String, List<String>> serviceEntry : serviceProviders.entrySet()) {
            final Network.Service service = Network.Service.getService(serviceEntry.getKey());
            if (svcProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<>();
                for (final String prvNameStr : serviceEntry.getValue()) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    providers.add(provider);
                }
                svcProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceEntry.getKey() + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    validateConnectivtyServiceCapabilities(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList);
    final boolean redundantRouter = isVpcOfferingRedundantRouter(serviceCapabilitystList);
    final VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, serviceOfferingId, secondaryServiceOfferingId, redundantRouter);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Service(com.cloud.legacymodel.network.Network.Service) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Provider(com.cloud.legacymodel.network.Network.Provider) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) ActionEvent(com.cloud.event.ActionEvent)

Example 48 with Service

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

the class VpcManagerImpl method getServices.

private Service[] getServices(final List<String> supportedServicesStr) {
    final Service[] supportedServices;
    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++;
    }
    return supportedServices;
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService)

Example 49 with Service

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

the class VpcManagerImpl method checkCapabilityPerServiceProvider.

protected void checkCapabilityPerServiceProvider(final Set<Provider> providers, final Capability capability, final Service service) {
    // TODO Shouldn't it fail it there are no providers?
    if (providers != null) {
        for (final Provider provider : providers) {
            final NetworkElement element = _ntwkModel.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);
                if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(capability)) {
                    throw new InvalidParameterValueException(String.format("Provider %s does not support %s  capability.", provider.getName(), capability.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) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Map(java.util.Map) HashMap(java.util.HashMap) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 50 with Service

use of com.cloud.legacymodel.network.Network.Service 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.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) DB(com.cloud.utils.db.DB)

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