use of com.hazelcast.internal.management.operation.ScriptExecutorOperation in project hazelcast by hazelcast.
the class ExecuteScriptRequest method writeResponse.
@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
JsonObject jsonResult = new JsonObject();
ArrayList results;
if (targetAllMembers) {
Set<Member> members = mcs.getHazelcastInstance().getCluster().getMembers();
ArrayList<Object> list = new ArrayList<Object>(members.size());
for (Member member : members) {
list.add(mcs.callOnMember(member, new ScriptExecutorOperation(engine, script, bindings)));
}
results = list;
} else {
ArrayList<Object> list = new ArrayList<Object>(targets.size());
for (String address : targets) {
AddressUtil.AddressHolder addressHolder = AddressUtil.getAddressHolder(address);
Address targetAddress = new Address(addressHolder.getAddress(), addressHolder.getPort());
list.add(mcs.callOnAddress(targetAddress, new ScriptExecutorOperation(engine, script, bindings)));
}
results = list;
}
StringBuilder sb = new StringBuilder();
for (Object result : results) {
if (result instanceof String) {
sb.append(result);
} else if (result instanceof List) {
List list = (List) result;
for (Object o : list) {
sb.append(o).append("\n");
}
} else if (result instanceof Map) {
Map map = (Map) result;
for (Object o : map.entrySet()) {
Map.Entry entry = (Map.Entry) o;
sb.append(entry.getKey()).append("->").append(entry.getValue()).append("\n");
}
} else if (result == null) {
sb.append("error");
}
sb.append("\n");
}
jsonResult.add("scriptResult", sb.toString());
root.add("result", jsonResult);
}
Aggregations