this.selectedStack = request.getParameter("name", null);
}
private void loadStacks(final boolean refreshDetails) {
ModelNode operation = new ModelNode();
operation.get(ADDRESS).set(Baseadress.get());
operation.get(ADDRESS).add("subsystem", "jgroups");
operation.get(OP).set(READ_CHILDREN_RESOURCES_OPERATION);
operation.get(CHILD_TYPE).set("stack");
operation.get(RECURSIVE).set(true);
dispatcher.execute(new DMRAction(operation), new SimpleCallback<DMRResponse>() {
@Override
public void onSuccess(DMRResponse result) {
ModelNode response = result.get();
if (response.isFailure()) {
Console.error(Console.MESSAGES.failed("JGroups Stack"), response.getFailureDescription());
} else {
List<JGroupsStack> stacks = new ArrayList<JGroupsStack>();
List<Property> subresources = response.get(RESULT).asPropertyList();
for(Property prop : subresources)
{
ModelNode model = prop.getValue();
JGroupsStack stack = factory.jGroupsStack().as();
stack.setName(prop.getName());
List<JGroupsProtocol> protocols = new ArrayList<JGroupsProtocol>();
if(model.hasDefined("protocol"))
{
if(!model.hasDefined("protocols"))
throw new RuntimeException("Protocol sort order not given!");
List<ModelNode> sortOrder = model.get("protocols").asList();
final List<String> keys = new LinkedList<String>();
for(ModelNode key : sortOrder)
keys.add(key.asString());
// parse protocols
List<Property> items = model.get("protocol").asPropertyList();
// todo: https://issues.jboss.org/browse/AS7-3863
Collections.sort(items, new Comparator<Property>() {
@Override
public int compare(Property property, Property property1) {
int firstIdx = keys.indexOf(property.getName());
int secondIdx = keys.indexOf(property1.getName());
if(firstIdx<secondIdx) return -1;
if(firstIdx>secondIdx) return 1;
return 0;
}
});
for(Property item : items)
{
ModelNode protocolModel = item.getValue();
JGroupsProtocol jGroupsProtocol = protocolAdapter.fromDMR(protocolModel);
jGroupsProtocol.setProperties(new ArrayList<PropertyRecord>());
// protocol properties
if(protocolModel.hasDefined("property"))
{
List<Property> propItems = protocolModel.get("property").asPropertyList();
for(Property p : propItems)
{
String name = p.getName();
String value = p.getValue().asObject().get("value").asString();
PropertyRecord propertyRecord = factory.property().as();
propertyRecord.setKey(name);
propertyRecord.setValue(value);
jGroupsProtocol.getProperties().add(propertyRecord);
}
}
protocols.add(jGroupsProtocol);
}
}
stack.setProtocols(protocols);
// TODO: parse transport
if(model.hasDefined("transport"))
{
List<Property> transportList = model.get("transport").asPropertyList();
if(transportList.isEmpty())
{
JGroupsTransport transport = factory.jGroupsTransport().as();
stack.setTransport(transport);
}
else
{
ModelNode transportDef = transportList.get(0).getValue();
JGroupsTransport transport = transportAdapter.fromDMR(transportDef);
stack.setTransport(transport);
}
}