use of com.cloud.legacymodel.network.Network.Service 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());
}
}
use of com.cloud.legacymodel.network.Network.Service 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;
}
use of com.cloud.legacymodel.network.Network.Service in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method getServices.
private Service[] getServices(final List<String> supportedServicesStr) {
final Service[] supportedServices;
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++;
}
return supportedServices;
}
use of com.cloud.legacymodel.network.Network.Service in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method checkCapabilityPerServiceProvider.
protected void checkCapabilityPerServiceProvider(final Set<Provider> providers, final Capability capability, final Service service) {
// TODO Shouldn't it fail it there are no providers?
if (providers != null) {
for (final Provider provider : providers) {
final NetworkElement element = _ntwkModel.getElementImplementingProvider(provider.getName());
final Map<Service, Map<Capability, String>> capabilities = element.getCapabilities();
if (capabilities != null && !capabilities.isEmpty()) {
final Map<Capability, String> connectivityCapabilities = capabilities.get(service);
if (connectivityCapabilities == null || connectivityCapabilities != null && !connectivityCapabilities.keySet().contains(capability)) {
throw new InvalidParameterValueException(String.format("Provider %s does not support %s capability.", provider.getName(), capability.getName()));
}
}
}
}
}
use of com.cloud.legacymodel.network.Network.Service in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method validateNtwkOffForNtwkInVpc.
@DB
@Override
public void validateNtwkOffForNtwkInVpc(final Long networkId, final long newNtwkOffId, final String newCidr, final String newNetworkDomain, final Vpc vpc, final String gateway, final Account networkOwner, final Long aclId) {
final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, newNtwkOffId);
if (guestNtwkOff == null) {
throw new InvalidParameterValueException("Can't find network offering by id specified");
}
if (networkId == null) {
// 1) Validate attributes that has to be passed in when create new
// guest network
validateNewVpcGuestNetwork(newCidr, gateway, networkOwner, vpc, newNetworkDomain);
}
// 2) validate network offering attributes
final List<Service> svcs = _ntwkModel.listNetworkOfferingServices(guestNtwkOff.getId());
validateNtwkOffForVpc(guestNtwkOff, svcs);
// 3) Check services/providers against VPC providers
final List<NetworkOfferingServiceMapVO> networkProviders = _ntwkOffServiceDao.listByNetworkOfferingId(guestNtwkOff.getId());
for (final NetworkOfferingServiceMapVO nSvcVO : networkProviders) {
final String pr = nSvcVO.getProvider();
final String service = nSvcVO.getService();
if (_vpcOffServiceDao.findByServiceProviderAndOfferingId(service, pr, vpc.getVpcOfferingId()) == null) {
throw new InvalidParameterValueException("Service/provider combination " + service + "/" + pr + " is not supported by VPC " + vpc);
}
}
// Internal LB can be supported on multiple VPC tiers
if (_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.Lb) && guestNtwkOff.getPublicLb()) {
final List<? extends Network> networks = getVpcNetworks(vpc.getId());
for (final Network network : networks) {
if (networkId != null && network.getId() == networkId.longValue()) {
// skip my own network
continue;
} else {
final NetworkOffering otherOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
// public lb support
if (_ntwkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb) && otherOff.getPublicLb() && guestNtwkOff.getId() != otherOff.getId()) {
throw new InvalidParameterValueException("Public LB service is already supported " + "by network " + network + " in VPC " + vpc);
}
}
}
}
// network offering
if (aclId != null && !_ntwkModel.areServicesSupportedByNetworkOffering(guestNtwkOff.getId(), Service.NetworkACL)) {
throw new InvalidParameterValueException("Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
}
}
Aggregations