@Override
public void updateResourceConfiguration(ConfigurationUpdateReport report) {
Configuration sgConfig = new Configuration();
loadAssignedServerGroups(sgConfig);
CompositeOperation operation = new CompositeOperation();
boolean needDiscovery = false; // we will request deferred child discovery on parent HC only in case new assignment was added
// load assigned server-groups to map, so we can easily look them up
Map<String, PropertyMap> assignedCurrent = new HashMap<String, PropertyMap>();
for (Property p : sgConfig.getList("*1").getList()) {
PropertyMap map = (PropertyMap) p;
assignedCurrent.put(map.getSimpleValue("server-group", null), map);
}
// also put new assignment to map, to detect possible duplicates
Map<String, PropertyMap> assignedNew = new HashMap<String, PropertyMap>();
// detect changes (enable/disable changes and new assignments)
for (Property prop : report.getConfiguration().getList("*1").getList()) {
PropertyMap mapNew = (PropertyMap) prop;
PropertyMap duplicate = assignedNew.put(mapNew.getSimpleValue("server-group", null), mapNew);
if (duplicate != null) {
report.setStatus(ConfigurationUpdateStatus.FAILURE);
report.setErrorMessage("Duplicate assignment to [" + duplicate.getSimpleValue("server-group", null)
+ "] you cannot assign deployment to server-group more than once");
return;
}
String key = mapNew.getSimpleValue("server-group", null);
String runtimeNew = mapNew.getSimpleValue("runtime-name", null);
boolean enabledNew = mapNew.getSimple("enabled").getBooleanValue();
PropertyMap mapCurrent = assignedCurrent.remove(key);
if (mapCurrent == null) {
// new assignment was added
operation.addStep(createServerGroupAssignmentStep("add", key, runtimeNew, enabledNew));
needDiscovery = true;
} else {
boolean enabledCurrent = mapCurrent.getSimple("enabled").getBooleanValue();
if (enabledCurrent != enabledNew) {
// deployment status change
String action = "undeploy";
if (enabledNew) {
action = "deploy";
}
operation.addStep(createServerGroupAssignmentStep(action, key, null, false));
}
}
}
// detect removals, items left in map (exist in old config, but were not sent in the new one) should be removed
for (PropertyMap map : assignedCurrent.values()) {
operation.addStep(createServerGroupAssignmentStep("remove", map.getSimpleValue("server-group", null), null,
false));
}
if (operation.numberOfSteps() == 0) {
report.setStatus(ConfigurationUpdateStatus.NOCHANGE);
return;
}
Result res = getASConnection().execute(operation, 120); // wait up to 2 minutes
if (res.isSuccess()) {