Search in sources :

Example 1 with VpcOfferingJoinVO

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

the class VpcManagerImpl method listVpcOfferings.

@Override
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(ListVPCOfferingsCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    final Long id = cmd.getId();
    final String name = cmd.getVpcOffName();
    final String displayText = cmd.getDisplayText();
    final List<String> supportedServicesStr = cmd.getSupportedServices();
    final Boolean isDefault = cmd.getIsDefault();
    final String keyword = cmd.getKeyword();
    final String state = cmd.getState();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSizeVal = cmd.getPageSizeVal();
    final Long zoneId = cmd.getZoneId();
    final Filter searchFilter = new Filter(VpcOfferingJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
    searchFilter.addOrderBy(VpcOfferingJoinVO.class, "id", true);
    final SearchCriteria<VpcOfferingJoinVO> sc = vpcOfferingJoinDao.createSearchCriteria();
    if (keyword != null) {
        final SearchCriteria<VpcOfferingJoinVO> ssc = vpcOfferingJoinDao.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.LIKE, "%" + name + "%");
    }
    if (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (isDefault != null) {
        sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (zoneId != null) {
        SearchBuilder<VpcOfferingJoinVO> sb = vpcOfferingJoinDao.createSearchBuilder();
        sb.and("zoneId", sb.entity().getZoneId(), Op.FIND_IN_SET);
        sb.or("zId", sb.entity().getZoneId(), Op.NULL);
        sb.done();
        SearchCriteria<VpcOfferingJoinVO> zoneSC = sb.create();
        zoneSC.setParameters("zoneId", String.valueOf(zoneId));
        sc.addAnd("zoneId", SearchCriteria.Op.SC, zoneSC);
    }
    final List<VpcOfferingJoinVO> offerings = vpcOfferingJoinDao.search(sc, searchFilter);
    // TODO: Better approach
    if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(offerings)) {
        ListIterator<VpcOfferingJoinVO> it = offerings.listIterator();
        while (it.hasNext()) {
            VpcOfferingJoinVO offering = it.next();
            if (org.apache.commons.lang3.StringUtils.isNotEmpty(offering.getDomainId())) {
                boolean toRemove = true;
                String[] domainIdsArray = offering.getDomainId().split(",");
                for (String domainIdString : domainIdsArray) {
                    Long dId = Long.valueOf(domainIdString.trim());
                    if (domainDao.isChildDomain(dId, caller.getDomainId())) {
                        toRemove = false;
                        break;
                    }
                }
                if (toRemove) {
                    it.remove();
                }
            }
        }
    }
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    if (listBySupportedServices) {
        final List<VpcOfferingJoinVO> 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 VpcOfferingJoinVO offering : offerings) {
            if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) {
                supportedOfferings.add(offering);
            }
        }
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
        if (wPagination != null) {
            return new Pair<>(wPagination, supportedOfferings.size());
        }
        return new Pair<List<? extends VpcOffering>, Integer>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
        if (wPagination != null) {
            return new Pair<>(wPagination, offerings.size());
        }
        return new Pair<List<? extends VpcOffering>, Integer>(offerings, offerings.size());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) QueryService(org.apache.cloudstack.query.QueryService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NetworkService(com.cloud.network.NetworkService) ResourceLimitService(com.cloud.user.ResourceLimitService) ExecutorService(java.util.concurrent.ExecutorService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) VpcOfferingJoinVO(com.cloud.api.query.vo.VpcOfferingJoinVO) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Pair(com.cloud.utils.Pair)

Example 2 with VpcOfferingJoinVO

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

the class ApiResponseHelper method createVpcOfferingResponse.

@Override
public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) {
    if (!(offering instanceof VpcOfferingJoinVO)) {
        offering = ApiDBUtils.newVpcOfferingView(offering);
    }
    VpcOfferingResponse response = ApiDBUtils.newVpcOfferingResponse(offering);
    Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(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);
        serviceResponses.add(svcRsp);
    }
    response.setServices(serviceResponses);
    return response;
}
Also used : VpcOfferingResponse(org.apache.cloudstack.api.response.VpcOfferingResponse) 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) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) 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) VpcOfferingJoinVO(com.cloud.api.query.vo.VpcOfferingJoinVO) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with VpcOfferingJoinVO

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

the class VpcOfferingJoinDaoImpl method newVpcOfferingResponse.

@Override
public VpcOfferingResponse newVpcOfferingResponse(VpcOffering offering) {
    VpcOfferingResponse offeringResponse = new VpcOfferingResponse();
    offeringResponse.setId(offering.getUuid());
    offeringResponse.setName(offering.getName());
    offeringResponse.setDisplayText(offering.getDisplayText());
    offeringResponse.setIsDefault(offering.isDefault());
    offeringResponse.setState(offering.getState().name());
    offeringResponse.setSupportsDistributedRouter(offering.isSupportsDistributedRouter());
    offeringResponse.setSupportsRegionLevelVpc(offering.isOffersRegionLevelVPC());
    offeringResponse.setCreated(offering.getCreated());
    if (offering instanceof VpcOfferingJoinVO) {
        VpcOfferingJoinVO offeringJoinVO = (VpcOfferingJoinVO) offering;
        offeringResponse.setDomainId(offeringJoinVO.getDomainUuid());
        offeringResponse.setDomain(offeringJoinVO.getDomainPath());
        offeringResponse.setZoneId(offeringJoinVO.getZoneUuid());
        offeringResponse.setZone(offeringJoinVO.getZoneName());
    }
    offeringResponse.setObjectName("vpcoffering");
    return offeringResponse;
}
Also used : VpcOfferingResponse(org.apache.cloudstack.api.response.VpcOfferingResponse) VpcOfferingJoinVO(com.cloud.api.query.vo.VpcOfferingJoinVO)

Aggregations

VpcOfferingJoinVO (com.cloud.api.query.vo.VpcOfferingJoinVO)3 Service (com.cloud.network.Network.Service)2 ArrayList (java.util.ArrayList)2 AnnotationService (org.apache.cloudstack.annotation.AnnotationService)2 VpcOfferingResponse (org.apache.cloudstack.api.response.VpcOfferingResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)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 Account (com.cloud.user.Account)1 ResourceLimitService (com.cloud.user.ResourceLimitService)1 Pair (com.cloud.utils.Pair)1 Filter (com.cloud.utils.db.Filter)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1