List<AutoScaleVmGroupPolicyMapVO> listMap = _asGroupPolicyDao.listByVmGroupId(groupId);
if ((listMap == null) || (listMap.size() == 0))
return null;
for (AutoScaleVmGroupPolicyMapVO asVmgPmap : listMap) {
AutoScalePolicyVO policyVO = _asPolicyDao.findById(asVmgPmap.getPolicyId());
if (policyVO != null) {
Integer quitetime = policyVO.getQuietTime();
Date quitetimeDate = policyVO.getLastQuiteTime();
long last_quitetime = 0L;
if (quitetimeDate != null) {
last_quitetime = policyVO.getLastQuiteTime().getTime();
}
long current_time = (new Date()).getTime();
// check quite time for this policy
if ((current_time - last_quitetime) >= (long)quitetime) {
// list all condition of this policy
boolean bValid = true;
List<ConditionVO> lstConditions = getConditionsbyPolicyId(policyVO.getId());
if ((lstConditions != null) && (lstConditions.size() > 0)) {
// check whole conditions of this policy
for (ConditionVO conditionVO : lstConditions) {
long thresholdValue = conditionVO.getThreshold();
Double thresholdPercent = (double)thresholdValue / 100;
CounterVO counterVO = _asCounterDao.findById(conditionVO.getCounterid());
//Double sum = avgCounter.get(conditionVO.getCounterid());
long counter_count = 1;
do {
String counter_param = params.get("counter" + String.valueOf(counter_count));
Counter.Source counter_source = counterVO.getSource();
if (counter_param.equals(counter_source.toString()))
break;
counter_count++;
} while (1 == 1);
Double sum = avgCounter.get(counter_count);
Double avg = sum / currentVM;
Operator op = conditionVO.getRelationalOperator();
boolean bConditionCheck = ((op == com.cloud.network.as.Condition.Operator.EQ) && (thresholdPercent.equals(avg)))
|| ((op == com.cloud.network.as.Condition.Operator.GE) && (avg.doubleValue() >= thresholdPercent.doubleValue()))
|| ((op == com.cloud.network.as.Condition.Operator.GT) && (avg.doubleValue() > thresholdPercent.doubleValue()))
|| ((op == com.cloud.network.as.Condition.Operator.LE) && (avg.doubleValue() <= thresholdPercent.doubleValue()))
|| ((op == com.cloud.network.as.Condition.Operator.LT) && (avg.doubleValue() < thresholdPercent.doubleValue()));
if (!bConditionCheck) {
bValid = false;
break;
}
}
if (bValid) {
return policyVO.getAction();
}
}
}
}
}