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 start() { lock(); try { Preconditions.checkState(!terminated, "Slot has been terminated"); Deployment activeDeployment = deploymentManager.getDeployment(); if (activeDeployment == null) { throw new IllegalStateException("Slot can not be started because the slot is not assigned"); } SlotLifecycleState state = lifecycleManager.start(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(); } }
@Override public SlotStatus status() { try { lock(); } catch (LockTimeoutException e) { // could not get the lock because there is an operation in progress // just return the last state we saw // todo consider adding "in-process" states like starting return lastSlotStatus.get(); } try { if (terminated) { return lastSlotStatus.get().changeState(TERMINATED); } Deployment activeDeployment = deploymentManager.getDeployment(); if (activeDeployment == null) { return lastSlotStatus.get().changeAssignment(UNKNOWN, null, ImmutableMap.<String, Integer>of()); } SlotStatus slotStatus = lastSlotStatus.get().changeState(lifecycleManager.status(activeDeployment)); lastSlotStatus.set(slotStatus); return slotStatus; } finally { unlock(); } }
@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 terminate() { lock(); try { if (!terminated) { SlotStatus status = status(); if (status.getState() != STOPPED) { return status; } // terminate the slot deploymentManager.terminate(); terminated = true; } SlotStatus slotStatus = lastSlotStatus.get().changeState(TERMINATED); lastSlotStatus.set(slotStatus); return slotStatus; } finally { unlock(); } }