@Test public void testConstructor() { URI binaryFile = URI.create("fake://localhost/binaryFile"); URI configFile = URI.create("fake://localhost/configFile"); Installation installation = new Installation("apple", APPLE_ASSIGNMENT, binaryFile, configFile, ImmutableMap.of("memory", 512)); assertEquals(installation.getAssignment(), APPLE_ASSIGNMENT); assertEquals(installation.getBinaryFile(), binaryFile); assertEquals(installation.getConfigFile(), configFile); }
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()); }
@Override public Deployment install(Installation installation) { Preconditions.checkNotNull(installation, "installation is null"); deployment = new Deployment(UUID.randomUUID(), location, new File("installation"), new File("data"), installation.getAssignment(), installation.getResources()); return deployment; }
private Predicate<RemoteAgent> filterAgentsWithAssignment(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 ((slot.status().getAssignment() != null) && assignmentEqualsIgnoreVersion(assignment, slot.status().getAssignment())) { return false; } } return true; } }; }
@Override public SlotStatus apply(RemoteSlot slot) { boolean expectRestart = slot.status().getState() == RUNNING; Assignment assignment = newAssignments.get(slot.getId()); Preconditions.checkState(assignment != null, "Error no assignment for slot " + slot.getId()); URI configFile = repository.configToHttpUri(assignment.getConfig()); Installation installation = new Installation( repository.configShortName(assignment.getConfig()), assignment, repository.binaryToHttpUri(assignment.getBinary()), configFile, ImmutableMap.<String, Integer>of()); stateManager.setExpectedState(new ExpectedSlotStatus(slot.getId(), expectRestart ? RUNNING : STOPPED, installation.getAssignment())); SlotStatus slotStatus = slot.assign(installation); return slotStatus; } });
public Installation toInstallation() { Installation installation = new Installation(shortName, assignment.toAssignment(), URI.create(binaryFile), URI.create(configFile), resources); return installation; }
if (!InstallationUtils.resourcesAreAvailable(availableResources, installation.getResources())) { continue;
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 Deployment install(Installation installation) { Preconditions.checkNotNull(installation, "installation is null"); deployment = new Deployment(UUID.randomUUID(), location, new File("installation"), new File("data"), installation.getAssignment(), installation.getResources()); return deployment; }
@Test public void testEquivalence() { equivalenceTester() .addEquivalentGroup( new Installation("apple", APPLE_ASSIGNMENT, URI.create("fetch://binary.tar.gz"), URI.create("fetch://config.txt"), ImmutableMap.of("memory", 512)), new Installation("apple", APPLE_ASSIGNMENT, URI.create("fetch://anything.tar.gz"), URI.create("fetch://anything.txt"), ImmutableMap.of("memory", 512))) .addEquivalentGroup( new Installation("banana", BANANA_ASSIGNMENT, URI.create("fetch://binary.tar.gz"), URI.create("fetch://config.txt"), ImmutableMap.of("memory", 512)), new Installation("banana", BANANA_ASSIGNMENT, URI.create("fetch://anything.tar.gz"), URI.create("fetch://anything.txt"), ImmutableMap.of("memory", 512))) .check(); } }
@Override public boolean apply(@Nullable AgentStatus status) { // We can only install on online agents if ((status == null) || (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 ((slot.getAssignment() != null) && assignmentEqualsIgnoreVersion(slot.getAssignment())) { 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 newDeployment = new Deployment(slotId, location, deploymentDir, getDataDir(), assignment, installation.getResources()); File tempDir = createTempDir(baseDir, "tmp-install"); try { Resources.asByteSource(installation.getBinaryFile().toURL()).copyTo(Files.asByteSink(binary)); throw new RuntimeException("Unable to download binary " + assignment.getBinary() + " from " + installation.getBinaryFile(), e); URL url = installation.getConfigFile().toURL(); ConfigUtils.unpackConfig(Resources.asByteSource(url), binaryRootDir);
@Test public void testConstructor() { URI binaryFile = URI.create("fake://localhost/binaryFile"); URI configFile = URI.create("fake://localhost/configFile"); Installation installation = new Installation("apple", APPLE_ASSIGNMENT, binaryFile, configFile, ImmutableMap.of("memory", 512)); assertEquals(installation.getAssignment(), APPLE_ASSIGNMENT); assertEquals(installation.getBinaryFile(), binaryFile); assertEquals(installation.getConfigFile(), configFile); }
@Override public SlotStatus apply(RemoteAgent agent) { SlotStatus slotStatus = agent.install(installation); stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), STOPPED, installation.getAssignment())); return slotStatus; } });
@Override public synchronized SlotStatus install(Installation installation) { checkNotNull(installation, "installation is null"); AgentStatus agentStatus = getAgentStatus(); Preconditions.checkState(agentStatus.getState() != OFFLINE, "agent is offline"); UUID slotId = UUID.randomUUID(); SlotStatus slotStatus = createSlotStatus(slotId, uriBuilderFrom(agentStatus.getInternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), uriBuilderFrom(agentStatus.getExternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), "instance", "/location", SlotLifecycleState.STOPPED, installation.getAssignment(), "/" + slotId, installation.getResources()); agentStatus.changeSlotStatus(slotStatus); return slotStatus; }
@Test public void testEquivalence() { equivalenceTester() .addEquivalentGroup( new Installation("apple", APPLE_ASSIGNMENT, URI.create("fetch://binary.tar.gz"), URI.create("fetch://config.txt"), ImmutableMap.of("memory", 512)), new Installation("apple", APPLE_ASSIGNMENT, URI.create("fetch://anything.tar.gz"), URI.create("fetch://anything.txt"), ImmutableMap.of("memory", 512))) .addEquivalentGroup( new Installation("banana", BANANA_ASSIGNMENT, URI.create("fetch://binary.tar.gz"), URI.create("fetch://config.txt"), ImmutableMap.of("memory", 512)), new Installation("banana", BANANA_ASSIGNMENT, URI.create("fetch://anything.tar.gz"), URI.create("fetch://anything.txt"), ImmutableMap.of("memory", 512))) .check(); } }
location, STOPPED, installation.getAssignment(), deployment.getDataDir().getAbsolutePath(), deployment.getResources()));
@Override public synchronized SlotStatus install(Installation installation) { checkNotNull(installation, "installation is null"); AgentStatus agentStatus = getAgentStatus(); Preconditions.checkState(agentStatus.getState() != OFFLINE, "agent is offline"); UUID slotId = UUID.randomUUID(); SlotStatus slotStatus = createSlotStatus(slotId, uriBuilderFrom(agentStatus.getInternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), uriBuilderFrom(agentStatus.getExternalUri()).appendPath("slot").appendPath(slotId.toString()).build(), "instance", "/location", SlotLifecycleState.STOPPED, installation.getAssignment(), "/" + slotId, installation.getResources()); agentStatus.changeSlotStatus(slotStatus); return slotStatus; }
public InstallationHelper() throws Exception { File targetRepo = null; File binaryFile; try { targetRepo = createTempDir("repo"); binaryFile = new File(targetRepo, "binary.tar.gz"); createArchive(binaryFile); } catch (Exception e) { if (targetRepo != null) { deleteRecursively(targetRepo); } throw e; } this.targetRepo = targetRepo; appleInstallation = new Installation("apple", APPLE_ASSIGNMENT, binaryFile.toURI(), new File("README.txt").toURI(), ImmutableMap.of("memory", 512)); bananaInstallation = new Installation("banana", BANANA_ASSIGNMENT, binaryFile.toURI(), new File("README.txt").toURI(), ImmutableMap.of("cpu", 1)); }
@Test public void testInstall() { // no deployment by default assertNull(manager.getDeployment()); // install apple deployment Deployment appleDeployment = manager.install(appleInstallation); assertNotNull(appleDeployment); assertEquals(manager.getDeployment(), appleDeployment); assertEquals(appleDeployment.getAssignment(), appleInstallation.getAssignment()); // install banana Deployment bananaDeployment = manager.install(bananaInstallation); assertNotNull(bananaDeployment); assertEquals(manager.getDeployment(), bananaDeployment); assertEquals(bananaDeployment.getAssignment(), bananaInstallation.getAssignment()); } }