use of com.netflix.titus.api.supervisor.model.event.MasterInstanceRemovedEvent in project titus-control-plane by Netflix.
the class DefaultSupervisorOperations method buildEventList.
private Pair<List<SupervisorEvent>, Map<String, MasterInstance>> buildEventList(List<MasterInstance> current, Map<String, MasterInstance> state) {
Map<String, MasterInstance> newState = new HashMap<>();
current.forEach(instance -> newState.put(instance.getInstanceId(), instance));
List<SupervisorEvent> events = new ArrayList<>();
// Removed Masters
Set<String> removed = CollectionsExt.copyAndRemove(state.keySet(), newState.keySet());
removed.forEach(id -> events.add(new MasterInstanceRemovedEvent(state.get(id))));
// Added Masters
Set<String> added = CollectionsExt.copyAndRemove(newState.keySet(), state.keySet());
added.forEach(id -> events.add(new MasterInstanceUpdateEvent(newState.get(id))));
// Compare with the previous state, and build the new one
Set<String> changeCandidates = CollectionsExt.copyAndRemove(newState.keySet(), added);
changeCandidates.forEach(id -> {
if (MasterInstanceFunctions.areDifferent(newState.get(id), state.get(id))) {
events.add(new MasterInstanceUpdateEvent(newState.get(id)));
}
});
logger.debug("Master instances updated: current={}", current);
logger.debug("Master instances updated: previous={}", state.values());
logger.debug("Master instances updated: events={}", events);
return Pair.of(events, newState);
}
use of com.netflix.titus.api.supervisor.model.event.MasterInstanceRemovedEvent in project titus-control-plane by Netflix.
the class DefaultSupervisorOperationsTest method expectMasterInstanceRemovedEvent.
private void expectMasterInstanceRemovedEvent(ExtTestSubscriber<SupervisorEvent> eventSubscriber, MasterInstance removed) {
SupervisorEvent event = eventSubscriber.takeNext();
assertThat(event).isInstanceOf(MasterInstanceRemovedEvent.class);
MasterInstanceRemovedEvent removedEvent = (MasterInstanceRemovedEvent) event;
assertThat(removedEvent.getMasterInstance()).isEqualTo(removed);
}
Aggregations