private SlotStatus setErrorStatus(String statusMessage) { slotStatus = slotStatus.changeState(UNKNOWN); return slotStatus.changeStatusMessage(statusMessage); }
public AgentStatus changeAllSlotsState(SlotLifecycleState slotState) { Map<UUID, SlotStatus> slots = newHashMap(this.slots); for (SlotStatus slotStatus : slots.values()) { // set all slots to unknown state slots.put(slotStatus.getId(), slotStatus.changeState(slotState)); } return new AgentStatus(agentId, state, instanceId, internalUri, externalUri, location, instanceType, slots.values(), resources); }
@Override public SlotStatus restart() { lock(); try { Preconditions.checkState(!terminated, "Slot has been terminated"); Deployment activeDeployment = deploymentManager.getDeployment(); if (activeDeployment == null) { throw new IllegalStateException("Slot can not be restarted because the slot is not assigned"); } SlotLifecycleState state = lifecycleManager.restart(activeDeployment); SlotStatus slotStatus = lastSlotStatus.get().changeState(state); lastSlotStatus.set(slotStatus); return slotStatus; } finally { unlock(); } }
@Override public SlotStatus stop() { lock(); try { Preconditions.checkState(!terminated, "Slot has been terminated"); Deployment activeDeployment = deploymentManager.getDeployment(); if (activeDeployment == null) { throw new IllegalStateException("Slot can not be stopped because the slot is not assigned"); } SlotLifecycleState state = lifecycleManager.stop(activeDeployment); SlotStatus slotStatus = lastSlotStatus.get().changeState(state); lastSlotStatus.set(slotStatus); return slotStatus; } finally { unlock(); } }
private void assertOkResponse(Response response, SlotLifecycleState state, SlotStatus... slots) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slotStatus : slots) { builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
private void assertOkResponse(Response response, SlotLifecycleState state, SlotStatus... slots) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (SlotStatus slotStatus : slots) { builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces } }
@Override public SlotStatus stop() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be stopped because the slot is not assigned"); } slotStatus = slotStatus.changeState(STOPPED); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus restart() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be restarted because the slot is not assigned"); } slotStatus = slotStatus.changeState(RUNNING); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus start() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be started because the slot is not assigned"); } slotStatus = slotStatus.changeState(RUNNING); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus start() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be started because the slot is not assigned"); } slotStatus = slotStatus.changeState(RUNNING); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus stop() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be stopped because the slot is not assigned"); } slotStatus = slotStatus.changeState(STOPPED); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus restart() { if (slotStatus.getAssignment() == null) { throw new IllegalStateException("Slot can not be restarted because the slot is not assigned"); } slotStatus = slotStatus.changeState(RUNNING); mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
@Override public SlotStatus terminate() { if (slotStatus.getState() == STOPPED) { slotStatus = slotStatus.changeState(TERMINATED); } mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (UUID slotId : slotIds) { SlotStatus slotStatus = agentStatus.getSlotStatus(slotId); builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertOkResponse(Response response, SlotLifecycleState state, UUID... slotIds) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); Builder<SlotStatusRepresentation> builder = ImmutableList.builder(); for (UUID slotId : slotIds) { SlotStatus slotStatus = agentStatus.getSlotStatus(slotId); builder.add(SlotStatusRepresentation.from(slotStatus.changeState(state), prefixSize, MOCK_REPO)); assertEquals(slotStatus.getAssignment(), APPLE_ASSIGNMENT); } assertEqualsNoOrder((Collection<?>) response.getEntity(), builder.build()); assertNull(response.getMetadata().get("Content-Type")); // content type is set by jersey based on @Produces }
private void assertOkResponse(Response response, SlotLifecycleState state) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); SlotStatusRepresentation expectedStatus = SlotStatusRepresentation.from(slot.status().changeState(state)); assertEquals(response.getEntity(), expectedStatus); assertEquals(slot.status().getAssignment(), APPLE_ASSIGNMENT); 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 } }
@Override public SlotStatus terminate() { if (slotStatus.getState() == STOPPED) { slotStatus = slotStatus.changeState(TERMINATED); } mockRemoteAgent.setSlotStatus(slotStatus); return slotStatus; }
private void assertOkResponse(Response response, SlotLifecycleState state) { assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); SlotStatusRepresentation expectedStatus = SlotStatusRepresentation.from(slot.status().changeState(state)); assertEquals(response.getEntity(), expectedStatus); assertEquals(slot.status().getAssignment(), APPLE_ASSIGNMENT); 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 testTerminateSlot() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); Response response = resource.terminateSlot(null, null, slotStatus.getId()); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); SlotStatus expectedStatus = slotStatus.changeState(TERMINATED); 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 assertNull(agent.getSlot(slotStatus.getId())); }
@Test public void testTerminateSlot() { SlotStatus slotStatus = agent.install(APPLE_INSTALLATION); Response response = resource.terminateSlot(null, null, slotStatus.getId()); assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); SlotStatus expectedStatus = slotStatus.changeState(TERMINATED); 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 assertNull(agent.getSlot(slotStatus.getId())); }