Checking success in deleteCounter

This commit is contained in:
Deepak Garg 2012-07-19 10:26:25 +05:30 committed by Vijay
parent 30cb0e74d2
commit edcd8e7394
1 changed files with 24 additions and 22 deletions

View File

@ -87,7 +87,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils;
@Local(value = { AutoScaleService.class })
@Local(value = { AutoScaleService.class })
public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
@ -168,12 +168,12 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
for (Counter counter : counters) {
if (!supportedCounters.contains(counter.getSource().name().toString())) {
throw new InvalidParameterException("AutoScale counter with source='" + counter.getSource() + "' is not supported " +
"in the network where lb is configured");
"in the network where lb is configured");
}
}
}
private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller,String paramName, Long id, GenericDao<VO, Long> dao)
private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller, String paramName, Long id, GenericDao<VO, Long> dao)
{
VO vo = dao.findById(id);
@ -366,7 +366,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups");
}
boolean success = _autoScaleVmProfileDao.remove(id);
if(success) {
if (success) {
s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
}
return success;
@ -416,7 +416,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVO);
if(conditionIds != null) {
if (conditionIds != null) {
SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
conditionsSearch.and("ids", conditionsSearch.entity().getId(), Op.IN);
conditionsSearch.done();
@ -474,7 +474,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
AutoScalePolicyVO policyVO = new AutoScalePolicyVO(cmd.getDomainId(), cmd.getAccountId(), duration, quietTime, action);
policyVO = checkValidityAndPersist(policyVO, cmd.getConditionIds());
policyVO = checkValidityAndPersist(policyVO, cmd.getConditionIds());
s_logger.info("Successfully created AutoScale Policy with Id: " + policyVO.getId());
return policyVO;
}
@ -542,7 +542,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
Account caller = UserContext.current().getCaller();
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
ListProjectResourcesCriteria>(domainId, isRecursive, null);
ListProjectResourcesCriteria>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject,
listAll, false);
domainId = domainIdRecursiveListProject.first();
@ -618,10 +618,10 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
if (!vmGroupVO.getState().equals(AutoScaleVmGroup.State_Disabled)) {
throw new InvalidParameterValueException("The AutoScale Policy can be updated only if the Vm Group it is associated with is disabled in state");
}
if(vmGroupVO.getInterval() < policy.getDuration()) {
if (vmGroupVO.getInterval() < policy.getDuration()) {
throw new InvalidParameterValueException("duration is less than the associated AutoScaleVmGroup's interval");
}
if(vmGroupVO.getInterval() < policy.getQuietTime()) {
if (vmGroupVO.getInterval() < policy.getQuietTime()) {
throw new InvalidParameterValueException("quietTime is less than the associated AutoScaleVmGroup's interval");
}
}
@ -638,7 +638,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
int maxMembers = cmd.getMaxMembers();
Integer interval = cmd.getInterval();
if(interval == null) {
if (interval == null) {
interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME;
}
@ -646,7 +646,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
if(_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancer.getId())) {
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");
}
@ -675,7 +675,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
public boolean configureAutoScaleVmGroup(long vmGroupid) {
AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
if(isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
if (isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid);
}
@ -689,7 +689,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
public boolean deleteAutoScaleVmGroup(long id) {
AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(UserContext.current().getCaller(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
if(autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
if (autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
/* This condition is for handling failures during creation command */
return _autoScaleVmGroupDao.remove(id);
}
@ -701,7 +701,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
try {
success = configureAutoScaleVmGroup(id);
} finally {
if(!success) {
if (!success) {
s_logger.warn("Could not delete AutoScale Vm Group id : " + id);
autoScaleVmGroupVO.setState(bakupState);
_autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
@ -795,11 +795,11 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new InvalidParameterValueException("interval is an invalid value: " + interval);
}
if(scaleUpPolicyIds != null) {
if (scaleUpPolicyIds != null) {
policies.addAll(getAutoScalePolicies("scaleuppolicyid", scaleUpPolicyIds, counters, interval, true));
}
if(scaleDownPolicyIds != null) {
if (scaleDownPolicyIds != null) {
policies.addAll(getAutoScalePolicies("scaledownpolicyid", scaleDownPolicyIds, counters, interval, false));
}
@ -817,16 +817,16 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
txn.start();
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
if(scaleUpPolicyIds != null || scaleDownPolicyIds != null) {
if (scaleUpPolicyIds != null || scaleDownPolicyIds != null) {
List<Long> bakupScaleUpPolicyIds = new ArrayList<Long>();
List<Long> bakupScaleDownPolicyIds = new ArrayList<Long>();
ApiDBUtils.getAutoScaleVmGroupPolicyIds(vmGroup.getId(), bakupScaleUpPolicyIds, bakupScaleDownPolicyIds);
if(scaleUpPolicyIds == null) {
if (scaleUpPolicyIds == null) {
policyIds.addAll(bakupScaleUpPolicyIds);
} else {
policyIds.addAll(scaleUpPolicyIds);
}
if(scaleDownPolicyIds == null) {
if (scaleDownPolicyIds == null) {
policyIds.addAll(bakupScaleDownPolicyIds);
} else {
policyIds.addAll(scaleDownPolicyIds);
@ -991,7 +991,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
String name = cmd.getName();
Long id = cmd.getId();
String source = cmd.getSource();
if(source != null )
if (source != null)
source = source.toLowerCase();
Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
@ -1043,7 +1043,9 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
}
boolean success = _counterDao.remove(counterId);
s_logger.info("Successfully deleted counter with Id: " + counterId);
if (success) {
s_logger.info("Successfully deleted counter with Id: " + counterId);
}
return success;
}
@ -1063,7 +1065,7 @@ public class AutoScaleManagerImpl<Type> implements AutoScaleService, Manager {
throw new ResourceInUseException("Cannot delete Condition when it is in use by one or more AutoScale Policies.");
}
boolean success = _conditionDao.remove(conditionId);
if(success) {
if (success) {
s_logger.info("Successfully deleted condition " + condition.getId());
}
return success;