private void readPolicy(OMElement policyElement) {
// retrieve attributes
String name = policyElement.getAttributeValue(new QName(NAME_ATTR));
boolean isDefault = Boolean.valueOf(policyElement.getAttributeValue(new QName(IS_DEFAULT_ATTR)));
Policy policy = new Policy();
policy.setName(name);
policy.setDefaultPolicy(isDefault);
// read description
Iterator<?> it = policyElement.getChildrenWithName(new QName(DESCRIPTION_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setDescription(element.getText());
}
// read min_app_instances
it = policyElement.getChildrenWithName(new QName(MIN_APP_INSTANCES_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setMinAppInstances(Integer.parseInt(element.getText()));
}
// read max_app_instances
it = policyElement.getChildrenWithName(new QName(MAX_APP_INSTANCES_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setMaxAppInstances(Integer.parseInt(element.getText()));
}
// read max_requests_per_second
it = policyElement.getChildrenWithName(new QName(MAX_REQUESTS_PER_SECOND_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setMaxRequestsPerSecond(Integer.parseInt(element.getText()));
}
// read rounds_to_average
it = policyElement.getChildrenWithName(new QName(ROUNDS_TO_AVERAGE_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setRoundsToAverage(Integer.parseInt(element.getText()));
}
// read alarming_upper_rate
it = policyElement.getChildrenWithName(new QName(ALARMING_UPPER_RATE_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setAlarmingUpperRate(new BigDecimal(element.getText()));
}
// read alarming_lower_rate
it = policyElement.getChildrenWithName(new QName(ALARMING_LOWER_RATE_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setAlarmingLowerRate(new BigDecimal(element.getText()));
}
// read scale_down_factor
it = policyElement.getChildrenWithName(new QName(SCALE_DOWN_FACTOR_ELEMENT));
if (it.hasNext()) {
OMElement element = (OMElement) it.next();
policy.setScaleDownFactor(new BigDecimal(element.getText()));
}
if (log.isDebugEnabled()) {
log.debug("Policy: " + new Gson().toJson(policy));
}
policyMap.put(policy.getName(), policy);
PolicyDefinition policyDefinition = new PolicyDefinition();
policyDefinition.setName(policy.getName());
policyDefinition.setDescription(policy.getDescription());
policyDefinition.setDefaultPolicy(policy.isDefaultPolicy());
policyDefinitions.add(policyDefinition);
// Set first default policy
if (defaultPolicy == null && policy.isDefaultPolicy()) {
defaultPolicy = policy;
}
}