(request.getClusterName());
Map<Long, ConfigGroup> configGroupMap = cluster.getConfigGroups();
// By group id
if (request.getId() != null) {
ConfigGroup configGroup = configGroupMap.get(request.getId());
if (configGroup != null) {
responses.add(configGroup.convertToResponse());
}
continue;
}
// By group name
if (request.getGroupName() != null) {
for (ConfigGroup configGroup : configGroupMap.values()) {
if (configGroup.getName().equals(request.getGroupName())) {
responses.add(configGroup.convertToResponse());
}
}
continue;
}
// By tag only
if (request.getTag() != null && request.getHosts().isEmpty()) {
for (ConfigGroup configGroup : configGroupMap.values()) {
if (configGroup.getTag().equals(request.getTag())) {
responses.add(configGroup.convertToResponse());
}
}
continue;
}
// By hostnames only
if (!request.getHosts().isEmpty() && request.getTag() == null) {
for (String hostname : request.getHosts()) {
Map<Long, ConfigGroup> groupMap = cluster
.getConfigGroupsByHostname(hostname);
if (!groupMap.isEmpty()) {
for (ConfigGroup configGroup : groupMap.values()) {
responses.add(configGroup.convertToResponse());
}
}
}
continue;
}
// By tag and hostnames
if (request.getTag() != null && !request.getHosts().isEmpty()) {
for (ConfigGroup configGroup : configGroupMap.values()) {
// Has tag
if (configGroup.getTag().equals(request.getTag())) {
// Has a match with hosts
Set<String> groupHosts = new HashSet<String>(configGroup
.getHosts().keySet());
groupHosts.retainAll(request.getHosts());
if (!groupHosts.isEmpty()) {
responses.add(configGroup.convertToResponse());
}
}
}
continue;
}
// Select all
for (ConfigGroup configGroup : configGroupMap.values()) {
responses.add(configGroup.convertToResponse());
}
}
}
return responses;
}