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()); }
public Installation toInstallation() { Installation installation = new Installation(shortName, assignment.toAssignment(), URI.create(binaryFile), URI.create(configFile), resources); return installation; }
private Predicate<RemoteAgent> filterAgentsWithAssignment(final Installation installation) { Preconditions.checkNotNull(installation, "installation is null"); final Assignment assignment = installation.getAssignment(); return new Predicate<RemoteAgent>() { @Override public boolean apply(RemoteAgent agent) { for (RemoteSlot slot : agent.getSlots()) { if (repository.binaryEqualsIgnoreVersion(assignment.getBinary(), slot.status().getAssignment().getBinary()) && repository.configEqualsIgnoreVersion(assignment.getConfig(), slot.status().getAssignment().getConfig())) { return false; } } return true; } }; } }
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; }
private String toBaseName(Installation installation) { String configSpec = installation.getAssignment().getConfig(); MavenCoordinates mavenCoordinates = MavenCoordinates.fromConfigGAV(configSpec); String baseName; if (mavenCoordinates != null) { baseName = mavenCoordinates.getArtifactId(); } else if (configSpec.startsWith("@")) { baseName = configSpec.substring(1); } else { baseName = configSpec; } return baseName; }
@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; } }
Assignment assignment = installation.getAssignment(); Deployment deployment = new Deployment(slotId, location, deploymentDir, dataDir, assignment, installation.getResources()); File tempDir = createTempDir(baseDir, "tmp-install"); try { Files.copy(Resources.newInputStreamSupplier(installation.getBinaryFile().toURL()), binary); throw new RuntimeException("Unable to download binary " + assignment.getBinary() + " from " + installation.getBinaryFile(), e); URL url = installation.getConfigFile().toURL(); ConfigUtils.unpackConfig(Resources.newInputStreamSupplier(url), binaryRootDir);
public List<SlotStatus> install(Predicate<AgentStatus> filter, int limit, Assignment assignment) { Installation installation = InstallationUtils.toInstallation(repository, assignment); List<RemoteAgent> targetAgents = selectAgents(filter, 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<SlotStatus> slots = newArrayList(); for (RemoteAgent agent : targetAgents) { if (slots.size() >= limit) { break; } // install SlotStatus slotStatus = agent.install(installation); stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), STOPPED, installation.getAssignment())); slots.add(slotStatus); } return ImmutableList.copyOf(slots); }
final Installation installation = new Installation( repository.configShortName(assignment.getConfig()), assignment,
@Override public SlotStatus apply(RemoteSlot slot) { SlotStatus slotStatus = slot.assign(installation); stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), STOPPED, installation.getAssignment())); return slotStatus; } }));
public static Installation toInstallation(Repository repository, Assignment assignment) { assignment = resolveAssignment(repository, assignment); // load resources Map<String, Integer> resources = readResources(repository, assignment); // create installation URI binaryUri = repository.binaryToHttpUri(assignment.getBinary()); Preconditions.checkNotNull(binaryUri, "Unknown binary %s", binaryUri); URI configUri = repository.configToHttpUri(assignment.getConfig()); Preconditions.checkNotNull(configUri, "Unknown config %s", configUri); return new Installation( repository.configShortName(assignment.getConfig()), assignment, binaryUri, configUri, resources); }
location, STOPPED, installation.getAssignment(), deployment.getDataDir().getAbsolutePath(), deployment.getResources()));
Preconditions.checkState(!terminated, "Slot has been terminated"); log.info("Becoming %s with %s", installation.getAssignment().getBinary(), installation.getAssignment().getConfig()); location, STOPPED, installation.getAssignment(), deployment.getDataDir().getAbsolutePath(), deployment.getResources());