Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public Map<String, String> getNodeConf(String nodeId)
throws NodeStoreException {
return nodeStore.getNodeConf(nodeId);
}


@Override
public boolean isCachedNodeConfig(String nodeId) throws NodeStoreException {
return nodeStore.isCachedNodeConfig(nodeId);
}

@Override
public boolean nodeExists(String nodeId) throws NodeStoreException {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/buddycloud/channelserver/db/NodeStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ void deleteNodeItemById(String nodeId, String nodeItemId)
*/
boolean isCachedJID(JID jid) throws NodeStoreException;

/**
* Return whether node config is cached locally
*
* @param nodeId
* @return
* @throws NodeStoreException
*/
boolean isCachedNodeConfig(String nodeId) throws NodeStoreException;

/**
* Allows the server to determine if the requested (subscriptions) node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,11 @@ public ArrayList<String> getNodeList() throws NodeStoreException {
public boolean isCachedNode(String nodeId) throws NodeStoreException {
return (this.countNodeItems(nodeId) > 0);
}

@Override
public boolean isCachedNodeConfig(String nodeId) throws NodeStoreException {
return (this.getNodeConf(nodeId).size() > 0);
}

@Override
public boolean isCachedJID(JID jid) throws NodeStoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.buddycloud.channelserver.channel.ChannelManager;
import org.buddycloud.channelserver.packetprocessor.PacketProcessor;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result.AffiliationsResult;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result.Configuration;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result.ItemsResult;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result.SubscriptionsResult;
import org.buddycloud.channelserver.queue.FederatedQueueManager;
Expand Down Expand Up @@ -42,6 +43,7 @@ private void initElementProcessors() {
elementProcessors.add(new SubscriptionsResult(channelManager));
elementProcessors.add(new AffiliationsResult(channelManager));
elementProcessors.add(new ItemsResult(channelManager));
elementProcessors.add(new Configuration(channelManager));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
return;
}

if (!channelManager.isLocalNode(node)) {
if (!channelManager.isLocalNode(node) && !channelManager.isCachedNodeConfig(node)) {
makeRemoteRequest();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.buddycloud.channelserver.channel.ChannelManager;
import org.buddycloud.channelserver.channel.node.configuration.NodeConfigurationException;
import org.buddycloud.channelserver.channel.node.configuration.field.Owner;
import org.buddycloud.channelserver.db.exception.NodeStoreException;
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.PubSubElementProcessorAbstract;
import org.buddycloud.channelserver.pubsub.model.NodeSubscription;
import org.buddycloud.channelserver.pubsub.model.impl.NodeSubscriptionImpl;
import org.buddycloud.channelserver.pubsub.subscription.Subscriptions;
import org.dom4j.Element;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;

public class Configuration extends PubSubElementProcessorAbstract {

private IQ request;
Element configure;

private static final Logger logger = Logger
.getLogger(Configuration.class);

public Configuration(ChannelManager channelManager) {
this.channelManager = channelManager;
}

@Override
public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
throws Exception {
this.request = reqIQ;

if (-1 != request.getFrom().toString().indexOf("@")) {
logger.debug("Ignoring result packet, only interested in stanzas "
+ "from other buddycloud servers");
return;
}

configure = request.getChildElement().element("configure");
node = configure.attributeValue("node");
if (0 == node.length()) return;

if (false == channelManager.nodeExists(node)) {
channelManager.addRemoteNode(node);
}
setNodeConfiguration();
}

private void setNodeConfiguration() throws Exception {
try {
getNodeConfigurationHelper().parse(request);
updateNodeConfiguration(getNodeConfigurationHelper()
.getValues());
} catch (NodeConfigurationException e) {
logger.error("Node configuration exception", e);
} catch (NodeStoreException e) {
logger.error("Data Store Exception", e);
}
}

private void updateNodeConfiguration(HashMap<String, String> configuration)
throws Exception {
channelManager.setNodeConf(node, configuration);
}

@Override
public boolean accept(Element elm) {
return elm.getName().equals("configure");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ public void testGetNodeConf() throws Exception {
entry.getValue(), result.get(entry.getKey()));
}
}

@Test
public void testNodeWithConfigSaysConfigIsCached() throws Exception {
dbTester.loadData("node_1");
Assert.assertTrue(store.isCachedNodeConfig(TEST_SERVER1_NODE1_ID));
}

@Test
public void testNodeWithoutConfigSaysConfigNotCached() throws Exception {
Assert.assertFalse(store.isCachedNodeConfig(TEST_SERVER1_NODE1_ID));
}

@Test
public void testAddUserSubscriptionNewSubscription() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result;

import junit.framework.Assert;

import org.buddycloud.channelserver.channel.ChannelManager;
import org.buddycloud.channelserver.packetHandler.iq.IQTestHandler;
import org.buddycloud.channelserver.pubsub.affiliation.Affiliations;
import org.buddycloud.channelserver.pubsub.model.NodeSubscription;
import org.dom4j.Element;
import org.dom4j.tree.BaseElement;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;

public class ConfigurationTest extends IQTestHandler {

private IQ resultWithNode;
private IQ resultNoNode;
private Configuration confResult;
private Element element;

private String node = "/user/pamela@denmark.lit/posts";
private JID jid = new JID("juliet@shakespeare.lit");
private ChannelManager channelManager;

@Before
public void setUp() throws Exception {

channelManager = Mockito.mock(ChannelManager.class);

confResult = new Configuration(channelManager);
resultWithNode = readStanzaAsIq("/iq/pubsub/subscriptions/reply-with-node.stanza");
resultNoNode = readStanzaAsIq("/iq/pubsub/subscriptions/reply-no-node.stanza");

element = new BaseElement("configure");
element.addAttribute("node", node);

confResult.setChannelManager(channelManager);
}

@Test
public void testPassingConfigureAsElementNameReturnsTrue() {
Assert.assertTrue(confResult.accept(element));
}

@Test
public void testPassingNotConfigureAsElementNameReturnsFalse() {
Element element = new BaseElement("not-configure");
Assert.assertFalse(confResult.accept(element));
}

@Test(expected = NullPointerException.class)
public void testInvalidStanzaThrowsException() throws Exception {

IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
+ "from=\"channels.shakespeare.lit\" "
+ "to=\"channels.denmark.lit\">"
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\" />"
+ "</iq>");

confResult.process(element, jid, result, null);
}

@Test
public void testEmptyNodeValueCausesNoAction() throws Exception {
IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
+ "from=\"channels.shakespeare.lit\" "
+ "to=\"channels.denmark.lit\">"
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\">"
+ "<configure node=\"\" />" + "</pubsub>" + "</iq>");

confResult.process(element, jid, result, null);

Mockito.verify(channelManager, Mockito.times(0)).nodeExists(
Mockito.anyString());
}

@Test
public void testIfNodeIsUnknownThenItIsAddedToDatabase() throws Exception {
IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
+ "from=\"channels.shakespeare.lit\" "
+ "to=\"channels.denmark.lit\">"
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\">"
+ "<configure node=\"some-node\" />" + "</pubsub>" + "</iq>");

confResult.process(element, jid, result, null);

Mockito.when(channelManager.nodeExists(Mockito.anyString())).thenReturn(false);
Mockito.verify(channelManager, Mockito.times(1)).nodeExists(
Mockito.anyString());
Mockito.verify(channelManager, Mockito.times(1)).addRemoteNode(
Mockito.anyString());
}
}