public UUID apply(SlotStatus input) { return input.getId(); } };
@Override public UUID getId() { return slotStatus.getId(); }
public String apply(SlotStatus input) { return input.getId().toString(); } };
private void updateStatus(SlotStatus slotStatus) { Preconditions.checkArgument(slotStatus.getId().equals(this.slotStatus.getId()), String.format("Agent returned status for slot %s, but the status for slot %s was expected", slotStatus.getId(), this.slotStatus.getId())); this.slotStatus = slotStatus; if (agent != null) { agent.setSlotStatus(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); }
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); }
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()); }
public static String createAgentVersion(String agentId, AgentLifecycleState state, Iterable<SlotStatus> slots, Map<String, Integer> resources) { List<Object> parts = new ArrayList<Object>(); parts.add(agentId); parts.add(state); // canonicalize slot order Map<UUID, String> slotVersions = new TreeMap<UUID, String>(); for (SlotStatus slot : slots) { slotVersions.put(slot.getId(), slot.getVersion()); } parts.addAll(slotVersions.values()); // canonicalize resources parts.add(Joiner.on("--").withKeyValueSeparator("=").join(ImmutableSortedMap.copyOf(resources))); String data = Joiner.on("||").useForNull("--NULL--").join(parts); return DigestUtils.md5Hex(data); }
public List<SlotStatus> terminate(Predicate<SlotStatus> filter, String expectedSlotsVersion) { Preconditions.checkNotNull(filter, "filter is null"); // filter the slots List<RemoteSlot> filteredSlots = selectRemoteSlots(filter, expectedSlotsVersion); ImmutableList.Builder<SlotStatus> builder = ImmutableList.builder(); for (RemoteSlot slot : filteredSlots) { if (filter.apply(slot.status())) { SlotStatus slotStatus = slot.terminate(); if (slotStatus.getState() == TERMINATED) { stateManager.deleteExpectedState(slotStatus.getId()); } builder.add(slotStatus); } } return builder.build(); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response installSlot(@HeaderParam(GALAXY_AGENT_VERSION_HEADER) String agentVersion, InstallationRepresentation installation, @Context UriInfo uriInfo) { Preconditions.checkNotNull(installation, "installation must not be null"); checkAgentVersion(agent.getAgentStatus(), agentVersion); SlotStatus slotStatus = agent.install(installation.toInstallation()); return Response .created(getSelfUri(slotStatus.getId(), uriInfo.getBaseUri())) .entity(SlotStatusRepresentation.from(slotStatus)) .header(GALAXY_AGENT_VERSION_HEADER, agent.getAgentStatus().getVersion()) .header(GALAXY_SLOT_VERSION_HEADER, slotStatus.getVersion()) .build(); }
@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; } }));
public List<SlotStatus> install(Predicate<AgentStatus> filter, int limit, Assignment assignment) { Installation installation = InstallationUtils.toInstallation(repository, assignment); List<RemoteAgent> targetAgents = selectAgents(filter, installation); // randomize agents so all processes don't end up on the same node // todo sort agents by number of process already installed on them List<SlotStatus> slots = newArrayList(); for (RemoteAgent agent : targetAgents) { if (slots.size() >= limit) { break; } // install SlotStatus slotStatus = agent.install(installation); stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), STOPPED, installation.getAssignment())); slots.add(slotStatus); } return ImmutableList.copyOf(slots); }
@Override public SlotStatus apply(RemoteSlot slot) { SlotStatus slotStatus = slot.assign(installation); stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), STOPPED, installation.getAssignment())); return slotStatus; } }));
@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(); }
@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; } }));
stateManager.setExpectedState(new ExpectedSlotStatus(slotStatus.getId(), slotStatus.getState(), slotStatus.getAssignment()));