Internal LB:

1) Added network_offering_details DB table and corresponding VO/DAO objects. Change createNetworkOffering web services api to accept the map of key/value pairs as details.
2) Allow to have multiple providers for the same service for the network to support the case when LB service can have separate providers for Internal LB and Public LB
This commit is contained in:
Alena Prokharchyk 2013-04-15 13:45:25 -07:00
parent 4530cebf2b
commit a4fc1d7d65
22 changed files with 352 additions and 32 deletions

View File

@ -268,4 +268,6 @@ public interface NetworkModel {
List<String> getUsedIpsInNetwork(Network network);
Map<String, String> getNtwkOffDetails(long offId);
}

View File

@ -16,6 +16,8 @@
// under the License.
package com.cloud.offering;
import java.util.Map;
import org.apache.cloudstack.acl.InfrastructureEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@ -38,6 +40,11 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
Disabled,
Enabled
}
public enum Details {
internalLbProvider,
publicLbProvider
}
public final static String SystemPublicNetwork = "System-Public-Network";
public final static String SystemControlNetwork = "System-Control-Network";
@ -114,5 +121,7 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
boolean isInline();
boolean getIsPersistent();
Map getDetails();
}

View File

@ -29,6 +29,7 @@ import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.BaseCmd.CommandType;
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
@ -95,6 +96,10 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.IS_PERSISTENT, type=CommandType.BOOLEAN, description="true if network offering supports persistent networks; defaulted to false if not specified")
private Boolean isPersistent;
@Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, since="4.2.0", description="Template details in key/value pairs." +
" Supported keys are internallbprovider/publiclbprovider with service provider as a value")
protected Map details;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -215,6 +220,16 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
return capabilityMap;
}
public Map<String, String> getDetails() {
if (details == null || details.isEmpty()) {
return null;
}
Collection paramsCollection = details.values();
Map<String, String> params = (Map<String, String>) (paramsCollection.toArray())[0];
return params;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -75,7 +75,7 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
@Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="if true is passed for this parameter, list only VPC routers")
private Boolean forVpc;
@Parameter(name=ApiConstants.ROLE, type=CommandType.STRING, description="list routers by role (Virtual_router or Internal_lb_vm)")
@Parameter(name=ApiConstants.ROLE, type=CommandType.STRING, description="list routers by role (Virtual_router or Internal_lb_vm)", since="4.2.0")
private String role;
/////////////////////////////////////////////////////

View File

@ -18,6 +18,7 @@ package org.apache.cloudstack.api.response;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
@ -83,6 +84,10 @@ public class NetworkOfferingResponse extends BaseResponse {
@SerializedName(ApiConstants.IS_PERSISTENT) @Param(description="true if network offering supports persistent networks, false otherwise")
private Boolean isPersistent;
@SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with network offering", since="4.2.0")
private Map details;
public void setId(String id) {
this.id = id;
@ -156,5 +161,9 @@ public class NetworkOfferingResponse extends BaseResponse {
public void setIsPersistent(Boolean isPersistent) {
this.isPersistent = isPersistent;
}
public void setDetails(Map details) {
this.details = details;
}
}

View File

@ -365,6 +365,7 @@
<bean id="vpcServiceMapDaoImpl" class="com.cloud.network.vpc.dao.VpcServiceMapDaoImpl" />
<bean id="vpnUserDaoImpl" class="com.cloud.network.dao.VpnUserDaoImpl" />
<bean id="applicationLbRuleDaoImpl" class="org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDaoImpl" />
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
<!--

View File

@ -188,6 +188,7 @@ import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetwork;
@ -288,6 +289,7 @@ public class ApiResponseHelper implements ResponseGenerator {
private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##");
@Inject private EntityManager _entityMgr = null;
@Inject private UsageService _usageSvc = null;
@Inject NetworkModel _ntwkModel;
@Override
public UserResponse createUserResponse(User user) {
@ -2223,6 +2225,10 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setForVpc(ApiDBUtils.isOfferingForVpc(offering));
response.setServices(serviceResponses);
//set network offering details
response.setDetails(_ntwkModel.getNtwkOffDetails(offering.getId()));
response.setObjectName("networkoffering");
return response;
}

View File

@ -180,8 +180,6 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* @param trafficType
* @param tags
* @param specifyVlan
* @param isPersistent
* ;
* @param networkRate
* TODO
* @param serviceProviderMap
@ -197,14 +195,16 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* ;
* @param specifyIpRanges
* TODO
* @param isPersistent
* ;
* @param details TODO
* @param id
*
* @return network offering object
*/
NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap,
boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap,
boolean specifyIpRanges, boolean isPersistent);
boolean specifyIpRanges, boolean isPersistent, Map<String, String> details);
Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;

View File

@ -3198,6 +3198,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
Network.GuestType guestType = null;
boolean specifyIpRanges = cmd.getSpecifyIpRanges();
boolean isPersistent = cmd.getIsPersistent();
Map<String, String> details = cmd.getDetails();
// Verify traffic type
for (TrafficType tType : TrafficType.values()) {
@ -3368,7 +3369,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false,
serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent);
serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent, details);
}
void validateLoadBalancerServiceCapabilities(Map<Capability, String> lbServiceCapabilityMap) {
@ -3456,7 +3457,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@DB
public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate,
Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId,
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent) {
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent, Map<String, String> details) {
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
@ -3568,13 +3569,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (serviceOfferingId != null) {
offering.setServiceOfferingId(serviceOfferingId);
}
//validate the details
if (details != null) {
validateNtwkOffDetails(details, serviceProviderMap);
}
Transaction txn = Transaction.currentTxn();
txn.start();
// create network offering object
//1) create network offering object
s_logger.debug("Adding network offering " + offering);
offering = _networkOfferingDao.persist(offering);
// populate services and providers
offering = _networkOfferingDao.persist(offering, details);
//2) populate services and providers
if (serviceProviderMap != null) {
for (Network.Service service : serviceProviderMap.keySet()) {
Set<Provider> providers = serviceProviderMap.get(service);
@ -3608,6 +3614,31 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
return offering;
}
protected void validateNtwkOffDetails(Map<String, String> details, Map<Service, Set<Provider>> serviceProviderMap) {
for (String key : details.keySet()) {
NetworkOffering.Details detail = null;
for (NetworkOffering.Details value : NetworkOffering.Details.values()) {
if (key.equalsIgnoreCase(value.toString())) {
detail = value;
break;
}
}
if (detail == null) {
throw new InvalidParameterValueException("Unsupported detail key");
}
if (detail == NetworkOffering.Details.internalLbProvider || detail == NetworkOffering.Details.publicLbProvider) {
Provider provider = Network.Provider.getProvider(details.get(key));
if (provider == null) {
throw new InvalidParameterValueException("Invalid value for the key " + key);
}
Set<Provider> providers = serviceProviderMap.get(Service.Lb);
if (providers == null || !providers.contains(details.get(key))) {
throw new InvalidParameterValueException("Invalid value for the key " + key + ". The provider is not supported by the network offering");
}
}
}
}
@Override
public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd cmd) {

View File

@ -998,7 +998,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
_configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices,
"Offering for QuickCloud with no services", TrafficType.Guest, null, true,
Availability.Optional, null, new HashMap<Network.Service, Set<Network.Provider>>(), true,
Network.GuestType.Shared, false, null, true, null, true, false);
Network.GuestType.Shared, false, null, true, null, true, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1007,14 +1007,14 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
_configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService,
"Offering for Shared Security group enabled networks", TrafficType.Guest, null, true,
Availability.Optional, null, defaultSharedNetworkOfferingProviders, true,
Network.GuestType.Shared, false, null, true, null, true, false);
Network.GuestType.Shared, false, null, true, null, true, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null,
defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false);
defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1037,7 +1037,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
"Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest,
null, false, Availability.Required, null, defaultINetworkOfferingProvidersForVpcNetwork,
true, Network.GuestType.Isolated, false, null, true, null, false, false);
true, Network.GuestType.Isolated, false, null, true, null, false, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1046,7 +1046,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
"Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest,
null, false, Availability.Optional, null, defaultVPCOffProviders,
true, Network.GuestType.Isolated, false, null, false, null, false, false);
true, Network.GuestType.Isolated, false, null, false, null, false, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1057,7 +1057,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
"Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest,
null, false, Availability.Optional, null, defaultVPCOffProviders,
true, Network.GuestType.Isolated, false, null, false, null, false, false);
true, Network.GuestType.Isolated, false, null, false, null, false, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1066,7 +1066,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering,
"Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true,
Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated,
false, null, true, null, true, false);
false, null, true, null, true, false, null);
offering.setState(NetworkOffering.State.Enabled);
_networkOfferingDao.update(offering.getId(), offering);
}
@ -1095,7 +1095,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true,
Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false);
Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null);
offering.setState(NetworkOffering.State.Enabled);
offering.setDedicatedLB(false);
_networkOfferingDao.update(offering.getId(), offering);

View File

@ -88,6 +88,7 @@ import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingServiceMapVO;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingDetailsDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.projects.dao.ProjectAccountDao;
import com.cloud.user.Account;
@ -185,6 +186,8 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
ApplicationLoadBalancerRuleDao _appLbRuleDao;
@Inject
private ProjectAccountDao _projectAccountDao;
@Inject
NetworkOfferingDetailsDao _ntwkOffDetailsDao;
private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
static Long _privateOfferingId = null;
@ -2074,4 +2077,9 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
return _ipAddressDao.findByIpAndSourceNetworkId(networks.get(0).getId(), ipAddress);
}
@Override
public Map<String, String> getNtwkOffDetails(long offId) {
return _ntwkOffDetailsDao.getNtwkOffDetails(offId);
}
}

View File

@ -0,0 +1,84 @@
// 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.offerings;
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 org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="network_offering_details")
public class NetworkOfferingDetailsVO implements InternalIdentity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="network_offering_id")
private long offeringId;
@Column(name="name")
private String name;
@Column(name="value", length=1024)
private String value;
public NetworkOfferingDetailsVO() {}
public NetworkOfferingDetailsVO(long offeringId, String name, String value) {
this.offeringId = offeringId;
this.name = name;
this.value = value;
}
public long getId() {
return id;
}
public long getOfferingId() {
return offeringId;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setId(long id) {
this.id = id;
}
public void setOfferingId(long offeringId) {
this.offeringId = offeringId;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -16,15 +16,25 @@
// under the License.
package com.cloud.offerings;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.db.GenericDao;
import javax.persistence.*;
import java.util.Date;
import java.util.UUID;
@Entity
@Table(name = "network_offerings")
public class NetworkOfferingVO implements NetworkOffering {
@ -123,6 +133,9 @@ public class NetworkOfferingVO implements NetworkOffering {
public String getDisplayText() {
return displayText;
}
@Transient
Map details;
@Override
public long getId() {
@ -377,5 +390,9 @@ public class NetworkOfferingVO implements NetworkOffering {
public boolean getIsPersistent() {
return isPersistent;
}
public Map getDetails() {
return this.details;
}
}

View File

@ -17,6 +17,7 @@
package com.cloud.offerings.dao;
import java.util.List;
import java.util.Map;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
@ -57,4 +58,6 @@ public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long>
List<NetworkOfferingVO> listByTrafficTypeGuestTypeAndState(NetworkOffering.State state, TrafficType trafficType, Network.GuestType type);
NetworkOfferingVO persist(NetworkOfferingVO off, Map<String, String> details);
}

View File

@ -17,8 +17,10 @@
package com.cloud.offerings.dao;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.persistence.EntityExistsException;
import org.springframework.stereotype.Component;
@ -27,6 +29,7 @@ import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@ -45,6 +48,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
final SearchBuilder<NetworkOfferingVO> AvailabilitySearch;
final SearchBuilder<NetworkOfferingVO> AllFieldsSearch;
private final GenericSearchBuilder<NetworkOfferingVO, Long> UpgradeSearch;
@Inject NetworkOfferingDetailsDao _detailsDao;
protected NetworkOfferingDaoImpl() {
super();
@ -165,5 +169,23 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
sc.setParameters("state", state);
return listBy(sc, null);
}
@Override
@DB
public NetworkOfferingVO persist(NetworkOfferingVO off, Map<String, String> details) {
Transaction txn = Transaction.currentTxn();
txn.start();
//1) TODO - persist the details
if (details != null && !details.isEmpty()) {
for (String detail : details.keySet()) {
_detailsDao.persist(new NetworkOfferingDetailsVO(off.getId(), detail, details.get(detail)));
}
}
//2) persist the offering
NetworkOfferingVO vo = super.persist(off);
txn.commit();
return vo;
}
}

View File

@ -0,0 +1,28 @@
// 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.offerings.dao;
import java.util.Map;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.utils.db.GenericDao;
public interface NetworkOfferingDetailsDao extends GenericDao<NetworkOfferingDetailsVO, Long>{
Map<String, String> getNtwkOffDetails(long offeringId);
}

View File

@ -0,0 +1,54 @@
// 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.offerings.dao;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloud.offerings.NetworkOfferingDetailsVO;
import com.cloud.storage.VMTemplateDetailVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
public class NetworkOfferingDetailsDaoImpl extends GenericDaoBase<NetworkOfferingDetailsVO, Long> implements NetworkOfferingDetailsDao{
protected final SearchBuilder<NetworkOfferingDetailsVO> DetailSearch;
public NetworkOfferingDetailsDaoImpl() {
DetailSearch = createSearchBuilder();
DetailSearch.and("offeringId", DetailSearch.entity().getOfferingId(), SearchCriteria.Op.EQ);
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
DetailSearch.done();
}
@Override
public Map<String, String> getNtwkOffDetails(long offeringId) {
SearchCriteria<NetworkOfferingDetailsVO> sc = DetailSearch.create();
sc.setParameters("offeringId", offeringId);
List<NetworkOfferingDetailsVO> results = search(sc, null);
Map<String, String> details = new HashMap<String, String>(results.size());
for (NetworkOfferingDetailsVO result : results) {
details.put(result.getName(), result.getValue());
}
return details;
}
}

View File

@ -862,4 +862,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<String, String> getNtwkOffDetails(long offId) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -500,7 +500,7 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
@Override
public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate,
Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode,
Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent) {
Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}

View File

@ -875,4 +875,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
return null;
}
@Override
public Map<String, String> getNtwkOffDetails(long offId) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -80,6 +80,7 @@ public class CreateNetworkOfferingTest extends TestCase{
Mockito.when(configDao.findByName(Mockito.anyString())).thenReturn(configVO);
Mockito.when(offDao.persist(Mockito.any(NetworkOfferingVO.class))).thenReturn(new NetworkOfferingVO());
Mockito.when(offDao.persist(Mockito.any(NetworkOfferingVO.class), Mockito.anyMap())).thenReturn(new NetworkOfferingVO());
Mockito.when(mapDao.persist(Mockito.any(NetworkOfferingServiceMapVO.class))).thenReturn(new NetworkOfferingServiceMapVO());
Mockito.when(accountMgr.getSystemUser()).thenReturn(new UserVO(1));
Mockito.when(accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
@ -92,7 +93,7 @@ public class CreateNetworkOfferingTest extends TestCase{
public void createSharedNtwkOffWithVlan() {
NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
null, false, null, true, false);
null, false, null, true, false, null);
assertNotNull("Shared network offering with specifyVlan=true failed to create ", off);
}
@ -101,7 +102,7 @@ public class CreateNetworkOfferingTest extends TestCase{
try {
NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, false,
Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
null, false, null, true, false);
null, false, null, true, false, null);
assertNull("Shared network offering with specifyVlan=false was created", off);
} catch (InvalidParameterValueException ex) {
}
@ -111,7 +112,7 @@ public class CreateNetworkOfferingTest extends TestCase{
public void createSharedNtwkOffWithSpecifyIpRanges() {
NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
null, false, null, true, false);
null, false, null, true, false, null);
assertNotNull("Shared network offering with specifyIpRanges=true failed to create ", off);
}
@ -121,7 +122,7 @@ public class CreateNetworkOfferingTest extends TestCase{
try {
NetworkOfferingVO off = configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true,
Availability.Optional, 200, null, false, Network.GuestType.Shared, false,
null, false, null, false, false);
null, false, null, false, false, null);
assertNull("Shared network offering with specifyIpRanges=false was created", off);
} catch (InvalidParameterValueException ex) {
}
@ -136,7 +137,7 @@ public class CreateNetworkOfferingTest extends TestCase{
serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
null, false, null, false, false);
null, false, null, false, false, null);
assertNotNull("Isolated network offering with specifyIpRanges=false failed to create ", off);
}
@ -149,7 +150,7 @@ public class CreateNetworkOfferingTest extends TestCase{
serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, true,
Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
null, false, null, false, false);
null, false, null, false, false, null);
assertNotNull("Isolated network offering with specifyVlan=true wasn't created", off);
}
@ -163,7 +164,7 @@ public class CreateNetworkOfferingTest extends TestCase{
serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
null, false, null, true, false);
null, false, null, true, false, null);
assertNull("Isolated network offering with specifyIpRanges=true and source nat service enabled, was created", off);
} catch (InvalidParameterValueException ex) {
}
@ -176,7 +177,7 @@ public class CreateNetworkOfferingTest extends TestCase{
Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false,
Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false,
null, false, null, true, false);
null, false, null, true, false, null);
assertNotNull("Isolated network offering with specifyIpRanges=true and with no sourceNatService, failed to create", off);
}

View File

@ -796,4 +796,22 @@ ALTER VIEW `cloud`.`domain_router_view` AS
left join
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
and async_job.instance_type = 'DomainRouter'
and async_job.job_status = 0;
and async_job.job_status = 0;
-- Add details talbe for the network offering
CREATE TABLE `cloud`.`network_offering_details` (
`id` bigint unsigned NOT NULL auto_increment,
`network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id',
`name` varchar(255) NOT NULL,
`value` varchar(1024) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_network_offering_details__network_offering_id` FOREIGN KEY `fk_network_offering_details__network_offering_id`(`network_offering_id`) REFERENCES `network_offerings`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Change the constraint for the network service map table. Now we support multiple provider for the same service
ALTER TABLE `cloud`.`ntwk_service_map` DROP FOREIGN KEY `fk_ntwk_service_map__network_id`;
ALTER TABLE `cloud`.`ntwk_service_map` DROP INDEX `network_id`;
ALTER TABLE `cloud`.`ntwk_service_map` ADD UNIQUE `network_id` (`network_id`,`service`,`provider`);
ALTER TABLE `cloud`.`ntwk_service_map` ADD CONSTRAINT `fk_ntwk_service_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE;