Search in sources :

Example 11 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getNetworkServiceCapabilities.

@Override
public Map<Capability, String> getNetworkServiceCapabilities(final long networkId, final Service service) {
    if (!areServicesSupportedInNetwork(networkId, service)) {
        // addProxyObject with hardcoded tablename. Or we should probably look up the correct dao proxy object.
        throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId);
    }
    Map<Capability, String> serviceCapabilities = new HashMap<>();
    // get the Provider for this Service for this offering
    final String provider = _ntwkSrvcDao.getProviderForServiceInNetwork(networkId, service);
    final NetworkElement element = getElementImplementingProvider(provider);
    if (element != null) {
        final 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);
        }
        serviceCapabilities = elementCapabilities.get(service);
    }
    return serviceCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) HashMap(java.util.HashMap) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class NetworkServiceImpl method getNetworkOfferingServiceCapabilities.

@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(final NetworkOffering offering, final Service service) {
    if (!areServicesSupportedByNetworkOffering(offering.getId(), service)) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    Map<Capability, String> serviceCapabilities = new HashMap<>();
    // get the Provider for this Service for this offering
    final List<String> providers = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
    if (providers.isEmpty()) {
        // TBD: We should be sending networkOfferingId and not the offering object itself.
        throw new InvalidParameterValueException("Service " + service.getName() + " is not supported by the network offering " + offering);
    }
    // FIXME - in post 3.0 we are going to support multiple providers for the same service per network offering, so
    // we have to calculate capabilities for all of them
    final String provider = providers.get(0);
    // FIXME we return the capabilities of the first provider of the service - what if we have multiple providers
    // for same Service?
    final NetworkElement element = _networkModel.getElementImplementingProvider(provider);
    if (element != null) {
        final Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
        if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
            // TBD: We should be sending providerId and not the offering object itself.
            throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
        }
        serviceCapabilities = elementCapabilities.get(service);
    }
    return serviceCapabilities;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method validateConnectivtyServiceCapabilities.

private void validateConnectivtyServiceCapabilities(final Set<Provider> providers, final Map serviceCapabilitystList) {
    if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
        final Collection serviceCapabilityCollection = serviceCapabilitystList.values();
        final Iterator iter = serviceCapabilityCollection.iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
            Capability capability = null;
            final String svc = svcCapabilityMap.get(SERVICE);
            final String capabilityName = svcCapabilityMap.get(CAPABILITYTYPE);
            final String capabilityValue = svcCapabilityMap.get(CAPABILITYVALUE);
            if (capabilityName != null) {
                capability = Capability.getCapability(capabilityName);
            }
            if (capability == null || capabilityValue == null) {
                throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
            }
            final Service usedService = Service.getService(svc);
            checkCapabilityPerServiceProvider(providers, capability, usedService);
            if (!capabilityValue.equalsIgnoreCase(TRUE_VALUE) && !capabilityValue.equalsIgnoreCase(FALSE_VALUE)) {
                throw new InvalidParameterValueException("Invalid Capability value:" + capabilityValue + " specified.");
            }
        }
    }
}
Also used : Capability(com.cloud.legacymodel.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService)

Example 14 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method checkCapabilityPerServiceProvider.

protected void checkCapabilityPerServiceProvider(final Set<Provider> providers, final Capability capability, final Service service) {
    // TODO Shouldn't it fail it there are no providers?
    if (providers != null) {
        for (final Provider provider : providers) {
            final NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName());
            final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
            if (capabilities != null && !capabilities.isEmpty()) {
                final Map<Capability, String> connectivityCapabilities = capabilities.get(service);
                if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(capability)) {
                    throw new InvalidParameterValueException(String.format("Provider %s does not support %s  capability.", provider.getName(), capability.getName()));
                }
            }
        }
    }
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) Capability(com.cloud.legacymodel.network.Network.Capability) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) NetworkService(com.cloud.network.NetworkService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Map(java.util.Map) HashMap(java.util.HashMap) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 15 with Capability

use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method startSite2SiteVpn.

@Override
public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException {
    final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn);
    if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) {
        s_logger.error("try to start site 2 site vpn on unsupported network element?");
        return false;
    }
    final Long vpcId = ip.getVpcId();
    final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
    if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
        throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId());
    }
    final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
    if (routers == null) {
        throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId());
    }
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.legacymodel.network.Network.Capability) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Capability (com.cloud.legacymodel.network.Network.Capability)20 HashMap (java.util.HashMap)12 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)11 Service (com.cloud.legacymodel.network.Network.Service)11 Map (java.util.Map)10 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)7 Provider (com.cloud.legacymodel.network.Network.Provider)6 NetworkElement (com.cloud.network.element.NetworkElement)6 ResourceLimitService (com.cloud.user.ResourceLimitService)6 NetworkService (com.cloud.network.NetworkService)5 UnsupportedServiceException (com.cloud.legacymodel.exceptions.UnsupportedServiceException)4 Vpc (com.cloud.legacymodel.network.vpc.Vpc)4 ArrayList (java.util.ArrayList)4 AffinityGroupService (com.cloud.affinity.AffinityGroupService)3 ServiceResponse (com.cloud.api.response.ServiceResponse)3 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)3 IpAddress (com.cloud.network.IpAddress)3 PublicIpAddress (com.cloud.network.PublicIpAddress)3 Site2SiteVpnGateway (com.cloud.network.Site2SiteVpnGateway)3 ManagementService (com.cloud.server.ManagementService)3