You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2014/03/11 14:13:04 UTC
[07/50] [abbrv] Dispatcher corrections, refactoring and tests
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c211f0bb/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
index 208b4a4..2fa3821 100644
--- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
+++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
@@ -53,10 +53,12 @@ import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.config.ApiServiceConfiguration;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
-import com.cloud.api.ApiDispatcher;
+import com.cloud.api.dispatch.DispatchChainFactory;
+import com.cloud.api.dispatch.DispatchTask;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
@@ -118,14 +120,17 @@ import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.UserVmService;
+
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@Local(value = {AutoScaleService.class, AutoScaleManager.class})
public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService {
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
- private ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1);
+ private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1);
+ @Inject()
+ protected DispatchChainFactory dispatchChainFactory = null;
@Inject
EntityManager _entityMgr;
@Inject
@@ -179,35 +184,35 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Inject
LoadBalancingRulesService _loadBalancingRulesService;
- public List<AutoScaleCounter> getSupportedAutoScaleCounters(long networkid) {
- String capability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName());
+ public List<AutoScaleCounter> getSupportedAutoScaleCounters(final long networkid) {
+ final String capability = _lbRulesMgr.getLBCapability(networkid, Capability.AutoScaleCounters.getName());
if (capability == null) {
return null;
}
- Gson gson = new Gson();
- java.lang.reflect.Type listType = new TypeToken<List<AutoScaleCounter>>() {
+ final Gson gson = new Gson();
+ final java.lang.reflect.Type listType = new TypeToken<List<AutoScaleCounter>>() {
}.getType();
- List<AutoScaleCounter> result = gson.fromJson(capability, listType);
+ final List<AutoScaleCounter> result = gson.fromJson(capability, listType);
return result;
}
- public void validateAutoScaleCounters(long networkid, List<Counter> counters, List<Pair<String, String>> counterParamPassed) {
- List<AutoScaleCounter> supportedCounters = getSupportedAutoScaleCounters(networkid);
+ public void validateAutoScaleCounters(final long networkid, final List<Counter> counters, final List<Pair<String, String>> counterParamPassed) {
+ final List<AutoScaleCounter> supportedCounters = getSupportedAutoScaleCounters(networkid);
if (supportedCounters == null) {
throw new InvalidParameterException("AutoScale is not supported in the network");
}
- for (Counter counter : counters) {
- String counterName = counter.getSource().name().toString();
+ for (final Counter counter : counters) {
+ final String counterName = counter.getSource().name().toString();
boolean isCounterSupported = false;
- for (AutoScaleCounter autoScaleCounter : supportedCounters) {
+ for (final AutoScaleCounter autoScaleCounter : supportedCounters) {
if (autoScaleCounter.getName().equals(counterName)) {
isCounterSupported = true;
- List<AutoScaleCounterParam> counterParams = autoScaleCounter.getParamList();
- for (AutoScaleCounterParam autoScaleCounterParam : counterParams) {
- boolean isRequiredParameter = autoScaleCounterParam.getRequired();
+ final List<AutoScaleCounterParam> counterParams = autoScaleCounter.getParamList();
+ for (final AutoScaleCounterParam autoScaleCounterParam : counterParams) {
+ final boolean isRequiredParameter = autoScaleCounterParam.getRequired();
if (isRequiredParameter) {
boolean isRequiredParamPresent = false;
- for (Pair<String, String> pair : counterParamPassed) {
+ for (final Pair<String, String> pair : counterParamPassed) {
if (pair.first().equals(autoScaleCounterParam.getParamName()))
isRequiredParamPresent = true;
@@ -227,9 +232,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
}
- private <VO extends ControlledEntity> VO getEntityInDatabase(Account caller, String paramName, Long id, GenericDao<VO, Long> dao) {
+ private <VO extends ControlledEntity> VO getEntityInDatabase(final Account caller, final String paramName, final Long id, final GenericDao<VO, Long> dao) {
- VO vo = dao.findById(id);
+ final VO vo = dao.findById(id);
if (vo == null) {
throw new InvalidParameterValueException("Unable to find " + paramName);
@@ -240,27 +245,27 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return vo;
}
- private boolean isAutoScaleScaleUpPolicy(AutoScalePolicy policyVO) {
+ private boolean isAutoScaleScaleUpPolicy(final AutoScalePolicy policyVO) {
return policyVO.getAction().equals("scaleup");
}
- private List<AutoScalePolicyVO> getAutoScalePolicies(String paramName, List<Long> policyIds, List<Counter> counters, int interval, boolean scaleUpPolicies) {
- SearchBuilder<AutoScalePolicyVO> policySearch = _autoScalePolicyDao.createSearchBuilder();
+ private List<AutoScalePolicyVO> getAutoScalePolicies(final String paramName, final List<Long> policyIds, final List<Counter> counters, final int interval, final boolean scaleUpPolicies) {
+ final SearchBuilder<AutoScalePolicyVO> policySearch = _autoScalePolicyDao.createSearchBuilder();
policySearch.and("ids", policySearch.entity().getId(), Op.IN);
policySearch.done();
- SearchCriteria<AutoScalePolicyVO> sc = policySearch.create();
+ final SearchCriteria<AutoScalePolicyVO> sc = policySearch.create();
sc.setParameters("ids", policyIds.toArray(new Object[0]));
- List<AutoScalePolicyVO> policies = _autoScalePolicyDao.search(sc, null);
+ final List<AutoScalePolicyVO> policies = _autoScalePolicyDao.search(sc, null);
int prevQuietTime = 0;
- for (AutoScalePolicyVO policy : policies) {
- int quietTime = policy.getQuietTime();
+ for (final AutoScalePolicyVO policy : policies) {
+ final int quietTime = policy.getQuietTime();
if (prevQuietTime == 0) {
prevQuietTime = quietTime;
}
- int duration = policy.getDuration();
+ final int duration = policy.getDuration();
if (duration < interval) {
throw new InvalidParameterValueException("duration : " + duration + " specified in a policy cannot be less than vm group's interval : " + interval);
}
@@ -278,11 +283,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
throw new InvalidParameterValueException("Only scaledown policies can be specified in scaledownpolicyids");
}
}
- List<AutoScalePolicyConditionMapVO> policyConditionMapVOs = _autoScalePolicyConditionMapDao.listByAll(policy.getId(), null);
- for (AutoScalePolicyConditionMapVO policyConditionMapVO : policyConditionMapVOs) {
- long conditionid = policyConditionMapVO.getConditionId();
- Condition condition = _conditionDao.findById(conditionid);
- Counter counter = _counterDao.findById(condition.getCounterid());
+ final List<AutoScalePolicyConditionMapVO> policyConditionMapVOs = _autoScalePolicyConditionMapDao.listByAll(policy.getId(), null);
+ for (final AutoScalePolicyConditionMapVO policyConditionMapVO : policyConditionMapVOs) {
+ final long conditionid = policyConditionMapVO.getConditionId();
+ final Condition condition = _conditionDao.findById(conditionid);
+ final Counter counter = _counterDao.findById(condition.getCounterid());
counters.add(counter);
}
}
@@ -291,11 +296,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@DB
protected AutoScaleVmProfileVO checkValidityAndPersist(AutoScaleVmProfileVO vmProfile) {
- long templateId = vmProfile.getTemplateId();
- long autoscaleUserId = vmProfile.getAutoScaleUserId();
- int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
+ final long templateId = vmProfile.getTemplateId();
+ final long autoscaleUserId = vmProfile.getAutoScaleUserId();
+ final int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
+ final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
// Make sure a valid template ID was specified
if (template == null) {
throw new InvalidParameterValueException("Unable to use the given template.");
@@ -305,14 +310,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
throw new InvalidParameterValueException("Destroy Vm Grace Period cannot be less than 0.");
}
- User user = _userDao.findById(autoscaleUserId);
+ final User user = _userDao.findById(autoscaleUserId);
if (user.getAccountId() != vmProfile.getAccountId()) {
throw new InvalidParameterValueException("AutoScale User id does not belong to the same account");
}
- String apiKey = user.getApiKey();
- String secretKey = user.getSecretKey();
- String csUrl = ApiServiceConfiguration.ApiServletPath.value();
+ final String apiKey = user.getApiKey();
+ final String secretKey = user.getSecretKey();
+ final String csUrl = ApiServiceConfiguration.ApiServletPath.value();
if (apiKey == null) {
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
@@ -333,39 +338,40 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE, eventDescription = "creating autoscale vm profile", create = true)
- public AutoScaleVmProfile createAutoScaleVmProfile(CreateAutoScaleVmProfileCmd cmd) {
+ public AutoScaleVmProfile createAutoScaleVmProfile(final CreateAutoScaleVmProfileCmd cmd) {
- Account owner = _accountDao.findById(cmd.getAccountId());
- Account caller = CallContext.current().getCallingAccount();
+ final Account owner = _accountDao.findById(cmd.getAccountId());
+ final Account caller = CallContext.current().getCallingAccount();
_accountMgr.checkAccess(caller, null, true, owner);
- long zoneId = cmd.getZoneId();
- long serviceOfferingId = cmd.getServiceOfferingId();
- long autoscaleUserId = cmd.getAutoscaleUserId();
+ final long zoneId = cmd.getZoneId();
+ final long serviceOfferingId = cmd.getServiceOfferingId();
+ final long autoscaleUserId = cmd.getAutoscaleUserId();
- DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
+ final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id");
}
- ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+ final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering by id");
}
// validations
- HashMap<String, String> deployParams = cmd.getDeployParamMap();
+ final HashMap<String, String> deployParams = cmd.getDeployParamMap();
if (deployParams.containsKey("networks") && deployParams.get("networks").length() > 0) {
throw new InvalidParameterValueException(
"'networks' is not a valid parameter, network for an AutoScaled VM is chosen automatically. An autoscaled VM is deployed in the loadbalancer's network");
}
+
/*
* Just for making sure the values are right in other deploy params.
* For ex. if projectId is given as a string instead of an long value, this
* will be throwing an error.
*/
- ApiDispatcher.processParameters(new DeployVMCmd(), deployParams);
+ dispatchChainFactory.getStandardDispatchChain().dispatch(new DispatchTask(new DeployVMCmd(), deployParams));
AutoScaleVmProfileVO profileVO =
new AutoScaleVmProfileVO(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getServiceOfferingId(), cmd.getTemplateId(), cmd.getOtherDeployParams(),
@@ -383,13 +389,13 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_UPDATE, eventDescription = "updating autoscale vm profile")
- public AutoScaleVmProfile updateAutoScaleVmProfile(UpdateAutoScaleVmProfileCmd cmd) {
- Long profileId = cmd.getId();
- Long templateId = cmd.getTemplateId();
- Long autoscaleUserId = cmd.getAutoscaleUserId();
- Map counterParamList = cmd.getCounterParamList();
+ public AutoScaleVmProfile updateAutoScaleVmProfile(final UpdateAutoScaleVmProfileCmd cmd) {
+ final Long profileId = cmd.getId();
+ final Long templateId = cmd.getTemplateId();
+ final Long autoscaleUserId = cmd.getAutoscaleUserId();
+ final Map counterParamList = cmd.getCounterParamList();
- Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod();
+ final Integer destroyVmGraceperiod = cmd.getDestroyVmGraceperiod();
AutoScaleVmProfileVO vmProfile = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Vm Profile", profileId, _autoScaleVmProfileDao);
@@ -434,13 +440,13 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMPROFILE_DELETE, eventDescription = "deleting autoscale vm profile")
- public boolean deleteAutoScaleVmProfile(long id) {
+ public boolean deleteAutoScaleVmProfile(final long id) {
/* Check if entity is in database */
getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Profile", id, _autoScaleVmProfileDao);
if (_autoScaleVmGroupDao.isProfileInUse(id)) {
throw new InvalidParameterValueException("Cannot delete AutoScale Vm Profile when it is in use by one more vm groups");
}
- boolean success = _autoScaleVmProfileDao.remove(id);
+ final boolean success = _autoScaleVmProfileDao.remove(id);
if (success) {
s_logger.info("Successfully deleted AutoScale Vm Profile with Id: " + id);
}
@@ -456,8 +462,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
Long zoneId = cmd.getZoneId();
Boolean display = cmd.getDisplay();
- SearchWrapper<AutoScaleVmProfileVO> searchWrapper = new SearchWrapper<AutoScaleVmProfileVO>(_autoScaleVmProfileDao, AutoScaleVmProfileVO.class, cmd, cmd.getId());
- SearchBuilder<AutoScaleVmProfileVO> sb = searchWrapper.getSearchBuilder();
+ final SearchWrapper<AutoScaleVmProfileVO> searchWrapper = new SearchWrapper<AutoScaleVmProfileVO>(_autoScaleVmProfileDao, AutoScaleVmProfileVO.class, cmd, cmd.getId());
+ final SearchBuilder<AutoScaleVmProfileVO> sb = searchWrapper.getSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
@@ -507,19 +513,19 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return Transaction.execute(new TransactionCallback<AutoScalePolicyVO>() {
@Override
- public AutoScalePolicyVO doInTransaction(TransactionStatus status) {
- AutoScalePolicyVO autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVOFinal);
+ public AutoScalePolicyVO doInTransaction(final TransactionStatus status) {
+ final AutoScalePolicyVO autoScalePolicyVO = _autoScalePolicyDao.persist(autoScalePolicyVOFinal);
if (conditionIds != null) {
- SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
+ final SearchBuilder<ConditionVO> conditionsSearch = _conditionDao.createSearchBuilder();
conditionsSearch.and("ids", conditionsSearch.entity().getId(), Op.IN);
conditionsSearch.done();
- SearchCriteria<ConditionVO> sc = conditionsSearch.create();
+ final SearchCriteria<ConditionVO> sc = conditionsSearch.create();
sc.setParameters("ids", conditionIds.toArray(new Object[0]));
- List<ConditionVO> conditions = _conditionDao.search(sc, null);
+ final List<ConditionVO> conditions = _conditionDao.search(sc, null);
- ControlledEntity[] sameOwnerEntities = conditions.toArray(new ControlledEntity[conditions.size() + 1]);
+ final ControlledEntity[] sameOwnerEntities = conditions.toArray(new ControlledEntity[conditions.size() + 1]);
sameOwnerEntities[sameOwnerEntities.length - 1] = autoScalePolicyVO;
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEntities);
@@ -528,8 +534,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
throw new InvalidParameterValueException("Unable to find the condition specified");
}
- ArrayList<Long> counterIds = new ArrayList<Long>();
- for (ConditionVO condition : conditions) {
+ final ArrayList<Long> counterIds = new ArrayList<Long>();
+ for (final ConditionVO condition : conditions) {
if (counterIds.contains(condition.getCounterid())) {
throw new InvalidParameterValueException(
"atleast two conditions in the conditionids have the same counter. It is not right to apply two different conditions for the same counter");
@@ -540,8 +546,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
/* For update case remove the existing mappings and create fresh ones */
_autoScalePolicyConditionMapDao.removeByAutoScalePolicyId(autoScalePolicyVO.getId());
- for (Long conditionId : conditionIds) {
- AutoScalePolicyConditionMapVO policyConditionMapVO = new AutoScalePolicyConditionMapVO(autoScalePolicyVO.getId(), conditionId);
+ for (final Long conditionId : conditionIds) {
+ final AutoScalePolicyConditionMapVO policyConditionMapVO = new AutoScalePolicyConditionMapVO(autoScalePolicyVO.getId(), conditionId);
_autoScalePolicyConditionMapDao.persist(policyConditionMapVO);
}
}
@@ -553,9 +559,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_CREATE, eventDescription = "creating autoscale policy", create = true)
- public AutoScalePolicy createAutoScalePolicy(CreateAutoScalePolicyCmd cmd) {
+ public AutoScalePolicy createAutoScalePolicy(final CreateAutoScalePolicyCmd cmd) {
- int duration = cmd.getDuration();
+ final int duration = cmd.getDuration();
Integer quietTime = cmd.getQuietTime();
String action = cmd.getAction();
@@ -588,7 +594,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
- public Boolean doInTransaction(TransactionStatus status) {
+ public Boolean doInTransaction(final TransactionStatus status) {
boolean success = true;
success = _autoScalePolicyDao.remove(id);
if (!success) {
@@ -607,11 +613,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
});
}
- public void checkCallerAccess(String accountName, Long domainId) {
- Account caller = CallContext.current().getCallingAccount();
- Account owner = _accountDao.findActiveAccount(accountName, domainId);
+ public void checkCallerAccess(final String accountName, final Long domainId) {
+ final Account caller = CallContext.current().getCallingAccount();
+ final Account owner = _accountDao.findActiveAccount(accountName, domainId);
if (owner == null) {
- List<String> idList = new ArrayList<String>();
+ final List<String> idList = new ArrayList<String>();
idList.add(ApiDBUtils.findDomainById(domainId).getUuid());
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain with specifed domainId");
}
@@ -628,23 +634,23 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
ListProjectResourcesCriteria listProjectResourcesCriteria;
Filter searchFilter;
- public SearchWrapper(GenericDao<VO, Long> dao, Class<VO> entityClass, BaseListAccountResourcesCmd cmd, Long id) {
+ public SearchWrapper(final GenericDao<VO, Long> dao, final Class<VO> entityClass, final BaseListAccountResourcesCmd cmd, final Long id) {
this.dao = dao;
this.searchBuilder = dao.createSearchBuilder();
domainId = cmd.getDomainId();
- String accountName = cmd.getAccountName();
+ final String accountName = cmd.getAccountName();
isRecursive = cmd.isRecursive();
- boolean listAll = cmd.listAll();
- long startIndex = cmd.getStartIndex();
- long pageSizeVal = cmd.getPageSizeVal();
- Account caller = CallContext.current().getCallingAccount();
+ final boolean listAll = cmd.listAll();
+ final long startIndex = cmd.getStartIndex();
+ final long pageSizeVal = cmd.getPageSizeVal();
+ final Account caller = CallContext.current().getCallingAccount();
- Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
+ final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject =
new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
- ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
+ final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
_accountMgr.buildACLSearchBuilder(searchBuilder, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
searchFilter = new Filter(entityClass, "id", false, startIndex, pageSizeVal);
}
@@ -665,30 +671,30 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
@Override
- public List<? extends AutoScalePolicy> listAutoScalePolicies(ListAutoScalePoliciesCmd cmd) {
- SearchWrapper<AutoScalePolicyVO> searchWrapper = new SearchWrapper<AutoScalePolicyVO>(_autoScalePolicyDao, AutoScalePolicyVO.class, cmd, cmd.getId());
- SearchBuilder<AutoScalePolicyVO> sb = searchWrapper.getSearchBuilder();
- Long id = cmd.getId();
- Long conditionId = cmd.getConditionId();
- String action = cmd.getAction();
- Long vmGroupId = cmd.getVmGroupId();
+ public List<? extends AutoScalePolicy> listAutoScalePolicies(final ListAutoScalePoliciesCmd cmd) {
+ final SearchWrapper<AutoScalePolicyVO> searchWrapper = new SearchWrapper<AutoScalePolicyVO>(_autoScalePolicyDao, AutoScalePolicyVO.class, cmd, cmd.getId());
+ final SearchBuilder<AutoScalePolicyVO> sb = searchWrapper.getSearchBuilder();
+ final Long id = cmd.getId();
+ final Long conditionId = cmd.getConditionId();
+ final String action = cmd.getAction();
+ final Long vmGroupId = cmd.getVmGroupId();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("action", sb.entity().getAction(), SearchCriteria.Op.EQ);
if (conditionId != null) {
- SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
+ final SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
asPolicyConditionSearch.and("conditionId", asPolicyConditionSearch.entity().getConditionId(), SearchCriteria.Op.EQ);
sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
}
if (vmGroupId != null) {
- SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
+ final SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
asVmGroupPolicySearch.and("vmGroupId", asVmGroupPolicySearch.entity().getVmGroupId(), SearchCriteria.Op.EQ);
sb.join("asVmGroupPolicySearch", asVmGroupPolicySearch, sb.entity().getId(), asVmGroupPolicySearch.entity().getPolicyId(), JoinBuilder.JoinType.INNER);
}
- SearchCriteria<AutoScalePolicyVO> sc = searchWrapper.buildSearchCriteria();
+ final SearchCriteria<AutoScalePolicyVO> sc = searchWrapper.buildSearchCriteria();
if (id != null) {
sc.setParameters("id", id);
@@ -711,11 +717,11 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEPOLICY_UPDATE, eventDescription = "updating autoscale policy")
- public AutoScalePolicy updateAutoScalePolicy(UpdateAutoScalePolicyCmd cmd) {
- Long policyId = cmd.getId();
- Integer duration = cmd.getDuration();
- Integer quietTime = cmd.getQuietTime();
- List<Long> conditionIds = cmd.getConditionIds();
+ public AutoScalePolicy updateAutoScalePolicy(final UpdateAutoScalePolicyCmd cmd) {
+ final Long policyId = cmd.getId();
+ final Integer duration = cmd.getDuration();
+ final Integer quietTime = cmd.getQuietTime();
+ final List<Long> conditionIds = cmd.getConditionIds();
AutoScalePolicyVO policy = getEntityInDatabase(CallContext.current().getCallingAccount(), "Auto Scale Policy", policyId, _autoScalePolicyDao);
if (duration != null) {
@@ -726,9 +732,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
policy.setQuietTime(quietTime);
}
- List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyList = _autoScaleVmGroupPolicyMapDao.listByPolicyId(policyId);
- for (AutoScaleVmGroupPolicyMapVO vmGroupPolicy : vmGroupPolicyList) {
- AutoScaleVmGroupVO vmGroupVO = _autoScaleVmGroupDao.findById(vmGroupPolicy.getVmGroupId());
+ final List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyList = _autoScaleVmGroupPolicyMapDao.listByPolicyId(policyId);
+ for (final AutoScaleVmGroupPolicyMapVO vmGroupPolicy : vmGroupPolicyList) {
+ final AutoScaleVmGroupVO vmGroupVO = _autoScaleVmGroupDao.findById(vmGroupPolicy.getVmGroupId());
if (vmGroupVO == null) {
s_logger.warn("Stale database entry! There is an entry in VmGroupPolicyMap but the vmGroup is missing:" + vmGroupPolicy.getVmGroupId());
@@ -750,9 +756,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@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();
+ public AutoScaleVmGroup createAutoScaleVmGroup(final CreateAutoScaleVmGroupCmd cmd) {
+ final int minMembers = cmd.getMinMembers();
+ final int maxMembers = cmd.getMaxMembers();
Integer interval = cmd.getInterval();
Boolean forDisplay = cmd.getDisplay();
@@ -760,9 +766,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
interval = NetUtils.DEFAULT_AUTOSCALE_POLICY_INTERVAL_TIME;
}
- LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
+ final LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, cmd.getLbRuleId(), _lbDao);
- Long zoneId = _ipAddressDao.findById(loadBalancer.getSourceIpAddressId()).getDataCenterId();
+ final 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");
@@ -787,23 +793,23 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
@Override
- public boolean configureAutoScaleVmGroup(CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException {
+ public boolean configureAutoScaleVmGroup(final CreateAutoScaleVmGroupCmd cmd) throws ResourceUnavailableException {
return configureAutoScaleVmGroup(cmd.getEntityId(), AutoScaleVmGroup.State_New);
}
- public boolean isLoadBalancerBasedAutoScaleVmGroup(AutoScaleVmGroup vmGroup) {
+ public boolean isLoadBalancerBasedAutoScaleVmGroup(final AutoScaleVmGroup vmGroup) {
return vmGroup.getLoadBalancerId() != null;
}
- private boolean configureAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException {
- AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
+ private boolean configureAutoScaleVmGroup(final long vmGroupid, final String currentState) throws ResourceUnavailableException {
+ final AutoScaleVmGroup vmGroup = _autoScaleVmGroupDao.findById(vmGroupid);
if (isLoadBalancerBasedAutoScaleVmGroup(vmGroup)) {
try {
return _lbRulesMgr.configureLbAutoScaleVmGroup(vmGroupid, currentState);
- } catch (ResourceUnavailableException re) {
+ } catch (final ResourceUnavailableException re) {
throw re;
- } catch (Exception e) {
+ } catch (final Exception e) {
s_logger.warn("Exception during configureLbAutoScaleVmGroup in lb rules manager", e);
return false;
}
@@ -817,20 +823,20 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DELETE, eventDescription = "deleting autoscale vm group")
public boolean deleteAutoScaleVmGroup(final long id) {
- AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
+ final AutoScaleVmGroupVO autoScaleVmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
if (autoScaleVmGroupVO.getState().equals(AutoScaleVmGroup.State_New)) {
/* This condition is for handling failures during creation command */
return _autoScaleVmGroupDao.remove(id);
}
- String bakupState = autoScaleVmGroupVO.getState();
+ final String bakupState = autoScaleVmGroupVO.getState();
autoScaleVmGroupVO.setState(AutoScaleVmGroup.State_Revoke);
_autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
boolean success = false;
try {
success = configureAutoScaleVmGroup(id, bakupState);
- } catch (ResourceUnavailableException e) {
+ } catch (final ResourceUnavailableException e) {
autoScaleVmGroupVO.setState(bakupState);
_autoScaleVmGroupDao.persist(autoScaleVmGroupVO);
} finally {
@@ -842,7 +848,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
- public Boolean doInTransaction(TransactionStatus status) {
+ public Boolean doInTransaction(final TransactionStatus status) {
boolean success = _autoScaleVmGroupDao.remove(id);
if (!success) {
@@ -872,8 +878,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
Long zoneId = cmd.getZoneId();
Boolean forDisplay = cmd.getDisplay();
- SearchWrapper<AutoScaleVmGroupVO> searchWrapper = new SearchWrapper<AutoScaleVmGroupVO>(_autoScaleVmGroupDao, AutoScaleVmGroupVO.class, cmd, cmd.getId());
- SearchBuilder<AutoScaleVmGroupVO> sb = searchWrapper.getSearchBuilder();
+ final SearchWrapper<AutoScaleVmGroupVO> searchWrapper = new SearchWrapper<AutoScaleVmGroupVO>(_autoScaleVmGroupDao, AutoScaleVmGroupVO.class, cmd, cmd.getId());
+ final SearchBuilder<AutoScaleVmGroupVO> sb = searchWrapper.getSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("loadBalancerId", sb.entity().getLoadBalancerId(), SearchCriteria.Op.EQ);
@@ -882,12 +888,12 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
if (policyId != null) {
- SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
+ final SearchBuilder<AutoScaleVmGroupPolicyMapVO> asVmGroupPolicySearch = _autoScaleVmGroupPolicyMapDao.createSearchBuilder();
asVmGroupPolicySearch.and("policyId", asVmGroupPolicySearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
sb.join("asVmGroupPolicySearch", asVmGroupPolicySearch, sb.entity().getId(), asVmGroupPolicySearch.entity().getVmGroupId(), JoinBuilder.JoinType.INNER);
}
- SearchCriteria<AutoScaleVmGroupVO> sc = searchWrapper.buildSearchCriteria();
+ final SearchCriteria<AutoScaleVmGroupVO> sc = searchWrapper.buildSearchCriteria();
if (id != null) {
sc.setParameters("id", id);
}
@@ -912,14 +918,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@DB
protected AutoScaleVmGroupVO checkValidityAndPersist(final AutoScaleVmGroupVO vmGroup, final List<Long> passedScaleUpPolicyIds,
final List<Long> passedScaleDownPolicyIds) {
- int minMembers = vmGroup.getMinMembers();
- int maxMembers = vmGroup.getMaxMembers();
- int interval = vmGroup.getInterval();
- List<Counter> counters = new ArrayList<Counter>();
- List<AutoScalePolicyVO> policies = new ArrayList<AutoScalePolicyVO>();
+ final int minMembers = vmGroup.getMinMembers();
+ final int maxMembers = vmGroup.getMaxMembers();
+ final int interval = vmGroup.getInterval();
+ final List<Counter> counters = new ArrayList<Counter>();
+ final List<AutoScalePolicyVO> policies = new ArrayList<AutoScalePolicyVO>();
final List<Long> policyIds = new ArrayList<Long>();
- List<Long> currentScaleUpPolicyIds = new ArrayList<Long>();
- List<Long> currentScaleDownPolicyIds = new ArrayList<Long>();
+ final List<Long> currentScaleUpPolicyIds = new ArrayList<Long>();
+ final List<Long> currentScaleDownPolicyIds = new ArrayList<Long>();
if (vmGroup.getCreated() != null) {
ApiDBUtils.getAutoScaleVmGroupPolicyIds(vmGroup.getId(), currentScaleUpPolicyIds, currentScaleDownPolicyIds);
}
@@ -958,26 +964,26 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
getAutoScalePolicies("scaledownpolicyid", currentScaleDownPolicyIds, counters, interval, false);
policyIds.addAll(currentScaleDownPolicyIds);
}
- AutoScaleVmProfileVO profileVO =
+ final AutoScaleVmProfileVO profileVO =
getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.VMPROFILE_ID, vmGroup.getProfileId(), _autoScaleVmProfileDao);
- LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao);
+ final LoadBalancerVO loadBalancer = getEntityInDatabase(CallContext.current().getCallingAccount(), ApiConstants.LBID, vmGroup.getLoadBalancerId(), _lbDao);
validateAutoScaleCounters(loadBalancer.getNetworkId(), counters, profileVO.getCounterParams());
- ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]);
+ final ControlledEntity[] sameOwnerEntities = policies.toArray(new ControlledEntity[policies.size() + 2]);
sameOwnerEntities[sameOwnerEntities.length - 2] = loadBalancer;
sameOwnerEntities[sameOwnerEntities.length - 1] = profileVO;
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, sameOwnerEntities);
return Transaction.execute(new TransactionCallback<AutoScaleVmGroupVO>() {
@Override
- public AutoScaleVmGroupVO doInTransaction(TransactionStatus status) {
- AutoScaleVmGroupVO vmGroupNew = _autoScaleVmGroupDao.persist(vmGroup);
+ public AutoScaleVmGroupVO doInTransaction(final TransactionStatus status) {
+ final AutoScaleVmGroupVO vmGroupNew = _autoScaleVmGroupDao.persist(vmGroup);
if (passedScaleUpPolicyIds != null || passedScaleDownPolicyIds != null) {
_autoScaleVmGroupPolicyMapDao.removeByGroupId(vmGroupNew.getId());
- for (Long policyId : policyIds) {
+ for (final Long policyId : policyIds) {
_autoScaleVmGroupPolicyMapDao.persist(new AutoScaleVmGroupPolicyMapVO(vmGroupNew.getId(), policyId));
}
}
@@ -990,15 +996,15 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_UPDATE, eventDescription = "updating autoscale vm group")
- public AutoScaleVmGroup updateAutoScaleVmGroup(UpdateAutoScaleVmGroupCmd cmd) {
- Long vmGroupId = cmd.getId();
- Integer minMembers = cmd.getMinMembers();
- Integer maxMembers = cmd.getMaxMembers();
- Integer interval = cmd.getInterval();
- Boolean forDisplay = cmd.getDisplay();
+ public AutoScaleVmGroup updateAutoScaleVmGroup(final UpdateAutoScaleVmGroupCmd cmd) {
+ final Long vmGroupId = cmd.getId();
+ final Integer minMembers = cmd.getMinMembers();
+ final Integer maxMembers = cmd.getMaxMembers();
+ final Integer interval = cmd.getInterval();
+ final Boolean forDisplay = cmd.getDisplay();
- List<Long> scaleUpPolicyIds = cmd.getScaleUpPolicyIds();
- List<Long> scaleDownPolicyIds = cmd.getScaleDownPolicyIds();
+ final List<Long> scaleUpPolicyIds = cmd.getScaleUpPolicyIds();
+ final List<Long> scaleDownPolicyIds = cmd.getScaleDownPolicyIds();
AutoScaleVmGroupVO vmGroupVO = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", vmGroupId, _autoScaleVmGroupDao);
@@ -1039,7 +1045,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_ENABLE, eventDescription = "enabling autoscale vm group")
- public AutoScaleVmGroup enableAutoScaleVmGroup(Long id) {
+ public AutoScaleVmGroup enableAutoScaleVmGroup(final Long id) {
AutoScaleVmGroupVO vmGroup = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
boolean success = false;
if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Disabled)) {
@@ -1050,7 +1056,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
vmGroup.setState(AutoScaleVmGroup.State_Enabled);
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
success = configureAutoScaleVmGroup(id, AutoScaleVmGroup.State_Disabled);
- } catch (ResourceUnavailableException e) {
+ } catch (final ResourceUnavailableException e) {
vmGroup.setState(AutoScaleVmGroup.State_Disabled);
_autoScaleVmGroupDao.persist(vmGroup);
} finally {
@@ -1066,7 +1072,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_AUTOSCALEVMGROUP_DISABLE, eventDescription = "disabling autoscale vm group")
@DB
- public AutoScaleVmGroup disableAutoScaleVmGroup(Long id) {
+ public AutoScaleVmGroup disableAutoScaleVmGroup(final Long id) {
AutoScaleVmGroupVO vmGroup = getEntityInDatabase(CallContext.current().getCallingAccount(), "AutoScale Vm Group", id, _autoScaleVmGroupDao);
boolean success = false;
if (!vmGroup.getState().equals(AutoScaleVmGroup.State_Enabled)) {
@@ -1077,7 +1083,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
vmGroup.setState(AutoScaleVmGroup.State_Disabled);
vmGroup = _autoScaleVmGroupDao.persist(vmGroup);
success = configureAutoScaleVmGroup(id, AutoScaleVmGroup.State_Enabled);
- } catch (ResourceUnavailableException e) {
+ } catch (final ResourceUnavailableException e) {
vmGroup.setState(AutoScaleVmGroup.State_Enabled);
_autoScaleVmGroupDao.persist(vmGroup);
} finally {
@@ -1093,14 +1099,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_COUNTER_CREATE, eventDescription = "Counter", create = true)
@DB
- public Counter createCounter(CreateCounterCmd cmd) {
- String source = cmd.getSource().toLowerCase();
- String name = cmd.getName();
+ public Counter createCounter(final CreateCounterCmd cmd) {
+ final String source = cmd.getSource().toLowerCase();
+ final String name = cmd.getName();
Counter.Source src;
// Validate Source
try {
src = Counter.Source.valueOf(source);
- } catch (Exception ex) {
+ } catch (final Exception ex) {
throw new InvalidParameterValueException("The Source " + source + " does not exist; Unable to create Counter");
}
@@ -1115,21 +1121,21 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_CONDITION_CREATE, eventDescription = "Condition", create = true)
- public Condition createCondition(CreateConditionCmd cmd) {
+ public Condition createCondition(final CreateConditionCmd cmd) {
checkCallerAccess(cmd.getAccountName(), cmd.getDomainId());
- String opr = cmd.getRelationalOperator().toUpperCase();
- long cid = cmd.getCounterId();
- long threshold = cmd.getThreshold();
+ final String opr = cmd.getRelationalOperator().toUpperCase();
+ final long cid = cmd.getCounterId();
+ final long threshold = cmd.getThreshold();
Condition.Operator op;
// Validate Relational Operator
try {
op = Condition.Operator.valueOf(opr);
- } catch (IllegalArgumentException ex) {
+ } catch (final IllegalArgumentException ex) {
throw new InvalidParameterValueException("The Operator " + opr + " does not exist; Unable to create Condition.");
}
// TODO - Validate threshold
- CounterVO counter = _counterDao.findById(cid);
+ final CounterVO counter = _counterDao.findById(cid);
if (counter == null) {
throw new InvalidParameterValueException("Unable to find counter");
@@ -1144,29 +1150,29 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
@Override
- public List<? extends Counter> listCounters(ListCountersCmd cmd) {
- String name = cmd.getName();
- Long id = cmd.getId();
+ public List<? extends Counter> listCounters(final ListCountersCmd cmd) {
+ final String name = cmd.getName();
+ final Long id = cmd.getId();
String source = cmd.getSource();
if (source != null)
source = source.toLowerCase();
- Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
+ final Filter searchFilter = new Filter(CounterVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
- List<CounterVO> counters = _counterDao.listCounters(id, name, source, cmd.getKeyword(), searchFilter);
+ final List<CounterVO> counters = _counterDao.listCounters(id, name, source, cmd.getKeyword(), searchFilter);
return counters;
}
@Override
- public List<? extends Condition> listConditions(ListConditionsCmd cmd) {
- Long id = cmd.getId();
- Long counterId = cmd.getCounterId();
- Long policyId = cmd.getPolicyId();
- SearchWrapper<ConditionVO> searchWrapper = new SearchWrapper<ConditionVO>(_conditionDao, ConditionVO.class, cmd, cmd.getId());
- SearchBuilder<ConditionVO> sb = searchWrapper.getSearchBuilder();
+ public List<? extends Condition> listConditions(final ListConditionsCmd cmd) {
+ final Long id = cmd.getId();
+ final Long counterId = cmd.getCounterId();
+ final Long policyId = cmd.getPolicyId();
+ final SearchWrapper<ConditionVO> searchWrapper = new SearchWrapper<ConditionVO>(_conditionDao, ConditionVO.class, cmd, cmd.getId());
+ final SearchBuilder<ConditionVO> sb = searchWrapper.getSearchBuilder();
if (policyId != null) {
- SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
+ final SearchBuilder<AutoScalePolicyConditionMapVO> asPolicyConditionSearch = _autoScalePolicyConditionMapDao.createSearchBuilder();
asPolicyConditionSearch.and("policyId", asPolicyConditionSearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
sb.join("asPolicyConditionSearch", asPolicyConditionSearch, sb.entity().getId(), asPolicyConditionSearch.entity().getConditionId(),
JoinBuilder.JoinType.INNER);
@@ -1176,7 +1182,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
sb.and("counterId", sb.entity().getCounterid(), SearchCriteria.Op.EQ);
// now set the SC criteria...
- SearchCriteria<ConditionVO> sc = searchWrapper.buildSearchCriteria();
+ final SearchCriteria<ConditionVO> sc = searchWrapper.buildSearchCriteria();
if (id != null) {
sc.setParameters("id", id);
@@ -1195,22 +1201,22 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_COUNTER_DELETE, eventDescription = "counter")
- public boolean deleteCounter(long counterId) throws ResourceInUseException {
+ public boolean deleteCounter(final long counterId) throws ResourceInUseException {
// Verify Counter id
- CounterVO counter = _counterDao.findById(counterId);
+ final CounterVO counter = _counterDao.findById(counterId);
if (counter == null) {
throw new InvalidParameterValueException("Unable to find Counter");
}
// Verify if it is used in any Condition
- ConditionVO condition = _conditionDao.findByCounterId(counterId);
+ final ConditionVO condition = _conditionDao.findByCounterId(counterId);
if (condition != null) {
s_logger.info("Cannot delete counter " + counter.getName() + " as it is being used in a condition.");
throw new ResourceInUseException("Counter is in use.");
}
- boolean success = _counterDao.remove(counterId);
+ final boolean success = _counterDao.remove(counterId);
if (success) {
s_logger.info("Successfully deleted counter with Id: " + counterId);
}
@@ -1220,9 +1226,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
@ActionEvent(eventType = EventTypes.EVENT_CONDITION_DELETE, eventDescription = "condition")
- public boolean deleteCondition(long conditionId) throws ResourceInUseException {
+ public boolean deleteCondition(final long conditionId) throws ResourceInUseException {
/* Check if entity is in database */
- ConditionVO condition = getEntityInDatabase(CallContext.current().getCallingAccount(), "Condition", conditionId, _conditionDao);
+ final ConditionVO condition = getEntityInDatabase(CallContext.current().getCallingAccount(), "Condition", conditionId, _conditionDao);
if (condition == null) {
throw new InvalidParameterValueException("Unable to find Condition");
}
@@ -1232,7 +1238,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
s_logger.info("Cannot delete condition " + conditionId + " as it is being used in a condition.");
throw new ResourceInUseException("Cannot delete Condition when it is in use by one or more AutoScale Policies.");
}
- boolean success = _conditionDao.remove(conditionId);
+ final boolean success = _conditionDao.remove(conditionId);
if (success) {
s_logger.info("Successfully deleted condition " + condition.getId());
}
@@ -1240,7 +1246,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
@Override
- public void cleanUpAutoScaleResources(Long accountId) {
+ public void cleanUpAutoScaleResources(final Long accountId) {
// cleans Autoscale VmProfiles, AutoScale Policies and Conditions belonging to an account
int count = 0;
count = _autoScaleVmProfileDao.removeByAccountId(accountId);
@@ -1257,10 +1263,10 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
}
- private boolean checkConditionUp(AutoScaleVmGroupVO asGroup, Integer numVm) {
+ private boolean checkConditionUp(final AutoScaleVmGroupVO asGroup, final Integer numVm) {
// check maximum
- Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
- Integer maxVm = asGroup.getMaxMembers();
+ final Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
+ final Integer maxVm = asGroup.getMaxMembers();
if (currentVM + numVm > maxVm) {
s_logger.warn("number of VM will greater than the maximum in this group if scaling up, so do nothing more");
return false;
@@ -1268,9 +1274,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return true;
}
- private boolean checkConditionDown(AutoScaleVmGroupVO asGroup) {
- Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
- Integer minVm = asGroup.getMinMembers();
+ private boolean checkConditionDown(final AutoScaleVmGroupVO asGroup) {
+ final Integer currentVM = _autoScaleVmGroupVmMapDao.countByGroup(asGroup.getId());
+ final Integer minVm = asGroup.getMinMembers();
if (currentVM - 1 < minVm) {
s_logger.warn("number of VM will less than the minimum in this group if scaling down, so do nothing more");
return false;
@@ -1278,29 +1284,29 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return true;
}
- private long createNewVM(AutoScaleVmGroupVO asGroup) {
- AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
- long templateId = profileVo.getTemplateId();
- long serviceOfferingId = profileVo.getServiceOfferingId();
+ private long createNewVM(final AutoScaleVmGroupVO asGroup) {
+ final AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
+ final long templateId = profileVo.getTemplateId();
+ final long serviceOfferingId = profileVo.getServiceOfferingId();
if (templateId == -1) {
return -1;
}
// create new VM into DB
try {
//Verify that all objects exist before passing them to the service
- Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
+ final Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
- DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
+ final DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id=" + profileVo.getZoneId());
}
- ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+ final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
- VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
+ final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
// Make sure a valid template ID was specified
if (template == null) {
throw new InvalidParameterValueException("Unable to use template " + templateId);
@@ -1313,7 +1319,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
UserVm vm = null;
- IpAddresses addrs = new IpAddresses(null, null);
+ final IpAddresses addrs = new IpAddresses(null, null);
if (zone.getNetworkType() == NetworkType.Basic) {
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" +
getCurrentTimeStampString(),
@@ -1339,41 +1345,41 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
} else {
return -1;
}
- } catch (InsufficientCapacityException ex) {
+ } catch (final InsufficientCapacityException ex) {
s_logger.info(ex);
s_logger.trace(ex.getMessage(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
- } catch (ResourceUnavailableException ex) {
+ } catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
- } catch (ConcurrentOperationException ex) {
+ } catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
- } catch (ResourceAllocationException ex) {
+ } catch (final ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
}
}
private String getCurrentTimeStampString() {
- Date current = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+ final Date current = new Date();
+ final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
return sdf.format(current);
}
- private boolean startNewVM(long vmId) {
+ private boolean startNewVM(final long vmId) {
try {
CallContext.current().setEventDetails("Vm Id: " + vmId);
_userVmManager.startVirtualMachine(vmId, null, null);
- } catch (ResourceUnavailableException ex) {
+ } catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
- } catch (ConcurrentOperationException ex) {
+ } catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
- } catch (InsufficientCapacityException ex) {
- StringBuilder message = new StringBuilder(ex.getMessage());
+ } catch (final InsufficientCapacityException ex) {
+ final StringBuilder message = new StringBuilder(ex.getMessage());
if (ex instanceof InsufficientServerCapacityException) {
if (((InsufficientServerCapacityException)ex).isAffinityApplied()) {
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
@@ -1386,14 +1392,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return true;
}
- private boolean assignLBruleToNewVm(long vmId, AutoScaleVmGroupVO asGroup) {
- List<Long> lstVmId = new ArrayList<Long>();
- long lbId = asGroup.getLoadBalancerId();
+ private boolean assignLBruleToNewVm(final long vmId, final AutoScaleVmGroupVO asGroup) {
+ final List<Long> lstVmId = new ArrayList<Long>();
+ final long lbId = asGroup.getLoadBalancerId();
- List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
+ final List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
if ((LbVmMapVos != null) && (LbVmMapVos.size() > 0)) {
- for (LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
- long instanceId = LbVmMapVo.getInstanceId();
+ for (final LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
+ final long instanceId = LbVmMapVo.getInstanceId();
if (instanceId == vmId) {
s_logger.warn("the new VM is already mapped to LB rule. What's wrong?");
return true;
@@ -1405,17 +1411,17 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
- private long removeLBrule(AutoScaleVmGroupVO asGroup) {
- long lbId = asGroup.getLoadBalancerId();
+ private long removeLBrule(final AutoScaleVmGroupVO asGroup) {
+ final long lbId = asGroup.getLoadBalancerId();
long instanceId = -1;
- List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
+ final List<LoadBalancerVMMapVO> LbVmMapVos = _lbVmMapDao.listByLoadBalancerId(lbId);
if ((LbVmMapVos != null) && (LbVmMapVos.size() > 0)) {
- for (LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
+ for (final LoadBalancerVMMapVO LbVmMapVo : LbVmMapVos) {
instanceId = LbVmMapVo.getInstanceId();
}
}
// take last VM out of the list
- List<Long> lstVmId = new ArrayList<Long>();
+ final List<Long> lstVmId = new ArrayList<Long>();
if (instanceId != -1)
lstVmId.add(instanceId);
if (_loadBalancingRulesService.removeFromLoadBalancer(lbId, lstVmId))
@@ -1425,8 +1431,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
@Override
- public void doScaleUp(long groupId, Integer numVm) {
- AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
+ public void doScaleUp(final long groupId, final Integer numVm) {
+ final AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
if (asGroup == null) {
s_logger.error("Can not find the groupid " + groupId + " for scaling up");
return;
@@ -1435,7 +1441,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
return;
}
for (int i = 0; i < numVm; i++) {
- long vmId = createNewVM(asGroup);
+ final long vmId = createNewVM(asGroup);
if (vmId == -1) {
s_logger.error("Can not deploy new VM for scaling up in the group "
+ asGroup.getId() + ". Waiting for next round");
@@ -1444,14 +1450,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
if (startNewVM(vmId)) {
if (assignLBruleToNewVm(vmId, asGroup)) {
// persist to DB
- AutoScaleVmGroupVmMapVO GroupVmVO = new AutoScaleVmGroupVmMapVO(
+ final AutoScaleVmGroupVmMapVO GroupVmVO = new AutoScaleVmGroupVmMapVO(
asGroup.getId(), vmId);
_autoScaleVmGroupVmMapDao.persist(GroupVmVO);
// update last_quiettime
- List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao
+ final List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao
.listByVmGroupId(groupId);
- for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
- AutoScalePolicyVO vo = _autoScalePolicyDao
+ for (final AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
+ final AutoScalePolicyVO vo = _autoScalePolicyDao
.findById(GroupPolicyVO.getPolicyId());
if (vo.getAction().equals("scaleup")) {
vo.setLastQuiteTime(new Date());
@@ -1473,7 +1479,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
@Override
public void doScaleDown(final long groupId) {
- AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
+ final AutoScaleVmGroupVO asGroup = _autoScaleVmGroupDao.findById(groupId);
if (asGroup == null) {
s_logger.error("Can not find the groupid " + groupId + " for scaling up");
return;
@@ -1483,14 +1489,14 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
final long vmId = removeLBrule(asGroup);
if (vmId != -1) {
- long profileId = asGroup.getProfileId();
+ final long profileId = asGroup.getProfileId();
// update group-vm mapping
_autoScaleVmGroupVmMapDao.remove(groupId, vmId);
// update last_quiettime
- List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(groupId);
- for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
- AutoScalePolicyVO vo = _autoScalePolicyDao.findById(GroupPolicyVO.getPolicyId());
+ final List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(groupId);
+ for (final AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
+ final AutoScalePolicyVO vo = _autoScalePolicyDao.findById(GroupPolicyVO.getPolicyId());
if (vo.getAction().equals("scaledown")) {
vo.setLastQuiteTime(new Date());
_autoScalePolicyDao.persist(vo);
@@ -1499,8 +1505,8 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
}
// get destroyvmgrace param
- AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
- Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
+ final AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
+ final Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
if (destroyVmGracePeriod >= 0) {
_executor.schedule(new Runnable() {
@Override
@@ -1509,9 +1515,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
_userVmManager.destroyVm(vmId);
- } catch (ResourceUnavailableException e) {
+ } catch (final ResourceUnavailableException e) {
e.printStackTrace();
- } catch (ConcurrentOperationException e) {
+ } catch (final ConcurrentOperationException e) {
e.printStackTrace();
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c211f0bb/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 8486f06..3c99867 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -105,7 +105,6 @@ import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiAsyncJobDispatcher;
-import com.cloud.api.ApiDispatcher;
import com.cloud.api.ApiGsonHelper;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
@@ -4195,7 +4194,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for(DomainRouterVO router: routers){
if(!checkRouterVersion(router)){
s_logger.debug("Upgrading template for router: "+router.getId());
- ApiDispatcher.getInstance();
Map<String, String> params = new HashMap<String, String>();
params.put("ctxUserId", "1");
params.put("ctxAccountId", "" + router.getAccountId());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c211f0bb/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
index a85c052..447697f 100644
--- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java
@@ -82,6 +82,8 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
protected VolumeDao _volsDao;
@Inject
protected ConfigurationDao _configDao;
+ @Inject
+ protected ApiDispatcher _dispatcher;
protected AsyncJobDispatcher _asyncDispatcher;
@@ -95,21 +97,21 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
return _asyncDispatcher;
}
- public void setAsyncJobDispatcher(AsyncJobDispatcher dispatcher) {
+ public void setAsyncJobDispatcher(final AsyncJobDispatcher dispatcher) {
_asyncDispatcher = dispatcher;
}
- private Date getNextScheduledTime(long policyId, Date currentTimestamp) {
- SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
+ private Date getNextScheduledTime(final long policyId, final Date currentTimestamp) {
+ final SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
Date nextTimestamp = null;
if (policy != null) {
- short intervalType = policy.getInterval();
- IntervalType type = DateUtil.getIntervalType(intervalType);
- String schedule = policy.getSchedule();
- String timezone = policy.getTimezone();
+ final short intervalType = policy.getInterval();
+ final IntervalType type = DateUtil.getIntervalType(intervalType);
+ final String schedule = policy.getSchedule();
+ final String timezone = policy.getTimezone();
nextTimestamp = DateUtil.getNextRunTime(type, schedule, timezone, currentTimestamp);
- String currentTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, currentTimestamp);
- String nextScheduledTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, nextTimestamp);
+ final String currentTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, currentTimestamp);
+ final String nextScheduledTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, nextTimestamp);
s_logger.debug("Current time is " + currentTime + ". NextScheduledTime of policyId " + policyId + " is " + nextScheduledTime);
}
return nextTimestamp;
@@ -119,7 +121,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
* {@inheritDoc}
*/
@Override
- public void poll(Date currentTimestamp) {
+ public void poll(final Date currentTimestamp) {
// We don't maintain the time. The timer task does.
_currentTimestamp = currentTimestamp;
@@ -151,12 +153,12 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
}
private void checkStatusOfCurrentlyExecutingSnapshots() {
- SearchCriteria<SnapshotScheduleVO> sc = _snapshotScheduleDao.createSearchCriteria();
+ final SearchCriteria<SnapshotScheduleVO> sc = _snapshotScheduleDao.createSearchCriteria();
sc.addAnd("asyncJobId", SearchCriteria.Op.NNULL);
- List<SnapshotScheduleVO> snapshotSchedules = _snapshotScheduleDao.search(sc, null);
- for (SnapshotScheduleVO snapshotSchedule : snapshotSchedules) {
- Long asyncJobId = snapshotSchedule.getAsyncJobId();
- AsyncJobVO asyncJob = _asyncJobDao.findById(asyncJobId);
+ final List<SnapshotScheduleVO> snapshotSchedules = _snapshotScheduleDao.search(sc, null);
+ for (final SnapshotScheduleVO snapshotSchedule : snapshotSchedules) {
+ final Long asyncJobId = snapshotSchedule.getAsyncJobId();
+ final AsyncJobVO asyncJob = _asyncJobDao.findById(asyncJobId);
switch (asyncJob.getStatus()) {
case SUCCEEDED:
// The snapshot has been successfully backed up.
@@ -167,7 +169,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
break;
case FAILED:
// Check the snapshot status.
- Long snapshotId = snapshotSchedule.getSnapshotId();
+ final Long snapshotId = snapshotSchedule.getSnapshotId();
if (snapshotId == null) {
// createSnapshotAsync exited, successfully or unsuccessfully,
// even before creating a snapshot record
@@ -175,7 +177,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
// Schedule the next snapshot.
scheduleNextSnapshotJob(snapshotSchedule);
} else {
- SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
+ final SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
if (snapshot == null || snapshot.getRemoved() != null) {
// This snapshot has been deleted successfully from the primary storage
// Again no cleanup needs to be done.
@@ -219,16 +221,16 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
String displayTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, _currentTimestamp);
s_logger.debug("Snapshot scheduler.poll is being called at " + displayTime);
- List<SnapshotScheduleVO> snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp);
+ final List<SnapshotScheduleVO> snapshotsToBeExecuted = _snapshotScheduleDao.getSchedulesToExecute(_currentTimestamp);
s_logger.debug("Got " + snapshotsToBeExecuted.size() + " snapshots to be executed at " + displayTime);
- for (SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) {
+ for (final SnapshotScheduleVO snapshotToBeExecuted : snapshotsToBeExecuted) {
SnapshotScheduleVO tmpSnapshotScheduleVO = null;
- long snapshotScheId = snapshotToBeExecuted.getId();
- long policyId = snapshotToBeExecuted.getPolicyId();
- long volumeId = snapshotToBeExecuted.getVolumeId();
+ final long snapshotScheId = snapshotToBeExecuted.getId();
+ final long policyId = snapshotToBeExecuted.getPolicyId();
+ final long volumeId = snapshotToBeExecuted.getVolumeId();
try {
- VolumeVO volume = _volsDao.findById(volumeId);
+ final VolumeVO volume = _volsDao.findById(volumeId);
if (volume.getPoolId() == null) {
// this volume is not attached
continue;
@@ -237,26 +239,26 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
_snapshotScheduleDao.remove(snapshotToBeExecuted.getId());
}
if (s_logger.isDebugEnabled()) {
- Date scheduledTimestamp = snapshotToBeExecuted.getScheduledTimestamp();
+ final Date scheduledTimestamp = snapshotToBeExecuted.getScheduledTimestamp();
displayTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, scheduledTimestamp);
s_logger.debug("Scheduling 1 snapshot for volume " + volumeId + " for schedule id: " + snapshotToBeExecuted.getId() + " at " + displayTime);
}
tmpSnapshotScheduleVO = _snapshotScheduleDao.acquireInLockTable(snapshotScheId);
- Long eventId =
+ final Long eventId =
ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_SNAPSHOT_CREATE, "creating snapshot for volume Id:" +
volumeId, true, 0);
- Map<String, String> params = new HashMap<String, String>();
+ final Map<String, String> params = new HashMap<String, String>();
params.put(ApiConstants.VOLUME_ID, "" + volumeId);
params.put(ApiConstants.POLICY_ID, "" + policyId);
params.put("ctxUserId", "1");
params.put("ctxAccountId", "" + volume.getAccountId());
params.put("ctxStartEventId", String.valueOf(eventId));
- CreateSnapshotCmd cmd = new CreateSnapshotCmd();
+ final CreateSnapshotCmd cmd = new CreateSnapshotCmd();
ComponentContext.inject(cmd);
- ApiDispatcher.getInstance().dispatchCreateCmd(cmd, params);
+ _dispatcher.dispatchCreateCmd(cmd, params);
params.put("id", "" + cmd.getEntityId());
params.put("ctxStartEventId", "1");
@@ -265,11 +267,12 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null);
job.setDispatcher(_asyncDispatcher.getName());
- long jobId = _asyncMgr.submitAsyncJob(job);
+ final long jobId = _asyncMgr.submitAsyncJob(job);
tmpSnapshotScheduleVO.setAsyncJobId(jobId);
_snapshotScheduleDao.update(snapshotScheId, tmpSnapshotScheduleVO);
- } catch (Exception e) {
+ } catch (final Exception e) {
+ // TODO Logging this exception is enough?
s_logger.warn("Scheduling snapshot failed due to " + e.toString());
} finally {
if (tmpSnapshotScheduleVO != null) {
@@ -279,16 +282,16 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
}
}
- private Date scheduleNextSnapshotJob(SnapshotScheduleVO snapshotSchedule) {
+ private Date scheduleNextSnapshotJob(final SnapshotScheduleVO snapshotSchedule) {
if (snapshotSchedule == null) {
return null;
}
- Long policyId = snapshotSchedule.getPolicyId();
+ final Long policyId = snapshotSchedule.getPolicyId();
if (policyId.longValue() == Snapshot.MANUAL_POLICY_ID) {
// Don't need to schedule the next job for this.
return null;
}
- SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
+ final SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
if (snapshotPolicy == null) {
_snapshotScheduleDao.expunge(snapshotSchedule.getId());
}
@@ -297,15 +300,15 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
@Override
@DB
- public Date scheduleNextSnapshotJob(SnapshotPolicyVO policy) {
+ public Date scheduleNextSnapshotJob(final SnapshotPolicyVO policy) {
if (policy == null) {
return null;
}
- long policyId = policy.getId();
+ final long policyId = policy.getId();
if (policyId == Snapshot.MANUAL_POLICY_ID) {
return null;
}
- Date nextSnapshotTimestamp = getNextScheduledTime(policyId, _currentTimestamp);
+ final Date nextSnapshotTimestamp = getNextScheduledTime(policyId, _currentTimestamp);
SnapshotScheduleVO spstSchedVO = _snapshotScheduleDao.findOneByVolumePolicy(policy.getVolumeId(), policy.getId());
if (spstSchedVO == null) {
spstSchedVO = new SnapshotScheduleVO(policy.getVolumeId(), policyId, nextSnapshotTimestamp);
@@ -329,9 +332,9 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
@Override
@DB
- public boolean removeSchedule(Long volumeId, Long policyId) {
+ public boolean removeSchedule(final Long volumeId, final Long policyId) {
// We can only remove schedules which are in the future. Not which are already executed in the past.
- SnapshotScheduleVO schedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false);
+ final SnapshotScheduleVO schedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false);
boolean success = true;
if (schedule != null) {
success = _snapshotScheduleDao.remove(schedule.getId());
@@ -343,18 +346,18 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
}
@Override
- public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_snapshotPollInterval = NumbersUtil.parseInt(_configDao.getValue("snapshot.poll.interval"), 300);
- boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
+ final boolean snapshotsRecurringTest = Boolean.parseBoolean(_configDao.getValue("snapshot.recurring.test"));
if (snapshotsRecurringTest) {
// look for some test values in the configuration table so that snapshots can be taken more frequently (QA test code)
- int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
- int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
- int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
- int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
- int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
- int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
+ final int minutesPerHour = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.minutes.per.hour"), 60);
+ final int hoursPerDay = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.hours.per.day"), 24);
+ final int daysPerWeek = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.week"), 7);
+ final int daysPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.days.per.month"), 30);
+ final int weeksPerMonth = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.weeks.per.month"), 4);
+ final int monthsPerYear = NumbersUtil.parseInt(_configDao.getValue("snapshot.test.months.per.year"), 12);
_testTimerTask = new TestClock(this, minutesPerHour, hoursPerDay, daysPerWeek, daysPerMonth, weeksPerMonth, monthsPerYear);
}
@@ -369,8 +372,8 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
@DB
public boolean start() {
// reschedule all policies after management restart
- List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
- for (SnapshotPolicyVO policyInstance : policyInstances) {
+ final List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
+ for (final SnapshotPolicyVO policyInstance : policyInstances) {
if (policyInstance.getId() != Snapshot.MANUAL_POLICY_ID) {
scheduleNextSnapshotJob(policyInstance);
}
@@ -381,13 +384,13 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
// Else it becomes too confusing.
_testClockTimer.schedule(_testTimerTask, 100 * 1000L, 60 * 1000L);
} else {
- TimerTask timerTask = new ManagedContextTimerTask() {
+ final TimerTask timerTask = new ManagedContextTimerTask() {
@Override
protected void runInContext() {
try {
- Date currentTimestamp = new Date();
+ final Date currentTimestamp = new Date();
poll(currentTimestamp);
- } catch (Throwable t) {
+ } catch (final Throwable t) {
s_logger.warn("Catch throwable in snapshot scheduler ", t);
}
}