Search in sources :

Example 1 with ConsensusModuleProxy

use of io.aeron.cluster.service.ConsensusModuleProxy in project Aeron by real-logic.

the class ClusterTool method removeMember.

/**
 * Remove a member from a running cluster.
 *
 * @param markFile  for the cluster component.
 * @param memberId  to be removed.
 * @param isPassive true if the member to be removed is a passive member.
 * @return true if the removal request was successful.
 */
public static boolean removeMember(final ClusterMarkFile markFile, final int memberId, final boolean isPassive) {
    final String aeronDirectoryName = markFile.decoder().aeronDirectory();
    final String controlChannel = markFile.decoder().controlChannel();
    final int consensusModuleStreamId = markFile.decoder().consensusModuleStreamId();
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
        ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlChannel, consensusModuleStreamId))) {
        if (consensusModuleProxy.removeMember(memberId, isPassive ? BooleanType.TRUE : BooleanType.FALSE)) {
            return true;
        }
    }
    return false;
}
Also used : CommonContext(io.aeron.CommonContext) ConsensusModuleProxy(io.aeron.cluster.service.ConsensusModuleProxy) Aeron(io.aeron.Aeron)

Example 2 with ConsensusModuleProxy

use of io.aeron.cluster.service.ConsensusModuleProxy in project Aeron by real-logic.

the class ClusterTool method queryClusterMembers.

/**
 * Query the membership of a cluster.
 *
 * @param controlProperties from a {@link ClusterMarkFile}.
 * @param timeoutMs         to wait for the query.
 * @param clusterMembership to populate.
 * @return true if the query was successful.
 */
public static boolean queryClusterMembers(final ClusterNodeControlProperties controlProperties, final long timeoutMs, final ClusterMembership clusterMembership) {
    final MutableLong id = new MutableLong(NULL_VALUE);
    final ClusterControlAdapter.Listener listener = new ClusterControlAdapter.Listener() {

        public void onClusterMembersResponse(final long correlationId, final int leaderMemberId, final String activeMembers, final String passiveMembers) {
            if (correlationId == id.get()) {
                clusterMembership.leaderMemberId = leaderMemberId;
                clusterMembership.activeMembersStr = activeMembers;
                clusterMembership.passiveMembersStr = passiveMembers;
                id.set(NULL_VALUE);
            }
        }

        public void onClusterMembersExtendedResponse(final long correlationId, final long currentTimeNs, final int leaderMemberId, final int memberId, final List<ClusterMember> activeMembers, final List<ClusterMember> passiveMembers) {
            if (correlationId == id.get()) {
                clusterMembership.currentTimeNs = currentTimeNs;
                clusterMembership.leaderMemberId = leaderMemberId;
                clusterMembership.memberId = memberId;
                clusterMembership.activeMembers = activeMembers;
                clusterMembership.passiveMembers = passiveMembers;
                clusterMembership.activeMembersStr = ClusterMember.encodeAsString(activeMembers);
                clusterMembership.passiveMembersStr = ClusterMember.encodeAsString(passiveMembers);
                id.set(NULL_VALUE);
            }
        }
    };
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(controlProperties.aeronDirectoryName));
        ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlProperties.controlChannel, controlProperties.consensusModuleStreamId));
        ClusterControlAdapter clusterControlAdapter = new ClusterControlAdapter(aeron.addSubscription(controlProperties.controlChannel, controlProperties.serviceStreamId), listener)) {
        id.set(aeron.nextCorrelationId());
        if (consensusModuleProxy.clusterMembersQuery(id.get())) {
            final long startTime = System.currentTimeMillis();
            do {
                if (clusterControlAdapter.poll() == 0) {
                    if ((System.currentTimeMillis() - startTime) > timeoutMs) {
                        break;
                    }
                    Thread.yield();
                }
            } while (NULL_VALUE != id.get());
        }
    }
    return id.get() == NULL_VALUE;
}
Also used : CommonContext(io.aeron.CommonContext) MutableLong(org.agrona.collections.MutableLong) ConsensusModuleProxy(io.aeron.cluster.service.ConsensusModuleProxy) ArrayList(java.util.ArrayList) List(java.util.List) Aeron(io.aeron.Aeron)

Example 3 with ConsensusModuleProxy

use of io.aeron.cluster.service.ConsensusModuleProxy in project aeron by real-logic.

the class ClusterTool method removeMember.

/**
 * Remove a member from a running cluster.
 *
 * @param markFile  for the cluster component.
 * @param memberId  to be removed.
 * @param isPassive true if the member to be removed is a passive member.
 * @return true if the removal request was successful.
 */
public static boolean removeMember(final ClusterMarkFile markFile, final int memberId, final boolean isPassive) {
    final String aeronDirectoryName = markFile.decoder().aeronDirectory();
    final String controlChannel = markFile.decoder().controlChannel();
    final int consensusModuleStreamId = markFile.decoder().consensusModuleStreamId();
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(aeronDirectoryName));
        ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlChannel, consensusModuleStreamId))) {
        if (consensusModuleProxy.removeMember(memberId, isPassive ? BooleanType.TRUE : BooleanType.FALSE)) {
            return true;
        }
    }
    return false;
}
Also used : CommonContext(io.aeron.CommonContext) ConsensusModuleProxy(io.aeron.cluster.service.ConsensusModuleProxy) Aeron(io.aeron.Aeron)

Example 4 with ConsensusModuleProxy

use of io.aeron.cluster.service.ConsensusModuleProxy in project aeron by real-logic.

the class ClusterTool method queryClusterMembers.

/**
 * Query the membership of a cluster.
 *
 * @param controlProperties from a {@link ClusterMarkFile}.
 * @param timeoutMs         to wait for the query.
 * @param clusterMembership to populate.
 * @return true if the query was successful.
 */
public static boolean queryClusterMembers(final ClusterNodeControlProperties controlProperties, final long timeoutMs, final ClusterMembership clusterMembership) {
    final MutableLong id = new MutableLong(NULL_VALUE);
    final ClusterControlAdapter.Listener listener = new ClusterControlAdapter.Listener() {

        public void onClusterMembersResponse(final long correlationId, final int leaderMemberId, final String activeMembers, final String passiveMembers) {
            if (correlationId == id.get()) {
                clusterMembership.leaderMemberId = leaderMemberId;
                clusterMembership.activeMembersStr = activeMembers;
                clusterMembership.passiveMembersStr = passiveMembers;
                id.set(NULL_VALUE);
            }
        }

        public void onClusterMembersExtendedResponse(final long correlationId, final long currentTimeNs, final int leaderMemberId, final int memberId, final List<ClusterMember> activeMembers, final List<ClusterMember> passiveMembers) {
            if (correlationId == id.get()) {
                clusterMembership.currentTimeNs = currentTimeNs;
                clusterMembership.leaderMemberId = leaderMemberId;
                clusterMembership.memberId = memberId;
                clusterMembership.activeMembers = activeMembers;
                clusterMembership.passiveMembers = passiveMembers;
                clusterMembership.activeMembersStr = ClusterMember.encodeAsString(activeMembers);
                clusterMembership.passiveMembersStr = ClusterMember.encodeAsString(passiveMembers);
                id.set(NULL_VALUE);
            }
        }
    };
    try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(controlProperties.aeronDirectoryName));
        ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlProperties.controlChannel, controlProperties.consensusModuleStreamId));
        ClusterControlAdapter clusterControlAdapter = new ClusterControlAdapter(aeron.addSubscription(controlProperties.controlChannel, controlProperties.serviceStreamId), listener)) {
        id.set(aeron.nextCorrelationId());
        if (consensusModuleProxy.clusterMembersQuery(id.get())) {
            final long startTime = System.currentTimeMillis();
            do {
                if (clusterControlAdapter.poll() == 0) {
                    if ((System.currentTimeMillis() - startTime) > timeoutMs) {
                        break;
                    }
                    Thread.yield();
                }
            } while (NULL_VALUE != id.get());
        }
    }
    return id.get() == NULL_VALUE;
}
Also used : CommonContext(io.aeron.CommonContext) MutableLong(org.agrona.collections.MutableLong) ConsensusModuleProxy(io.aeron.cluster.service.ConsensusModuleProxy) ArrayList(java.util.ArrayList) List(java.util.List) Aeron(io.aeron.Aeron)

Aggregations

Aeron (io.aeron.Aeron)4 CommonContext (io.aeron.CommonContext)4 ConsensusModuleProxy (io.aeron.cluster.service.ConsensusModuleProxy)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MutableLong (org.agrona.collections.MutableLong)2