public static Function<AgentStatus, AgentStatusRepresentation> fromAgentStatus(List<AgentStatus> agentStatuses, Repository repository) { return fromAgentStatus(new AgentStatusRepresentationFactory(agentStatuses, repository)); }
return agentStatus.getShortAgentId(); case uuid: return agentStatus.getAgentId(); case machine: return agentStatus.getInstanceId(); case internalHost: return agentStatus.getInternalHost(); case internalIp: return agentStatus.getInternalIp(); case externalHost: return agentStatus.getExternalHost(); case status: return agentStatus.getState(); case location: return agentStatus.getLocation(); case shortLocation: return agentStatus.getShortLocation(); case instanceType: return agentStatus.getInstanceType(); case internalUri: return agentStatus.getSelf(); case externalUri: return agentStatus.getExternalUri(); default: return null;
@GET @Produces(MediaType.APPLICATION_JSON) public Response getAllSlotsStatus() { AgentStatus agentStatus = agent.getAgentStatus(); AgentStatusRepresentation agentStatusRepresentation = AgentStatusRepresentation.from(agentStatus); return Response.ok(agentStatusRepresentation) .header(GALAXY_AGENT_VERSION_HEADER, agentStatus.getVersion()) .build(); } }
@Override public List<Instance> listAgents() { ImmutableList.Builder<Instance> instances = ImmutableList.builder(); for (Entry<String, String> entry : agents.entrySet()) { String instanceId = entry.getKey(); String agentUri = entry.getValue(); URI uri = UriBuilder.fromUri(agentUri).path("/v1/agent").build(); Request request = RequestBuilder.prepareGet() .setUri(uri) .build(); try { AgentStatusRepresentation agent = httpClient.execute(request, createJsonResponseHandler(agentCodec)); instances.add(new Instance(instanceId, firstNonNull(agent.getInstanceType(), "unknown"), firstNonNull(agent.getLocation(), "/static/" + uri.getHost() + "/agent"), agent.getSelf(), agent.getExternalUri())); } catch (Exception e) { instances.add(new Instance(instanceId, "unknown", "/static/" + uri.getHost() + "/agent", uri, uri)); } } return ImmutableList.copyOf(instances.build()); }
public String getInternalIp() { String host = getInternalHost(); if (host == null) { return null; } if ("localhost".equalsIgnoreCase(host)) { return "127.0.0.1"; } try { return InetAddress.getByName(host).getHostAddress(); } catch (UnknownHostException e) { return "unknown"; } }
uuidFilter.uuid.add(agent.getAgentId());
public AgentStatusRepresentation create(AgentStatus status) { Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slot : status.getSlotStatuses()) { builder.add(SlotStatusRepresentation.from(slot, Integer.MAX_VALUE, repository)); } return new AgentStatusRepresentation( status.getAgentId(), safeTruncate(status.getAgentId(), shortIdPrefixSize), status.getInstanceId(), status.getState(), status.getInternalUri(), status.getExternalUri(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), status.getInstanceType(), builder.build(), status.getResources(), status.getVersion()); } }
@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(); }
@POST @Path("/agent") @Produces(MediaType.APPLICATION_JSON) public Response provisionAgent( AgentProvisioningRepresentation provisioning, @Context UriInfo uriInfo) throws Exception { List<AgentStatus> agents = coordinator.provisionAgents( provisioning.getAgentConfig(), provisioning.getAgentCount(), provisioning.getInstanceType(), provisioning.getAvailabilityZone(), provisioning.getAmi(), provisioning.getKeyPair(), provisioning.getSecurityGroup()); return Response.ok(transform(agents, fromAgentStatus(coordinator.getAgents(), repository))).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))); }