Search in sources :

Example 31 with Service

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

the class NiciraNvpElementTest method applyIpTest.

@Test
public void applyIpTest() throws ResourceUnavailableException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final List<PublicIpAddress> ipAddresses = new ArrayList<>();
    final PublicIpAddress pipReleased = mock(PublicIpAddress.class);
    final PublicIpAddress pipAllocated = mock(PublicIpAddress.class);
    final Ip ipReleased = new Ip(NetUtils.ip2Long("42.10.10.10"));
    final Ip ipAllocated = new Ip(NetUtils.ip2Long("10.10.10.10"));
    when(pipAllocated.getState()).thenReturn(IpAddress.State.Allocated);
    when(pipAllocated.getAddress()).thenReturn(ipAllocated);
    when(pipAllocated.getNetmask()).thenReturn("255.255.255.0");
    when(pipReleased.getState()).thenReturn(IpAddress.State.Releasing);
    when(pipReleased.getAddress()).thenReturn(ipReleased);
    when(pipReleased.getNetmask()).thenReturn("255.255.255.0");
    ipAddresses.add(pipAllocated);
    ipAddresses.add(pipReleased);
    final Set<Service> services = new HashSet<>();
    services.add(Service.SourceNat);
    services.add(Service.StaticNat);
    services.add(Service.PortForwarding);
    final List<NiciraNvpDeviceVO> deviceList = new ArrayList<>();
    final NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class);
    final NiciraNvpRouterMappingVO nnrmVO = mock(NiciraNvpRouterMappingVO.class);
    when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(nnrmVO);
    when(nnrmVO.getLogicalRouterUuid()).thenReturn("abcde");
    when(nndVO.getHostId()).thenReturn(NETWORK_ID);
    final HostVO hvo = mock(HostVO.class);
    when(hvo.getId()).thenReturn(NETWORK_ID);
    when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde");
    when(hostDao.findById(NETWORK_ID)).thenReturn(hvo);
    deviceList.add(nndVO);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(deviceList);
    final ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NETWORK_ID), any(ConfigurePublicIpsOnLogicalRouterCommand.class))).thenReturn(answer);
    assertTrue(element.applyIps(network, ipAddresses, services));
    verify(agentManager, atLeast(1)).easySend(eq(NETWORK_ID), argThat(new ArgumentMatcher<ConfigurePublicIpsOnLogicalRouterCommand>() {

        @Override
        public boolean matches(final Object argument) {
            final ConfigurePublicIpsOnLogicalRouterCommand command = (ConfigurePublicIpsOnLogicalRouterCommand) argument;
            if (command.getPublicCidrs().size() == 1) {
                return true;
            }
            return false;
        }
    }));
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Ip(com.cloud.legacymodel.network.Ip) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) HostVO(com.cloud.host.HostVO) PublicIpAddress(com.cloud.network.PublicIpAddress) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) Network(com.cloud.legacymodel.network.Network) ArgumentMatcher(org.mockito.ArgumentMatcher) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with Service

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

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
    final VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setState(vpc.getState().name());
    final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
        response.setVpcOfferingName(voff.getName());
        response.setVpcOfferingDisplayText(voff.getDisplayText());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setRedundantRouter(vpc.isRedundant());
    response.setSourceNatList(vpc.getSourceNatList());
    response.setSyslogServerList(vpc.getSyslogServerList());
    response.setAdvertInterval(vpc.getAdvertInterval());
    response.setAdvertMethod(vpc.getAdvertMethod());
    response.setComplianceStatus(vpc.getComplianceStatus());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
    final List<NetworkResponse> networkResponses = new ArrayList<>();
    final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (final Network network : networks) {
        final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    final DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setNetworks(networkResponses);
    response.setServices(serviceResponses);
    populateOwner(response, vpc);
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        if (tagResponse != null) {
            tagResponses.add(tagResponse);
        }
    }
    response.setTags(tagResponses);
    response.setObjectName("vpc");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) ServiceResponse(com.cloud.api.response.ServiceResponse) DataCenter(com.cloud.legacymodel.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(com.cloud.api.response.VpcResponse) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse)

Example 33 with Service

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

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(final NetworkOffering offering) {
    final 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());
    final Long so;
    if (offering.getServiceOfferingId() != null) {
        so = offering.getServiceOfferingId();
    } else {
        so = ApiDBUtils.findDefaultRouterServiceOffering();
    }
    if (so != null) {
        final ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingById(so);
        if (serviceOffering != null) {
            response.setServiceOfferingId(serviceOffering.getUuid());
            response.setServiceOfferingName(serviceOffering.getName());
        }
    }
    final ServiceOffering secondaryServiceOffering = this._serviceOfferingDao.findById(offering.getSecondaryServiceOfferingId());
    if (secondaryServiceOffering != null) {
        response.setSecondaryServiceOfferingId(secondaryServiceOffering.getUuid());
        response.setSecondaryServiceOfferingName(secondaryServiceOffering.getName());
    }
    if (offering.getGuestType() != null) {
        response.setGuestIpType(offering.getGuestType().toString());
    }
    response.setState(offering.getState().name());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
    final List<ServiceResponse> serviceResponses = new ArrayList<>();
    for (final Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
        final Service service = entry.getKey();
        final Set<Provider> srvc_providers = entry.getValue();
        final ServiceResponse svcRsp = new ServiceResponse();
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        svcRsp.setName(service.getName());
        final List<ProviderResponse> providers = getProviderResponses(srvc_providers);
        svcRsp.setProviders(providers);
        if (Service.Lb == service) {
            final List<CapabilityResponse> lbCapResponse = new ArrayList<>();
            final CapabilityResponse lbIsoaltion = new CapabilityResponse();
            lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
            lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            final CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.getElasticLb() ? "true" : "false");
            lbCapResponse.add(eLb);
            final 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) {
            final List<CapabilityResponse> capabilities = new ArrayList<>();
            final CapabilityResponse sharedSourceNat = new CapabilityResponse();
            sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
            sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            final 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) {
            final List<CapabilityResponse> staticNatCapResponse = new ArrayList<>();
            final CapabilityResponse eIp = new CapabilityResponse();
            eIp.setName(Capability.ElasticIp.getName());
            eIp.setValue(offering.getElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            final 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(this._configMgr.isOfferingForVpc(offering));
    response.setServices(serviceResponses);
    // set network offering details
    final Map<Detail, String> details = this._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) VirtualRouterProviderResponse(com.cloud.api.response.VirtualRouterProviderResponse) ProviderResponse(com.cloud.api.response.ProviderResponse) NetworkOfferingResponse(com.cloud.api.response.NetworkOfferingResponse) ServiceOffering(com.cloud.offering.ServiceOffering) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) CapabilityResponse(com.cloud.api.response.CapabilityResponse) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.legacymodel.network.Network.Provider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) ServiceResponse(com.cloud.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 34 with Service

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

the class NetworkModelImpl method getProviderToIpList.

@Override
public Map<Provider, ArrayList<PublicIpAddress>> getProviderToIpList(final Network network, final Map<PublicIpAddress, Set<Service>> ipToServices) {
    final NetworkOffering offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (!offering.isConserveMode()) {
        for (final PublicIpAddress ip : ipToServices.keySet()) {
            final Set<Service> services = new HashSet<>();
            services.addAll(ipToServices.get(ip));
            if (services != null && services.contains(Service.Firewall)) {
                services.remove(Service.Firewall);
            }
        }
    }
    final Map<Service, Set<PublicIpAddress>> serviceToIps = new HashMap<>();
    for (final PublicIpAddress ip : ipToServices.keySet()) {
        for (final Service service : ipToServices.get(ip)) {
            Set<PublicIpAddress> ips = serviceToIps.get(service);
            if (ips == null) {
                ips = new HashSet<>();
            }
            ips.add(ip);
            serviceToIps.put(service, ips);
        }
    }
    // TODO Check different provider for same IP
    final Map<Provider, Set<Service>> providerToServices = getProviderServicesMap(network.getId());
    final Map<Provider, ArrayList<PublicIpAddress>> providerToIpList = new HashMap<>();
    for (final Provider provider : providerToServices.keySet()) {
        if (!(getElementImplementingProvider(provider.getName()) instanceof IpDeployingRequester)) {
            continue;
        }
        final Set<Service> services = providerToServices.get(provider);
        final ArrayList<PublicIpAddress> ipList = new ArrayList<>();
        final Set<PublicIpAddress> ipSet = new HashSet<>();
        for (final Service service : services) {
            final Set<PublicIpAddress> serviceIps = serviceToIps.get(service);
            if (serviceIps == null || serviceIps.isEmpty()) {
                continue;
            }
            ipSet.addAll(serviceIps);
        }
        final Set<PublicIpAddress> sourceNatIps = serviceToIps.get(Service.SourceNat);
        if (sourceNatIps != null && !sourceNatIps.isEmpty()) {
            ipList.addAll(0, sourceNatIps);
            ipSet.removeAll(sourceNatIps);
        }
        ipList.addAll(ipSet);
        providerToIpList.put(provider, ipList);
    }
    return providerToIpList;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) IpDeployingRequester(com.cloud.network.element.IpDeployingRequester) NetworkOffering(com.cloud.offering.NetworkOffering) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) HashSet(java.util.HashSet)

Example 35 with Service

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

the class NetworkModelImpl 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 = 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) Service(com.cloud.legacymodel.network.Network.Service) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Service (com.cloud.legacymodel.network.Network.Service)62 HashMap (java.util.HashMap)31 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)29 Provider (com.cloud.legacymodel.network.Network.Provider)29 ArrayList (java.util.ArrayList)29 HashSet (java.util.HashSet)29 ResourceLimitService (com.cloud.user.ResourceLimitService)27 Set (java.util.Set)24 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)18 Map (java.util.Map)15 Network (com.cloud.legacymodel.network.Network)14 NetworkElement (com.cloud.network.element.NetworkElement)14 NetworkService (com.cloud.network.NetworkService)13 SortedSet (java.util.SortedSet)12 Capability (com.cloud.legacymodel.network.Network.Capability)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 Test (org.junit.Test)11 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)10 ExecutorService (java.util.concurrent.ExecutorService)10 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)9