use of com.cloud.network.NetScalerPodVO 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());
try {
_agentMgr.reconnect(host.getId());
} catch (AgentUnavailableException e) {
s_logger.warn("failed to reconnect host " + host, e);
}
return lbDeviceVo;
}
use of com.cloud.network.NetScalerPodVO in project cloudstack by apache.
the class NetscalerElement method createNetscalerLoadBalancerResponse.
@Override
public NetscalerLoadBalancerResponse createNetscalerLoadBalancerResponse(ExternalLoadBalancerDeviceVO lbDeviceVO) {
NetscalerLoadBalancerResponse response = new NetscalerLoadBalancerResponse();
Host lbHost = _hostDao.findById(lbDeviceVO.getHostId());
Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVO.getHostId());
response.setId(lbDeviceVO.getUuid());
response.setIpAddress(lbHost.getPrivateIpAddress());
PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(lbDeviceVO.getPhysicalNetworkId());
if (pnw != null) {
response.setPhysicalNetworkId(pnw.getUuid());
}
response.setPublicInterface(lbDetails.get("publicInterface"));
response.setPrivateInterface(lbDetails.get("privateInterface"));
response.setDeviceName(lbDeviceVO.getDeviceName());
if (lbDeviceVO.getCapacity() == 0) {
long defaultLbCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalLoadBalancerCapacity.key()), 50);
response.setDeviceCapacity(defaultLbCapacity);
} else {
response.setDeviceCapacity(lbDeviceVO.getCapacity());
}
response.setDedicatedLoadBalancer(lbDeviceVO.getIsDedicatedDevice());
response.setProvider(lbDeviceVO.getProviderName());
response.setDeviceState(lbDeviceVO.getState().name());
response.setObjectName("netscalerloadbalancer");
response.setGslbProvider(lbDeviceVO.getGslbProvider());
response.setExclusiveGslbProvider(lbDeviceVO.getExclusiveGslbProvider());
response.setGslbSitePublicIp(lbDeviceVO.getGslbSitePublicIP());
response.setGslbSitePrivateIp(lbDeviceVO.getGslbSitePrivateIP());
List<Long> associatedPods = new ArrayList<Long>();
List<NetScalerPodVO> currentPodVOs = _netscalerPodDao.listByNetScalerDeviceId(lbDeviceVO.getId());
if (currentPodVOs != null && currentPodVOs.size() > 0) {
for (NetScalerPodVO nsPodVo : currentPodVOs) {
associatedPods.add(nsPodVo.getPodId());
}
}
response.setAssociatedPods(associatedPods);
return response;
}
use of com.cloud.network.NetScalerPodVO in project cloudstack by apache.
the class NetscalerElement method getNetScalerForEIP.
// returns configured NetScaler device that is associated with the pod that
// owns guest IP
private ExternalLoadBalancerDeviceVO getNetScalerForEIP(StaticNat rule) {
String guestIP = rule.getDestIpAddress();
List<DataCenterIpAddressVO> dcGuestIps = _privateIpAddressDao.listAll();
if (dcGuestIps != null) {
for (DataCenterIpAddressVO dcGuestIp : dcGuestIps) {
if (dcGuestIp.getIpAddress().equalsIgnoreCase(guestIP)) {
long podId = dcGuestIp.getPodId();
NetScalerPodVO nsPodVO = _netscalerPodDao.findByPodId(podId);
if (nsPodVO != null) {
ExternalLoadBalancerDeviceVO lbDeviceVO = _lbDeviceDao.findById(nsPodVO.getNetscalerDeviceId());
return lbDeviceVO;
}
}
}
}
return null;
}
Aggregations