Search in sources :

Example 11 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SymphonyRoomSharedLog method handleEvent.

@Override
public Optional<LogMessage> handleEvent(V4Event e) {
    Optional<LogMessage> out = super.handleEvent(e);
    if (out.isPresent()) {
        LogMessage logMessage = out.get();
        Participant newParticipant = logMessage.participant;
        if (logMessage.messageType == LogMessageType.LEADER) {
            cachedLastKnownLeader = newParticipant;
        }
        List<Participant> allKnownParticipants = getRecentParticipants();
        if (!allKnownParticipants.contains(newParticipant)) {
            allKnownParticipants.add(newParticipant);
        }
    }
    return out;
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant)

Example 12 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class SharedStreamHandlerConfig method streamHandler.

protected SymphonyStreamHandler streamHandler(ApiInstance symphonyApi, List<StreamEventConsumer> consumers, ExceptionConsumer ec) {
    SymphonyStreamHandler out = new SymphonyStreamHandler(symphonyApi, consumers, ec, false);
    String email = symphonyApi.getIdentity().getEmail();
    LOG.info("Created SymphonyStreamHandler for " + email + " with consumers " + consumers);
    boolean cluster = true;
    if (!StringUtils.hasText(streamProperties.getCoordinationStreamId())) {
        LOG.info("No clustering = symphony.stream.coordinationStreamId not set");
        cluster = false;
    } else if (mc == null) {
        LOG.info("No clustering = no multicaster available (maybe include spring-starter-web?)");
        cluster = false;
    } else if (self == null) {
        LOG.info("No clustering = participant not set (maybe include spring-starter-web?)");
        cluster = false;
    }
    if (cluster) {
        SharedLog ls = symphonySharedLog(symphonyApi);
        LOG.info("Creating cluster using " + email);
        ClusterMember cm = clusterMember(email, mc, self, health == null ? () -> true : health, ls);
        allClusterMembers.add(cm);
        List<Participant> registeredParticipants = ls.getRecentParticipants();
        LOG.info("Discovered cluster members: " + registeredParticipants.size());
        participationNotifier(symphonyApi, self, taskScheduler, ls);
        // filter cluster events so user doesn't see them
        SymphonyLeaderEventFilter f = leaderEventFilter(ls);
        out.setFilter(f);
    }
    out.start();
    return out;
}
Also used : SymphonyRoomSharedLog(org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog) SharedLog(org.finos.symphony.toolkit.stream.log.SharedLog) ClusterMember(org.finos.symphony.toolkit.stream.cluster.ClusterMember) Participant(org.finos.symphony.toolkit.stream.Participant)

Example 13 with Participant

use of org.finos.symphony.toolkit.stream.Participant in project spring-bot by finos.

the class BullyDeathClusterTest method testClusterLeadership.

@ParameterizedTest
@MethodSource("setupConfigurations")
public void testClusterLeadership(Configuration c) throws InterruptedException {
    System.out.println("--------------------------------------");
    System.out.println("TEST: " + c.size + "  " + c.time + "ms");
    System.out.println("--------------------------------------");
    Setup s = setupNetwork(c);
    s.startup();
    waitForLeaderCount(s);
    if (c.size > 1) {
        // kill the old leader, get a new one
        Participant oldLeader = getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
        System.out.println("--------------------------------------");
        s.c.isolate(oldLeader);
        s.canTalkToSymphony.remove(oldLeader);
        waitForLeaderCount(s);
        getLeaders(s).stream().filter(l -> !l.equals(oldLeader)).findFirst().orElseThrow(() -> new IllegalStateException("Should be a new leader"));
        // when we heal the network, we should go back to a single leader
        System.out.println("--------------------------------------");
        s.c.connect(oldLeader);
        waitForLeaderCount(s);
        getLeaders(s).stream().findFirst().orElseThrow(() -> new IllegalStateException("Should be a leader"));
    }
    s.shutdown();
    Assertions.assertTrue(((DummyLeaderServiceImpl) s.ls).leaderHistory.size() < 10);
}
Also used : Participant(org.finos.symphony.toolkit.stream.Participant) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Participant (org.finos.symphony.toolkit.stream.Participant)13 Random (java.util.Random)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 MessagesApi (com.symphony.api.agent.MessagesApi)2 V4Event (com.symphony.api.model.V4Event)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 LogMessage (org.finos.symphony.toolkit.stream.log.LogMessage)2 SymphonyRoomSharedLog (org.finos.symphony.toolkit.stream.log.SymphonyRoomSharedLog)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 MessageSearchQuery (com.symphony.api.model.MessageSearchQuery)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1 IntStream (java.util.stream.IntStream)1 ApiInstance (org.finos.symphony.toolkit.spring.api.factories.ApiInstance)1 StreamEventConsumer (org.finos.symphony.toolkit.stream.StreamEventConsumer)1