Search in sources :

Example 6 with Service

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

the class NetworkModelImpl method isSharedNetworkWithoutServices.

@Override
public boolean isSharedNetworkWithoutServices(final long networkId) {
    final Network network = _networksDao.findById(networkId);
    if (network != null && network.getGuestType() != GuestType.Shared) {
        return false;
    }
    final List<Service> services = listNetworkOfferingServices(network.getNetworkOfferingId());
    if (services == null || services.isEmpty()) {
        return true;
    }
    return false;
}
Also used : Network(com.cloud.legacymodel.network.Network) Service(com.cloud.legacymodel.network.Network.Service)

Example 7 with Service

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

the class NetworkModelImpl method areServicesEnabledInZone.

@Override
public boolean areServicesEnabledInZone(final long zoneId, final NetworkOffering offering, final List<Service> services) {
    final long physicalNtwkId = findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
    boolean result = true;
    final List<String> checkedProvider = new ArrayList<>();
    for (final Service service : services) {
        // get all the providers, and check if each provider is enabled
        final List<String> providerNames = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), service);
        for (final String providerName : providerNames) {
            if (!checkedProvider.contains(providerName)) {
                result = result && isProviderEnabledInPhysicalNetwork(physicalNtwkId, providerName);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service)

Example 8 with Service

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

the class NetworkModelImpl method getProviderServicesMap.

Map<Provider, Set<Service>> getProviderServicesMap(final long networkId) {
    final Map<Provider, Set<Service>> map = new HashMap<>();
    final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (final NetworkServiceMapVO nsm : nsms) {
        Set<Service> services = map.get(Provider.getProvider(nsm.getProvider()));
        if (services == null) {
            services = new HashSet<>();
        }
        services.add(Service.getService(nsm.getService()));
        map.put(Provider.getProvider(nsm.getProvider()), services);
    }
    return map;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Service(com.cloud.legacymodel.network.Network.Service) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Example 9 with Service

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

the class VpcManagerImpl method getServiceSetMap.

private Map<Service, Set<Provider>> getServiceSetMap(final List<Service> serviceToAdd) {
    final Map<Service, Set<Provider>> svcProviderMap = new HashMap<>();
    final Set<Provider> defaultProviders = new HashSet<>();
    defaultProviders.add(Provider.VPCVirtualRouter);
    for (final Service svc : serviceToAdd) {
        if (svc == Service.Lb) {
            final Set<Provider> lbProviders = new HashSet<>();
            lbProviders.add(Provider.VPCVirtualRouter);
            svcProviderMap.put(svc, lbProviders);
        } else {
            svcProviderMap.put(svc, defaultProviders);
        }
    }
    return svcProviderMap;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) 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) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) HashSet(java.util.HashSet)

Example 10 with Service

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

the class VpcManagerImpl method listVpcs.

@Override
public Pair<List<? extends Vpc>, Integer> listVpcs(final Long id, final String vpcName, final String displayText, final List<String> supportedServicesStr, final String cidr, final Long vpcOffId, final String state, final String accountName, Long domainId, final String keyword, final Long startIndex, final Long pageSizeVal, final Long zoneId, Boolean isRecursive, final Boolean listAll, final Boolean restartRequired, final Map<String, String> tags, final Long projectId, final Boolean display, final String complianceStatus) {
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(VpcVO.class, "created", false, null, null);
    final SearchBuilder<VpcVO> sb = _vpcDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("displayText", sb.entity().getDisplayText(), SearchCriteria.Op.LIKE);
    sb.and("vpcOfferingId", sb.entity().getVpcOfferingId(), SearchCriteria.Op.EQ);
    sb.and("zoneId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("restartRequired", sb.entity().isRestartRequired(), SearchCriteria.Op.EQ);
    sb.and("cidr", sb.entity().getCidr(), SearchCriteria.Op.EQ);
    sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
    sb.and("complianceStatus", sb.entity().getComplianceStatus(), SearchCriteria.Op.EQ);
    if (tags != null && !tags.isEmpty()) {
        final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < tags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    // now set the SC criteria...
    final SearchCriteria<VpcVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (keyword != null) {
        final SearchCriteria<VpcVO> ssc = _vpcDao.createSearchCriteria();
        ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (vpcName != null) {
        sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + vpcName + "%");
    }
    if (displayText != null) {
        sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
    }
    if (tags != null && !tags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Vpc.toString());
        for (final Map.Entry<String, String> entry : tags.entrySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
            count++;
        }
    }
    if (display != null) {
        sc.setParameters("display", display);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (vpcOffId != null) {
        sc.addAnd("vpcOfferingId", SearchCriteria.Op.EQ, vpcOffId);
    }
    if (zoneId != null) {
        sc.addAnd("zoneId", SearchCriteria.Op.EQ, zoneId);
    }
    if (state != null) {
        sc.addAnd("state", SearchCriteria.Op.EQ, state);
    }
    if (cidr != null) {
        sc.addAnd("cidr", SearchCriteria.Op.EQ, cidr);
    }
    if (restartRequired != null) {
        sc.addAnd("restartRequired", SearchCriteria.Op.EQ, restartRequired);
    }
    if (complianceStatus != null) {
        sc.addAnd("complianceStatus", SearchCriteria.Op.EQ, complianceStatus);
    }
    final List<VpcVO> vpcs = _vpcDao.search(sc, searchFilter);
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !vpcs.isEmpty();
    if (listBySupportedServices) {
        final List<VpcVO> supportedVpcs = new ArrayList<>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = getServices(supportedServicesStr);
        }
        for (final VpcVO vpc : vpcs) {
            if (areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), supportedServices)) {
                supportedVpcs.add(vpc);
            }
        }
        final List<? extends Vpc> wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<>(wPagination, supportedVpcs.size());
            return listWPagination;
        }
        return new Pair<>(supportedVpcs, supportedVpcs.size());
    } else {
        final List<? extends Vpc> wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<>(wPagination, vpcs.size());
            return listWPagination;
        }
        return new Pair<>(vpcs, vpcs.size());
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) ArrayList(java.util.ArrayList) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.legacymodel.utils.Pair) Ternary(com.cloud.legacymodel.utils.Ternary) 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) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) 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