use of org.neo4j.management.ClusterMemberInfo in project neo4j by neo4j.
the class HighlyAvailableKernelData method getClusterInfo.
public ClusterMemberInfo[] getClusterInfo() {
List<ClusterMemberInfo> clusterMemberInfos = new ArrayList<ClusterMemberInfo>();
Function<Object, String> nullSafeToString = from -> from == null ? "" : from.toString();
for (ClusterMember clusterMember : memberInfo.getMembers()) {
ClusterMemberInfo clusterMemberInfo = new ClusterMemberInfo(clusterMember.getInstanceId().toString(), clusterMember.getHAUri() != null, clusterMember.isAlive(), clusterMember.getHARole(), asArray(String.class, map(nullSafeToString, clusterMember.getRoleURIs())), asArray(String.class, map(nullSafeToString, clusterMember.getRoles())));
clusterMemberInfos.add(clusterMemberInfo);
}
return clusterMemberInfos.toArray(new ClusterMemberInfo[clusterMemberInfos.size()]);
}
use of org.neo4j.management.ClusterMemberInfo in project neo4j by neo4j.
the class ClusterMemberMatcher method matches.
@Override
public boolean matches(Object item) {
if (item instanceof Iterable) {
@SuppressWarnings("unchecked") Iterable<ClusterMemberInfo> other = (Iterable<ClusterMemberInfo>) item;
int foundCount = 0;
for (ClusterMemberMatch expectedMember : expectedMembers) {
boolean found = false;
for (ClusterMemberInfo member : other) {
if (expectedMember.match(member)) {
found = true;
foundCount++;
break;
}
}
if (!found) {
return false;
}
}
if (exactMatch && foundCount != expectedMembers.length) {
return false;
}
} else {
return false;
}
return true;
}
use of org.neo4j.management.ClusterMemberInfo in project neo4j by neo4j.
the class HighAvailabilityBeanTest method assertMasterAndSlaveInformation.
private void assertMasterAndSlaveInformation(ClusterMemberInfo[] instancesInCluster) throws Exception {
ClusterMemberInfo master = member(instancesInCluster, 1);
assertEquals(1137, getUriForScheme("ha", Iterables.map(URI::create, Arrays.asList(master.getUris()))).getPort());
assertEquals(HighAvailabilityModeSwitcher.MASTER, master.getHaRole());
ClusterMemberInfo slave = member(instancesInCluster, 2);
assertEquals(1138, getUriForScheme("ha", Iterables.map(URI::create, Arrays.asList(slave.getUris()))).getPort());
assertEquals(HighAvailabilityModeSwitcher.SLAVE, slave.getHaRole());
assertTrue("Slave not available", slave.isAvailable());
}
use of org.neo4j.management.ClusterMemberInfo in project neo4j by neo4j.
the class HighAvailabilityBeanTest method shouldSeeChangesInClusterMembers.
@Test
public void shouldSeeChangesInClusterMembers() throws Exception {
// GIVEN
when(clusterMembers.getMembers()).thenReturn(asList(clusterMember(1, MASTER, 1137), clusterMember(2, SLAVE, 1138), clusterMember(3, SLAVE, 1139)));
// THEN
assertMasterAndSlaveInformation(haBean.getInstancesInCluster());
// and WHEN
when(clusterMembers.getMembers()).thenReturn(asList(clusterMember(1, SLAVE, 1137), clusterMember(2, MASTER, 1138), clusterMember(3, SLAVE, 1139)));
// THEN
for (ClusterMemberInfo info : haBean.getInstancesInCluster()) {
assertTrue("every instance should be available", info.isAvailable());
assertTrue("every instances should have at least one role", info.getRoles().length > 0);
if (HighAvailabilityModeSwitcher.MASTER.equals(info.getRoles()[0])) {
assertEquals("coordinator should be master", HighAvailabilityModeSwitcher.MASTER, info.getHaRole());
} else {
assertEquals("Either master or slave, no other way", HighAvailabilityModeSwitcher.SLAVE, info.getRoles()[0]);
assertEquals("instance " + info.getInstanceId() + " is cluster slave but HA master", HighAvailabilityModeSwitcher.SLAVE, info.getHaRole());
}
for (String uri : info.getUris()) {
assertTrue("roles should contain URIs", uri.startsWith("ha://") || uri.startsWith("backup://"));
}
}
}
use of org.neo4j.management.ClusterMemberInfo in project neo4j by neo4j.
the class ClusterDatabaseInfoProvider method getInfo.
public ClusterDatabaseInfo getInfo() {
ClusterMember currentMember = members.getCurrentMember();
if (currentMember == null) {
return null;
}
Function<Object, String> nullSafeToString = from -> from == null ? "" : from.toString();
return new ClusterDatabaseInfo(new ClusterMemberInfo(currentMember.getInstanceId().toString(), currentMember.getHAUri() != null, true, currentMember.getHARole(), Iterables.asArray(String.class, Iterables.map(nullSafeToString, currentMember.getRoleURIs())), Iterables.asArray(String.class, Iterables.map(nullSafeToString, currentMember.getRoles()))), txIdGetter.getLastTxId(), lastUpdateTime.getLastUpdateTime());
}
Aggregations