Project

General

Profile

Ad-hoc commands

All scripts for ad-hoc commands are available in src/main/groovy/tigase/admin in source code or at location https://projects.tigase.org/projects/tigase-pubsub/repository/revisions/master/show/src/main/groovy/tigase/admin and to use them scripts need to be copied to subpath scripts/admin/pubsub in Tigase XMPP Server instance directory.

pubsub.example.com in following examples is address of pubsub component

Create a node

Ad-hoc command node: create-node

Required role: service administrator

Command requires fields node and pubsub#node_type to be filled with proper values for execution.

node - field should contain id of node to create

pubsub#node_type - should contain type of node to create (two values are possible: leaf - node to which items will be published, collection - node which will contain other nodes)

Other fields are optional fields that can be set to change configuration of newly create node to diffrent configuration than default.

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com create-node example admin@example.com leaf

Delete a node

Ad-hoc command node: delete-node

Required role: service administrator

Command requires field node to be filled.

node - field should contain id of node to delete

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com delete-node example

Subscribe to a node

Ad-hoc command node: subscribe-node

Required role: service administrator

Command requires fields node and jids to be filled.

node - field should contain id of node to subscribe to

jids - field should contain list of jids to be subscribed to node

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com subscribe-node example admin@example.com,test1@example.com

Unsubscribe from a node

Ad-hoc command node: unsubscribe-node

Required role: service administrator

Command requires fields node and jids to be filled.

node - field should contain id of node to unsubscribe from

jids - field should contain list of jids to be unsubscribed from node

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com unsubscribe-node example admin@example.com,test2@example.com

Publish an item to a node

Ad-hoc command node: publish-item

Required role: service administrator

Command requires fields node and entry to be filled

node - field should contain id of node to publish to

item-id - field may contain id of entry to publish

entry - field should contain multiline entry content which should be valid XML value for an item

This command due to it's complexity cannot be easily executed by TCLMT using default remote script which provides support for basic adhoc commands.

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com publish-item example item-1 '<entry><title>Example 1</title></entry>'

Delete an item from a node

Available since: 3.2.0-SNAPSHOT newer than 2016-01-20

Ad-hoc command node: delete-item

Required role: service administrator

Command requires fields node and item-id to be filled

node - field contains id of node to publish to

item-id - field contains id of entry to publish

Example call using TCLMT:

bin/tclmt.sh -u admin@example.com -p admin123 remote pubsub.example.com delete-item example item-1

Example Groovy script to execute create-node command using JaXMPP2

import tigase.jaxmpp.j2se.Jaxmpp
import tigase.jaxmpp.core.client.AsyncCallback
import tigase.jaxmpp.core.client.exceptions.JaxmppException
import tigase.jaxmpp.core.client.xmpp.stanzas.Stanza
import tigase.jaxmpp.core.client.SessionObject
import tigase.jaxmpp.j2se.ConnectionConfiguration
import tigase.jaxmpp.core.client.xml.Element
import tigase.jaxmpp.core.client.xml.DefaultElement
import tigase.jaxmpp.core.client.xmpp.forms.JabberDataElement

Jaxmpp jaxmpp = new Jaxmpp();

jaxmpp.with {
    getConnectionConfiguration().setConnectionType(ConnectionConfiguration.ConnectionType.socket)
    getConnectionConfiguration().setUserJID("admin@example.com")
    getConnectionConfiguration().setUserPassword("admin123")
}

jaxmpp.login(true);

def packet = IQ.create();
packet.setAttribute("to", "pubsub.example.com");

Element command = new DefaultElement("command");
command.setXMLNS("http://jabber.org/protocol/commands");
command.setAttribute("node", "create-node");
packet.addChild(command);

Element x = new DefaultElement("x");
x.setXMLNS("jabber:x:data");

command.addChild(x);

def data = new JabberDataElement(x);
data.addTextSingleField("node", "example");
data.addListSingleField("pubsub#node_type", "leaf");

jaxmpp.send(packet, new AsyncCallback() {
    void onError(Stanza responseStanza, tigase.jaxmpp.core.client.XMPPException.ErrorCondition error) throws JaxmppException {
        println "received error during processing request";
    }

    void onSuccess(Stanza responseStanza) throws JaxmppException {
        x = responseStanza.getFirstChild("command").getFirstChid("x");      
        data = new JabberDataElement(x);
        def error = data.getField("Error");
        println "command executed with result = " + (error ? "failure, error = " + error.getFieldValue() : "success");
    }

    void onTimeout() {
        println "command timed out"
    }
});

Thread.sleep(30000);
jaxmpp.disconnect();