}
}
@DB
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(long lbDeviceId, Long capacity, Boolean inline, Boolean dedicatedUse, List<Long> newPodsConfig) {
ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
}
List<Long> currentPodsConfig = new ArrayList<Long>();
List<NetScalerPodVO> currentPodVOs = _netscalerPodDao.listByNetScalerDeviceId(lbDeviceVo.getId());
if (currentPodVOs != null && currentPodVOs.size() > 0) {
for (NetScalerPodVO nsPodVo: currentPodVOs) {
currentPodsConfig.add(nsPodVo.getPodId());
}
}
List<Long> podsToAssociate = new ArrayList<Long>();
if (newPodsConfig != null && newPodsConfig.size() > 0) {
for (Long podId: newPodsConfig) {
HostPodVO pod = _podDao.findById(podId);
if (pod == null) {
throw new InvalidParameterValueException("Can't find pod by id " + podId);
}
}
for (Long podId: newPodsConfig) {
if (!currentPodsConfig.contains(podId)) {
podsToAssociate.add(podId);
}
}
}
List<Long> podsToDeassociate = new ArrayList<Long>();
for (Long podId: currentPodsConfig) {
if (!newPodsConfig.contains(podId)) {
podsToDeassociate.add(podId);
}
}
String deviceName = lbDeviceVo.getDeviceName();
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 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 != null && capacity < networks.size()) {
throw new CloudRuntimeException("There are more number of networks already using this netscaler device than configured capacity");
}
if (dedicatedUse != null && dedicatedUse == true) {
throw new CloudRuntimeException("There are networks already using this netscaler device to make device dedicated");
}
if (inline != null) {
boolean _setInline = Boolean.parseBoolean((String) lbDetails.get("inline"));
if (inline != _setInline) {
throw new CloudRuntimeException("There are networks already using this netscaler device to change the device inline or side-by-side configuration");
}
}
}
}
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);
}
if (inline != null && inline == true) {
lbDeviceVo.setIsInlineMode(true);
lbDetails.put("inline", "true");
} else {
lbDeviceVo.setIsInlineMode(false);
lbDetails.put("inline", "false");
}
Transaction txn = Transaction.currentTxn();
txn.start();
_lbDeviceDao.update(lbDeviceId, lbDeviceVo);
for (Long podId: podsToAssociate) {
NetScalerPodVO nsPodVo = new NetScalerPodVO(lbDeviceId, podId);
_netscalerPodDao.persist(nsPodVo);
}
for (Long podId: podsToDeassociate) {
NetScalerPodVO nsPodVo = _netscalerPodDao.findByPodId(podId);
_netscalerPodDao.remove(nsPodVo.getId());
}
// FIXME get the row lock to avoid race condition
_detailsDao.persist(lbDeviceVo.getHostId(), lbDetails);
HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
txn.commit();
_agentMgr.reconnect(host.getId());
return lbDeviceVo;
}