@JsonProperty public String getBinary() { if (assignment == null) { return null; } return assignment.getBinary(); }
@Override public boolean apply(@Nullable SlotStatus slotStatus) { return (slotStatus != null) && (slotStatus.getAssignment() != null) && glob.apply(slotStatus.getAssignment().getBinary()); } }
public static AssignmentRepresentation from(Assignment assignment) { return new AssignmentRepresentation(assignment.getBinary(), assignment.getConfig()); }
public static Assignment resolveAssignment(Repository repository, Assignment assignment) { // resolve assignment String resolvedBinary = repository.binaryResolve(assignment.getBinary()); Preconditions.checkArgument(resolvedBinary != null, "Unknown binary " + assignment.getBinary()); String resolvedConfig = repository.configResolve(assignment.getConfig()); Preconditions.checkArgument(resolvedConfig != null, "Unknown config " + assignment.getConfig()); assignment = new Assignment(resolvedBinary, resolvedConfig); return assignment; }
public Assignment upgradeAssignment(Repository repository, Assignment assignment) { Preconditions.checkNotNull(assignment, "assignment is null"); String binary = assignment.getBinary(); if (binaryVersion != null) { binary = repository.binaryUpgrade(binary, binaryVersion); checkArgument(binary != null, "Can not upgrade binary " + assignment.getBinary() + " to " + binaryVersion); } else { checkArgument(repository.binaryToHttpUri(assignment.getBinary()) != null, "Can not locate existing binary " + assignment.getBinary() + " for upgrade"); } String config = assignment.getConfig(); if (configVersion != null) { config = repository.configUpgrade(config, configVersion); checkArgument(config != null, "Can not upgrade config " + assignment.getConfig() + " to " + configVersion); } else { checkArgument(repository.configToHttpUri(assignment.getConfig()) != null, "Can not locate existing config " + assignment.getConfig() + " for upgrade"); } return new Assignment(binary, config); }
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); }
@Override public void setExpectedState(ExpectedSlotStatus slotStatus) { Preconditions.checkNotNull(slotStatus, "slotStatus is null"); if (isDomainCreated()) { List<ReplaceableAttribute> attributes = newArrayList(); attributes.add(new ReplaceableAttribute("state", slotStatus.getStatus().toString(), true)); if (slotStatus.getAssignment() != null) { attributes.add(new ReplaceableAttribute("binary", slotStatus.getAssignment().getBinary(), true)); attributes.add(new ReplaceableAttribute("config", slotStatus.getAssignment().getConfig(), true)); } try { simpleDb.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(slotStatus.getId().toString()).withAttributes(attributes)); expectedStateStoreUp(); } catch (Exception e) { expectedStateStoreDown(e); } } }
@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; } });
private void assertSlotStatus(SlotStatusRepresentation slot, UUID expectedSlotId, Assignment expectedAssignment, SlotLifecycleState expectedState, AgentStatusRepresentation expectedAgent) { assertEquals(slot.getId(), expectedSlotId); if (expectedState != SlotLifecycleState.TERMINATED) { assertEquals(slot.getBinary(), expectedAssignment.getBinary()); assertEquals(slot.getConfig(), expectedAssignment.getConfig()); assertTrue(slot.getInstallPath().startsWith(tempDir.getAbsolutePath())); } else { assertNull(slot.getBinary()); assertNull(slot.getConfig()); assertNull(slot.getInstallPath()); } assertEquals(slot.getStatus(), expectedState.toString()); assertEquals(slot.getInstanceId(), expectedAgent.getInstanceId()); assertTrue(slot.getLocation().startsWith(expectedAgent.getLocation())); assertTrue(slot.getLocation().endsWith(slot.getShortLocation())); assertTrue(slot.getSelf().toASCIIString().startsWith(expectedAgent.getSelf().toASCIIString())); assertTrue(slot.getExternalUri().toASCIIString().startsWith(expectedAgent.getExternalUri().toASCIIString())); }
@Test public void testRestart() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("restarting", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", RUNNING.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), RUNNING, appleInstallation.getAssignment())) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
private void assertSlotStatus(SlotStatusRepresentation slot, UUID expectedSlotId, Assignment expectedAssignment, SlotLifecycleState expectedState, AgentStatusRepresentation expectedAgent) { assertEquals(slot.getId(), expectedSlotId); if (expectedState != SlotLifecycleState.TERMINATED) { assertEquals(slot.getBinary(), expectedAssignment.getBinary()); assertEquals(slot.getConfig(), expectedAssignment.getConfig()); assertTrue(slot.getInstallPath().startsWith(tempDir.getAbsolutePath())); } else { assertNull(slot.getBinary()); assertNull(slot.getConfig()); assertNull(slot.getInstallPath()); } assertEquals(slot.getStatus(), expectedState.toString()); assertEquals(slot.getInstanceId(), expectedAgent.getInstanceId()); assertTrue(slot.getLocation().startsWith(expectedAgent.getLocation())); assertTrue(slot.getLocation().endsWith(slot.getShortLocation())); assertTrue(slot.getSelf().toASCIIString().startsWith(expectedAgent.getSelf().toASCIIString())); assertTrue(slot.getExternalUri().toASCIIString().startsWith(expectedAgent.getExternalUri().toASCIIString())); }
@Test public void testStart() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("running", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", RUNNING.toString()) .put("version", VersionsUtil.createSlotVersion(slotStatus.getId(), RUNNING, appleInstallation.getAssignment())) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
private void assertSlotStatus(SlotStatusRepresentation slot, UUID expectedSlotId, Assignment expectedAssignment, SlotLifecycleState expectedState, AgentStatusRepresentation expectedAgent) { assertEquals(slot.getId(), expectedSlotId); if (expectedState != SlotLifecycleState.TERMINATED) { assertEquals(slot.getBinary(), expectedAssignment.getBinary()); assertEquals(slot.getConfig(), expectedAssignment.getConfig()); assertNotNull(slot.getInstallPath()); } else { assertNull(slot.getBinary()); assertNull(slot.getConfig()); assertNull(slot.getInstallPath()); } assertEquals(slot.getStatus(), expectedState.toString()); assertEquals(slot.getInstanceId(), expectedAgent.getInstanceId()); assertTrue(slot.getLocation().startsWith(expectedAgent.getLocation())); assertTrue(slot.getLocation().endsWith(slot.getShortLocation())); assertTrue(slot.getSelf().toASCIIString().startsWith(expectedAgent.getSelf().toASCIIString())); assertTrue(slot.getExternalUri().toASCIIString().startsWith(expectedAgent.getExternalUri().toASCIIString())); }
@Test public void testStop() throws Exception { SlotStatus slotStatus = agent.install(appleInstallation); agent.getSlot(slotStatus.getId()).start(); Request request = Request.Builder.preparePut() .setUri(urlFor(slotStatus, "lifecycle")) .setBodyGenerator(createStaticBodyGenerator("stopped", UTF_8)) .build(); Map<String, Object> response = client.execute(request, createJsonResponseHandler(mapCodec, Status.OK.getStatusCode())); Map<String, Object> expected = ImmutableMap.<String, Object>builder() .put("id", slotStatus.getId().toString()) .put("shortId", slotStatus.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig()) .put("self", urlFor(slotStatus).toASCIIString()) .put("externalUri", urlFor(slotStatus).toASCIIString()) .put("location", slotStatus.getLocation()) .put("shortLocation", slotStatus.getLocation()) .put("status", STOPPED.toString()) .put("version", slotStatus.getVersion()) .put("installPath", slotStatus.getInstallPath()) .put("resources", ImmutableMap.<String, Integer>of("memory", 512)) .build(); assertEquals(response, expected); }
.put("id", slot.getId().toString()) .put("shortId", slot.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig())
.put("id", slot.getId().toString()) .put("shortId", slot.getId().toString()) .put("binary", appleInstallation.getAssignment().getBinary()) .put("shortBinary", appleInstallation.getAssignment().getBinary()) .put("config", appleInstallation.getAssignment().getConfig()) .put("shortConfig", appleInstallation.getAssignment().getConfig())
appleSlot1 = agent.getSlot(agent.install(new Installation("apple", APPLE_ASSIGNMENT, repository.binaryToHttpUri(APPLE_ASSIGNMENT.getBinary()), repository.configToHttpUri(APPLE_ASSIGNMENT.getConfig()), ImmutableMap.of("memory", 512))).getId()); appleSlot2 = agent.getSlot(agent.install(new Installation("apple", APPLE_ASSIGNMENT, repository.binaryToHttpUri(APPLE_ASSIGNMENT.getBinary()), repository.configToHttpUri(APPLE_ASSIGNMENT.getConfig()), ImmutableMap.of("memory", 512))).getId()); bananaSlot = agent.getSlot(agent.install(new Installation("banana", BANANA_ASSIGNMENT, repository.binaryToHttpUri(BANANA_ASSIGNMENT.getBinary()), repository.configToHttpUri(BANANA_ASSIGNMENT.getConfig()), ImmutableMap.of("memory", 512))).getId());