public static Map<String, Integer> getAvailableResources(AgentStatus agentStatus) { Map<String, Integer> availableResources = new TreeMap<String, Integer>(agentStatus.getResources()); for (SlotStatus slotStatus : agentStatus.getSlotStatuses()) { for (Entry<String, Integer> entry : slotStatus.getResources().entrySet()) { int value = Objects.firstNonNull(availableResources.get(entry.getKey()), 0); availableResources.put(entry.getKey(), value - entry.getValue()); } } return availableResources; }
private void assertAppleSlot(SlotStatus slot) { assertEquals(slot.getAssignment(), RESOLVED_APPLE_ASSIGNMENT); assertEquals(slot.getState(), STOPPED); assertEquals(slot.getResources(), ImmutableMap.of("cpu", 1, "memory", 512)); } }
private void assertAppleSlot(SlotStatus slot) { assertEquals(slot.getAssignment(), RESOLVED_APPLE_ASSIGNMENT); assertEquals(slot.getState(), STOPPED); assertEquals(slot.getResources(), ImmutableMap.of("cpu", 1, "memory", 512)); } }
private void assertAppleSlot(SlotStatusRepresentation slotRepresentation) { SlotStatus slot = slotRepresentation.toSlotStatus("instance"); assertEquals(slot.getAssignment(), APPLE_ASSIGNMENT); assertEquals(slot.getState(), STOPPED); assertEquals(slot.getResources(), ImmutableMap.of("cpu", 1, "memory", 512)); } }
private void assertAppleSlot(SlotStatusRepresentation slotRepresentation) { SlotStatus slot = slotRepresentation.toSlotStatus("instance"); assertEquals(slot.getAssignment(), APPLE_ASSIGNMENT); assertEquals(slot.getState(), STOPPED); assertEquals(slot.getResources(), ImmutableMap.of("cpu", 1, "memory", 512)); } }
@Override public SlotStatus assign(Installation installation) { Preconditions.checkNotNull(installation, "installation is null"); slotStatus = slotStatus.changeAssignment(STOPPED, installation.getAssignment(), slotStatus.getResources()); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus assign(Installation installation) { Preconditions.checkNotNull(installation, "installation is null"); slotStatus = slotStatus.changeAssignment(STOPPED, installation.getAssignment(), slotStatus.getResources()); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
public void assertInstallSlot(String agentVersion) { Response response = resource.installSlot(agentVersion, InstallationRepresentation.from(APPLE_INSTALLATION), uriInfo); // find the new slot Slot slot = agent.getAllSlots().iterator().next(); assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); assertEquals(response.getMetadata().getFirst(HttpHeaders.LOCATION), URI.create("http://localhost/v1/agent/slot/" + slot.getId().toString())); SlotStatus status = slot.status(); SlotStatus expectedStatus = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources()); assertEquals(response.getEntity(), SlotStatusRepresentation.from(expectedStatus)); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); assertEquals(response.getMetadata().get(AIRSHIP_SLOT_VERSION_HEADER).get(0), expectedStatus.getVersion()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertUpgrade(SlotStatus slotStatus, String agentVersion, String slotVersion) { Response response = resource.assign(agentVersion, slotVersion, slotStatus.getId(), UPGRADE); assertEquals(response.getStatus(), Status.OK.getStatusCode()); SlotStatusRepresentation actualStatus = (SlotStatusRepresentation) response.getEntity(); SlotStatus expectedStatus = slotStatus.changeAssignment(slotStatus.getState(), APPLE_V2, slotStatus.getResources()); assertEquals(actualStatus, SlotStatusRepresentation.from(expectedStatus)); assertEquals(actualStatus.toSlotStatus(null), expectedStatus); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); assertEquals(response.getMetadata().get(AIRSHIP_SLOT_VERSION_HEADER).get(0), expectedStatus.getVersion()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
public void assertInstallSlot(String agentVersion) { Response response = resource.installSlot(agentVersion, InstallationRepresentation.from(APPLE_INSTALLATION), uriInfo); // find the new slot Slot slot = agent.getAllSlots().iterator().next(); assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); assertEquals(response.getMetadata().getFirst(HttpHeaders.LOCATION), URI.create("http://localhost/v1/agent/slot/" + slot.getId().toString())); SlotStatus status = slot.status(); SlotStatus expectedStatus = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources()); assertEquals(response.getEntity(), SlotStatusRepresentation.from(expectedStatus)); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); assertEquals(response.getMetadata().get(AIRSHIP_SLOT_VERSION_HEADER).get(0), expectedStatus.getVersion()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertUpgrade(SlotStatus slotStatus, String agentVersion, String slotVersion) { Response response = resource.assign(agentVersion, slotVersion, slotStatus.getId(), UPGRADE); assertEquals(response.getStatus(), Status.OK.getStatusCode()); SlotStatusRepresentation actualStatus = (SlotStatusRepresentation) response.getEntity(); SlotStatus expectedStatus = slotStatus.changeAssignment(slotStatus.getState(), APPLE_V2, slotStatus.getResources()); assertEquals(actualStatus, SlotStatusRepresentation.from(expectedStatus)); assertEquals(actualStatus.toSlotStatus(null), expectedStatus); assertEquals(response.getMetadata().get(AIRSHIP_AGENT_VERSION_HEADER).get(0), agent.getAgentStatus().getVersion()); assertEquals(response.getMetadata().get(AIRSHIP_SLOT_VERSION_HEADER).get(0), expectedStatus.getVersion()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
@Test public void testAssign() throws Exception { // setup SlotStatus status1 = slot.status(); assertEquals(slot.status(), status1.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status1.getResources())); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.assign(BANANA_INSTALLATION); // verify SlotStatus status = slot.status(); SlotStatus expected = status.changeAssignment(STOPPED, BANANA_ASSIGNMENT, status.getResources()); assertEquals(actual, expected); }
@Test public void testStart() throws Exception { // setup assertEquals(slot.assign(APPLE_INSTALLATION).getState(), STOPPED); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.start(); // verify SlotStatus status = slot.status(); SlotStatus expected = status.changeAssignment(RUNNING, APPLE_ASSIGNMENT, status.getResources()); assertEquals(actual, expected); }
@Test public void testRestart() throws Exception { // setup assertEquals(slot.assign(APPLE_INSTALLATION).getState(), STOPPED); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.restart(); // verify SlotStatus status = slot.status(); SlotStatus expected = status.changeAssignment(RUNNING, APPLE_ASSIGNMENT, status.getResources()); assertEquals(actual, expected); } }
@Test public void testStop() throws Exception { // setup slot.assign(APPLE_INSTALLATION); assertEquals(slot.start().getState(), RUNNING); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.stop(); // verify SlotStatus status = slot.status(); SlotStatus expected = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources()); assertEquals(actual, expected); }
@Test public void testKill() throws Exception { // setup slot.assign(APPLE_INSTALLATION); assertEquals(slot.start().getState(), RUNNING); // test remoteAgent.setStatus(agent.getAgentStatus()); RemoteSlot remoteSlot = new HttpRemoteSlot(slot.status(), client, remoteAgent); SlotStatus actual = remoteSlot.kill(); // verify SlotStatus status = slot.status(); SlotStatus expected = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources()); assertEquals(actual, expected); }
new Duration(1, SECONDS)); SlotStatus status1 = slot.status(); SlotStatus running = status1.changeAssignment(RUNNING, APPLE_ASSIGNMENT, status1.getResources()); SlotStatus status = slot.status(); SlotStatus stopped = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources());
new Duration(1, SECONDS)); SlotStatus status1 = slot.status(); SlotStatus running = status1.changeAssignment(RUNNING, APPLE_ASSIGNMENT, status1.getResources()); SlotStatus status = slot.status(); SlotStatus stopped = status.changeAssignment(STOPPED, APPLE_ASSIGNMENT, status.getResources());
null, slot.getInstallPath(), slot.getResources()); status = status.changeSlotStatus(slot);
slotStatus.getStatusMessage(), slotStatus.getInstallPath(), slotStatus.getResources(), expectedBinary, expectedConfig,