Search in sources :

Example 6 with VpcOffering

use of com.cloud.legacymodel.network.vpc.VpcOffering 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 7 with VpcOffering

use of com.cloud.legacymodel.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.

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<>();
        Service[] supportedServices = null;
        if (listBySupportedServices) {
            supportedServices = getServices(supportedServicesStr);
        }
        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<>(wPagination, supportedOfferings.size());
            return listWPagination;
        }
        return new Pair<>(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<>(wPagination, offerings.size());
            return listWPagination;
        }
        return new Pair<>(offerings, offerings.size());
    }
}
Also used : ArrayList(java.util.ArrayList) 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) Filter(com.cloud.utils.db.Filter) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.legacymodel.utils.Pair)

Example 8 with VpcOffering

use of com.cloud.legacymodel.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method createVpcOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create = true)
public VpcOffering createVpcOffering(final String name, final String displayText, final List<String> supportedServices, final Map<String, List<String>> serviceProviders, final Map serviceCapabilitystList, final Long serviceOfferingId, final Long secondaryServiceOfferingId) {
    final Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<>();
    final Set<Network.Provider> defaultProviders = new HashSet<>();
    defaultProviders.add(Provider.VPCVirtualRouter);
    // Just here for 4.1, replaced by commit 836ce6c1 in newer versions
    final Set<Network.Provider> sdnProviders = new HashSet<>();
    sdnProviders.add(Provider.NiciraNvp);
    boolean firewallSvs = false;
    // populate the services first
    for (final String serviceName : supportedServices) {
        // validate if the service is supported
        final Service service = Network.Service.getService(serviceName);
        if (service == null || nonSupportedServices.contains(service)) {
            throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC");
        }
        if (service == Service.Connectivity) {
            s_logger.debug("Applying Connectivity workaround, setting provider to NiciraNvp");
            svcProviderMap.put(service, sdnProviders);
        } else {
            svcProviderMap.put(service, defaultProviders);
        }
        if (service == Service.NetworkACL) {
            firewallSvs = true;
        }
    }
    if (!firewallSvs) {
        s_logger.debug("Automatically adding network ACL service to the list of VPC services");
        svcProviderMap.put(Service.NetworkACL, defaultProviders);
    }
    if (serviceProviders != null) {
        for (final Entry<String, List<String>> serviceEntry : serviceProviders.entrySet()) {
            final Network.Service service = Network.Service.getService(serviceEntry.getKey());
            if (svcProviderMap.containsKey(service)) {
                final Set<Provider> providers = new HashSet<>();
                for (final String prvNameStr : serviceEntry.getValue()) {
                    // check if provider is supported
                    final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
                    if (provider == null) {
                        throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
                    }
                    providers.add(provider);
                }
                svcProviderMap.put(service, providers);
            } else {
                throw new InvalidParameterValueException("Service " + serviceEntry.getKey() + " is not enabled for the network " + "offering, can't add a provider to it");
            }
        }
    }
    validateConnectivtyServiceCapabilities(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList);
    final boolean redundantRouter = isVpcOfferingRedundantRouter(serviceCapabilitystList);
    final VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, serviceOfferingId, secondaryServiceOfferingId, redundantRouter);
    CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
    return offering;
}
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) Service(com.cloud.legacymodel.network.Network.Service) VpcProvider(com.cloud.network.element.VpcProvider) Provider(com.cloud.legacymodel.network.Network.Provider) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Provider(com.cloud.legacymodel.network.Network.Provider) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VpcOffering(com.cloud.legacymodel.network.vpc.VpcOffering) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

VpcOffering (com.cloud.legacymodel.network.vpc.VpcOffering)8 ArrayList (java.util.ArrayList)4 ServerApiException (com.cloud.api.ServerApiException)3 VpcOfferingResponse (com.cloud.api.response.VpcOfferingResponse)3 Service (com.cloud.legacymodel.network.Network.Service)3 List (java.util.List)3 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)2 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 Network (com.cloud.legacymodel.network.Network)2 NetworkService (com.cloud.network.NetworkService)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 ResourceLimitService (com.cloud.user.ResourceLimitService)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ListResponse (com.cloud.api.response.ListResponse)1 NetworkResponse (com.cloud.api.response.NetworkResponse)1