Search in sources :

Example 66 with NetworkElement

use of com.cloud.network.element.NetworkElement 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)

Example 67 with NetworkElement

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

the class NetworkModelImpl method checkCapabilityForProvider.

@Override
public void checkCapabilityForProvider(Set<Provider> providers, Service service, Capability cap, String capValue) {
    for (Provider provider : providers) {
        NetworkElement element = getElementImplementingProvider(provider.getName());
        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.getName());
            }
            Map<Capability, String> serviceCapabilities = elementCapabilities.get(service);
            if (serviceCapabilities == null || serviceCapabilities.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capabilities for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            String value = serviceCapabilities.get(cap);
            if (value == null || value.isEmpty()) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't have capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            if (!value.toLowerCase().contains(capValue.toLowerCase())) {
                throw new UnsupportedServiceException("Service " + service.getName() + " doesn't support value " + capValue + " for capability " + cap.getName() + " for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
        } else {
            throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 68 with NetworkElement

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

the class NetworkModelImpl method canProviderSupportServices.

@Override
public void canProviderSupportServices(Map<Provider, Set<Service>> providersMap) {
    for (Provider provider : providersMap.keySet()) {
        // check if services can be turned off
        NetworkElement element = getElementImplementingProvider(provider.getName());
        if (element == null) {
            throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getName() + "'");
        }
        Set<Service> enabledServices = new HashSet<Service>();
        enabledServices.addAll(providersMap.get(provider));
        if (enabledServices != null && !enabledServices.isEmpty()) {
            if (!element.canEnableIndividualServices()) {
                Set<Service> requiredServices = new HashSet<Service>();
                requiredServices.addAll(element.getCapabilities().keySet());
                if (requiredServices.contains(Network.Service.Gateway)) {
                    requiredServices.remove(Network.Service.Gateway);
                }
                if (requiredServices.contains(Network.Service.Firewall)) {
                    requiredServices.remove(Network.Service.Firewall);
                }
                if (enabledServices.contains(Network.Service.Firewall)) {
                    enabledServices.remove(Network.Service.Firewall);
                }
                // exclude gateway service
                if (enabledServices.size() != requiredServices.size()) {
                    StringBuilder servicesSet = new StringBuilder();
                    for (Service requiredService : requiredServices) {
                        // skip gateway service as we don't allow setting it via API
                        if (requiredService == Service.Gateway) {
                            continue;
                        }
                        servicesSet.append(requiredService.getName() + ", ");
                    }
                    servicesSet.delete(servicesSet.toString().length() - 2, servicesSet.toString().length());
                    throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services: " + servicesSet.toString() + "  for Service Provider " + provider.getName());
                }
            }
            List<String> serviceList = new ArrayList<String>();
            for (Service service : enabledServices) {
                // check if the service is provided by this Provider
                if (!element.getCapabilities().containsKey(service)) {
                    throw new UnsupportedServiceException(provider.getName() + " Provider cannot provide service " + service.getName());
                }
                serviceList.add(service.getName());
            }
            if (!element.verifyServicesCombination(enabledServices)) {
                throw new UnsupportedServiceException("Provider " + provider.getName() + " doesn't support services combination: " + serviceList);
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) 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) HashSet(java.util.HashSet)

Example 69 with NetworkElement

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

the class VpcManagerImplTest method prepareVpcManagerForCheckingCapabilityPerService.

protected Set<Network.Provider> prepareVpcManagerForCheckingCapabilityPerService(Service service, Map<Capability, String> capabilities) {
    final Set<Network.Provider> providers = new HashSet<>();
    providers.add(Provider.VPCVirtualRouter);
    final Network.Capability capability = Capability.DistributedRouter;
    final boolean regionLevel = true;
    final boolean distributedRouter = true;
    final NetworkElement nwElement1 = mock(NetworkElement.class);
    this.manager._ntwkModel = mock(NetworkModel.class);
    when(this.manager._ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())).thenReturn(nwElement1);
    final Map<Service, Map<Network.Capability, String>> capabilitiesService1 = new HashMap<>();
    when(nwElement1.getCapabilities()).thenReturn(capabilitiesService1);
    capabilities.put(Capability.RegionLevelVpc, "");
    capabilities.put(Capability.DistributedRouter, "");
    capabilitiesService1.put(service, capabilities);
    return providers;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) HashMap(java.util.HashMap) Network(com.cloud.network.Network) NetworkModel(com.cloud.network.NetworkModel) Service(com.cloud.network.Network.Service) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) Map(java.util.Map) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Aggregations

NetworkElement (com.cloud.network.element.NetworkElement)69 Provider (com.cloud.network.Network.Provider)43 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)33 Service (com.cloud.network.Network.Service)29 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)27 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)25 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)25 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)20 HashMap (java.util.HashMap)20 Map (java.util.Map)20 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 NetworkVO (com.cloud.network.dao.NetworkVO)17 ArrayList (java.util.ArrayList)17 ConfigDriveNetworkElement (com.cloud.network.element.ConfigDriveNetworkElement)16 NetworkGuru (com.cloud.network.guru.NetworkGuru)16 NicProfile (com.cloud.vm.NicProfile)16 Capability (com.cloud.network.Network.Capability)15 NicVO (com.cloud.vm.NicVO)13 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)13