Search in sources :

Example 1 with ClusterMemberInfo

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()]);
}
Also used : PageCache(org.neo4j.io.pagecache.PageCache) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Config(org.neo4j.kernel.configuration.Config) KernelData(org.neo4j.kernel.internal.KernelData) ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) Iterables.asArray(org.neo4j.helpers.collection.Iterables.asArray) Version(org.neo4j.kernel.internal.Version) ClusterDatabaseInfo(org.neo4j.management.ClusterDatabaseInfo) Function(java.util.function.Function) File(java.io.File) ArrayList(java.util.ArrayList) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) List(java.util.List) Iterables.map(org.neo4j.helpers.collection.Iterables.map) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) ArrayList(java.util.ArrayList)

Example 2 with ClusterMemberInfo

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;
}
Also used : ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo)

Example 3 with ClusterMemberInfo

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());
}
Also used : ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo)

Example 4 with ClusterMemberInfo

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://"));
        }
    }
}
Also used : ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) Test(org.junit.Test)

Example 5 with ClusterMemberInfo

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());
}
Also used : ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) Iterables(org.neo4j.helpers.collection.Iterables) LastUpdateTime(org.neo4j.kernel.ha.LastUpdateTime) ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) ClusterDatabaseInfo(org.neo4j.management.ClusterDatabaseInfo) Function(java.util.function.Function) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) LastTxIdGetter(org.neo4j.kernel.impl.core.LastTxIdGetter) ClusterMember(org.neo4j.kernel.ha.cluster.member.ClusterMember) ClusterMemberInfo(org.neo4j.management.ClusterMemberInfo) ClusterDatabaseInfo(org.neo4j.management.ClusterDatabaseInfo)

Aggregations

ClusterMemberInfo (org.neo4j.management.ClusterMemberInfo)7 Function (java.util.function.Function)2 Test (org.junit.Test)2 ClusterMember (org.neo4j.kernel.ha.cluster.member.ClusterMember)2 ClusterMembers (org.neo4j.kernel.ha.cluster.member.ClusterMembers)2 ClusterDatabaseInfo (org.neo4j.management.ClusterDatabaseInfo)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Iterables (org.neo4j.helpers.collection.Iterables)1 Iterables.asArray (org.neo4j.helpers.collection.Iterables.asArray)1 Iterables.map (org.neo4j.helpers.collection.Iterables.map)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 Config (org.neo4j.kernel.configuration.Config)1 LastUpdateTime (org.neo4j.kernel.ha.LastUpdateTime)1 LastTxIdGetter (org.neo4j.kernel.impl.core.LastTxIdGetter)1 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 KernelData (org.neo4j.kernel.internal.KernelData)1