Search in sources :

Example 16 with Service

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

the class VpcManagerImpl method listVpcOfferings.

@Override
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List<String> supportedServicesStr, final Boolean isDefault, final String keyword, final String state, final Long startIndex, final Long pageSizeVal) {
    final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
    final SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
    if (keyword != null) {
        final SearchCriteria<VpcOfferingVO> ssc = _vpcOffDao.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);
    }
    final List<VpcOfferingVO> offerings = _vpcOffDao.search(sc, searchFilter);
    // filter by supported services
    final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
    if (listBySupportedServices) {
        final List<VpcOfferingVO> supportedOfferings = new ArrayList<VpcOfferingVO>();
        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 VpcOfferingVO offering : offerings) {
            if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) {
                supportedOfferings.add(offering);
            }
        }
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>(wPagination, supportedOfferings.size());
            return listWPagination;
        }
        return new Pair<List<? extends VpcOffering>, Integer>(supportedOfferings, supportedOfferings.size());
    } else {
        final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
        if (wPagination != null) {
            final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<List<? extends VpcOffering>, Integer>(offerings, offerings.size());
    }
}
Also used : ArrayList(java.util.ArrayList) 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) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 17 with Service

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

the class VpcManagerImpl method getVpcOffSvcProvidersMap.

@Override
public Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(final long vpcOffId) {
    final Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Service, Set<Provider>>();
    final List<VpcOfferingServiceMapVO> map = _vpcOffSvcMapDao.listByVpcOffId(vpcOffId);
    for (final VpcOfferingServiceMapVO instance : map) {
        final Service service = Service.getService(instance.getService());
        Set<Provider> providers;
        providers = serviceProviderMap.get(service);
        if (providers == null) {
            providers = new HashSet<Provider>();
        }
        providers.add(Provider.getProvider(instance.getProvider()));
        serviceProviderMap.put(service, providers);
    }
    return serviceProviderMap;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) 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) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider)

Example 18 with Service

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

the class VpcManagerImpl method configure.

@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    // configure default vpc offering
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCOfferingName) == null) {
                s_logger.debug("Creating default VPC offering " + VpcOffering.defaultVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.VPCVirtualRouter);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.defaultVPCOfferingName, VpcOffering.defaultVPCOfferingName, svcProviderMap, true, State.Enabled, null, false, false, false);
            }
            // configure default vpc offering with Netscaler as LB Provider
            if (_vpcOffDao.findByUniqueName(VpcOffering.defaultVPCNSOfferingName) == null) {
                s_logger.debug("Creating default VPC offering with Netscaler as LB Provider" + VpcOffering.defaultVPCNSOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.Netscaler);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.defaultVPCNSOfferingName, VpcOffering.defaultVPCNSOfferingName, svcProviderMap, false, State.Enabled, null, false, false, false);
            }
            if (_vpcOffDao.findByUniqueName(VpcOffering.redundantVPCOfferingName) == null) {
                s_logger.debug("Creating Redundant VPC offering " + VpcOffering.redundantVPCOfferingName);
                final Map<Service, Set<Provider>> svcProviderMap = new HashMap<Service, Set<Provider>>();
                final Set<Provider> defaultProviders = new HashSet<Provider>();
                defaultProviders.add(Provider.VPCVirtualRouter);
                for (final Service svc : getSupportedServices()) {
                    if (svc == Service.Lb) {
                        final Set<Provider> lbProviders = new HashSet<Provider>();
                        lbProviders.add(Provider.VPCVirtualRouter);
                        lbProviders.add(Provider.InternalLbVm);
                        svcProviderMap.put(svc, lbProviders);
                    } else {
                        svcProviderMap.put(svc, defaultProviders);
                    }
                }
                createVpcOffering(VpcOffering.redundantVPCOfferingName, VpcOffering.redundantVPCOfferingName, svcProviderMap, true, State.Enabled, null, false, false, true);
            }
        }
    });
    final Map<String, String> configs = _configDao.getConfiguration(params);
    final String value = configs.get(Config.VpcCleanupInterval.key());
    // 1 hour
    _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60);
    final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
    // max=3 is default
    _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3);
    IpAddressSearch = _ipAddressDao.createSearchBuilder();
    IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
    IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
    IpAddressSearch.and("vpcId", IpAddressSearch.entity().getVpcId(), Op.EQ);
    IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
    final SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
    virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
    IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
    IpAddressSearch.done();
    return true;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) TransactionStatus(com.cloud.utils.db.TransactionStatus) 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) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.network.Network.Provider) VlanVO(com.cloud.dc.VlanVO) Map(java.util.Map) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Example 19 with Service

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

the class VpcManagerImpl method validateConnectivtyServiceCapabilities.

private void validateConnectivtyServiceCapabilities(final Set<Provider> providers, final Map serviceCapabilitystList) {
    if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
        final Collection serviceCapabilityCollection = serviceCapabilitystList.values();
        final Iterator iter = serviceCapabilityCollection.iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
            Capability capability = null;
            final String svc = svcCapabilityMap.get(SERVICE);
            final String capabilityName = svcCapabilityMap.get(CAPABILITYTYPE);
            final String capabilityValue = svcCapabilityMap.get(CAPABILITYVALUE);
            if (capabilityName != null) {
                capability = Capability.getCapability(capabilityName);
            }
            if (capability == null || capabilityValue == null) {
                throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
            }
            final Service usedService = Service.getService(svc);
            checkCapabilityPerServiceProvider(providers, capability, usedService);
            if (!capabilityValue.equalsIgnoreCase(TRUE_VALUE) && !capabilityValue.equalsIgnoreCase(FALSE_VALUE)) {
                throw new InvalidParameterValueException("Invalid Capability value:" + capabilityValue + " specified.");
            }
        }
    }
}
Also used : Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) 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)

Example 20 with Service

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

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 Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<Long>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(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);
    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);
    }
    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<VpcVO>();
        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 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<List<? extends Vpc>, Integer>(wPagination, supportedVpcs.size());
            return listWPagination;
        }
        return new Pair<List<? extends Vpc>, Integer>(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<List<? extends Vpc>, Integer>(wPagination, vpcs.size());
            return listWPagination;
        }
        return new Pair<List<? extends Vpc>, Integer>(vpcs, vpcs.size());
    }
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) Ternary(com.cloud.utils.Ternary) 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) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) Map(java.util.Map) HashMap(java.util.HashMap)

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