class DefaultAgentManagementService implements AgentManagementService {

    @Override
    public List<Pair<AgentInstanceGroup, List<AgentInstance>>> findAgentInstances(Predicate<Pair<AgentInstanceGroup, AgentInstance>> filter) {
        return agentCache.getInstanceGroups().stream()
                .map(instanceGroup -> {
                    List<AgentInstance> matchingAgents = agentCache.getAgentInstances(instanceGroup.getId()).stream()
                            .filter(agent -> filter.test(Pair.of(instanceGroup, agent)))
                            .collect(Collectors.toList());
                    return Pair.of(instanceGroup, matchingAgents);
                })
                .filter(pair -> !pair.getRight().isEmpty())
                .collect(Collectors.toList());
    }

    @Inject public  DefaultAgentManagementService(AgentManagementConfiguration configuration,
                                         @Named(KUBE_SCHEDULER_INSTANCE_GROUP_PREDICATE) Predicate<AgentInstanceGroup> kubeSchedulerInstanceGroupPredicate,
                                         InstanceCloudConnector instanceCloudConnector,
                                         AgentCache AgentCache,
                                         ServerInfoResolver serverInfoResolver,
                                         TitusRuntime titusRuntime);

}