Search in sources :

Example 1 with MasterInstanceUpdateEvent

use of com.netflix.titus.api.supervisor.model.event.MasterInstanceUpdateEvent 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);
}
Also used : SupervisorEvent(com.netflix.titus.api.supervisor.model.event.SupervisorEvent) MasterInstanceRemovedEvent(com.netflix.titus.api.supervisor.model.event.MasterInstanceRemovedEvent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MasterInstance(com.netflix.titus.api.supervisor.model.MasterInstance) MasterInstanceUpdateEvent(com.netflix.titus.api.supervisor.model.event.MasterInstanceUpdateEvent)

Example 2 with MasterInstanceUpdateEvent

use of com.netflix.titus.api.supervisor.model.event.MasterInstanceUpdateEvent in project titus-control-plane by Netflix.

the class DefaultSupervisorOperationsTest method expectMasterInstanceUpdateEvent.

private void expectMasterInstanceUpdateEvent(ExtTestSubscriber<SupervisorEvent> eventSubscriber, MasterInstance instance) {
    SupervisorEvent event = eventSubscriber.takeNext();
    assertThat(event).isInstanceOf(MasterInstanceUpdateEvent.class);
    MasterInstanceUpdateEvent updateEvent = (MasterInstanceUpdateEvent) event;
    assertThat(updateEvent.getMasterInstance()).isEqualTo(instance);
}
Also used : SupervisorEvent(com.netflix.titus.api.supervisor.model.event.SupervisorEvent) MasterInstanceUpdateEvent(com.netflix.titus.api.supervisor.model.event.MasterInstanceUpdateEvent)

Aggregations

MasterInstanceUpdateEvent (com.netflix.titus.api.supervisor.model.event.MasterInstanceUpdateEvent)2 SupervisorEvent (com.netflix.titus.api.supervisor.model.event.SupervisorEvent)2 MasterInstance (com.netflix.titus.api.supervisor.model.MasterInstance)1 MasterInstanceRemovedEvent (com.netflix.titus.api.supervisor.model.event.MasterInstanceRemovedEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1