CLOUDSTACK-749: External device support for VPC. VPC offering can be created with providers other than VPCVirtualRouter

This commit is contained in:
Kishan Kavala 2013-02-25 14:33:35 +05:30
parent 4d573ddd1b
commit 836ce6c11a
12 changed files with 474 additions and 51 deletions

View File

@ -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 // 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 NiciraNvp = new Provider("NiciraNvp", false);
public static final Provider MidokuraMidonet = new Provider("MidokuraMidonet", true); public static final Provider MidokuraMidonet = new Provider("MidokuraMidonet", true);
public static final Provider VPCNetscaler = new Provider("VPCNetscaler", true);
private String name; private String name;
private boolean isExternal; private boolean isExternal;

View File

@ -41,7 +41,7 @@ public interface VpcService {
public VpcOffering getVpcOffering(long vpcOfferingId); 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); public Vpc getVpc(long vpcId);

View File

@ -16,7 +16,7 @@
// under the License. // under the License.
package org.apache.cloudstack.api.command.admin.vpc; 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.APICommand;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
@ -52,6 +52,10 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
description="services supported by the vpc offering") description="services supported by the vpc offering")
private List<String> supportedServices; 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 /////////////////////// /////////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -68,10 +72,33 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
return supportedServices; 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 @Override
public void create() throws ResourceAllocationException { public void create() throws ResourceAllocationException {
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices()); VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices(), getServiceProviders());
if (vpcOff != null) { if (vpcOff != null) {
this.setEntityId(vpcOff.getId()); this.setEntityId(vpcOff.getId());
this.setEntityUuid(vpcOff.getUuid()); this.setEntityUuid(vpcOff.getUuid());

View File

@ -446,7 +446,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
Long vpcId = ip.getVpcId(); Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId); 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(), throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId()); DataCenter.class, vpc.getZoneId());
} }
@ -474,7 +474,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
Long vpcId = ip.getVpcId(); Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId); 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(), throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId()); DataCenter.class, vpc.getZoneId());
} }

View File

@ -71,9 +71,10 @@ public interface VpcManager extends VpcService{
/** /**
* @param zoneId * @param zoneId
* @param provider
* @return * @return
*/ */
boolean vpcProviderEnabledInZone(long zoneId); boolean vpcProviderEnabledInZone(long zoneId, String provider);
/** /**
* @param vpcId * @param vpcId

View File

@ -31,6 +31,7 @@ import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import com.cloud.network.element.StaticNatServiceProvider;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd; import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; 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.VpcGatewayDao;
import com.cloud.network.vpc.dao.VpcOfferingDao; import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao;
import com.cloud.network.vpc.dao.VpcServiceMapDao;
import com.cloud.network.vpn.Site2SiteVpnManager; import com.cloud.network.vpn.Site2SiteVpnManager;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingServiceMapVO; import com.cloud.offerings.NetworkOfferingServiceMapVO;
@ -173,10 +175,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
VlanDao _vlanDao = null; VlanDao _vlanDao = null;
@Inject @Inject
ResourceLimitService _resourceLimitMgr; ResourceLimitService _resourceLimitMgr;
@Inject
VpcServiceMapDao _vpcSrvcDao;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("VpcChecker")); 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); private final List<Service> nonSupportedServices = Arrays.asList(Service.SecurityGroup, Service.Firewall);
int _cleanupInterval; int _cleanupInterval;
@ -255,7 +258,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create=true) @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>>(); Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>(); Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
defaultProviders.add(Provider.VPCVirtualRouter); defaultProviders.add(Provider.VPCVirtualRouter);
@ -291,7 +294,34 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
} }
svcProviderMap.put(Service.Gateway, defaultProviders); 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); VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null);
UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name); UserContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
@ -556,11 +586,11 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
} }
@Override @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 //the provider has to be enabled at least in one network in the zone
for (PhysicalNetwork pNtwk : _pNtwkDao.listByZone(zoneId)) { for (PhysicalNetwork pNtwk : _pNtwkDao.listByZone(zoneId)) {
if (_ntwkModel.isProviderEnabledInPhysicalNetwork(pNtwk.getId(), Provider.VPCVirtualRouter.getName())) { if (_ntwkModel.isProviderEnabledInPhysicalNetwork(pNtwk.getId(), provider)) {
return true; 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, protected Vpc createVpc(long zoneId, long vpcOffId, Account vpcOwner, String vpcName, String displayText, String cidr,
String networkDomain) { 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 //Validate CIDR
if (!NetUtils.isValidCIDR(cidr)) { if (!NetUtils.isValidCIDR(cidr)) {
throw new InvalidParameterValueException("Invalid CIDR specified " + cidr); throw new InvalidParameterValueException("Invalid CIDR specified " + cidr);
@ -601,7 +626,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
txn.start(); txn.start();
VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr, VpcVO vpc = new VpcVO (zoneId, vpcName, displayText, vpcOwner.getId(), vpcOwner.getDomainId(), vpcOffId, cidr,
networkDomain); networkDomain);
vpc = _vpcDao.persist(vpc); vpc = _vpcDao.persist(vpc, finalizeServicesAndProvidersForVpc(zoneId, vpcOffId));
_resourceLimitMgr.incrementResourceCount(vpcOwner.getId(), ResourceType.vpc); _resourceLimitMgr.incrementResourceCount(vpcOwner.getId(), ResourceType.vpc);
txn.commit(); txn.commit();
@ -609,7 +634,44 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
return vpc; 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 @Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC")
public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
@ -903,13 +965,19 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context) protected boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
//deploy provider //deploy provider
if (getVpcElement().implementVpc(vpc, dest, context)) { boolean success = true;
s_logger.debug("Vpc " + vpc + " has started succesfully"); List<Provider> providersToImplement = getVpcProviders(vpc.getId());
return true; for (VpcProvider element: getVpcElements()){
} else { if(providersToImplement.contains(element.getProvider())){
s_logger.warn("Vpc " + vpc + " failed to start"); if (element.implementVpc(vpc, dest, context)) {
return false; s_logger.debug("Vpc " + vpc + " has started succesfully");
} else {
s_logger.warn("Vpc " + vpc + " failed to start");
success = false;
}
}
} }
return success;
} }
@Override @Override
@ -928,15 +996,22 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
//shutdown provider //shutdown provider
s_logger.debug("Shutting down vpc " + vpc); 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) //TODO - shutdown all vpc resources here (ACLs, gateways, etc)
if (success) {
s_logger.debug("Vpc " + vpc + " has been shutdown succesfully"); boolean success = true;
} else { List<Provider> providersToImplement = getVpcProviders(vpc.getId());
s_logger.warn("Vpc " + vpc + " failed to shutdown"); 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; return success;
} }
@ -1085,16 +1160,18 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
} }
protected VpcProvider getVpcElement() { protected List<VpcProvider> getVpcElements() {
if (vpcElement == null) { if (vpcElements == null) {
vpcElement = ((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName())); vpcElements = new ArrayList<VpcProvider>();
vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Provider.VPCNetscaler.getName()));
} }
if (vpcElement == null) { if (vpcElements == null) {
throw new CloudRuntimeException("Failed to initialize vpc element"); throw new CloudRuntimeException("Failed to initialize vpc elements");
} }
return vpcElement; return vpcElements;
} }
@Override @Override
@ -1268,10 +1345,14 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException { public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException {
VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId); VpcGatewayVO vo = _vpcGatewayDao.findById(gatewayId);
boolean success = false; boolean success = true;
try { try {
PrivateGateway gateway = getVpcPrivateGateway(gatewayId); PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
success = getVpcElement().createPrivateGateway(gateway); for (VpcProvider provider: getVpcElements()){
if(!provider.createPrivateGateway(gateway)){
success = false;
}
}
if (success) { if (success) {
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend"); s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
if (vo.getState() != VpcGateway.State.Ready) { if (vo.getState() != VpcGateway.State.Ready) {
@ -1327,11 +1408,13 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
//1) delete the gateway on the backend //1) delete the gateway on the backend
PrivateGateway gateway = getVpcPrivateGateway(gatewayId); PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
if (getVpcElement().deletePrivateGateway(gateway)) { for (VpcProvider provider: getVpcElements()){
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend"); if (provider.deletePrivateGateway(gateway)) {
} else { s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
s_logger.warn("Private gateway " + gateway + " failed to apply on the backend"); } else {
return false; s_logger.warn("Private gateway " + gateway + " failed to apply on the backend");
return false;
}
} }
//2) Delete private gateway from the DB //2) Delete private gateway from the DB
@ -1499,11 +1582,19 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
Vpc vpc = getVpc(routes.get(0).getVpcId()); Vpc vpc = getVpc(routes.get(0).getVpcId());
s_logger.debug("Applying static routes for vpc " + vpc); s_logger.debug("Applying static routes for vpc " + vpc);
if (getVpcElement().applyStaticRoutes(vpc, routes)) { String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat);
s_logger.debug("Applied static routes for vpc " + vpc);
} else { for (VpcProvider provider: getVpcElements()){
s_logger.warn("Failed to apply static routes for vpc " + vpc); if (!(provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(staticNatProvider))) {
return false; 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; return true;
@ -1958,4 +2049,16 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
hTypes.add(HypervisorType.KVM); hTypes.add(HypervisorType.KVM);
return hTypes; 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());
}
} }

View 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();
}
}

View File

@ -17,6 +17,7 @@
package com.cloud.network.vpc.dao; package com.cloud.network.vpc.dao;
import java.util.List; import java.util.List;
import java.util.Map;
import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVO; import com.cloud.network.vpc.VpcVO;
@ -39,4 +40,8 @@ public interface VpcDao extends GenericDao<VpcVO, Long>{
long countByAccountId(long accountId); long countByAccountId(long accountId);
VpcVO persist(VpcVO vpc, Map<String, String> serviceProviderMap);
void persistVpcServiceProviders(long vpcId,
Map<String, String> serviceProviderMap);
} }

View File

@ -17,10 +17,13 @@
package com.cloud.network.vpc.dao; package com.cloud.network.vpc.dao;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import com.cloud.network.Network;
import com.cloud.network.vpc.VpcServiceMapVO;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.cloud.network.vpc.Vpc; import com.cloud.network.vpc.Vpc;
@ -45,6 +48,7 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
final SearchBuilder<VpcVO> AllFieldsSearch; final SearchBuilder<VpcVO> AllFieldsSearch;
final GenericSearchBuilder<VpcVO, Long> CountByAccountId; final GenericSearchBuilder<VpcVO, Long> CountByAccountId;
@Inject ResourceTagsDaoImpl _tagsDao; @Inject ResourceTagsDaoImpl _tagsDao;
@Inject VpcServiceMapDaoImpl _vpcSvcMap;
protected VpcDaoImpl() { protected VpcDaoImpl() {
super(); super();
@ -120,5 +124,28 @@ public class VpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
List<Long> results = customSearch(sc, null); List<Long> results = customSearch(sc, null);
return results.get(0); 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();
}
} }

View 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);
}

View 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;
}
}

View File

@ -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); 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'; 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'); 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 state varchar(255);
alter table template_host_ref add update_count bigint unsigned; alter table template_host_ref add update_count bigint unsigned;
alter table template_host_ref add updated datetime; 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` 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'; 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; SET foreign_key_checks = 1;