Search in sources :

Example 1 with IpDeployer

use of com.cloud.network.element.IpDeployer in project cloudstack by apache.

the class NetworkModelImpl method canIpUsedForService.

public boolean canIpUsedForService(PublicIp publicIp, Service service, Long networkId) {
    List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
    ipList.add(publicIp);
    Map<PublicIpAddress, Set<Service>> ipToServices = getIpToServices(ipList, false, true);
    Set<Service> services = ipToServices.get(publicIp);
    if (services == null || services.isEmpty()) {
        return true;
    }
    if (networkId == null) {
        networkId = publicIp.getAssociatedWithNetworkId();
    }
    // We only support one provider for one service now
    Map<Service, Set<Provider>> serviceToProviders = getServiceProvidersMap(networkId);
    // Since IP already has service to bind with, the oldProvider can't be null
    Set<Provider> newProviders = serviceToProviders.get(service);
    if (newProviders == null || newProviders.isEmpty()) {
        throw new InvalidParameterException("There is no new provider for IP " + publicIp.getAddress() + " of service " + service.getName() + "!");
    }
    Provider newProvider = (Provider) newProviders.toArray()[0];
    Set<Provider> oldProviders = serviceToProviders.get(services.toArray()[0]);
    Provider oldProvider = (Provider) oldProviders.toArray()[0];
    Network network = _networksDao.findById(networkId);
    NetworkElement oldElement = getElementImplementingProvider(oldProvider.getName());
    NetworkElement newElement = getElementImplementingProvider(newProvider.getName());
    if (oldElement instanceof IpDeployingRequester && newElement instanceof IpDeployingRequester) {
        IpDeployer oldIpDeployer = ((IpDeployingRequester) oldElement).getIpDeployer(network);
        IpDeployer newIpDeployer = ((IpDeployingRequester) newElement).getIpDeployer(network);
    // FIXME: I ignored this check
    } else {
        throw new InvalidParameterException("Ip cannot be applied for new provider!");
    }
    return true;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider) InvalidParameterException(java.security.InvalidParameterException) NetworkElement(com.cloud.network.element.NetworkElement) IpDeployer(com.cloud.network.element.IpDeployer)

Example 2 with IpDeployer

use of com.cloud.network.element.IpDeployer in project cosmic by MissionCriticalCloud.

the class IpAddressManagerImpl method applyIpAssociations.

// CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as
// it will not know what a acquired IP will be used for. An IP is actually associated with a provider when first
// rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider
// but still be associated with the account. Its up to caller of this function to decide when to invoke IPAssociation
@Override
public boolean applyIpAssociations(final Network network, final boolean postApplyRules, final boolean continueOnError, final List<? extends PublicIpAddress> publicIps) throws ResourceUnavailableException {
    boolean success = true;
    final Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(publicIps, postApplyRules, true);
    final Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = _networkModel.getProviderToIpList(network, ipToServices);
    for (final Provider provider : providerToIpList.keySet()) {
        try {
            final ArrayList<PublicIpAddress> ips = providerToIpList.get(provider);
            if (ips == null || ips.isEmpty()) {
                continue;
            }
            IpDeployer deployer = null;
            final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
            if (!(element instanceof IpDeployingRequester)) {
                throw new CloudRuntimeException("Element " + element + " is not a IpDeployingRequester!");
            }
            deployer = ((IpDeployingRequester) element).getIpDeployer(network);
            if (deployer == null) {
                throw new CloudRuntimeException("Fail to get ip deployer for element: " + element);
            }
            final Set<Service> services = new HashSet<>();
            for (final PublicIpAddress ip : ips) {
                if (!ipToServices.containsKey(ip)) {
                    continue;
                }
                services.addAll(ipToServices.get(ip));
            }
            deployer.applyIps(network, ips, services);
        } catch (final ResourceUnavailableException e) {
            success = false;
            if (!continueOnError) {
                throw e;
            } else {
                s_logger.debug("Resource is not available: " + provider.getName(), e);
            }
        }
    }
    return success;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) ResourceLimitService(com.cloud.user.ResourceLimitService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IpDeployer(com.cloud.network.element.IpDeployer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HashSet(java.util.HashSet)

Example 3 with IpDeployer

use of com.cloud.network.element.IpDeployer in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method getIpDeployerForInlineMode.

protected IpDeployer getIpDeployerForInlineMode(Network network) {
    // We won't deploy IP, instead the firewall in front of us would do it
    List<Provider> providers = _networkMgr.getProvidersForServiceInNetwork(network, Service.Firewall);
    // Only support one provider now
    if (providers == null) {
        s_logger.error("Cannot find firewall provider for network " + network.getId());
        return null;
    }
    if (providers.size() != 1) {
        s_logger.error("Found " + providers.size() + " firewall provider for network " + network.getId());
        return null;
    }
    NetworkElement element = _networkModel.getElementImplementingProvider(providers.get(0).getName());
    if (!(element instanceof IpDeployer)) {
        s_logger.error("The firewall provider for network " + network.getName() + " don't have ability to deploy IP address!");
        return null;
    }
    s_logger.info("Let " + element.getName() + " handle ip association for " + getName() + " in network " + network.getId());
    return (IpDeployer) element;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) IpDeployer(com.cloud.network.element.IpDeployer) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 4 with IpDeployer

use of com.cloud.network.element.IpDeployer in project cloudstack by apache.

the class IpAddressManagerImpl method applyIpAssociations.

// CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as
// it will not know what a acquired IP will be used for. An IP is actually associated with a provider when first
// rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider
// but still be associated with the account. Its up to caller of this function to decide when to invoke IPAssociation
@Override
public boolean applyIpAssociations(Network network, boolean postApplyRules, boolean continueOnError, List<? extends PublicIpAddress> publicIps) throws ResourceUnavailableException {
    boolean success = true;
    Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(publicIps, postApplyRules, true);
    Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = _networkModel.getProviderToIpList(network, ipToServices);
    for (Provider provider : providerToIpList.keySet()) {
        try {
            ArrayList<PublicIpAddress> ips = providerToIpList.get(provider);
            if (ips == null || ips.isEmpty()) {
                continue;
            }
            IpDeployer deployer = null;
            NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
            if (!(element instanceof IpDeployingRequester)) {
                throw new CloudRuntimeException("Element " + element + " is not a IpDeployingRequester!");
            }
            deployer = ((IpDeployingRequester) element).getIpDeployer(network);
            if (deployer == null) {
                throw new CloudRuntimeException("Fail to get ip deployer for element: " + element);
            }
            Set<Service> services = new HashSet<Service>();
            for (PublicIpAddress ip : ips) {
                if (!ipToServices.containsKey(ip)) {
                    continue;
                }
                services.addAll(ipToServices.get(ip));
            }
            deployer.applyIps(network, ips, services);
        } catch (ResourceUnavailableException e) {
            success = false;
            if (!continueOnError) {
                throw e;
            } else {
                s_logger.debug("Resource is not available: " + provider.getName(), e);
            }
        }
    }
    return success;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IpDeployer(com.cloud.network.element.IpDeployer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HashSet(java.util.HashSet)

Aggregations

Provider (com.cloud.network.Network.Provider)4 IpDeployer (com.cloud.network.element.IpDeployer)4 NetworkElement (com.cloud.network.element.NetworkElement)4 Service (com.cloud.network.Network.Service)3 IpDeployingRequester (com.cloud.network.element.IpDeployingRequester)3 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 RemoteAccessVpnService (com.cloud.network.vpn.RemoteAccessVpnService)2 ResourceLimitService (com.cloud.user.ResourceLimitService)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)2 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)1 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)1 InvalidParameterException (java.security.InvalidParameterException)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 AnnotationService (org.apache.cloudstack.annotation.AnnotationService)1