Search in sources :

Example 66 with Service

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

the class NetworkServiceMapDaoImpl method areServicesSupportedInNetwork.

@Override
public boolean areServicesSupportedInNetwork(long networkId, Service... services) {
    SearchCriteria<NetworkServiceMapVO> sc = MultipleServicesSearch.create();
    sc.setParameters("networkId", networkId);
    if (services != null) {
        String[] servicesStr = new String[services.length];
        int i = 0;
        for (Service service : services) {
            servicesStr[i] = service.getName();
            i++;
        }
        sc.setParameters("service", (Object[]) servicesStr);
    }
    List<NetworkServiceMapVO> networkServices = listBy(sc);
    if (services != null) {
        if (networkServices.size() == services.length) {
            return true;
        }
    } else if (!networkServices.isEmpty()) {
        return true;
    }
    return false;
}
Also used : Service(com.cloud.network.Network.Service)

Example 67 with Service

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

the class MidoNetElement method applyIps.

/**
     * From interface IpDeployer
     *
     * @param network
     * @param ipAddress
     * @param services
     * @return
     * @throws ResourceUnavailableException
     */
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
    s_logger.debug("applyIps called with network: " + network.toString());
    if (!this.midoInNetwork(network)) {
        return false;
    }
    boolean canHandle = true;
    for (Service service : services) {
        if (!canHandle(network, service)) {
            canHandle = false;
            break;
        }
    }
    if (canHandle) {
        return associatePublicIP(network, ipAddress);
    } else {
        return false;
    }
}
Also used : Service(com.cloud.network.Network.Service) PluggableService(com.cloud.utils.component.PluggableService)

Example 68 with Service

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

the class NetworkModelImpl method getNetworkOfferingServiceProvidersMap.

@Override
public Map<Service, Set<Provider>> getNetworkOfferingServiceProvidersMap(long networkOfferingId) {
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Service, Set<Provider>>();
    List<NetworkOfferingServiceMapVO> map = _ntwkOfferingSrvcDao.listByNetworkOfferingId(networkOfferingId);
    for (NetworkOfferingServiceMapVO instance : map) {
        String service = instance.getService();
        Set<Provider> providers;
        providers = serviceProviderMap.get(Service.getService(service));
        if (providers == null) {
            providers = new HashSet<Provider>();
        }
        providers.add(Provider.getProvider(instance.getProvider()));
        serviceProviderMap.put(Service.getService(service), providers);
    }
    return serviceProviderMap;
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 69 with Service

use of com.cloud.network.Network.Service 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 70 with Service

use of com.cloud.network.Network.Service 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)

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