Search in sources :

Example 1 with NetworkOfferingJoinVO

use of com.cloud.api.query.vo.NetworkOfferingJoinVO in project cloudstack by apache.

the class NetworkOfferingJoinDaoImpl method newNetworkOfferingResponse.

@Override
public NetworkOfferingResponse newNetworkOfferingResponse(NetworkOffering offering) {
    NetworkOfferingResponse networkOfferingResponse = new NetworkOfferingResponse();
    networkOfferingResponse.setId(offering.getUuid());
    networkOfferingResponse.setName(offering.getName());
    networkOfferingResponse.setDisplayText(offering.getDisplayText());
    networkOfferingResponse.setTags(offering.getTags());
    networkOfferingResponse.setTrafficType(offering.getTrafficType().toString());
    networkOfferingResponse.setIsDefault(offering.isDefault());
    networkOfferingResponse.setSpecifyVlan(offering.isSpecifyVlan());
    networkOfferingResponse.setConserveMode(offering.isConserveMode());
    networkOfferingResponse.setSpecifyIpRanges(offering.isSpecifyIpRanges());
    networkOfferingResponse.setAvailability(offering.getAvailability().toString());
    networkOfferingResponse.setIsPersistent(offering.isPersistent());
    networkOfferingResponse.setEgressDefaultPolicy(offering.isEgressDefaultPolicy());
    networkOfferingResponse.setConcurrentConnections(offering.getConcurrentConnections());
    networkOfferingResponse.setSupportsStrechedL2Subnet(offering.isSupportingStrechedL2());
    networkOfferingResponse.setSupportsPublicAccess(offering.isSupportingPublicAccess());
    networkOfferingResponse.setCreated(offering.getCreated());
    if (offering.getGuestType() != null) {
        networkOfferingResponse.setGuestIpType(offering.getGuestType().toString());
    }
    networkOfferingResponse.setState(offering.getState().name());
    if (offering instanceof NetworkOfferingJoinVO) {
        networkOfferingResponse.setDomainId(((NetworkOfferingJoinVO) offering).getDomainUuid());
        networkOfferingResponse.setDomain(((NetworkOfferingJoinVO) offering).getDomainPath());
        networkOfferingResponse.setZoneId(((NetworkOfferingJoinVO) offering).getZoneUuid());
        networkOfferingResponse.setZone(((NetworkOfferingJoinVO) offering).getZoneName());
    }
    networkOfferingResponse.setObjectName("networkoffering");
    return networkOfferingResponse;
}
Also used : NetworkOfferingResponse(org.apache.cloudstack.api.response.NetworkOfferingResponse) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO)

Example 2 with NetworkOfferingJoinVO

use of com.cloud.api.query.vo.NetworkOfferingJoinVO in project cloudstack by apache.

the class KubernetesClusterManagerImpl method isKubernetesServiceNetworkOfferingConfigured.

private boolean isKubernetesServiceNetworkOfferingConfigured(DataCenter zone) {
    // Check network offering
    String networkOfferingName = KubernetesClusterNetworkOffering.value();
    if (networkOfferingName == null || networkOfferingName.isEmpty()) {
        LOGGER.warn(String.format("Global setting %s is empty. Admin has not yet specified the network offering to be used for provisioning isolated network for the cluster", KubernetesClusterNetworkOffering.key()));
        return false;
    }
    NetworkOfferingVO networkOffering = networkOfferingDao.findByUniqueName(networkOfferingName);
    if (networkOffering == null) {
        LOGGER.warn(String.format("Unable to find the network offering %s to be used for provisioning Kubernetes cluster", networkOfferingName));
        return false;
    }
    if (networkOffering.getState() == NetworkOffering.State.Disabled) {
        LOGGER.warn(String.format("Network offering ID: %s is not enabled", networkOffering.getUuid()));
        return false;
    }
    List<String> services = networkOfferingServiceMapDao.listServicesForNetworkOffering(networkOffering.getId());
    if (services == null || services.isEmpty() || !services.contains("SourceNat")) {
        LOGGER.warn(String.format("Network offering ID: %s does not have necessary services to provision Kubernetes cluster", networkOffering.getUuid()));
        return false;
    }
    if (!networkOffering.isEgressDefaultPolicy()) {
        LOGGER.warn(String.format("Network offering ID: %s has egress default policy turned off should be on to provision Kubernetes cluster", networkOffering.getUuid()));
        return false;
    }
    boolean offeringAvailableForZone = false;
    List<NetworkOfferingJoinVO> networkOfferingJoinVOs = networkOfferingJoinDao.findByZoneId(zone.getId(), true);
    for (NetworkOfferingJoinVO networkOfferingJoinVO : networkOfferingJoinVOs) {
        if (networkOffering.getId() == networkOfferingJoinVO.getId()) {
            offeringAvailableForZone = true;
            break;
        }
    }
    if (!offeringAvailableForZone) {
        LOGGER.warn(String.format("Network offering ID: %s is not available for zone ID: %s", networkOffering.getUuid(), zone.getUuid()));
        return false;
    }
    long physicalNetworkId = networkModel.findPhysicalNetworkId(zone.getId(), networkOffering.getTags(), networkOffering.getTrafficType());
    PhysicalNetwork physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        LOGGER.warn(String.format("Unable to find physical network with tag: %s", networkOffering.getTags()));
        return false;
    }
    return true;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 3 with NetworkOfferingJoinVO

use of com.cloud.api.query.vo.NetworkOfferingJoinVO in project cloudstack by apache.

the class ConfigurationManagerImpl method searchForNetworkOfferings.

@Override
public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(final ListNetworkOfferingsCmd cmd) {
    final Filter searchFilter = new Filter(NetworkOfferingJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
    searchFilter.addOrderBy(NetworkOfferingJoinVO.class, "id", true);
    final Account caller = CallContext.current().getCallingAccount();
    final SearchCriteria<NetworkOfferingJoinVO> sc = networkOfferingJoinDao.createSearchCriteria();
    final Long id = cmd.getId();
    final Object name = cmd.getNetworkOfferingName();
    final Object displayText = cmd.getDisplayText();
    final Object trafficType = cmd.getTrafficType();
    final Object isDefault = cmd.getIsDefault();
    final Object specifyVlan = cmd.getSpecifyVlan();
    final Object availability = cmd.getAvailability();
    final Object state = cmd.getState();
    final Long domainId = cmd.getDomainId();
    final Long zoneId = cmd.getZoneId();
    DataCenter zone = null;
    final Long networkId = cmd.getNetworkId();
    final String guestIpType = cmd.getGuestIpType();
    final List<String> supportedServicesStr = cmd.getSupportedServices();
    final Object specifyIpRanges = cmd.getSpecifyIpRanges();
    final String tags = cmd.getTags();
    final Boolean isTagged = cmd.isTagged();
    final Boolean forVpc = cmd.getForVpc();
    if (domainId != null) {
        Domain domain = _entityMgr.findById(Domain.class, domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Unable to find the domain by id=" + domainId);
        }
        if (!_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
            throw new InvalidParameterValueException(String.format("Unable to list network offerings for domain: %s as caller does not have access for it", domain.getUuid()));
        }
    }
    if (zoneId != null) {
        zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId);
        }
    }
    final Object keyword = cmd.getKeyword();
    if (keyword != null) {
        final SearchCriteria<NetworkOfferingJoinVO> ssc = networkOfferingJoinDao.createSearchCriteria();
        ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    }
    if (guestIpType != null) {
        sc.addAnd("guestType", SearchCriteria.Op.EQ, guestIpType);
    }
    if (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (trafficType != null) {
        sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType);
    }
    if (isDefault != null) {
        sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
    }
    // only root admin can list network offering with specifyVlan = true
    if (specifyVlan != null) {
        sc.addAnd("specifyVlan", SearchCriteria.Op.EQ, specifyVlan);
    }
    if (availability != null) {
        sc.addAnd("availability", SearchCriteria.Op.EQ, availability);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (specifyIpRanges != null) {
        sc.addAnd("specifyIpRanges", SearchCriteria.Op.EQ, specifyIpRanges);
    }
    if (zone != null) {
        if (zone.getNetworkType() == NetworkType.Basic) {
            // basic zone, and shouldn't display networkOfferings
            return new Pair<List<? extends NetworkOffering>, Integer>(new ArrayList<NetworkOffering>(), 0);
        }
    }
    // Don't return system network offerings to the user
    sc.addAnd("systemOnly", SearchCriteria.Op.EQ, false);
    // if networkId is specified, list offerings available for upgrade only
    // (for this network)
    Network network = null;
    if (networkId != null) {
        // check if network exists and the caller can operate with it
        network = _networkModel.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find the network by id=" + networkId);
        }
        // Don't allow to update system network
        final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
        if (offering.isSystemOnly()) {
            throw new InvalidParameterValueException("Can't update system networks");
        }
        _accountMgr.checkAccess(caller, null, true, network);
        final List<Long> offeringIds = _networkModel.listNetworkOfferingsForUpgrade(networkId);
        if (!offeringIds.isEmpty()) {
            sc.addAnd("id", SearchCriteria.Op.IN, offeringIds.toArray());
        } else {
            return new Pair<List<? extends NetworkOffering>, Integer>(new ArrayList<NetworkOffering>(), 0);
        }
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (tags != null) {
        sc.addAnd("tags", SearchCriteria.Op.EQ, tags);
    }
    if (isTagged != null) {
        if (isTagged) {
            sc.addAnd("tags", SearchCriteria.Op.NNULL);
        } else {
            sc.addAnd("tags", SearchCriteria.Op.NULL);
        }
    }
    if (zoneId != null) {
        SearchBuilder<NetworkOfferingJoinVO> sb = networkOfferingJoinDao.createSearchBuilder();
        sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.FIND_IN_SET);
        sb.or("zId", sb.entity().getZoneId(), SearchCriteria.Op.NULL);
        sb.done();
        SearchCriteria<NetworkOfferingJoinVO> zoneSC = sb.create();
        zoneSC.setParameters("zoneId", String.valueOf(zoneId));
        sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
    }
    final List<NetworkOfferingJoinVO> offerings = networkOfferingJoinDao.search(sc, searchFilter);
    // Remove offerings that are not associated with caller's domain or domainId passed
    if ((caller.getType() != Account.ACCOUNT_TYPE_ADMIN || domainId != null) && CollectionUtils.isNotEmpty(offerings)) {
        ListIterator<NetworkOfferingJoinVO> it = offerings.listIterator();
        while (it.hasNext()) {
            NetworkOfferingJoinVO offering = it.next();
            if (StringUtils.isNotEmpty(offering.getDomainId())) {
                boolean toRemove = false;
                String[] domainIdsArray = offering.getDomainId().split(",");
                for (String domainIdString : domainIdsArray) {
                    Long dId = Long.valueOf(domainIdString.trim());
                    if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && !_domainDao.isChildDomain(dId, caller.getDomainId())) {
                        toRemove = true;
                        break;
                    }
                    if (domainId != null && !_domainDao.isChildDomain(dId, domainId)) {
                        toRemove = true;
                        break;
                    }
                }
                if (toRemove) {
                    it.remove();
                }
            }
        }
    }
    final Boolean sourceNatSupported = cmd.getSourceNatSupported();
    final List<String> pNtwkTags = new ArrayList<String>();
    boolean checkForTags = false;
    if (zone != null) {
        final List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
        if (pNtwks.size() > 1) {
            checkForTags = true;
            // go through tags
            for (final PhysicalNetworkVO pNtwk : pNtwks) {
                final List<String> pNtwkTag = pNtwk.getTags();
                if (pNtwkTag == null || pNtwkTag.isEmpty()) {
                    throw new CloudRuntimeException("Tags are not defined for physical network in the zone id=" + zoneId);
                }
                pNtwkTags.addAll(pNtwkTag);
            }
        }
    }
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    final boolean checkIfProvidersAreEnabled = zoneId != null;
    final boolean parseOfferings = listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null;
    if (parseOfferings) {
        final List<NetworkOfferingJoinVO> supportedOfferings = new ArrayList<>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = new Service[supportedServicesStr.size()];
            int i = 0;
            for (final String supportedServiceStr : supportedServicesStr) {
                final Service service = Service.getService(supportedServiceStr);
                if (service == null) {
                    throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
                } else {
                    supportedServices[i] = service;
                }
                i++;
            }
        }
        for (final NetworkOfferingJoinVO offering : offerings) {
            boolean addOffering = true;
            List<Service> checkForProviders = new ArrayList<Service>();
            if (checkForTags) {
                if (!pNtwkTags.contains(offering.getTags())) {
                    continue;
                }
            }
            if (listBySupportedServices) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), supportedServices);
            }
            if (checkIfProvidersAreEnabled) {
                if (supportedServices != null && supportedServices.length > 0) {
                    checkForProviders = Arrays.asList(supportedServices);
                } else {
                    checkForProviders = _networkModel.listNetworkOfferingServices(offering.getId());
                }
                addOffering = addOffering && _networkModel.areServicesEnabledInZone(zoneId, offering, checkForProviders);
            }
            if (sourceNatSupported != null) {
                addOffering = addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported;
            }
            if (forVpc != null) {
                addOffering = addOffering && offering.isForVpc() == forVpc.booleanValue();
            } else if (network != null) {
                addOffering = addOffering && offering.isForVpc() == (network.getVpcId() != null);
            }
            if (addOffering) {
                supportedOfferings.add(offering);
            }
        }
        // Now apply pagination
        final List<NetworkOfferingJoinVO> wPagination = com.cloud.utils.StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<List<? extends NetworkOffering>, Integer>(wPagination, supportedOfferings.size());
            return listWPagination;
        }
        return new Pair<List<? extends NetworkOffering>, Integer>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<NetworkOfferingJoinVO> wPagination = com.cloud.utils.StringUtils.applyPagination(offerings, cmd.getStartIndex(), cmd.getPageSizeVal());
        if (wPagination != null) {
            final Pair<List<? extends NetworkOffering>, Integer> listWPagination = new Pair<>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<List<? extends NetworkOffering>, Integer>(offerings, offerings.size());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) QueryService(org.apache.cloudstack.query.QueryService) NetworkService(com.cloud.network.NetworkService) ManagementService(com.cloud.server.ManagementService) ResourceLimitService(com.cloud.user.ResourceLimitService) AffinityGroupService(org.apache.cloudstack.affinity.AffinityGroupService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) DataCenter(com.cloud.dc.DataCenter) Filter(com.cloud.utils.db.Filter) Domain(com.cloud.domain.Domain)

Example 4 with NetworkOfferingJoinVO

use of com.cloud.api.query.vo.NetworkOfferingJoinVO in project cloudstack by apache.

the class ApiResponseHelper method createNetworkOfferingResponse.

@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
    if (!(offering instanceof NetworkOfferingJoinVO)) {
        offering = ApiDBUtils.newNetworkOfferingView(offering);
    }
    NetworkOfferingResponse response = ApiDBUtils.newNetworkOfferingResponse(offering);
    response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
    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());
        }
    }
    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.isDedicatedLB() ? "dedicated" : "shared");
            lbCapResponse.add(lbIsoaltion);
            CapabilityResponse eLb = new CapabilityResponse();
            eLb.setName(Capability.ElasticLb.getName());
            eLb.setValue(offering.isElasticLb() ? "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.isSharedSourceNat() ? "perzone" : "peraccount");
            capabilities.add(sharedSourceNat);
            CapabilityResponse redundantRouter = new CapabilityResponse();
            redundantRouter.setName(Capability.RedundantRouter.getName());
            redundantRouter.setValue(offering.isRedundantRouter() ? "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.isElasticIp() ? "true" : "false");
            staticNatCapResponse.add(eIp);
            CapabilityResponse associatePublicIp = new CapabilityResponse();
            associatePublicIp.setName(Capability.AssociatePublicIP.getName());
            associatePublicIp.setValue(offering.isAssociatePublicIP() ? "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.setHasAnnotation(annotationDao.hasAnnotations(offering.getUuid(), AnnotationService.EntityType.NETWORK_OFFERING.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    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) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) 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) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Detail(com.cloud.offering.NetworkOffering.Detail)

Example 5 with NetworkOfferingJoinVO

use of com.cloud.api.query.vo.NetworkOfferingJoinVO in project cloudstack by apache.

the class ConfigurationManagerTest method searchForNetworkOfferingsTest.

@Test
public void searchForNetworkOfferingsTest() {
    NetworkOfferingJoinVO forVpcOfferingJoinVO = new NetworkOfferingJoinVO();
    forVpcOfferingJoinVO.setForVpc(true);
    List<NetworkOfferingJoinVO> offerings = Arrays.asList(new NetworkOfferingJoinVO(), new NetworkOfferingJoinVO(), forVpcOfferingJoinVO);
    Mockito.when(networkOfferingJoinDao.createSearchCriteria()).thenReturn(Mockito.mock(SearchCriteria.class));
    Mockito.when(networkOfferingJoinDao.search(Mockito.any(SearchCriteria.class), Mockito.any(Filter.class))).thenReturn(offerings);
    ListNetworkOfferingsCmd cmd = Mockito.spy(ListNetworkOfferingsCmd.class);
    Mockito.when(cmd.getPageSize()).thenReturn(10);
    assertThat(configurationMgr.searchForNetworkOfferings(cmd).second(), is(3));
    Mockito.when(cmd.getForVpc()).thenReturn(Boolean.FALSE);
    assertThat(configurationMgr.searchForNetworkOfferings(cmd).second(), is(2));
}
Also used : Filter(com.cloud.utils.db.Filter) NetworkOfferingJoinVO(com.cloud.api.query.vo.NetworkOfferingJoinVO) ListNetworkOfferingsCmd(org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd) SearchCriteria(com.cloud.utils.db.SearchCriteria) Test(org.junit.Test)

Aggregations

NetworkOfferingJoinVO (com.cloud.api.query.vo.NetworkOfferingJoinVO)5 Service (com.cloud.network.Network.Service)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 Filter (com.cloud.utils.db.Filter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AnnotationService (org.apache.cloudstack.annotation.AnnotationService)2 NetworkOfferingResponse (org.apache.cloudstack.api.response.NetworkOfferingResponse)2 DataCenter (com.cloud.dc.DataCenter)1 Domain (com.cloud.domain.Domain)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Network (com.cloud.network.Network)1 Provider (com.cloud.network.Network.Provider)1 NetworkService (com.cloud.network.NetworkService)1 OvsProvider (com.cloud.network.OvsProvider)1 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)1 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 NetworkOffering (com.cloud.offering.NetworkOffering)1 Detail (com.cloud.offering.NetworkOffering.Detail)1