Search in sources :

Example 21 with Provider

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

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    NetworkOfferingResponse response = new NetworkOfferingResponse();
    response.setId(offering.getUuid());
    response.setName(offering.getName());
    response.setDisplayText(offering.getDisplayText());
    response.setTags(offering.getTags());
    response.setTrafficType(offering.getTrafficType().toString());
    response.setIsDefault(offering.isDefault());
    response.setSpecifyVlan(offering.getSpecifyVlan());
    response.setConserveMode(offering.isConserveMode());
    response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
    response.setAvailability(offering.getAvailability().toString());
    response.setIsPersistent(offering.getIsPersistent());
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
    response.setConcurrentConnections(offering.getConcurrentConnections());
    response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
    response.setSupportsPublicAccess(offering.getSupportsPublicAccess());
    Long so = null;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
        if (soffering != null) {
            response.setServiceOfferingId(soffering.getUuid());
        }
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        Service service = entry.getKey();
        Set<Provider> srvc_providers = entry.getValue();
        ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
        for (Provider provider : srvc_providers) {
            if (provider != null) {
                ProviderResponse providerRsp = new ProviderResponse();
                providerRsp.setName(provider.getName());
                providers.add(providerRsp);
            }
        }
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            CapabilityResponse inline = new CapabilityResponse();
            inline.setName(Capability.InlineMode.getName());
            inline.setValue(offering.isInline() ? "true" : "false");
            lbCapResponse.add(inline);
            svcRsp.setCapabilities(lbCapResponse);
        } else if (Service.SourceNat == service) {
            List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
            CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
            capabilities.add(redundantRouter);
            svcRsp.setCapabilities(capabilities);
        } else if (service == Service.StaticNat) {
            List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
            CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
            staticNatCapResponse.add(associatePublicIp);
            svcRsp.setCapabilities(staticNatCapResponse);
        }
        serviceResponses.add(svcRsp);
    }
    response.setForVpc(_configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    //set network offering details
    Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
    if (details != null && !details.isEmpty()) {
        response.setDetails(details);
    }
    response.setObjectName("networkoffering");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) CapabilityResponse(org.apache.cloudstack.api.response.CapabilityResponse) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 22 with Provider

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

the class NetworkServiceImpl method addProviderToPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List<String> enabledServices) {
    // verify input parameters
    PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
    if (network == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
        throw ex;
    }
    // verify input parameters
    if (destinationPhysicalNetworkId != null) {
        PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
        if (destNetwork == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
            ex.addProxyObject(destinationPhysicalNetworkId.toString(), "destinationPhysicalNetworkId");
            throw ex;
        }
    }
    if (providerName != null) {
        Provider provider = Network.Provider.getProvider(providerName);
        if (provider == null) {
            throw new InvalidParameterValueException("Invalid Network Service Provider=" + providerName);
        }
    }
    if (_pNSPDao.findByServiceProvider(physicalNetworkId, providerName) != null) {
        // TBD: send uuid instead of physicalNetworkId.
        throw new CloudRuntimeException("The '" + providerName + "' provider already exists on physical network : " + physicalNetworkId);
    }
    // check if services can be turned off
    NetworkElement element = _networkModel.getElementImplementingProvider(providerName);
    if (element == null) {
        throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + providerName + "'");
    }
    List<Service> services = new ArrayList<Service>();
    if (enabledServices != null) {
        if (!element.canEnableIndividualServices()) {
            if (enabledServices.size() != element.getCapabilities().keySet().size()) {
                throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services for this Service Provider '" + providerName + "'");
            }
        }
        // validate Services
        boolean addGatewayService = false;
        for (String serviceName : enabledServices) {
            Network.Service service = Network.Service.getService(serviceName);
            if (service == null || service == Service.Gateway) {
                throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
            } else if (service == Service.SourceNat) {
                addGatewayService = true;
            }
            // check if the service is provided by this Provider
            if (!element.getCapabilities().containsKey(service)) {
                throw new InvalidParameterValueException(providerName + " Provider cannot provide this Service specified=" + serviceName);
            }
            services.add(service);
        }
        if (addGatewayService) {
            services.add(Service.Gateway);
        }
    } else {
        // enable all the default services supported by this element.
        services = new ArrayList<Service>(element.getCapabilities().keySet());
    }
    try {
        // Create the new physical network in the database
        PhysicalNetworkServiceProviderVO nsp = new PhysicalNetworkServiceProviderVO(physicalNetworkId, providerName);
        // set enabled services
        nsp.setEnabledServices(services);
        if (destinationPhysicalNetworkId != null) {
            nsp.setDestinationPhysicalNetworkId(destinationPhysicalNetworkId);
        }
        nsp = _pNSPDao.persist(nsp);
        return nsp;
    } catch (Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to add a provider to physical network");
    }
}
Also used : ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) Service(com.cloud.network.Network.Service) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) Provider(com.cloud.network.Network.Provider) NetworkElement(com.cloud.network.element.NetworkElement) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 23 with Provider

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

the class NetworkServiceImpl method canIpsUseOffering.

private boolean canIpsUseOffering(List<PublicIp> publicIps, long offeringId) {
    Map<PublicIp, Set<Service>> ipToServices = getIpToServices(publicIps, false, true);
    Map<Service, Set<Provider>> serviceToProviders = _networkModel.getNetworkOfferingServiceProvidersMap(offeringId);
    NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
    //For inline mode checking, using firewall provider for LB instead, because public ip would apply on firewall provider
    if (offering.isInline()) {
        Provider firewallProvider = null;
        if (serviceToProviders.containsKey(Service.Firewall)) {
            firewallProvider = (Provider) serviceToProviders.get(Service.Firewall).toArray()[0];
        }
        Set<Provider> p = new HashSet<Provider>();
        p.add(firewallProvider);
        serviceToProviders.remove(Service.Lb);
        serviceToProviders.put(Service.Lb, p);
    }
    for (PublicIp ip : ipToServices.keySet()) {
        Set<Service> services = ipToServices.get(ip);
        Provider provider = null;
        for (Service service : services) {
            Set<Provider> curProviders = serviceToProviders.get(service);
            if (curProviders == null || curProviders.isEmpty()) {
                continue;
            }
            Provider curProvider = (Provider) curProviders.toArray()[0];
            if (provider == null) {
                provider = curProvider;
                continue;
            }
            // We don't support multiple providers for one service now
            if (!provider.equals(curProvider)) {
                throw new InvalidParameterException("There would be multiple providers for IP " + ip.getAddress() + " with the new network offering!");
            }
        }
    }
    return true;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ResultSet(java.sql.ResultSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) PublicIp(com.cloud.network.addr.PublicIp) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) SecurityGroupService(com.cloud.network.security.SecurityGroupService) ResourceLimitService(com.cloud.user.ResourceLimitService) InternalLoadBalancerElementService(org.apache.cloudstack.network.element.InternalLoadBalancerElementService) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Example 24 with Provider

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

the class ConfigurationManagerImpl method validateNtwkOffDetails.

protected void validateNtwkOffDetails(final Map<Detail, String> details, final Map<Service, Set<Provider>> serviceProviderMap) {
    for (final Detail detail : details.keySet()) {
        Provider lbProvider = null;
        if (detail == NetworkOffering.Detail.InternalLbProvider || detail == NetworkOffering.Detail.PublicLbProvider) {
            // 1) Vaidate the detail values - have to match the lb provider
            // name
            final String providerStr = details.get(detail);
            if (Network.Provider.getProvider(providerStr) == null) {
                throw new InvalidParameterValueException("Invalid value " + providerStr + " for the detail " + detail);
            }
            if (serviceProviderMap.get(Service.Lb) != null) {
                for (final Provider provider : serviceProviderMap.get(Service.Lb)) {
                    if (provider.getName().equalsIgnoreCase(providerStr)) {
                        lbProvider = provider;
                        break;
                    }
                }
            }
            if (lbProvider == null) {
                throw new InvalidParameterValueException("Invalid value " + details.get(detail) + " for the detail " + detail + ". The provider is not supported by the network offering");
            }
            // 2) validate if the provider supports the scheme
            final Set<Provider> lbProviders = new HashSet<Provider>();
            lbProviders.add(lbProvider);
            if (detail == NetworkOffering.Detail.InternalLbProvider) {
                _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, Scheme.Internal.toString());
            } else if (detail == NetworkOffering.Detail.PublicLbProvider) {
                _networkModel.checkCapabilityForProvider(lbProviders, Service.Lb, Capability.LbSchemes, Scheme.Public.toString());
            }
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Detail(com.cloud.offering.NetworkOffering.Detail) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet)

Example 25 with Provider

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

the class LoadBalancingRulesManagerImpl method applyLbRules.

protected boolean applyLbRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
    boolean handled = false;
    for (LoadBalancingServiceProvider lbElement : _lbProviders) {
        Provider provider = lbElement.getProvider();
        boolean isLbProvider = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Lb, provider);
        if (!isLbProvider) {
            continue;
        }
        handled = lbElement.applyLBRules(network, rules);
        if (handled)
            break;
    }
    return handled;
}
Also used : LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

Provider (com.cloud.network.Network.Provider)66 Service (com.cloud.network.Network.Service)35 HashSet (java.util.HashSet)31 HashMap (java.util.HashMap)28 Set (java.util.Set)27 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)25 NetworkElement (com.cloud.network.element.NetworkElement)22 ArrayList (java.util.ArrayList)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Network (com.cloud.network.Network)17 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)15 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)12 Map (java.util.Map)12 ResourceLimitService (com.cloud.user.ResourceLimitService)11 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)11 NicProfile (com.cloud.vm.NicProfile)10