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 static DeploymentRepresentation from(Deployment deployment) { return new DeploymentRepresentation( deployment.getNodeId(), AssignmentRepresentation.from(deployment.getAssignment()), deployment.getResources()); }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No agents have the available resources to run the specified binary and configuration.") public void testInstallNotEnoughResources() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 0, "memory", 0)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); response.getEntity(); }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No agents have the available resources to run the specified binary and configuration.") public void testInstallNotEnoughResources() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 0, "memory", 0)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); response.getEntity(); }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No agents have the available resources to run the specified binary and configuration.") public void testInstallResourcesConsumed() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 1, "memory", 512)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); // install an apple server Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), 1); assertAppleSlot(Iterables.get(slots, 0)); // try to install a banana server which will fail response = resource.install(AssignmentRepresentation.from(BANANA_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); response.getEntity(); }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No agents have the available resources to run the specified binary and configuration.") public void testInstallResourcesConsumed() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 1, "memory", 512)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); // install an apple server Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), 1); assertAppleSlot(Iterables.get(slots, 0)); // try to install a banana server which will fail response = resource.install(AssignmentRepresentation.from(BANANA_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); response.getEntity(); }
@Test public void testInstallWithinResourceLimit() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 1, "memory", 512)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), 1); for (SlotStatusRepresentation slotRepresentation : slots) { assertAppleSlot(slotRepresentation); } assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
@Test public void testInstallWithinResourceLimit() { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 1, "memory", 512)); coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment"); Response response = resource.install(AssignmentRepresentation.from(APPLE_ASSIGNMENT), 1, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), 1); for (SlotStatusRepresentation slotRepresentation : slots) { assertAppleSlot(slotRepresentation); } assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
public void testInstall(int numberOfAgents, int limit, Assignment assignment) { for (int i = 0; i < numberOfAgents; i++) { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 8, "memory", 1024)); } coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment?host=apple*"); Response response = resource.install(AssignmentRepresentation.from(assignment), limit, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), min(numberOfAgents, limit)); for (SlotStatusRepresentation slotRepresentation : slots) { SlotStatus slot = slotRepresentation.toSlotStatus("instance"); assertEquals(slot.getAssignment(), assignment); assertEquals(slot.getState(), STOPPED); } assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
public void testInstall(int numberOfAgents, int limit, Assignment assignment) { for (int i = 0; i < numberOfAgents; i++) { provisioner.addAgent(UUID.randomUUID().toString(), URI.create("fake://appleServer1/"), ImmutableMap.of("cpu", 8, "memory", 1024)); } coordinator.updateAllAgentsAndWait(); UriInfo uriInfo = MockUriInfo.from("http://localhost/v1/slot/assignment?host=apple*"); Response response = resource.install(AssignmentRepresentation.from(assignment), limit, uriInfo, null); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Collection<SlotStatusRepresentation> slots = (Collection<SlotStatusRepresentation>) response.getEntity(); assertEquals(slots.size(), min(numberOfAgents, limit)); for (SlotStatusRepresentation slotRepresentation : slots) { SlotStatus slot = slotRepresentation.toSlotStatus("instance"); assertEquals(slot.getAssignment(), assignment); assertEquals(slot.getState(), STOPPED); } assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
@Override public List<SlotStatusRepresentation> install(AgentFilter agentFilter, int count, Assignment assignment, String expectedVersion) { URI uri = agentFilter.toUri(uriBuilderFrom(coordinatorUri).replacePath("/v1/slot").addParameter("limit", String.valueOf(count))); Request.Builder requestBuilder = Request.Builder.preparePost() .setUri(uri) .setHeader("Content-Type", "application/json") .setBodyGenerator(jsonBodyGenerator(ASSIGNMENT_CODEC, AssignmentRepresentation.from(assignment))); if (expectedVersion != null) { requestBuilder.setHeader(AIRSHIP_SLOTS_VERSION_HEADER, expectedVersion); } List<SlotStatusRepresentation> slots = client.execute(requestBuilder.build(), createJsonResponseHandler(SLOTS_CODEC)); return slots; }
@Override public List<SlotStatusRepresentation> install(AgentFilter agentFilter, int count, Assignment assignment, String expectedVersion) { URI uri = agentFilter.toUri(uriBuilderFrom(coordinatorUri).replacePath("/v1/slot").addParameter("limit", String.valueOf(count))); Request.Builder requestBuilder = Request.Builder.preparePost() .setUri(uri) .setHeader("Content-Type", "application/json") .setBodyGenerator(jsonBodyGenerator(ASSIGNMENT_CODEC, AssignmentRepresentation.from(assignment))); if (expectedVersion != null) { requestBuilder.setHeader(AIRSHIP_SLOTS_VERSION_HEADER, expectedVersion); } List<SlotStatusRepresentation> slots = client.execute(requestBuilder.build(), createJsonResponseHandler(SLOTS_CODEC)); return slots; }