making devices enabled independent of config commands

adding default device capacity when admin does not specify a vlaue
fixed bug in device allocation logic
This commit is contained in:
Murali Reddy 2011-11-22 19:52:07 -08:00
parent fc7bbc39f3
commit beb38c8310
13 changed files with 233 additions and 167 deletions

View File

@ -89,7 +89,7 @@ public class NetscalerResource implements ServerResource {
private String _objectNamePathSep = "-";
nitro_service _netscalerService ;
Long timeout = new Long(100000);
Long _timeout = new Long(100000);
base_response apiCallResult;
public NetscalerResource () {
@ -157,10 +157,12 @@ public class NetscalerResource implements ServerResource {
_inline = Boolean.parseBoolean((String) params.get("inline"));
// validate device configration parameters
login();
enableNetScalerLoadBalancing();
checkLoadBalancingFeatureEnabled();
validateInterfaces(_publicInterface, _privateInterface);
validateDeviceType(_deviceName);
return true;
} catch (Exception e) {
throw new ConfigurationException(e.getMessage());
@ -170,7 +172,9 @@ public class NetscalerResource implements ServerResource {
private void login() throws ExecutionException {
try {
_netscalerService = new nitro_service(_ip, "https");
apiCallResult = _netscalerService.login(_username, _password, timeout);
_netscalerService.set_credential(_username, _password);
_netscalerService.set_timeout(_timeout);
apiCallResult = _netscalerService.login();
if (apiCallResult.errorcode != 0) {
throw new ExecutionException ("Failed to log in to Netscaler device at " + _ip + " due to error " + apiCallResult.errorcode + " and message " + apiCallResult.message);
}
@ -181,15 +185,21 @@ public class NetscalerResource implements ServerResource {
}
}
private void enableNetScalerLoadBalancing() throws ExecutionException {
private void checkLoadBalancingFeatureEnabled() throws ExecutionException {
try {
String[] feature = new String[1];
feature[0] = "LB";
_netscalerService.enable_features(feature);
String[] features = _netscalerService.get_enabled_features();
if (features != null) {
for (String feature : features) {
if (feature.equalsIgnoreCase("LB")) {
return;
}
}
}
throw new ExecutionException("Load balancing feature is not enabled on the device. Please enable the load balancing feature and add the device.");
} catch (nitro_exception e) {
throw new ExecutionException("Enabling netscaler load balancing feature failed due to error " + apiCallResult.errorcode + " and message " + e.getMessage());
throw new ExecutionException("Failed to verify load balancing is enalbed due to error " + apiCallResult.errorcode + " and message " + e.getMessage());
} catch (Exception e) {
throw new ExecutionException("Enabling netscaler load balancing feature failed due to " + e.getMessage());
throw new ExecutionException("Failed to verify load balancing is enalbed due to " + e.getMessage());
}
}
@ -291,32 +301,16 @@ public class NetscalerResource implements ServerResource {
return Answer.createUnsupportedCommandAnswer(cmd);
}
String lbProtocol;
String lbMethod;
LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
if (loadBalancers == null) {
return new Answer(cmd);
}
for (LoadBalancerTO loadBalancer : loadBalancers) {
if (loadBalancer.getProtocol() == null) {
lbProtocol = "TCP";
} else if (loadBalancer.getProtocol().equals(NetUtils.TCP_PROTO)){
lbProtocol = "TCP";
} else if (loadBalancer.getProtocol().equals(NetUtils.UDP_PROTO)) {
lbProtocol = "UDP";
} else {
throw new ExecutionException("Got invalid protocol: " + loadBalancer.getProtocol());
}
if (loadBalancer.getAlgorithm().equals("roundrobin")) {
lbMethod = "ROUNDROBIN";
} else if (loadBalancer.getAlgorithm().equals("leastconn")) {
lbMethod = "LEASTCONNECTION";
} else {
throw new ExecutionException("Got invalid load balancing algorithm: " + loadBalancer.getAlgorithm());
}
String srcIp = loadBalancer.getSrcIp();
int srcPort = loadBalancer.getSrcPort();
String lbProtocol = loadBalancer.getProtocol();
String lbAlgorithm = loadBalancer.getAlgorithm();
String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort, lbProtocol);
boolean destinationsToAdd = false;
@ -330,7 +324,7 @@ public class NetscalerResource implements ServerResource {
if (!loadBalancer.isRevoked() && destinationsToAdd) {
// create a load balancing virtual server
addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbMethod, lbProtocol);
addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device");
}
@ -391,13 +385,13 @@ public class NetscalerResource implements ServerResource {
// delete the binding
apiCallResult = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.delete(_netscalerService, binding);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to delete the binding between the virtual server: " + nsVirtualServerName + " and service:" + nsServiceName);
throw new ExecutionException("Failed to delete the binding between the virtual server: " + nsVirtualServerName + " and service:" + nsServiceName + " due to" + apiCallResult.message);
}
// delete the service
apiCallResult = com.citrix.netscaler.nitro.resource.config.basic.service.delete(_netscalerService, nsServiceName);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to delete service: " + nsServiceName);
throw new ExecutionException("Failed to delete service: " + nsServiceName + " due to " + apiCallResult.message);
}
// delete the server if there is no associated services
@ -405,7 +399,7 @@ public class NetscalerResource implements ServerResource {
if ((services == null) || (services.length == 0)) {
apiCallResult = com.citrix.netscaler.nitro.resource.config.basic.server.delete(_netscalerService, nsServerName);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to remove server:" + nsServerName);
throw new ExecutionException("Failed to remove server:" + nsServerName + " due to " + apiCallResult.message);
}
}
}
@ -414,8 +408,8 @@ public class NetscalerResource implements ServerResource {
}
}
} else {
// delete the deployed load balancing rule and its destinations
lbvserver lbserver = lbvserver.get(_netscalerService, nsVirtualServerName);
// delete the implemented load balancing rule and its destinations
lbvserver lbserver = getVirtualServerIfExisits(nsVirtualServerName);
if (lbserver == null) {
throw new ExecutionException("Failed to find virtual server with name:" + nsVirtualServerName);
}
@ -427,7 +421,7 @@ public class NetscalerResource implements ServerResource {
String serviceName = binding.get_servicename();
apiCallResult = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.delete(_netscalerService, binding);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to unbind servic from the lb virtual server: " + nsVirtualServerName);
throw new ExecutionException("Failed to unbind service from the lb virtual server: " + nsVirtualServerName + " due to " + apiCallResult.message);
}
com.citrix.netscaler.nitro.resource.config.basic.service svc = com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, serviceName);
@ -441,7 +435,7 @@ public class NetscalerResource implements ServerResource {
if ((services == null) || (services.length == 0)) {
apiCallResult = com.citrix.netscaler.nitro.resource.config.basic.server.delete(_netscalerService, nsServerName);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to remove server:" + nsServerName);
throw new ExecutionException("Failed to remove server:" + nsServerName + " due to " + apiCallResult.message);
}
}
}
@ -494,10 +488,7 @@ public class NetscalerResource implements ServerResource {
}
private void addGuestVlanAndSubnet(long vlanTag, String vlanSelfIp, String vlanNetmask) throws ExecutionException {
org.apache.axis.types.UnsignedInt result;
try {
String vlanName = generateVlanName(vlanTag);
if (!nsVlanExists(vlanTag)) {
// add new vlan
vlan vlanObj = new vlan();
@ -547,8 +538,6 @@ public class NetscalerResource implements ServerResource {
}
private void deleteGuestVlan(long vlanTag, String vlanSelfIp, String vlanNetmask) throws ExecutionException {
org.apache.axis.types.UnsignedInt result;
try {
if (nsVlanExists(vlanTag)) {
@ -624,6 +613,20 @@ public class NetscalerResource implements ServerResource {
}
}
private lbvserver getVirtualServerIfExisits(String lbVServerName ) throws ExecutionException {
try {
return lbvserver.get(_netscalerService, lbVServerName);
} catch (nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return null;
} else {
throw new ExecutionException(e.getMessage());
}
} catch (Exception e) {
throw new ExecutionException(e.getMessage());
}
}
private boolean nsServiceExists(String serviceName) throws ExecutionException {
try {
if (com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, serviceName) != null) {
@ -698,15 +701,49 @@ public class NetscalerResource implements ServerResource {
private void addLBVirtualServer(String virtualServerName, String srcIp, int srcPort, String lbMethod, String lbProtocol) throws ExecutionException {
try {
lbvserver vserver = new lbvserver();
if (lbProtocol == null) {
lbProtocol = "TCP";
} else if (lbProtocol.equals(NetUtils.TCP_PROTO)){
lbProtocol = "TCP";
} else if (lbProtocol.equals(NetUtils.UDP_PROTO)) {
lbProtocol = "UDP";
} else {
throw new ExecutionException("Got invalid protocol: " + lbProtocol);
}
if (lbMethod.equals("roundrobin")) {
lbMethod = "ROUNDROBIN";
} else if (lbMethod.equals("leastconn")) {
lbMethod = "LEASTCONNECTION";
} else {
throw new ExecutionException("Got invalid load balancing algorithm: " + lbMethod);
}
boolean vserverExisis = false;
lbvserver vserver = getVirtualServerIfExisits(virtualServerName);
if (vserver == null) {
vserver = new lbvserver();
} else {
vserverExisis = true;
}
vserver.set_name(virtualServerName);
vserver.set_ipv46(srcIp);
vserver.set_port(srcPort);
vserver.set_servicetype(lbProtocol);
vserver.set_lbmethod(lbMethod);
if (vserverExisis) {
apiCallResult = lbvserver.update(_netscalerService,vserver);
} else {
apiCallResult = lbvserver.add(_netscalerService,vserver);
}
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to create new virtual server:" + virtualServerName);
throw new ExecutionException("Failed to create new virtual server:" + virtualServerName+ " due to " + apiCallResult.message);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created load balancing virtual server " + virtualServerName + " on the Netscaler device");
}
} catch (nitro_exception e) {
if (e.getErrorCode() != NitroError.NS_RESOURCE_EXISTS) {
@ -725,10 +762,14 @@ public class NetscalerResource implements ServerResource {
}
apiCallResult = lbvserver.delete(_netscalerService, vserver);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to remove virtual server:" + virtualServerName);
throw new ExecutionException("Failed to remove virtual server:" + virtualServerName + " due to " + apiCallResult.message);
}
} catch (nitro_exception e) {
throw new ExecutionException("Failed to remove virtual server:" + virtualServerName +" due to " + e.getMessage());
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return;
} else {
throw new ExecutionException("Failed remove virtual server:" + virtualServerName +" due to " + e.getMessage());
}
} catch (Exception e) {
throw new ExecutionException("Failed to remove virtual server:" + virtualServerName +" due to " + e.getMessage());
}
@ -738,7 +779,7 @@ public class NetscalerResource implements ServerResource {
try {
apiCallResult = nsconfig.save(_netscalerService);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Error occured while saving configuration changes to Netscaler device due to error:" + apiCallResult.errorcode);
throw new ExecutionException("Error occured while saving configuration changes to Netscaler device due to " + apiCallResult.message);
}
} catch (nitro_exception e) {
throw new ExecutionException("Failed to save configuration changes to Netscaler device due to " + e.getMessage());
@ -796,10 +837,6 @@ public class NetscalerResource implements ServerResource {
return false;
}
private String generateVlanName(long vlanTag) {
return genObjectName("cloud-vlan", String.valueOf(vlanTag));
}
private String generateNSVirtualServerName(String srcIp, long srcPort, String protocol) {
return genObjectName("cloud-VirtualServer", protocol, srcIp, srcPort);
}

BIN
deps/cloud-netscaler.jar vendored Normal file → Executable file

Binary file not shown.

View File

@ -322,7 +322,10 @@ public enum Config {
ProjectSMTPPassword("Project Defaults", ManagementServer.class, String.class, "project.smtp.password", null, "Password for SMTP authentication (applies only if project.smtp.useAuth is true)", null),
ProjectSMTPPort("Project Defaults", ManagementServer.class, Integer.class, "project.smtp.port", "465", "Port the SMTP server is listening on", null),
ProjectSMTPUseAuth("Project Defaults", ManagementServer.class, String.class, "project.smtp.useAuth", null, "If true, use SMTP authentication when sending emails", null),
ProjectSMTPUsername("Project Defaults", ManagementServer.class, String.class, "project.smtp.username", null, "Username for SMTP authentication (applies only if project.smtp.useAuth is true)", null);
ProjectSMTPUsername("Project Defaults", ManagementServer.class, String.class, "project.smtp.username", null, "Username for SMTP authentication (applies only if project.smtp.useAuth is true)", null),
DefaultExternalLoadBalancerCapacity("Advanced", ManagementServer.class, String.class, "external.lb.default.capacity", "50", "default number of networks permitted per external load balancer device", null),
DefaultExternalFirewallCapacity("Advanced", ManagementServer.class, String.class, "external.firewall.default.capacity", "50", "default number of networks permitted per external load firewall device", null);
private final String _category;
private final Class<?> _componentClass;

View File

@ -214,9 +214,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
ExternalFirewallDeviceVO fwDevice = new ExternalFirewallDeviceVO(externalFirewall.getId(), pNetwork.getId(), ntwkSvcProvider.getProviderName(),
deviceName, capacity, dedicatedUse);
if (capacity != 0) {
fwDevice.setState(FirewallDeviceState.Enabled);
}
_externalFirewallDeviceDao.persist(fwDevice);
DetailVO hostDetail = new DetailVO(externalFirewall.getId(), ApiConstants.FIREWALL_DEVICE_ID, String.valueOf(fwDevice.getId()));

View File

@ -56,9 +56,9 @@ public class ExternalFirewallDeviceVO {
@Column(name = "device_name")
private String deviceName;
@Column(name="state")
@Column(name="device_state")
@Enumerated(value=EnumType.STRING)
FirewallDeviceState state;
FirewallDeviceState deviceState;
@Column(name="is_dedicated")
private boolean isDedicatedDevice;
@ -86,10 +86,11 @@ public class ExternalFirewallDeviceVO {
this.providerName = provider_name;
this.deviceName = device_name;
this.hostId = hostId;
this.state = FirewallDeviceState.Disabled;
this.deviceState = FirewallDeviceState.Disabled;
this.allocationState = FirewallDeviceAllocationState.Free;
this.capacity = capacity;
this.isDedicatedDevice = dedicated;
this.deviceState = FirewallDeviceState.Enabled;
this.uuid = UUID.randomUUID().toString();
}
@ -125,12 +126,12 @@ public class ExternalFirewallDeviceVO {
this.capacity = capacity;
}
public FirewallDeviceState getState() {
return state;
public FirewallDeviceState getDeviceState() {
return deviceState;
}
public void setState(FirewallDeviceState state) {
this.state = state;
public void setDeviceState(FirewallDeviceState state) {
this.deviceState = state;
}
public FirewallDeviceAllocationState getAllocationState() {

View File

@ -35,6 +35,9 @@ import com.cloud.utils.component.Manager;
public interface ExternalLoadBalancerDeviceManager extends Manager{
public static final int DEFAULT_LOAD_BALANCER_CAPACITY = 50;
/**
* adds a load balancer device in to a physical network
* @param physicalNetworkId physical network id of the network in to which device to be added

View File

@ -122,35 +122,62 @@ import com.cloud.vm.dao.NicDao;
public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase implements ExternalLoadBalancerDeviceManager, ResourceStateAdapter {
@Inject NetworkExternalLoadBalancerDao _networkExternalLBDao;
@Inject ExternalLoadBalancerDeviceDao _externalLoadBalancerDeviceDao;
@Inject HostDao _hostDao;
@Inject DataCenterDao _dcDao;
@Inject HostDetailsDao _detailsDao;
@Inject NetworkManager _networkMgr;
@Inject InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao;
@Inject NicDao _nicDao;
@Inject AgentManager _agentMgr;
@Inject ResourceManager _resourceMgr;
@Inject IPAddressDao _ipAddressDao;
@Inject VlanDao _vlanDao;
@Inject NetworkOfferingDao _networkOfferingDao;
@Inject AccountDao _accountDao;
@Inject PhysicalNetworkDao _physicalNetworkDao;
@Inject PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@Inject AccountManager _accountMgr;
@Inject UserStatisticsDao _userStatsDao;
@Inject NetworkDao _networkDao;
@Inject DomainRouterDao _routerDao;
@Inject LoadBalancerDao _loadBalancerDao;
@Inject PortForwardingRulesDao _portForwardingRulesDao;
@Inject ConfigurationDao _configDao;
@Inject HostDetailsDao _hostDetailDao;
@Inject NetworkExternalLoadBalancerDao _networkLBDao;
@Inject NetworkServiceMapDao _ntwkSrvcProviderDao;
@Inject
NetworkExternalLoadBalancerDao _networkExternalLBDao;
@Inject
ExternalLoadBalancerDeviceDao _externalLoadBalancerDeviceDao;
@Inject
HostDao _hostDao;
@Inject
DataCenterDao _dcDao;
@Inject
HostDetailsDao _detailsDao;
@Inject
NetworkManager _networkMgr;
@Inject
InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao;
@Inject
NicDao _nicDao;
@Inject
AgentManager _agentMgr;
@Inject
ResourceManager _resourceMgr;
@Inject
IPAddressDao _ipAddressDao;
@Inject
VlanDao _vlanDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
@Inject
AccountDao _accountDao;
@Inject
PhysicalNetworkDao _physicalNetworkDao;
@Inject
PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@Inject
AccountManager _accountMgr;
@Inject
UserStatisticsDao _userStatsDao;
@Inject
NetworkDao _networkDao;
@Inject
DomainRouterDao _routerDao;
@Inject
LoadBalancerDao _loadBalancerDao;
@Inject
PortForwardingRulesDao _portForwardingRulesDao;
@Inject
ConfigurationDao _configDao;
@Inject
HostDetailsDao _hostDetailDao;
@Inject
NetworkExternalLoadBalancerDao _networkLBDao;
@Inject
NetworkServiceMapDao _ntwkSrvcProviderDao;
ScheduledExecutorService _executor;
int _externalNetworkStatsInterval;
private int _externalNetworkStatsInterval;
private long _defaultLbCapacity;
private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class);
@Override
@ -222,9 +249,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
ExternalLoadBalancerDeviceVO lbDeviceVO = new ExternalLoadBalancerDeviceVO(host.getId(), pNetwork.getId(), ntwkSvcProvider.getProviderName(),
deviceName, capacity, dedicatedUse, inline);
if (capacity != 0) {
lbDeviceVO.setState(LBDeviceState.Enabled);
}
_externalLoadBalancerDeviceDao.persist(lbDeviceVO);
DetailVO hostDetail = new DetailVO(host.getId(), ApiConstants.LOAD_BALANCER_DEVICE_ID, String.valueOf(lbDeviceVO.getId()));
@ -322,20 +347,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
if (dedicatedLb) {
lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
if (lbDevices != null && !lbDevices.isEmpty()) {
// return first device that is free, fully configured and meant for dedicated use
for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
if (lbdevice.getState() == LBDeviceState.Enabled && lbdevice.getIsDedicatedDevice()) {
return lbdevice;
}
}
//if there are no dedicated lb device then return first device that is free, fully configured
for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
if (lbdevice.getState() == LBDeviceState.Enabled) {
return lbdevice;
}
}
}
} else {
// get the LB devices that are already allocated for shared use
@ -354,33 +371,36 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
continue;
}
// skip if the device is intended to be used in dedicated mode only
if (lbdevice.getIsDedicatedDevice()) {
continue;
}
// get the used capacity from the list of guest networks that are mapped to this load balancer
List<NetworkExternalLoadBalancerVO> mappedNetworks = _networkExternalLBDao.listByLoadBalancerDeviceId(lbdevice.getId());
// get the list of guest networks that are mapped to this load balancer
long usedCapacity = ((mappedNetworks == null) || (mappedNetworks.isEmpty()))? 0 : mappedNetworks.size();
// get max number of guest networks that can be mapped to this device
// get the configured capacity for this device
long fullCapacity = lbdevice.getCapacity();
if (fullCapacity == 0) {
fullCapacity = _defaultLbCapacity; // if capacity not configured then use the default
}
long freeCapacity = fullCapacity - usedCapacity;
if (freeCapacity > 0) {
if (maxFreeCapacityLbdevice == null) {
maxFreeCapacityLbdevice = lbdevice;
maxFreeCapacity = freeCapacity;
}
if (freeCapacity > maxFreeCapacity) {
} else if (freeCapacity > maxFreeCapacity) {
maxFreeCapacityLbdevice = lbdevice;
maxFreeCapacity = freeCapacity;
}
}
}
// return the device with maximum free capacity and is meant for shared use
if (maxFreeCapacityLbdevice != null) {
return maxFreeCapacityLbdevice;
}
}
// if we are here then there are no existing LB devices in shared use or the devices in shared use has no free capacity
// so allocate a new one from the pool of free LB devices
// if we are here then there are no existing LB devices in shared use or the devices in shared use has no free capacity left
// so allocate a new load balancer configured for shared use from the pool of free LB devices
lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
if (lbDevices != null && !lbDevices.isEmpty()) {
for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
@ -391,6 +411,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
}
}
// there are no devices which capcity
throw new InsufficientNetworkCapacityException("Unable to find a load balancing provider with sufficient capcity " +
" to implement the network", Network.class, network.getId());
}
@ -614,9 +635,9 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
// FIXME: should the device allocation be done during network implement phase or do a lazy allocation
// when first rule for the network is configured??
// find a load balancer device as per the network offering
boolean dedicatedLB = offering.getDedicatedLB();
try {
// find a load balancer device for this network as per the network offering
ExternalLoadBalancerDeviceVO lbDevice = findSuitableLoadBalancerForNetwork(guestConfig, dedicatedLB);
lbDeviceId = lbDevice.getId();
@ -763,6 +784,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ExternalNetworkMonitor"));
}
_defaultLbCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalLoadBalancerCapacity.key()), 50);
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
return true;
}

View File

@ -57,7 +57,7 @@ public class ExternalLoadBalancerDeviceVO {
@Column(name = "device_name")
private String deviceName;
@Column(name="state")
@Column(name="device_state")
@Enumerated(value=EnumType.STRING)
private LBDeviceState state;
@ -105,6 +105,7 @@ public class ExternalLoadBalancerDeviceVO {
this.isDedicatedDevice = dedicated;
this.isInlineMode = inline;
this.isManagedDevice = false;
this.state = LBDeviceState.Enabled;
this.uuid = UUID.randomUUID().toString();
if (device_name.equalsIgnoreCase(ExternalNetworkDeviceManager.NetworkDevice.NetscalerSDXLoadBalancer.getName())) {

View File

@ -55,7 +55,7 @@ public class ExternalFirewallDeviceDaoImpl extends GenericDaoBase<ExternalFirewa
deviceStatusSearch = createSearchBuilder();
deviceStatusSearch.and("physicalNetworkId", deviceStatusSearch.entity().getPhysicalNetworkId(), Op.EQ);
deviceStatusSearch.and("providerName", deviceStatusSearch.entity().getProviderName(), Op.EQ);
deviceStatusSearch.and("deviceState", deviceStatusSearch.entity().getState(), Op.EQ);
deviceStatusSearch.and("deviceState", deviceStatusSearch.entity().getDeviceState(), Op.EQ);
deviceStatusSearch.done();
}

View File

@ -83,7 +83,6 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@SuppressWarnings("deprecation")
@Local(value=NetworkElement.class)
public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, F5ExternalLoadBalancerElementService, ExternalLoadBalancerDeviceManager {

View File

@ -288,7 +288,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
// true if at-least one SRX device is added in to physical network and is in configured (in enabled state) state
if (fwDevices != null && !fwDevices.isEmpty()) {
for (ExternalFirewallDeviceVO fwDevice : fwDevices) {
if (fwDevice.getState() == FirewallDeviceState.Enabled) {
if (fwDevice.getDeviceState() == FirewallDeviceState.Enabled) {
return true;
}
}
@ -421,7 +421,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
}
}
fwDeviceVO.setState(FirewallDeviceState.Enabled);
fwDeviceVO.setDeviceState(FirewallDeviceState.Enabled);
_fwDevicesDao.update(fwDeviceId, fwDeviceVO);
return fwDeviceVO;
}
@ -488,7 +488,7 @@ public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceMan
response.setDeviceName(fwDeviceVO.getDeviceName());
response.setDeviceCapacity(fwDeviceVO.getCapacity());
response.setProvider(fwDeviceVO.getProviderName());
response.setDeviceState(fwDeviceVO.getState().name());
response.setDeviceState(fwDeviceVO.getDeviceState().name());
response.setIpAddress(fwHost.getPrivateIpAddress());
response.setPublicInterface(fwDetails.get("publicInterface"));
response.setUsageInterface(fwDetails.get("usageInterface"));

View File

@ -234,21 +234,19 @@ public class NetscalerExternalLoadBalancerElement extends ExternalLoadBalancerDe
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
}
if (dedicatedUse != null || capacity != null || inline != null) {
String deviceName = lbDeviceVo.getDeviceName();
if (NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
// FIXME: how to interpret SDX device capacity
} else if (NetworkDevice.NetscalerMPXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
if (dedicatedUse != null || capacity != null || inline != null) {
if (NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName) ||
NetworkDevice.NetscalerMPXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
if (dedicatedUse != null && dedicatedUse == true) {
throw new InvalidParameterValueException("Netscaler MPX device should be shared and can not be dedicated to a single accoutnt.");
throw new InvalidParameterValueException("Netscaler MPX and SDX device should be shared and can not be dedicated to a single account.");
}
}
// check if any networks are using this netscaler device
List<NetworkExternalLoadBalancerVO> networks = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
if ((networks != null) && !networks.isEmpty()) {
if (capacity < networks.size()) {
if (capacity != null && capacity < networks.size()) {
throw new CloudRuntimeException("There are more number of networks already using this netscaler device than configured capacity");
}
@ -265,9 +263,13 @@ public class NetscalerExternalLoadBalancerElement extends ExternalLoadBalancerDe
}
}
if (!NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
if (capacity != null) {
lbDeviceVo.setCapacity(capacity);
}
} else {
// FIXME how to interpret configured capacity of the SDX device
}
if(dedicatedUse != null) {
lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
@ -284,9 +286,9 @@ public class NetscalerExternalLoadBalancerElement extends ExternalLoadBalancerDe
Transaction txn = Transaction.currentTxn();
txn.start();
lbDeviceVo.setState(LBDeviceState.Enabled);
_lbDeviceDao.update(lbDeviceId, lbDeviceVo);
// FIXME get the row lock to avoid race condition
_detailsDao.persist(lbDeviceVo.getHostId(), lbDetails);
HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
txn.commit();

View File

@ -1948,13 +1948,13 @@ CREATE TABLE `cloud`.`external_load_balancer_devices` (
`provider_name` varchar(255) NOT NULL COMMENT 'Service Provider name corresponding to this load balancer device',
`device_name` varchar(255) NOT NULL COMMENT 'name of the load balancer device',
`capacity` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'Capacity of the load balancer device',
`state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'state (enabled/disabled/shutdown) of the device',
`device_state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'state (enabled/disabled/shutdown) of the device',
`allocation_state` varchar(32) NOT NULL DEFAULT 'Free' COMMENT 'Allocation state (Free/Shared/Dedicated/Provider) of the device',
`is_dedicated` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if device/appliance meant for dedicated use only',
`is_inline` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if netscaler load balancer to be used in in-line configuration with firewall',
`is_managed` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if device/appliance is provisioned and its life cycle is managed by by cloudstack',
`is_dedicated` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if device/appliance is provisioned for dedicated use only',
`is_inline` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if load balancer will be used in in-line configuration with firewall',
`is_managed` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if load balancer appliance is provisioned and its life cycle is managed by by cloudstack',
`host_id` bigint unsigned NOT NULL COMMENT 'host id coresponding to the external load balancer device',
`parent_host_id` bigint unsigned COMMENT 'if the device/appliance is cloudstack managed, then host id on which this device/appliance is provisioned',
`parent_host_id` bigint unsigned COMMENT 'if the load balancer appliance is cloudstack managed, then host id on which this appliance is provisioned',
PRIMARY KEY (`id`),
CONSTRAINT `fk_external_lb_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_external_lb_devices_parent_host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE,
@ -1967,7 +1967,7 @@ CREATE TABLE `cloud`.`external_firewall_devices` (
`physical_network_id` bigint unsigned NOT NULL COMMENT 'id of the physical network in to which firewall device is added',
`provider_name` varchar(255) NOT NULL COMMENT 'Service Provider name corresponding to this firewall device',
`device_name` varchar(255) NOT NULL COMMENT 'name of the firewall device',
`state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'state (enabled/disabled/shutdown) of the device',
`device_state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'state (enabled/disabled/shutdown) of the device',
`is_dedicated` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if device/appliance meant for dedicated use only',
`allocation_state` varchar(32) NOT NULL DEFAULT 'Free' COMMENT 'Allocation state (Free/Allocated) of the device',
`host_id` bigint unsigned NOT NULL COMMENT 'host id coresponding to the external firewall device',