Search in sources :

Example 26 with NetworkElement

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

the class NetworkModelImpl method providerSupportsCapability.

@Override
public boolean providerSupportsCapability(Set<Provider> providers, Service service, Capability cap) {
    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 capabilites for element=" + element.getName() + " implementing Provider=" + provider.getName());
            }
            if (serviceCapabilities.containsKey(cap)) {
                return true;
            }
        } else {
            throw new UnsupportedServiceException("Unable to find network element for provider " + provider.getName());
        }
    }
    return false;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.network.Network.Capability) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) 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 27 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) 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 28 with NetworkElement

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

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

the class NetworkServiceImpl method deleteNetworkServiceProvider.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_DELETE, eventDescription = "Deleting physical network ServiceProvider", async = true)
public boolean deleteNetworkServiceProvider(Long id) throws ConcurrentOperationException, ResourceUnavailableException {
    PhysicalNetworkServiceProviderVO provider = _pNSPDao.findById(id);
    if (provider == null) {
        throw new InvalidParameterValueException("Network Service Provider id=" + id + "doesn't exist in the system");
    }
    // check if there are networks using this provider
    List<NetworkVO> networks = _networksDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), provider.getProviderName());
    if (networks != null && !networks.isEmpty()) {
        throw new CloudRuntimeException("Provider is not deletable because there are active networks using this provider, please upgrade these networks to new network offerings");
    }
    User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    Account callerAccount = _accountMgr.getActiveAccountById(callerUser.getAccountId());
    // shutdown the provider instances
    ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Shutting down the service provider id=" + id + " on physical network: " + provider.getPhysicalNetworkId());
    }
    NetworkElement element = _networkModel.getElementImplementingProvider(provider.getProviderName());
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + provider.getProviderName() + "'");
    }
    if (element != null && element.shutdownProviderInstances(provider, context)) {
        provider.setState(PhysicalNetworkServiceProvider.State.Shutdown);
    }
    return _pNSPDao.remove(id);
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

NetworkElement (com.cloud.network.element.NetworkElement)36 Provider (com.cloud.network.Network.Provider)23 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)17 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)15 Service (com.cloud.network.Network.Service)14 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)13 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 Capability (com.cloud.network.Network.Capability)8 NetworkVO (com.cloud.network.dao.NetworkVO)8 NetworkGuru (com.cloud.network.guru.NetworkGuru)8 ArrayList (java.util.ArrayList)8 NicProfile (com.cloud.vm.NicProfile)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6