Search in sources :

Example 1 with ClientRoute

use of org.jivesoftware.openfire.spi.ClientRoute in project Openfire by igniterealtime.

the class ClientSessionTask method run.

public void run() {
    if (getSession() == null || getSession().isClosed()) {
        logger.error("Session not found for JID: " + address);
        return;
    }
    super.run();
    ClientSession session = (ClientSession) getSession();
    if (session instanceof RemoteClientSession) {
        // The session is being hosted by other cluster node so log this unexpected case
        Cache<String, ClientRoute> usersCache = CacheFactory.createCache(RoutingTableImpl.C2S_CACHE_NAME);
        ClientRoute route = usersCache.get(address.toString());
        NodeID nodeID = route.getNodeID();
        logger.warn("Found remote session instead of local session. JID: " + address + " found in Node: " + nodeID.toByteArray() + " and local node is: " + XMPPServer.getInstance().getNodeID().toByteArray());
    }
    if (operation == Operation.isInitialized) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = true;
        } else {
            result = session.isInitialized();
        }
    } else if (operation == Operation.incrementConflictCount) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = 2;
        } else {
            result = session.incrementConflictCount();
        }
    }
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) ClientRoute(org.jivesoftware.openfire.spi.ClientRoute) NodeID(org.jivesoftware.openfire.cluster.NodeID)

Example 2 with ClientRoute

use of org.jivesoftware.openfire.spi.ClientRoute in project Openfire by igniterealtime.

the class ConsistencyChecks method generateReportForUserSessions.

public static Multimap<String, String> generateReportForUserSessions(@Nonnull final Cache<String, HashSet<String>> usersSessionsCache, @Nonnull final Cache<String, ClientRoute> usersCache, @Nonnull final Cache<String, ClientRoute> anonymousUsersCache) {
    final Set<NodeID> clusterNodeIDs = ClusterManager.getNodesInfo().stream().map(ClusterNodeInfo::getNodeID).collect(Collectors.toSet());
    // Take snapshots of all data structures at as much the same time as possible.
    final ConcurrentMap<String, HashSet<String>> cache = new ConcurrentHashMap<>(usersSessionsCache);
    final Set<String> usersCacheKeys = usersCache.keySet();
    final Set<String> anonymousUsersCacheKeys = anonymousUsersCache.keySet();
    final Set<String> userCacheKeysNotInSessionsCache = usersCacheKeys.stream().filter(fullJid -> {
        HashSet<String> fullJids = cache.get(new JID(fullJid).toBareJID());
        return fullJids == null || !fullJids.contains(fullJid);
    }).collect(Collectors.toSet());
    final Set<String> anonymousUserCacheKeysNotInSessionsCache = anonymousUsersCacheKeys.stream().filter(fullJid -> {
        HashSet<String> fullJids = cache.get(new JID(fullJid).toBareJID());
        return fullJids == null || !fullJids.contains(fullJid);
    }).collect(Collectors.toSet());
    final Set<String> sessionCacheItemsNotInUserCaches = cache.values().stream().flatMap(HashSet::stream).filter(fullJid -> !usersCacheKeys.contains(fullJid) && !anonymousUsersCacheKeys.contains(fullJid)).collect(Collectors.toSet());
    final Set<String> duplicatesBetweenAnonAndNonAnonUsers = CollectionUtils.findDuplicates(usersCacheKeys, anonymousUsersCacheKeys);
    // Generate report
    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 session infos.", usersSessionsCache.getName(), cache.size()));
    result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", usersSessionsCache.getName(), cache.entrySet().stream().map(e -> e.getKey() + " -> " + e.getValue()).sorted().collect(Collectors.joining("\n"))));
    result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", usersCache.getName(), usersCacheKeys.stream().sorted().collect(Collectors.joining("\n"))));
    result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", anonymousUsersCache.getName(), anonymousUsersCacheKeys.stream().sorted().collect(Collectors.joining("\n"))));
    if (userCacheKeysNotInSessionsCache.isEmpty()) {
        result.put("pass", "All user cache entries exist in the user sessions cache.");
    } else {
        result.put("fail", String.format("User sessions cache is missing entries that are present in the user cache. These %d entries are missing: %s", userCacheKeysNotInSessionsCache.size(), String.join(", ", userCacheKeysNotInSessionsCache)));
    }
    if (anonymousUserCacheKeysNotInSessionsCache.isEmpty()) {
        result.put("pass", "All anonymous user cache entries exist in the user sessions cache.");
    } else {
        result.put("fail", String.format("User sessions cache is missing entries that are present in the anonymous user cache. These %d entries are missing: %s", anonymousUserCacheKeysNotInSessionsCache.size(), String.join(", ", anonymousUserCacheKeysNotInSessionsCache)));
    }
    if (sessionCacheItemsNotInUserCaches.isEmpty()) {
        result.put("pass", "All user sessions cache entries exist in either the user cache or the anonymous user cache.");
    } else {
        result.put("fail", String.format("User cache and/or anonymous user cache is missing entries that are present in the user sessions cache. These %d entries are missing: %s", sessionCacheItemsNotInUserCaches.size(), String.join(", ", sessionCacheItemsNotInUserCaches)));
    }
    if (duplicatesBetweenAnonAndNonAnonUsers.isEmpty()) {
        result.put("pass", "There are no duplicates between non-anonymous users cache and anonymous users cache.");
    } else {
        result.put("fail", String.format("There are users both present in non-anonymous users cache and anonymous users cache. These %d entries are duplicates: %s", duplicatesBetweenAnonAndNonAnonUsers.size(), String.join(", ", duplicatesBetweenAnonAndNonAnonUsers)));
    }
    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) JID(org.xmpp.packet.JID) NodeID(org.jivesoftware.openfire.cluster.NodeID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with ClientRoute

use of org.jivesoftware.openfire.spi.ClientRoute in project Openfire by igniterealtime.

the class ClientSessionTask method run.

public void run() {
    super.run();
    ClientSession session = (ClientSession) getSession();
    if (session instanceof RemoteClientSession) {
        // The session is being hosted by other cluster node so log this unexpected case
        Cache<String, ClientRoute> usersCache = CacheFactory.createCache(RoutingTableImpl.C2S_CACHE_NAME);
        ClientRoute route = usersCache.get(address.toString());
        NodeID nodeID = route.getNodeID();
        Log.warn("Found remote session instead of local session. JID: " + address + " found in Node: " + nodeID.toByteArray() + " and local node is: " + XMPPServer.getInstance().getNodeID().toByteArray());
    }
    if (operation == Operation.isInitialized) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = true;
        } else {
            result = session.isInitialized();
        }
    } else if (operation == Operation.incrementConflictCount) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session shoud be local instead of remote
            // Assume some default value
            result = 2;
        } else {
            result = session.incrementConflictCount();
        }
    }
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) ClientRoute(org.jivesoftware.openfire.spi.ClientRoute) NodeID(org.jivesoftware.openfire.cluster.NodeID)

Example 4 with ClientRoute

use of org.jivesoftware.openfire.spi.ClientRoute in project Openfire by igniterealtime.

the class ClientSessionTask method run.

public void run() {
    if (getSession() == null || getSession().isClosed()) {
        logger.error("Session not found for JID: " + address);
        return;
    }
    super.run();
    ClientSession session = (ClientSession) getSession();
    if (session instanceof RemoteClientSession) {
        // The session is being hosted by other cluster node so log this unexpected case
        Cache<String, ClientRoute> usersCache = CacheFactory.createCache(RoutingTableImpl.C2S_CACHE_NAME);
        ClientRoute route = usersCache.get(address.toString());
        byte[] nodeIDByte = route != null ? route.getNodeID().toByteArray() : new byte[0];
        logger.warn("Found remote session instead of local session. JID: {} found in Node: {} and local node is: {}", address, nodeIDByte, XMPPServer.getInstance().getNodeID().toByteArray());
    }
    if (operation == Operation.isInitialized) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session should be local instead of remote
            // Assume some default value
            result = true;
        } else {
            result = session.isInitialized();
        }
    } else if (operation == Operation.incrementConflictCount) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session should be local instead of remote
            // Assume some default value
            result = 2;
        } else {
            result = session.incrementConflictCount();
        }
    } else if (operation == Operation.hasRequestedBlocklist) {
        if (session instanceof RemoteClientSession) {
            // Something is wrong since the session should be local instead of remote
            // Assume some default value
            result = false;
        } else {
            result = session.hasRequestedBlocklist();
        }
    }
}
Also used : ClientRoute(org.jivesoftware.openfire.spi.ClientRoute)

Aggregations

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