String shortBinary = null; String shortConfig = null; if (status.getAssignment() != null) { binary = status.getAssignment().getBinary(); config = status.getAssignment().getConfig(); if (repository != null) { shortBinary = Objects.firstNonNull(repository.binaryRelativize(binary), binary); if (status.getExpectedAssignment() != null) { expectedBinary = status.getExpectedAssignment().getBinary(); expectedConfig = status.getExpectedAssignment().getConfig(); if (status.getExpectedState() != null) { expectedStatus = status.getExpectedState().toString(); return new SlotStatusRepresentation(status.getId(), safeTruncate(status.getId().toString(), shortIdPrefixSize), status.getSelf(), status.getExternalUri(), status.getInstanceId(), status.getLocation(), trimLeadingSegments(status.getLocation(), '/', commonLocationParts), binary, shortBinary, config, shortConfig, status.getState().toString(), status.getVersion(), status.getStatusMessage(),
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 terminate() { return slot.terminate().changeInstanceId(instanceId); }
private SlotStatus setErrorStatus(String statusMessage) { slotStatus = slotStatus.changeState(UNKNOWN); return slotStatus.changeStatusMessage(statusMessage); }
public SlotStatus apply(@Nullable SlotStatus slotStatus) { if (!Objects.equal(slotStatus.getInstanceId(), instanceId)) { slotStatus = slotStatus.changeInstanceId(instanceId); } return slotStatus; } });
public AgentStatus changeSlotStatus(SlotStatus slotStatus) { Map<UUID,SlotStatus> slots = newHashMap(this.slots); if (slotStatus.getState() != TERMINATED) { slots.put(slotStatus.getId(), slotStatus); } else { slots.remove(slotStatus.getId()); } return new AgentStatus(agentId, state, instanceId, internalUri, externalUri, location, instanceType, slots.values(), resources); }
@Override public SlotStatus terminate() { try { Request request = RequestBuilder.prepareDelete() .setUri(slotStatus.getSelf()) .setHeader(GALAXY_AGENT_VERSION_HEADER, agent.status().getVersion()) .setHeader(GALAXY_SLOT_VERSION_HEADER, slotStatus.getVersion()) .build(); SlotStatusRepresentation slotStatusRepresentation = httpClient.execute(request, createJsonResponseHandler(slotStatusCodec, Status.OK.getStatusCode())); updateStatus(slotStatusRepresentation.toSlotStatus(slotStatus.getInstanceId())); return slotStatus; } catch (Exception e) { log.error(e); return setErrorStatus(e.getMessage()); } }
@Override public SlotStatus apply(SlotStatus slotStatus) { if (slotStatus.getState() != SlotLifecycleState.UNKNOWN) { stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), slotStatus.getState(), slotStatus.getAssignment())); } else { stateManager.deleteExpectedState(slotStatus.getId()); } return slotStatus; } }));
private List<SlotStatus> getAllSlotsStatus(Predicate<SlotStatus> slotFilter, List<RemoteSlot> allSlots) ImmutableMap<UUID, SlotStatus> actualStates = Maps.uniqueIndex(transform(allSlots, getSlotStatus()), SlotStatus.uuidGetter()); fullSlotStatus = SlotStatus.createSlotStatusWithExpectedState(uuid, null, null, fullSlotStatus = actualState.changeStatusMessage("Unexpected slot").changeExpectedState(null, null); fullSlotStatus = actualState.changeExpectedState(expectedState.getStatus(), expectedState.getAssignment()); if (!Objects.equal(actualState.getState(), expectedState.getStatus())) { messages.add("Expected state to be " + expectedState.getStatus()); if (!Objects.equal(actualState.getAssignment(), expectedState.getAssignment())) { Assignment assignment = expectedState.getAssignment(); if (assignment != null) { fullSlotStatus = fullSlotStatus.changeStatusMessage(Joiner.on("; ").join(messages));
@Override public ImmutableList<ServiceDescriptor> getServiceInventory(Iterable<SlotStatus> allSlotStatus) { ImmutableList.Builder<ServiceDescriptor> newDescriptors = ImmutableList.builder(); for (SlotStatus slotStatus : allSlotStatus) { // if the self reference is null, the slot is totally offline so skip for now if (slotStatus.getSelf() == null) { continue; } List<ServiceDescriptor> serviceDescriptors = getServiceInventory(slotStatus); if (serviceDescriptors == null) { continue; } for (ServiceDescriptor serviceDescriptor : serviceDescriptors) { newDescriptors.add(new ServiceDescriptor(null, slotStatus.getId().toString(), serviceDescriptor.getType(), serviceDescriptor.getPool(), slotStatus.getLocation(), slotStatus.getState() == SlotLifecycleState.RUNNING ? ServiceState.RUNNING : ServiceState.STOPPED, interpolateProperties(serviceDescriptor.getProperties(), slotStatus))); } } return newDescriptors.build(); }
public static String createSlotsVersion(Iterable<SlotStatus> slots) { Preconditions.checkNotNull(slots, "slots is null"); // canonicalize slot order Map<UUID, String> slotVersions = new TreeMap<UUID, String>(); for (SlotStatus slot : slots) { slotVersions.put(slot.getId(), slot.getVersion()); } return DigestUtils.md5Hex(slotVersions.values().toString()); }
this.slots = Maps.uniqueIndex(slots, SlotStatus.uuidGetter());
@Override public UUID getId() { return slotStatus.getId(); }
@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(); } }
@Override public SlotStatus apply(RemoteSlot slot) { SlotStatus slotStatus; SlotLifecycleState expectedState; switch (state) { case RUNNING: slotStatus = slot.start(); expectedState = RUNNING; break; case RESTARTING: slotStatus = slot.restart(); expectedState = RUNNING; break; case STOPPED: slotStatus = slot.stop(); expectedState = STOPPED; break; default: throw new IllegalArgumentException("Unexpected state transition " + state); } stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), expectedState, slotStatus.getAssignment())); return slotStatus; } }));
for (RemoteSlot slot : filteredSlots) { SlotStatus status = slot.status(); SlotLifecycleState state = status.getState(); if (state != TERMINATED && state != UNKNOWN) { Assignment assignment = upgradeVersions.upgradeAssignment(repository, status.getAssignment()); newAssignments.add(assignment); slotsToUpgrade.add(slot);
@Override public boolean apply(@Nullable SlotStatus slotStatus) { return slotStatus != null && glob.apply(slotStatus.getAssignment().getConfig()); } }
public static void checkSlotVersion(SlotStatus slotStatus, String expectedSlotVersion) { Preconditions.checkNotNull(slotStatus, "slotStatus is null"); if (expectedSlotVersion == null) { return; } if (!expectedSlotVersion.equals(slotStatus.getVersion())) { throw new VersionConflictException(GALAXY_SLOT_VERSION_HEADER, slotStatus.getVersion()); } }
@Override public boolean apply(SlotStatus slotStatus) { return slotStatus.getState() == state; } }
@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(); } }