Search in sources :

Example 41 with Service

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

the class VpcManagerImpl method validateNtwkOffForNtwkInVpc.

@DB
@Override
public void validateNtwkOffForNtwkInVpc(final Long networkId, final long newNtwkOffId, final String newCidr, final String newNetworkDomain, final Vpc vpc, final String gateway, final Account networkOwner, final Long aclId) {
    final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId);
    if (guestNtwkOff == null) {
        throw new InvalidParameterValueException("Can't find network offering by id specified");
    }
    if (networkId == null) {
        // 1) Validate attributes that has to be passed in when create new
        // guest network
        validateNewVpcGuestNetwork(newCidr, gateway, networkOwner, vpc, newNetworkDomain);
    }
    // 2) validate network offering attributes
    final List<Service> svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId());
    validateNtwkOffForVpc(guestNtwkOff, svcs);
    // 3) Check services/providers against VPC providers
    final List<NetworkOfferingServiceMapVO> networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId());
    for (final NetworkOfferingServiceMapVO nSvcVO : networkProviders) {
        final String pr = nSvcVO.getProvider();
        final String service = nSvcVO.getService();
        if (_vpcOffServiceDao.findByServiceProviderAndOfferingId(service, pr, vpc.getVpcOfferingId()) == null) {
            throw new InvalidParameterValueException("Service/provider combination " + service + "/" + pr + " is not supported by VPC " + vpc);
        }
    }
    // Internal LB can be supported on multiple VPC tiers
    if (_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.Lb) && guestNtwkOff.getPublicLb()) {
        final List<? extends Network> networks = getVpcNetworks(vpc.getId());
        for (final Network network : networks) {
            if (networkId != null && network.getId() == networkId.longValue()) {
                // skip my own network
                continue;
            } else {
                final NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
                // public lb support
                if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.getPublicLb() && guestNtwkOff.getId() != otherOff.getId()) {
                    throw new InvalidParameterValueException("Public LB service is already supported " + "by network " + network + " in VPC " + vpc);
                }
            }
        }
    }
    // network offering
    if (aclId != null && !_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
        throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
    }
}
Also used : NetworkOfferingServiceMapVO(com.cloud.offerings.NetworkOfferingServiceMapVO) NetworkOffering(com.cloud.offering.NetworkOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NetworkService(com.cloud.network.NetworkService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) DB(com.cloud.utils.db.DB)

Example 42 with Service

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

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.network.Network.Capability) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NetworkService(com.cloud.network.NetworkService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) Map(java.util.Map) HashMap(java.util.HashMap) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider)

Example 43 with Service

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

the class VirtualRouterElementTest method mockMgrs.

/**
     * @param networks
     * @param offerings
     * @throws ConcurrentOperationException
     */
private void mockMgrs() throws ConcurrentOperationException {
    final Service service = Service.Connectivity;
    testNetwork.setState(Network.State.Implementing);
    testNetwork.setTrafficType(TrafficType.Guest);
    when(_networkMdl.isProviderEnabledInPhysicalNetwork(0L, "VirtualRouter")).thenReturn(true);
    when(_networkMdl.isProviderSupportServiceInNetwork(testNetwork.getId(), service, Network.Provider.VirtualRouter)).thenReturn(true);
    when(_networkMdl.isProviderForNetwork(Network.Provider.VirtualRouter, 0L)).thenReturn(true);
    when(testVMProfile.getType()).thenReturn(VirtualMachine.Type.User);
    when(testVMProfile.getHypervisorType()).thenReturn(HypervisorType.XenServer);
    final List<NetworkVO> networks = new ArrayList<NetworkVO>(1);
    networks.add(testNetwork);
    final List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(1);
    offerings.add(testOffering);
    doReturn(offerings).when(_networkModel).getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
    doReturn(networks).when(_networkMgr).setupNetwork(any(Account.class), any(NetworkOffering.class), any(DeploymentPlan.class), any(String.class), any(String.class), anyBoolean());
    // being anti-social and testing my own case first
    doReturn(HypervisorType.XenServer).when(_resourceMgr).getDefaultHypervisor(anyLong());
    doReturn(new AccountVO()).when(_accountMgr).getAccount(testNetwork.getAccountId());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) AccountVO(com.cloud.user.AccountVO)

Example 44 with Service

use of com.cloud.network.Network.Service 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) HashSet(java.util.HashSet) Provider(com.cloud.network.Network.Provider)

Example 45 with Service

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

the class InternalLbElementTest method verifyApplyIps.

//TEST FOR applyIps METHOD
@Test
public void verifyApplyIps() throws ResourceUnavailableException {
    List<PublicIp> ips = new ArrayList<PublicIp>();
    boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>());
    assertTrue("Wrong value is returned by applyIps method", result);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) Test(org.junit.Test)

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