private List<RemoteAgent> selectAgents(Predicate<AgentStatus> filter, Installation installation) { // randomize agents so all processes don't end up on the same node // todo sort agents by number of process already installed on them List<RemoteAgent> targetAgents = newArrayList(); List<RemoteAgent> allAgents = newArrayList(filter(this.agents.values(), filterAgentsBy(filter))); if (!allowDuplicateInstallationsOnAnAgent) { allAgents = newArrayList(filter(this.agents.values(), filterAgentsWithAssignment(installation))); } Collections.shuffle(allAgents); for (RemoteAgent agent : allAgents) { // verify agent state AgentStatus status = agent.status(); if (status.getState() != AgentLifecycleState.ONLINE) { continue; } // agents without declared resources are considered to have unlimited resources if (!status.getResources().isEmpty()) { // verify that required resources are available Map<String, Integer> availableResources = InstallationUtils.getAvailableResources(status); if (!InstallationUtils.resourcesAreAvailable(availableResources, installation.getResources())) { continue; } } targetAgents.add(agent); } return targetAgents; }
public static InstallationRepresentation from(Installation installation) { Assignment assignment = installation.getAssignment(); return new InstallationRepresentation( installation.getShortName(), AssignmentRepresentation.from(assignment), installation.getBinaryFile().toString(), installation.getConfigFile().toString(), installation.getResources()); }
Deployment deployment = new Deployment(slotId, location, deploymentDir, dataDir, assignment, installation.getResources()); File tempDir = createTempDir(baseDir, "tmp-install"); try {
@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; } }