private boolean assignLBruleToNewVm(long vmId, AutoScaleVmGroupVO asGroup) { List<Long> lstVmId = new ArrayList<Long>(); long lbId = asGroup.getLoadBalancerId(); List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId); if ((LbVmMapVos != null) && (LbVmMapVos.size() > 0)) { for (LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) { long instanceId = LbVmMapVo.getInstanceId(); if (instanceId == vmId) { s_logger.warn("the new VM is already mapped to LB rule. What's wrong?"); return true; } } } lstVmId.add(new Long(vmId)); return _loadBalancingRulesService.assignToLoadBalancer(lbId, lstVmId, new HashMap<Long, List<String>>()); }
@Override public void execute() { CallContext.current().setEventDetails("Load balancer Id: " + getLoadBalancerId() + " VmIds: " + StringUtils.join(getVirtualMachineIds(), ",")); Map<Long, List<String>> vmIdIpsMap = getVmIdIpListMap(); boolean result = false; try { result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds, vmIdIpsMap); }catch (CloudRuntimeException ex) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule"); } if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule"); } }
@Override public void execute() { CallContext.current().setEventDetails("Load balancer Id: " + getLoadBalancerId() + " VmIds: " + StringUtils.join(getVirtualMachineIds(), ",")); final Map<Long, List<String>> vmIdIpsMap = getVmIdIpListMap(); boolean result = false; try { result = _lbService.assignToLoadBalancer(getLoadBalancerId(), virtualMachineIds, vmIdIpsMap); } catch (final CloudRuntimeException ex) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule"); } if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign load balancer rule"); } }