public static void checkAgentsVersion(String expectedAgentsVersion, Iterable<AgentStatus> agentStatuses) { Preconditions.checkNotNull(agentStatuses, "agentStatuses is null"); if (expectedAgentsVersion == null) { return; } String actualAgentsVersion = createAgentsVersion(agentStatuses); if (!expectedAgentsVersion.equals(actualAgentsVersion)) { throw new VersionConflictException(GALAXY_AGENTS_VERSION_HEADER, actualAgentsVersion); } }
@GET @Path("/agent") @Produces(MediaType.APPLICATION_JSON) public Response getAllAgents(@Context UriInfo uriInfo) { List<SlotStatus> allSlotStatus = coordinator.getAllSlotStatus(); Predicate<AgentStatus> agentPredicate = AgentFilterBuilder.build(uriInfo, transform(coordinator.getAgents(), idGetter()), transform(allSlotStatus, SlotStatus.uuidGetter()), false, repository); List<AgentStatus> agents = coordinator.getAgents(agentPredicate); return Response.ok(transform(agents, fromAgentStatus(coordinator.getAgents(), repository))) .header(GALAXY_AGENTS_VERSION_HEADER, createAgentsVersion(agents)) .build(); }
@Override public CommanderResponse<List<AgentStatusRepresentation>> showAgents(AgentFilter agentFilter) { Predicate<AgentStatus> agentPredicate = agentFilter.toAgentPredicate( transform(coordinator.getAgents(), idGetter()), transform(coordinator.getAllSlotStatus(), SlotStatus.uuidGetter()), true, repository); List<AgentStatus> agentStatuses = coordinator.getAgents(agentPredicate); // update just in case something changed updateServiceInventory(); return createCommanderResponse(createAgentsVersion(agentStatuses), transform(agentStatuses, fromAgentStatus(coordinator.getAgents(), repository))); }