use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.
the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.
private ReadReplicaTopology fakeReadReplicaTopology(MemberId[] readReplicaIds, NoEastGroupGenerator groupGenerator) {
assert readReplicaIds.length > 0;
Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
int offset = 0;
for (MemberId memberId : readReplicaIds) {
readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset), groupGenerator.get(memberId)));
offset++;
}
return new ReadReplicaTopology(readReplicas);
}
use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.
the class ClusterOverviewProcedure method apply.
@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
List<ReadWriteEndPoint> endpoints = new ArrayList<>();
CoreTopology coreTopology = topologyService.coreServers();
Set<MemberId> coreMembers = coreTopology.members().keySet();
MemberId leader = null;
try {
leader = leaderLocator.getLeader();
} catch (NoLeaderFoundException e) {
log.debug("No write server found. This can happen during a leader switch.");
}
for (MemberId memberId : coreMembers) {
Optional<CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
if (coreServerInfo.isPresent()) {
Role role = memberId.equals(leader) ? Role.LEADER : Role.FOLLOWER;
endpoints.add(new ReadWriteEndPoint(coreServerInfo.get().connectors(), role, memberId.getUuid(), asList(coreServerInfo.get().groups())));
} else {
log.debug("No Address found for " + memberId);
}
}
for (Map.Entry<MemberId, ReadReplicaInfo> readReplica : topologyService.readReplicas().members().entrySet()) {
ReadReplicaInfo readReplicaInfo = readReplica.getValue();
endpoints.add(new ReadWriteEndPoint(readReplicaInfo.connectors(), Role.READ_REPLICA, readReplica.getKey().getUuid(), asList(readReplicaInfo.groups())));
}
endpoints.sort(comparing(o -> o.addresses().toString()));
return map((endpoint) -> new Object[] { endpoint.memberId().toString(), endpoint.addresses().uriList().stream().map(URI::toString).toArray(), endpoint.role().name(), endpoint.groups() }, asRawIterator(endpoints.iterator()));
}
use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.
the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.
static ReadReplicaTopology fakeReadReplicaTopology(MemberId... readReplicaIds) {
assert readReplicaIds.length > 0;
Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
int offset = 0;
for (MemberId memberId : readReplicaIds) {
readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset)));
offset++;
}
return new ReadReplicaTopology(readReplicas);
}
use of org.neo4j.causalclustering.discovery.ReadReplicaInfo in project neo4j by neo4j.
the class ClusterOverviewProcedureTest method shouldProvideOverviewOfCoreServersAndReadReplicas.
@Test
public void shouldProvideOverviewOfCoreServersAndReadReplicas() throws Exception {
// given
final CoreTopologyService topologyService = mock(CoreTopologyService.class);
Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
MemberId theLeader = new MemberId(UUID.randomUUID());
MemberId follower1 = new MemberId(UUID.randomUUID());
MemberId follower2 = new MemberId(UUID.randomUUID());
coreMembers.put(theLeader, adressesForCore(0));
coreMembers.put(follower1, adressesForCore(1));
coreMembers.put(follower2, adressesForCore(2));
Map<MemberId, ReadReplicaInfo> replicaMembers = new HashMap<>();
MemberId replica4 = new MemberId(UUID.randomUUID());
MemberId replica5 = new MemberId(UUID.randomUUID());
replicaMembers.put(replica4, addressesForReadReplica(4));
replicaMembers.put(replica5, addressesForReadReplica(5));
when(topologyService.coreServers()).thenReturn(new CoreTopology(null, false, coreMembers));
when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(replicaMembers));
LeaderLocator leaderLocator = mock(LeaderLocator.class);
when(leaderLocator.getLeader()).thenReturn(theLeader);
ClusterOverviewProcedure procedure = new ClusterOverviewProcedure(topologyService, leaderLocator, NullLogProvider.getInstance());
// when
final RawIterator<Object[], ProcedureException> members = procedure.apply(null, new Object[0]);
assertThat(members.next(), new IsRecord(theLeader.getUuid(), 5000, Role.LEADER, asSet("core", "core0")));
assertThat(members.next(), new IsRecord(follower1.getUuid(), 5001, Role.FOLLOWER, asSet("core", "core1")));
assertThat(members.next(), new IsRecord(follower2.getUuid(), 5002, Role.FOLLOWER, asSet("core", "core2")));
assertThat(members.next(), new IsRecord(replica4.getUuid(), 6004, Role.READ_REPLICA, asSet("replica", "replica4")));
assertThat(members.next(), new IsRecord(replica5.getUuid(), 6005, Role.READ_REPLICA, asSet("replica", "replica5")));
assertFalse(members.hasNext());
}
Aggregations