Search in sources :

Example 6 with ClusterNodeInfo

use of org.jivesoftware.openfire.cluster.ClusterNodeInfo in project Openfire by igniterealtime.

the class ClusterListener method memberAttributeChanged.

@Override
public void memberAttributeChanged(MemberAttributeEvent event) {
    ClusterNodeInfo priorNodeInfo = clusterNodesInfo.get(event.getMember().getUuid());
    clusterNodesInfo.put(event.getMember().getUuid(), new HazelcastClusterNodeInfo(event.getMember(), priorNodeInfo.getJoinedTime()));
}
Also used : HazelcastClusterNodeInfo(org.jivesoftware.openfire.plugin.util.cluster.HazelcastClusterNodeInfo) ClusterNodeInfo(org.jivesoftware.openfire.cluster.ClusterNodeInfo) HazelcastClusterNodeInfo(org.jivesoftware.openfire.plugin.util.cluster.HazelcastClusterNodeInfo)

Example 7 with ClusterNodeInfo

use of org.jivesoftware.openfire.cluster.ClusterNodeInfo in project Openfire by igniterealtime.

the class ConsistencyChecks method generateReportForRoutingTableComponentRoutes.

/**
 * Verifies that #componentsCache, #localRoutingTable#getComponentRoute and #componentsByClusterNode of
 * {@link org.jivesoftware.openfire.spi.RoutingTableImpl} are in a consistent state.
 * <p>
 * Note that this operation can be costly in terms of resource usage. Use with caution in large / busy systems.
 * <p>
 * The returned multi-map can contain up to four keys: info, fail, pass, data. All entry values are a human readable
 * description of a checked characteristic. When the state is consistent, no 'fail' entries will be returned.
 *
 * @param componentsCache         The cache that is used to share data across cluster nodes
 * @param localComponentRoutes    The data structure that keeps track of what data was added to the cache by the local cluster node.
 * @param componentsByClusterNode The data structure that keeps track of what data was added to the cache by the remote cluster nodes.
 * @return A consistency state report.
 */
public static Multimap<String, String> generateReportForRoutingTableComponentRoutes(@Nonnull final Cache<String, HashSet<NodeID>> componentsCache, @Nonnull final Collection<RoutableChannelHandler> localComponentRoutes, @Nonnull final HashMap<NodeID, Set<String>> componentsByClusterNode) {
    final Set<NodeID> clusterNodeIDs = ClusterManager.getNodesInfo().stream().map(ClusterNodeInfo::getNodeID).collect(Collectors.toSet());
    // Take a snapshots to reduce the chance of data changing while diagnostics are being performed
    final ConcurrentMap<String, HashSet<NodeID>> cache = new ConcurrentHashMap<>(componentsCache);
    final List<String> localComponentRoutesAddressing = localComponentRoutes.stream().map(r -> r.getAddress().toString()).collect(Collectors.toList());
    final Set<String> localComponentRoutesAddressingDuplicates = CollectionUtils.findDuplicates(localComponentRoutesAddressing);
    final List<String> remoteComponentRoutesAddressingWithNodeId = new ArrayList<>();
    for (Map.Entry<NodeID, Set<String>> entry : componentsByClusterNode.entrySet()) {
        for (String item : entry.getValue()) {
            remoteComponentRoutesAddressingWithNodeId.add(item + " (" + entry.getKey() + ")");
        }
    }
    final Multimap<String, String> result = HashMultimap.create();
    result.put("info", String.format("The cache named %s is used to share data in the cluster, which contains %d component routes.", componentsCache.getName(), cache.size()));
    result.put("info", String.format("LocalRoutingTable's getComponentRoute() response is used to track 'local' data to be restored after a cache switch-over. It tracks %d routes.", localComponentRoutesAddressing.size()));
    result.put("info", String.format("The field componentsByClusterNode is used to track data in the cache from every other cluster node. It contains %d routes for %d cluster nodes.", componentsByClusterNode.values().stream().reduce(0, (subtotal, values) -> subtotal + values.size(), Integer::sum), componentsByClusterNode.keySet().size()));
    result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", componentsCache.getName(), cache.entrySet().stream().map(e -> e.getKey() + "on nodes: " + e.getValue().stream().map(NodeID::toString).collect(Collectors.joining(", "))).collect(Collectors.joining("\n"))));
    result.put("data", String.format("LocalRoutingTable's getComponentRoute() response contains these entries (these represent 'local' data):\n%s", localComponentRoutes.stream().map(RoutableChannelHandler::getAddress).map(JID::toString).collect(Collectors.joining("\n"))));
    result.put("data", String.format("componentsByClusterNode contains these entries (these represent 'remote' data):\n%s", String.join("\n", remoteComponentRoutesAddressingWithNodeId)));
    if (localComponentRoutesAddressingDuplicates.isEmpty()) {
        result.put("pass", "There is no overlap in addressing of LocalRoutingTable's getComponentRoute() response (They are all unique values).");
    } else {
        result.put("fail", String.format("There is overlap in addressing of LocalRoutingTable's getComponentRoute() response (They are not all unique values). These %d values are duplicated: %s", localComponentRoutesAddressingDuplicates.size(), String.join(", ", localComponentRoutesAddressingDuplicates)));
    }
    if (!componentsByClusterNode.containsKey(XMPPServer.getInstance().getNodeID())) {
        result.put("pass", "componentsByClusterNode does not track data for the local cluster node.");
    } else {
        result.put("fail", "componentsByClusterNode tracks data for the local cluster node.");
    }
    if (clusterNodeIDs.containsAll(componentsByClusterNode.keySet())) {
        result.put("pass", "componentsByClusterNode tracks data for cluster nodes that are recognized in the cluster.");
    } else {
        result.put("fail", String.format("componentsByClusterNode tracks data for cluster nodes that are not recognized. All cluster nodeIDs as recognized: %s All cluster nodeIDs for which data is tracked: %s.", clusterNodeIDs.stream().map(NodeID::toString).collect(Collectors.joining(", ")), componentsByClusterNode.keySet().stream().map(NodeID::toString).collect(Collectors.joining(", "))));
    }
    final Set<String> nonCachedLocalComponentRouteAddressing = localComponentRoutesAddressing.stream().filter(v -> !cache.containsKey(v) || !cache.get(v).contains(XMPPServer.getInstance().getNodeID())).collect(Collectors.toSet());
    if (nonCachedLocalComponentRouteAddressing.isEmpty()) {
        result.put("pass", String.format("All elements in LocalRoutingTable's getComponentRoute() response exist in %s.", componentsCache.getName()));
    } else {
        result.put("fail", String.format("Not all elements in of LocalRoutingTable's getComponentRoute() response exist in %s. These %d entries do not: %s", componentsCache.getName(), nonCachedLocalComponentRouteAddressing.size(), nonCachedLocalComponentRouteAddressing.stream().map(v -> v + " on " + XMPPServer.getInstance().getNodeID()).collect(Collectors.joining(", "))));
    }
    final Set<String> nonCachedRemoteComponentRouteAddressing = new HashSet<>();
    for (final Map.Entry<NodeID, Set<String>> entry : componentsByClusterNode.entrySet()) {
        final NodeID remoteNodeID = entry.getKey();
        final Set<String> remoteComponentAddresses = entry.getValue();
        for (final String remoteComponentAddress : remoteComponentAddresses) {
            if (!cache.containsKey(remoteComponentAddress) || !cache.get(remoteComponentAddress).contains(remoteNodeID)) {
                nonCachedRemoteComponentRouteAddressing.add(remoteComponentAddress + " on " + remoteNodeID);
            }
        }
    }
    if (nonCachedRemoteComponentRouteAddressing.isEmpty()) {
        result.put("pass", String.format("All elements in componentsByClusterNode exist in %s.", componentsCache.getName()));
    } else {
        result.put("fail", String.format("Not all component routes in componentsByClusterNode exist in %s. These %d entries do not: %s", componentsCache.getName(), nonCachedRemoteComponentRouteAddressing.size(), String.join(", ", nonCachedLocalComponentRouteAddressing)));
    }
    final Set<String> nonLocallyStoredCachedComponentRouteAddressing = new HashSet<>();
    for (final Map.Entry<String, HashSet<NodeID>> entry : cache.entrySet()) {
        final String componentAddress = entry.getKey();
        final Set<NodeID> nodeIDs = entry.getValue();
        for (final NodeID nodeID : nodeIDs) {
            if (nodeID.equals(XMPPServer.getInstance().getNodeID())) {
                if (localComponentRoutes.stream().noneMatch(v -> v.getAddress().toString().equals(componentAddress))) {
                    nonLocallyStoredCachedComponentRouteAddressing.add(componentAddress + " on " + nodeID + " (the local cluster node)");
                }
            } else {
                if (!componentsByClusterNode.containsKey(nodeID) || !componentsByClusterNode.get(nodeID).contains(componentAddress)) {
                    nonLocallyStoredCachedComponentRouteAddressing.add(componentAddress + " on " + nodeID);
                }
            }
        }
    }
    if (nonLocallyStoredCachedComponentRouteAddressing.isEmpty()) {
        result.put("pass", String.format("All cache entries of %s exist in componentsByClusterNode and/or LocalRoutingTable's getComponentRoute() response.", componentsCache.getName()));
    } else {
        result.put("fail", String.format("Not all cache entries of %s exist in componentsByClusterNode and/or LocalRoutingTable's getComponentRoute() response. These %d entries do not: %s", componentsCache.getName(), nonLocallyStoredCachedComponentRouteAddressing.size(), String.join(", ", nonLocallyStoredCachedComponentRouteAddressing)));
    }
    return result;
}
Also used : java.util(java.util) ClusterManager(org.jivesoftware.openfire.cluster.ClusterManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) Multimap(com.google.common.collect.Multimap) StreamID(org.jivesoftware.openfire.StreamID) JID(org.xmpp.packet.JID) Collectors(java.util.stream.Collectors) org.jivesoftware.openfire.session(org.jivesoftware.openfire.session) ClientRoute(org.jivesoftware.openfire.spi.ClientRoute) ConcurrentMap(java.util.concurrent.ConcurrentMap) OccupantManager(org.jivesoftware.openfire.muc.spi.OccupantManager) ClusterNodeInfo(org.jivesoftware.openfire.cluster.ClusterNodeInfo) MUCRole(org.jivesoftware.openfire.muc.MUCRole) HashMultimap(com.google.common.collect.HashMultimap) NodeID(org.jivesoftware.openfire.cluster.NodeID) XMPPServer(org.jivesoftware.openfire.XMPPServer) RoutableChannelHandler(org.jivesoftware.openfire.RoutableChannelHandler) Nonnull(javax.annotation.Nonnull) CollectionUtils(org.jivesoftware.util.CollectionUtils) NodeID(org.jivesoftware.openfire.cluster.NodeID) RoutableChannelHandler(org.jivesoftware.openfire.RoutableChannelHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ClusterNodeInfo (org.jivesoftware.openfire.cluster.ClusterNodeInfo)7 HashMultimap (com.google.common.collect.HashMultimap)3 Multimap (com.google.common.collect.Multimap)3 java.util (java.util)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 Collectors (java.util.stream.Collectors)3 Nonnull (javax.annotation.Nonnull)3 RoutableChannelHandler (org.jivesoftware.openfire.RoutableChannelHandler)3 StreamID (org.jivesoftware.openfire.StreamID)3 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 ClusterManager (org.jivesoftware.openfire.cluster.ClusterManager)3 NodeID (org.jivesoftware.openfire.cluster.NodeID)3 MUCRole (org.jivesoftware.openfire.muc.MUCRole)3 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)3 OccupantManager (org.jivesoftware.openfire.muc.spi.OccupantManager)3 org.jivesoftware.openfire.session (org.jivesoftware.openfire.session)3 ClientRoute (org.jivesoftware.openfire.spi.ClientRoute)3 CollectionUtils (org.jivesoftware.util.CollectionUtils)3 JID (org.xmpp.packet.JID)3