@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_CREATE, eventDescription = "creating autoscale vm group", create = true)
public AutoScaleVmGroup createAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) {
int minMembers = cmd.getMinMembers();
int maxMembers = cmd.getMaxMembers();
Integer interval = cmd.getInterval();
Boolean forDisplay = cmd.getDisplay();
if (interval == null) {
interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME;
}
LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancer.getId())) {
throw new InvalidParameterValueException("an AutoScaleVmGroup is already attached to the lb rule, the existing vm group has to be first deleted");
}
if (_lb2VmMapDao.isVmAttachedToLoadBalancer(loadBalancer.getId())) {
throw new InvalidParameterValueException(
"there are Vms already bound to the specified LoadBalancing Rule. User bound Vms and AutoScaled Vm Group cannot co-exist on a Load Balancing Rule");
}
AutoScaleVmGroupVO vmGroupVO = new AutoScaleVmGroupVO(cmd.getLbRuleId(), zoneId, loadBalancer.getDomainId(), loadBalancer.getAccountId(), minMembers, maxMembers,
loadBalancer.getDefaultPortStart(), interval, null, cmd.getProfileId(), AutoScaleVmGroup.State_New);
if (forDisplay != null) {
vmGroupVO.setDisplay(forDisplay);
}
vmGroupVO = checkValidityAndPersist(vmGroupVO, cmd.getScaleUpPolicyIds(), cmd.getScaleDownPolicyIds());
s_logger.info("Successfully created Autoscale Vm Group with Id: " + vmGroupVO.getId());
return vmGroupVO;
}