Search in sources :

Example 6 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class IpAddressManagerImpl method isPortableIpTransferableFromNetwork.

@Override
public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
    Network network = _networksDao.findById(networkId);
    if (network == null) {
        throw new InvalidParameterValueException("Invalid network id is given");
    }
    IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
    if (ip == null) {
        throw new InvalidParameterValueException("Invalid network id is given");
    }
    // Check if IP has any services (rules) associated in the network
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
    if (!ipToServices.isEmpty()) {
        Set<Service> ipServices = ipToServices.get(publicIp);
        if (ipServices != null && !ipServices.isEmpty()) {
            return false;
        }
    }
    return true;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 7 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class IpAddressManagerImpl method disassociatePortableIPToGuestNetwork.

@DB
@Override
public IPAddressVO disassociatePortableIPToGuestNetwork(long ipId, long networkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
    Account caller = CallContext.current().getCallingAccount();
    Account owner = null;
    Network network = _networksDao.findById(networkId);
    if (network == null) {
        throw new InvalidParameterValueException("Invalid network id is given");
    }
    IPAddressVO ipToAssoc = _ipAddressDao.findById(ipId);
    if (ipToAssoc != null) {
        if (ipToAssoc.getAssociatedWithNetworkId() == null) {
            throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with any network");
        }
        if (ipToAssoc.getAssociatedWithNetworkId() != network.getId()) {
            throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with network id" + networkId);
        }
        DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
        if (zone.getNetworkType() == NetworkType.Advanced) {
            if (network.getGuestType() == Network.GuestType.Shared) {
                assert (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()));
                _accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.UseEntry, false, network);
            }
        } else {
            _accountMgr.checkAccess(caller, null, true, ipToAssoc);
        }
        owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
    } else {
        s_logger.debug("Unable to find ip address by id: " + ipId);
        return null;
    }
    DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
    //     - and it belongs to the system
    if (network.getAccountId() != owner.getId()) {
        if (zone.getNetworkType() != NetworkType.Basic && !(zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Shared)) {
            throw new InvalidParameterValueException("The owner of the network is not the same as owner of the IP");
        }
    }
    // Check if IP has any services (rules) associated in the network
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipToAssoc, _vlanDao.findById(ipToAssoc.getVlanId()));
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList, false, true);
    if (!ipToServices.isEmpty()) {
        Set<Service> services = ipToServices.get(publicIp);
        if (services != null && !services.isEmpty()) {
            throw new InvalidParameterValueException("IP " + ipToAssoc + " has services and rules associated in the network " + networkId);
        }
    }
    IPAddressVO ip = _ipAddressDao.findById(ipId);
    ip.setAssociatedWithNetworkId(null);
    _ipAddressDao.update(ipId, ip);
    try {
        boolean success = applyIpAssociations(network, false);
        if (success) {
            s_logger.debug("Successfully associated ip address " + ip.getAddress().addr() + " to network " + network);
        } else {
            s_logger.warn("Failed to associate ip address " + ip.getAddress().addr() + " to network " + network);
        }
        return ip;
    } finally {
    }
}
Also used : Account(com.cloud.user.Account) Set(java.util.Set) HashSet(java.util.HashSet) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IPAddressVO(com.cloud.network.dao.IPAddressVO) DB(com.cloud.utils.db.DB)

Example 8 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method areServicesEnabledInZone.

@Override
public boolean areServicesEnabledInZone(long zoneId, NetworkOffering offering, List<Service> services) {
    long physicalNtwkId = findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
    boolean result = true;
    List<String> checkedProvider = new ArrayList<String>();
    for (Service service : services) {
        // get all the providers, and check if each provider is enabled
        List<String> providerNames = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
        for (String providerName : providerNames) {
            if (!checkedProvider.contains(providerName)) {
                result = result && isProviderEnabledInPhysicalNetwork(physicalNtwkId, providerName);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service)

Example 9 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method getNetworkServiceCapabilities.

@Override
public Map<Capability, String> getNetworkServiceCapabilities(long networkId, Service service) {
    if (!areServicesSupportedInNetwork(networkId, service)) {
        // addProxyObject with hardcoded tablename. Or we should probably look up the correct dao proxy object.
        throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId);
    }
    Map<Capability, String> serviceCapabilities = new HashMap<Capability, String>();
    // get the Provider for this Service for this offering
    String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(networkId, service);
    NetworkElement element = getElementImplementingProvider(provider);
    if (element != null) {
        Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
        ;
        if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
            throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
        }
        serviceCapabilities = elementCapabilities.get(service);
    }
    return serviceCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with Service

use of com.cloud.network.Network.Service in project cloudstack by apache.

the class NetworkModelImpl method getProviderToIpList.

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(Network network, Map<PublicIpAddress, Set<Service>> ipToServices) {
    NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (PublicIpAddress ip : ipToServices.keySet()) {
            Set<Service> services = new HashSet<Service>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }
            if (services != null && services.size() > 1) {
                throw new CloudRuntimeException("Ip " + ip.getAddress() + " is used by multiple services!");
            }
        }
    }
    Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<Service, Set<PublicIpAddress>>();
    for (PublicIpAddress ip : ipToServices.keySet()) {
        for (Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<PublicIpAddress>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<Provider, ArrayList<PublicIpAddress>>();
    for (Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        Set<Service> services = providerToServices.get(provider);
        ArrayList<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
        Set<PublicIpAddress> ipSet = new HashSet<PublicIpAddress>();
        for (Service service : services) {
            Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HashSet(java.util.HashSet)

Aggregations

Service (com.cloud.network.Network.Service)76 HashMap (java.util.HashMap)40 ArrayList (java.util.ArrayList)37 Provider (com.cloud.network.Network.Provider)36 HashSet (java.util.HashSet)36 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)31 Set (java.util.Set)30 ResourceLimitService (com.cloud.user.ResourceLimitService)28 Map (java.util.Map)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 Network (com.cloud.network.Network)18 Capability (com.cloud.network.Network.Capability)17 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)15 NetworkElement (com.cloud.network.element.NetworkElement)14 Test (org.junit.Test)13 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)12 NetworkService (com.cloud.network.NetworkService)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 NetworkOffering (com.cloud.offering.NetworkOffering)10 Account (com.cloud.user.Account)10