mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-749: External device support for VPC. VPC offering can be created with providers other than VPCVirtualRouter
This commit is contained in:
parent
4d573ddd1b
commit
836ce6c11a
@ -138,6 +138,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
|
||||
// NiciraNvp is not an "External" provider, otherwise we get in trouble with NetworkServiceImpl.providersConfiguredForExternalNetworking
|
||||
public static final Provider NiciraNvp = new Provider("NiciraNvp", false);
|
||||
public static final Provider MidokuraMidonet = new Provider("MidokuraMidonet", true);
|
||||
public static final Provider VPCNetscaler = new Provider("VPCNetscaler", true);
|
||||
|
||||
private String name;
|
||||
private boolean isExternal;
|
||||
|
||||
@ -41,7 +41,7 @@ public interface VpcService {
|
||||
|
||||
public VpcOffering getVpcOffering(long vpcOfferingId);
|
||||
|
||||
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices);
|
||||
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices, Map<String, List<String>> serviceProviders);
|
||||
|
||||
public Vpc getVpc(long vpcId);
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.admin.vpc;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -52,6 +52,10 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
|
||||
description="services supported by the vpc offering")
|
||||
private List<String> supportedServices;
|
||||
|
||||
@Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST, type = CommandType.MAP, description = "provider to service mapping. " +
|
||||
"If not specified, the provider for the service will be mapped to the default provider on the physical network")
|
||||
private Map<String, String> serviceProviderList;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -68,10 +72,33 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
|
||||
return supportedServices;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getServiceProviders() {
|
||||
Map<String, List<String>> serviceProviderMap = null;
|
||||
if (serviceProviderList != null && !serviceProviderList.isEmpty()) {
|
||||
serviceProviderMap = new HashMap<String, List<String>>();
|
||||
Collection servicesCollection = serviceProviderList.values();
|
||||
Iterator iter = servicesCollection.iterator();
|
||||
while (iter.hasNext()) {
|
||||
HashMap<String, String> services = (HashMap<String, String>) iter.next();
|
||||
String service = services.get("service");
|
||||
String provider = services.get("provider");
|
||||
List<String> providerList = null;
|
||||
if (serviceProviderMap.containsKey(service)) {
|
||||
providerList = serviceProviderMap.get(service);
|
||||
} else {
|
||||
providerList = new ArrayList<String>();
|
||||
}
|
||||
providerList.add(provider);
|
||||
serviceProviderMap.put(service, providerList);
|
||||
}
|
||||
}
|
||||
|
||||
return serviceProviderMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices());
|
||||
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices(), getServiceProviders());
|
||||
if (vpcOff != null) {
|
||||
this.setEntityId(vpcOff.getId());
|
||||
this.setEntityUuid(vpcOff.getUuid());
|
||||
|
||||
@ -446,7 +446,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
Long vpcId = ip.getVpcId();
|
||||
Vpc vpc = _vpcMgr.getVpc(vpcId);
|
||||
|
||||
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId())) {
|
||||
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
|
||||
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
|
||||
DataCenter.class, vpc.getZoneId());
|
||||
}
|
||||
@ -474,7 +474,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
Long vpcId = ip.getVpcId();
|
||||
Vpc vpc = _vpcMgr.getVpc(vpcId);
|
||||
|
||||
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId())) {
|
||||
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
|
||||
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
|
||||
DataCenter.class, vpc.getZoneId());
|
||||
}
|
||||
|
||||
@ -71,9 +71,10 @@ public interface VpcManager extends VpcService{
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* @param provider
|
||||
* @return
|
||||
*/
|
||||
boolean vpcProviderEnabledInZone(long zoneId);
|
||||
boolean vpcProviderEnabledInZone(long zoneId, String provider);
|
||||
|
||||
/**
|
||||
* @param vpcId
|
||||
|
||||
@ -31,6 +31,7 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.network.element.StaticNatServiceProvider;
|
||||
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -84,6 +85,7 @@ import com.cloud.network.vpc.dao.VpcDao;
|
||||
import com.cloud.network.vpc.dao.VpcGatewayDao;
|
||||
import com.cloud.network.vpc.dao.VpcOfferingDao;
|
||||
import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao;
|
||||
import com.cloud.network.vpc.dao.VpcServiceMapDao;
|
||||
import com.cloud.network.vpn.Site2SiteVpnManager;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.NetworkOfferingServiceMapVO;
|
||||
@ -173,10 +175,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
VlanDao _vlanDao = null;
|
||||
@Inject
|
||||
ResourceLimitService _resourceLimitMgr;
|
||||
|
||||
@Inject
|
||||
VpcServiceMapDao _vpcSrvcDao;
|
||||
|
||||
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker"));
|
||||
private VpcProvider vpcElement = null;
|
||||
private List<VpcProvider> vpcElements = null;
|
||||
private final List<Service> nonSupportedServices = Arrays.asList(Service.SecurityGroup, Service.Firewall);
|
||||
|
||||
int _cleanupInterval;
|
||||
@ -255,7 +258,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create=true)
|
||||
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices) {
|
||||
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices, Map<String, List<String>> serviceProviders) {
|
||||
Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
|
||||
Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
|
||||
defaultProviders.add(Provider.VPCVirtualRouter);
|
||||
@ -292,6 +295,33 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
|
||||
svcProviderMap.put(Service.Gateway, defaultProviders);
|
||||
|
||||
if (serviceProviders != null) {
|
||||
for (String serviceStr : serviceProviders.keySet()) {
|
||||
Network.Service service = Network.Service.getService(serviceStr);
|
||||
if (svcProviderMap.containsKey(service)) {
|
||||
Set<Provider> providers = new HashSet<Provider>();
|
||||
// don't allow to specify more than 1 provider per service
|
||||
if (serviceProviders.get(serviceStr) != null && serviceProviders.get(serviceStr).size() > 1) {
|
||||
throw new InvalidParameterValueException("In the current release only one provider can be " +
|
||||
"specified for the service");
|
||||
}
|
||||
for (String prvNameStr : serviceProviders.get(serviceStr)) {
|
||||
// check if provider is supported
|
||||
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 " + serviceStr + " is not enabled for the network " +
|
||||
"offering, can't add a provider to it");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null);
|
||||
UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
|
||||
|
||||
@ -556,11 +586,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean vpcProviderEnabledInZone(long zoneId)
|
||||
public boolean vpcProviderEnabledInZone(long zoneId, String provider)
|
||||
{
|
||||
//the provider has to be enabled at least in one network in the zone
|
||||
for (PhysicalNetwork pNtwk : _pNtwkDao.listByZone(zoneId)) {
|
||||
if (_ntwkModel.isProviderEnabledInPhysicalNetwork(pNtwk.getId(), Provider.VPCVirtualRouter.getName())) {
|
||||
if (_ntwkModel.isProviderEnabledInPhysicalNetwork(pNtwk.getId(), provider)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -573,11 +603,6 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
protected Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr,
|
||||
String networkDomain) {
|
||||
|
||||
if (!vpcProviderEnabledInZone(zoneId)) {
|
||||
throw new InvalidParameterValueException("Provider " + Provider.VPCVirtualRouter.getName() +
|
||||
" should be enabled in at least one physical network of the zone specified");
|
||||
}
|
||||
|
||||
//Validate CIDR
|
||||
if (!NetUtils.isValidCIDR(cidr)) {
|
||||
throw new InvalidParameterValueException("Invalid CIDR specified " + cidr);
|
||||
@ -601,7 +626,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
txn.start();
|
||||
VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr,
|
||||
networkDomain);
|
||||
vpc = _vpcDao.persist(vpc);
|
||||
vpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(zoneId, vpcOffId));
|
||||
_resourceLimitMgr.incrementResourceCount(vpcOwner.getId(), ResourceType.vpc);
|
||||
txn.commit();
|
||||
|
||||
@ -610,6 +635,43 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
return vpc;
|
||||
}
|
||||
|
||||
private Map<String, String> finalizeServicesAndProvidersForVpc(long zoneId, long offeringId) {
|
||||
Map<String, String> svcProviders = new HashMap<String, String>();
|
||||
Map<String, List<String>> providerSvcs = new HashMap<String, List<String>>();
|
||||
List<VpcOfferingServiceMapVO> servicesMap = _vpcOffSvcMapDao.listByVpcOffId(offeringId);
|
||||
|
||||
for (VpcOfferingServiceMapVO serviceMap : servicesMap) {
|
||||
if (svcProviders.containsKey(serviceMap.getService())) {
|
||||
// FIXME - right now we pick up the first provider from the list, need to add more logic based on
|
||||
// provider load, etc
|
||||
continue;
|
||||
}
|
||||
|
||||
String service = serviceMap.getService();
|
||||
String provider = serviceMap.getProvider();
|
||||
|
||||
if (provider == null) {
|
||||
// Default to VPCVirtualRouter
|
||||
provider = Provider.VPCVirtualRouter.getName();
|
||||
}
|
||||
|
||||
|
||||
if (!vpcProviderEnabledInZone(zoneId, provider)) {
|
||||
throw new InvalidParameterValueException("Provider " + provider +
|
||||
" should be enabled in at least one physical network of the zone specified");
|
||||
}
|
||||
|
||||
svcProviders.put(service, provider);
|
||||
List<String> l = providerSvcs.get(provider);
|
||||
if (l == null) {
|
||||
providerSvcs.put(provider, l = new ArrayList<String>());
|
||||
}
|
||||
l.add(service);
|
||||
}
|
||||
|
||||
return svcProviders;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC")
|
||||
public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
@ -903,14 +965,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
//deploy provider
|
||||
if (getVpcElement().implementVpc(vpc, dest, context)) {
|
||||
boolean success = true;
|
||||
List<Provider> providersToImplement = getVpcProviders(vpc.getId());
|
||||
for (VpcProvider element: getVpcElements()){
|
||||
if(providersToImplement.contains(element.getProvider())){
|
||||
if (element.implementVpc(vpc, dest, context)) {
|
||||
s_logger.debug("Vpc " + vpc + " has started succesfully");
|
||||
return true;
|
||||
} else {
|
||||
s_logger.warn("Vpc " + vpc + " failed to start");
|
||||
return false;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
@ -928,15 +996,22 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
|
||||
//shutdown provider
|
||||
s_logger.debug("Shutting down vpc " + vpc);
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallerUserId()), caller);
|
||||
boolean success = getVpcElement().shutdownVpc(vpc, context);
|
||||
|
||||
//TODO - shutdown all vpc resources here (ACLs, gateways, etc)
|
||||
if (success) {
|
||||
|
||||
boolean success = true;
|
||||
List<Provider> providersToImplement = getVpcProviders(vpc.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallerUserId()), caller);
|
||||
for (VpcProvider element: getVpcElements()){
|
||||
if(providersToImplement.contains(element.getProvider())){
|
||||
if (element.shutdownVpc(vpc, context)) {
|
||||
s_logger.debug("Vpc " + vpc + " has been shutdown succesfully");
|
||||
} else {
|
||||
s_logger.warn("Vpc " + vpc + " failed to shutdown");
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -1085,16 +1160,18 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
}
|
||||
|
||||
|
||||
protected VpcProvider getVpcElement() {
|
||||
if (vpcElement == null) {
|
||||
vpcElement = ((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
|
||||
protected List<VpcProvider> getVpcElements() {
|
||||
if (vpcElements == null) {
|
||||
vpcElements = new ArrayList<VpcProvider>();
|
||||
vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
|
||||
vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCNetscaler.getName()));
|
||||
}
|
||||
|
||||
if (vpcElement == null) {
|
||||
throw new CloudRuntimeException("Failed to initialize vpc element");
|
||||
if (vpcElements == null) {
|
||||
throw new CloudRuntimeException("Failed to initialize vpc elements");
|
||||
}
|
||||
|
||||
return vpcElement;
|
||||
return vpcElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1268,10 +1345,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId);
|
||||
|
||||
boolean success = false;
|
||||
boolean success = true;
|
||||
try {
|
||||
PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
|
||||
success = getVpcElement().createPrivateGateway(gateway);
|
||||
for (VpcProvider provider: getVpcElements()){
|
||||
if(!provider.createPrivateGateway(gateway)){
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
|
||||
if (vo.getState() != VpcGateway.State.Ready) {
|
||||
@ -1327,12 +1408,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
|
||||
//1) delete the gateway on the backend
|
||||
PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
|
||||
if (getVpcElement().deletePrivateGateway(gateway)) {
|
||||
for (VpcProvider provider: getVpcElements()){
|
||||
if (provider.deletePrivateGateway(gateway)) {
|
||||
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
|
||||
} else {
|
||||
s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//2) Delete private gateway from the DB
|
||||
return deletePrivateGatewayFromTheDB(gateway);
|
||||
@ -1499,12 +1582,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
Vpc vpc = getVpc(routes.get(0).getVpcId());
|
||||
|
||||
s_logger.debug("Applying static routes for vpc " + vpc);
|
||||
if (getVpcElement().applyStaticRoutes(vpc, routes)) {
|
||||
String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat);
|
||||
|
||||
for (VpcProvider provider: getVpcElements()){
|
||||
if (!(provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(staticNatProvider))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (provider.applyStaticRoutes(vpc, routes)) {
|
||||
s_logger.debug("Applied static routes for vpc " + vpc);
|
||||
} else {
|
||||
s_logger.warn("Failed to apply static routes for vpc " + vpc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1958,4 +2049,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
|
||||
hTypes.add(HypervisorType.KVM);
|
||||
return hTypes;
|
||||
}
|
||||
|
||||
private List<Provider> getVpcProviders(long vpcId) {
|
||||
List<String> providerNames = _vpcSrvcDao.getDistinctProviders(vpcId);
|
||||
Map<String, Provider> providers = new HashMap<String, Provider>();
|
||||
for (String providerName : providerNames) {
|
||||
if(!providers.containsKey(providerName)){
|
||||
providers.put(providerName, Network.Provider.getProvider(providerName));
|
||||
}
|
||||
}
|
||||
|
||||
return new ArrayList<Provider>(providers.values());
|
||||
}
|
||||
}
|
||||
|
||||
90
server/src/com/cloud/network/vpc/VpcServiceMapVO.java
Normal file
90
server/src/com/cloud/network/vpc/VpcServiceMapVO.java
Normal file
@ -0,0 +1,90 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.network.vpc;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name="vpc_service_map")
|
||||
public class VpcServiceMapVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
long id;
|
||||
|
||||
@Column(name="vpc_id")
|
||||
long vpcId;
|
||||
|
||||
@Column(name="service")
|
||||
String service;
|
||||
|
||||
@Column(name="provider")
|
||||
String provider;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getVpcId() {
|
||||
return vpcId;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public VpcServiceMapVO() {
|
||||
}
|
||||
|
||||
public VpcServiceMapVO(long vpcId, Service service, Provider provider) {
|
||||
this.vpcId = vpcId;
|
||||
this.service = service.getName();
|
||||
this.provider = provider.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder("[VPC Service[");
|
||||
return buf.append(vpcId).append("-").append(service).append("-").append(provider).append("]").toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package com.cloud.network.vpc.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.network.vpc.VpcVO;
|
||||
@ -39,4 +40,8 @@ public interface VpcDao extends GenericDao<VpcVO, Long>{
|
||||
|
||||
long countByAccountId(long accountId);
|
||||
|
||||
VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap);
|
||||
|
||||
void persistVpcServiceProviders(long vpcId,
|
||||
Map<String, String> serviceProviderMap);
|
||||
}
|
||||
|
||||
@ -17,10 +17,13 @@
|
||||
package com.cloud.network.vpc.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.vpc.VpcServiceMapVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
@ -45,6 +48,7 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
|
||||
final SearchBuilder<VpcVO> AllFieldsSearch;
|
||||
final GenericSearchBuilder<VpcVO, Long> CountByAccountId;
|
||||
@Inject ResourceTagsDaoImpl _tagsDao;
|
||||
@Inject VpcServiceMapDaoImpl _vpcSvcMap;
|
||||
|
||||
protected VpcDaoImpl() {
|
||||
super();
|
||||
@ -120,5 +124,28 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
|
||||
List<Long> results = customSearch(sc, null);
|
||||
return results.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
VpcVO newVpc = super.persist(vpc);
|
||||
persistVpcServiceProviders(vpc.getId(), serviceProviderMap);
|
||||
txn.commit();
|
||||
return newVpc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void persistVpcServiceProviders(long vpcId, Map<String, String> serviceProviderMap) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
for (String service : serviceProviderMap.keySet()) {
|
||||
VpcServiceMapVO serviceMap = new VpcServiceMapVO(vpcId, Network.Service.getService(service), Network.Provider.getProvider(serviceProviderMap.get(service)));
|
||||
_vpcSvcMap.persist(serviceMap);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
40
server/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java
Normal file
40
server/src/com/cloud/network/vpc/dao/VpcServiceMapDao.java
Normal file
@ -0,0 +1,40 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.network.vpc.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.dao.NetworkServiceMapVO;
|
||||
import com.cloud.network.vpc.VpcServiceMapVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
/**
|
||||
* VpcServiceMapDao deals with searches and operations done on the
|
||||
* vpc_service_map table.
|
||||
*
|
||||
*/
|
||||
public interface VpcServiceMapDao extends GenericDao<VpcServiceMapVO, Long>{
|
||||
boolean areServicesSupportedInVpc(long vpcId, Service... services);
|
||||
boolean canProviderSupportServiceInVpc(long vpcId, Service service, Provider provider);
|
||||
List<NetworkServiceMapVO> getServicesInVpc(long vpcId);
|
||||
String getProviderForServiceInVpc(long vpcId, Service service);
|
||||
void deleteByVpcId(long vpcId);
|
||||
List<String> getDistinctProviders(long vpcId);
|
||||
String isProviderForVpc(long vpcId, Provider provider);
|
||||
}
|
||||
115
server/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java
Normal file
115
server/src/com/cloud/network/vpc/dao/VpcServiceMapDaoImpl.java
Normal file
@ -0,0 +1,115 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.network.vpc.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.exception.UnsupportedServiceException;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.dao.NetworkServiceMapVO;
|
||||
import com.cloud.network.vpc.VpcServiceMapVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Local(value=VpcServiceMapDao.class) @DB(txn=false)
|
||||
public class VpcServiceMapDaoImpl extends GenericDaoBase<VpcServiceMapVO, Long> implements VpcServiceMapDao {
|
||||
final SearchBuilder<VpcServiceMapVO> AllFieldsSearch;
|
||||
final SearchBuilder<VpcServiceMapVO> MultipleServicesSearch;
|
||||
final GenericSearchBuilder<VpcServiceMapVO, String> DistinctProvidersSearch;
|
||||
|
||||
protected VpcServiceMapDaoImpl(){
|
||||
super();
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
MultipleServicesSearch = createSearchBuilder();
|
||||
MultipleServicesSearch.and("vpcId", MultipleServicesSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
|
||||
MultipleServicesSearch.and("service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
|
||||
MultipleServicesSearch.and("provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
MultipleServicesSearch.done();
|
||||
|
||||
DistinctProvidersSearch = createSearchBuilder(String.class);
|
||||
DistinctProvidersSearch.and("vpcId", DistinctProvidersSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.and("provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
|
||||
DistinctProvidersSearch.selectField(DistinctProvidersSearch.entity().getProvider());
|
||||
DistinctProvidersSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areServicesSupportedInVpc(long vpcId, Service... services) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProviderSupportServiceInVpc(long vpcId, Service service,
|
||||
Provider provider) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkServiceMapVO> getServicesInVpc(long vpcId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProviderForServiceInVpc(long vpcId, Service service) {
|
||||
SearchCriteria<VpcServiceMapVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("vpcId", vpcId);
|
||||
sc.setParameters("service", service.getName());
|
||||
VpcServiceMapVO ntwkSvc = findOneBy(sc);
|
||||
if (ntwkSvc == null) {
|
||||
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the vpc id=" + vpcId);
|
||||
}
|
||||
|
||||
return ntwkSvc.getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByVpcId(long vpcId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDistinctProviders(long vpcId) {
|
||||
SearchCriteria<String> sc = DistinctProvidersSearch.create();
|
||||
sc.setParameters("vpcId", vpcId);
|
||||
List<String> results = customSearch(sc, null);
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String isProviderForVpc(long vpcId, Provider provider) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,6 +26,7 @@ UPDATE `cloud`.`hypervisor_capabilities` SET `max_hosts_per_cluster`=32 WHERE `h
|
||||
INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_hosts_per_cluster) VALUES ('VMware', '5.1', 128, 0, 32);
|
||||
DELETE FROM `cloud`.`configuration` where name='vmware.percluster.host.max';
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'AgentManager', 'xen.nics.max', '7', 'Maximum allowed nics for Vms created on Xen');
|
||||
|
||||
alter table template_host_ref add state varchar(255);
|
||||
alter table template_host_ref add update_count bigint unsigned;
|
||||
alter table template_host_ref add updated datetime;
|
||||
@ -83,5 +84,18 @@ ALTER TABLE `cloud`.`service_offering` ADD COLUMN `is_volatile` tinyint(1) unsig
|
||||
ALTER TABLE `cloud`.`networks` ADD COLUMN `network_cidr` VARCHAR(18) COMMENT 'The network cidr for the isolated guest network which uses IP Reservation facility.For networks not using IP reservation, network_cidr is always null.';
|
||||
ALTER TABLE `cloud`.`networks` CHANGE `cidr` `cidr` varchar(18) COMMENT 'CloudStack managed vms get IP address from cidr.In general this cidr also serves as the network CIDR. But in case IP reservation feature is being used by a Guest network, networkcidr is the Effective network CIDR for that network';
|
||||
|
||||
|
||||
CREATE TABLE `vpc_service_map` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`vpc_id` bigint unsigned NOT NULL COMMENT 'vpc_id',
|
||||
`service` varchar(255) NOT NULL COMMENT 'service',
|
||||
`provider` varchar(255) COMMENT 'service provider',
|
||||
`created` datetime COMMENT 'date created',
|
||||
PRIMARY KEY (`id`),
|
||||
CONSTRAINT `fk_vpc_service_map__vpc_id` FOREIGN KEY(`vpc_id`) REFERENCES `vpc`(`id`) ON DELETE CASCADE,
|
||||
UNIQUE (`vpc_id`, `service`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
SET foreign_key_checks = 1;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user