use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.
the class NetscalerElement method configureNetscalerLoadBalancer.
@DB
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(final long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
final ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
final 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());
}
}
final 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);
}
}
}
final 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) {
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 (!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);
}
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_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());
_agentMgr.reconnect(host.getId());
return lbDeviceVo;
}
use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.
the class ExternalLoadBalancerDeviceManagerImplTest method setupLBHealthChecksMocks.
private void setupLBHealthChecksMocks() throws URISyntaxException {
Mockito.when(network.getId()).thenReturn(42l);
Mockito.when(network.getBroadcastUri()).thenReturn(new URI("vlan://1"));
NetworkExternalLoadBalancerVO externalLb = Mockito.mock(NetworkExternalLoadBalancerVO.class);
Mockito.when(externalLb.getExternalLBDeviceId()).thenReturn(66l);
Mockito.when(_networkExternalLBDao.findByNetworkId(42)).thenReturn(externalLb);
ExternalLoadBalancerDeviceVO lbDevice = Mockito.mock(ExternalLoadBalancerDeviceVO.class);
Mockito.when(_externalLoadBalancerDeviceDao.findById(66l)).thenReturn(lbDevice);
Mockito.when(rule.getAlgorithm()).thenReturn("TEST");
Mockito.when(rule.getProtocol()).thenReturn("TEST");
Mockito.when(rule.getSourceIp()).thenReturn(new Ip(1l));
Mockito.when(lbDevice.getHostId()).thenReturn(99l);
HostVO hostVo = Mockito.mock(HostVO.class);
Mockito.when(_hostDao.findById(Mockito.anyLong())).thenReturn(hostVo);
}
Aggregations