@Override public List<? extends RemoteSlot> getSlots() { return ImmutableList.copyOf(Iterables.transform(agentStatus.getSlotStatuses(), new Function<SlotStatus, HttpRemoteSlot>() { @Override public HttpRemoteSlot apply(SlotStatus slotStatus) { return new HttpRemoteSlot(slotStatus, httpClient, HttpRemoteAgent.this); } })); }
@Override public boolean apply(AgentStatus agentStatus) { if (agentStatus == null) { return false; } for (SlotStatus slotStatus : agentStatus.getSlotStatuses()) { if (predicate.apply(slotStatus)) { return true; } } return false; } }
public static Map<String, Integer> getAvailableResources(AgentStatus agentStatus) { Map<String, Integer> availableResources = new TreeMap<String, Integer>(agentStatus.getResources()); for (SlotStatus slotStatus : agentStatus.getSlotStatuses()) { for (Entry<String, Integer> entry : slotStatus.getResources().entrySet()) { int value = Objects.firstNonNull(availableResources.get(entry.getKey()), 0); availableResources.put(entry.getKey(), value - entry.getValue()); } } return availableResources; }
for (SlotStatus slotStatus : agent.getAgentStatus().getSlotStatuses()) { stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), slotStatus.getState(), slotStatus.getAssignment()));
@Override public AgentStatus status() { AgentStatus agentStatus = agent.getAgentStatus(); return new AgentStatus(agentStatus.getAgentId(), agentStatus.getState(), instanceId, agentStatus.getInternalUri(), agentStatus.getExternalUri(), agentStatus.getLocation(), instanceType, agentStatus.getSlotStatuses(), agentStatus.getResources()); }
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()); } }
@Override public boolean apply(@Nullable AgentStatus status) { // We can only install on online agents if (status.getState() != ONLINE) { return false; } // Constraints: normally we only allow only instance of a binary+config on each agent if (!allowDuplicateInstallationsOnAnAgent) { for (SlotStatus slot : status.getSlotStatuses()) { if (repository.binaryEqualsIgnoreVersion(assignment.getBinary(), slot.getAssignment().getBinary()) && repository.configEqualsIgnoreVersion(assignment.getConfig(), slot.getAssignment().getConfig())) { return false; } } } // agents without declared resources are considered to have unlimited resources if (!status.getResources().isEmpty()) { // verify that required resources are available Installation installation = toInstallation(repository, assignment); Map<String, Integer> availableResources = getAvailableResources(status); if (!resourcesAreAvailable(availableResources, installation.getResources())) { return false; } } return true; } }