Deploying Connectors on a Remote Server

We recommend deploying custom connectors as plugins within Exalead CloudView. You may however need to deploy them on a remote server and still want to benefit from the Exalead CloudView Administration Console to manage them.

This task shows you how to:


Before you begin: The Exalead CloudView kit contains a set of JAR files that must be deployed on your remote server:
  • datainteg-java-commons.jar - contains the Remote Scan Server (RScan). It allows to manage Exalead CloudView scan operations on remote connectors. To do so you must instantiate these connectors as described in the code sample below. Once the RScan server is deployed, you can create RScan Client connectors in the Exalead CloudView Administration Console to launch scan operations.
  • Developing unmanaged connectors requires the following jar files:
    • datainteg-java-commons.jar
    • cloudview-java-plugin.jar
    • papi-java-client.jar
    • papi-java-connector.jar

Instantiate a connector

The following code snippet shows how to instantiate a connector (myConnector).
package com.exalead.papi.datainteg.connectors;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.exalead.mercury.plugin.simple.SimplePluginManager;
import com.exalead.papi.datainteg.connectors.rscan.unmanaged.Runner;
import com.exalead.papi.framework.connectors.Connector;
import com.exalead.papi.framework.connectors.ConnectorConfig;
import com.exalead.papi.helper.Document;
import com.exalead.papi.helper.PushAPI;

public class RScanServerSample {
    public static void main(final String[] args) throws Exception {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);
        SimplePluginManager.getCurrentInstance();
        // Start a RSCAN server
        final Runner rscanRunner = new Runner(10005);
        // Add a new connector
        rscanRunner.registerConnector(MyConnectorClass.class, "myConnector");
        try {
            // wait for input requests on RSCAN server indefinitely.
            Thread.sleep(Long.MAX_VALUE);
        } catch (final InterruptedException e) { /* do nothing */ }
        rscanRunner.stop();
    }

    /**
     * Connector sample pushing one document.
     */
    public static class MyConnectorClass extends Connector {
        public MyConnectorClass(final ConnectorConfig config) throws Exception {
            super(config);
        }
        @Override
        public void scan(final PushAPI papi, final String scanMode, final Object scanModeConfig) throws 
Exception {
            final Document doc = new Document("document1234");
            doc.addMeta("author", "foo");
            doc.addMeta("content", "Lorem ipsum dolor sit amet...");
            papi.addDocument(doc);
        }
    }
}

Launch your connector using a command line

  1. Copy all .jar files from your Exalead CloudView <INSTALLDIR>/sdk/java-customcode/lib to a work­ing directory.
  2. Copy all the connector .jar files to the working directory.
  3. Open a shell, go to your working directory and type the following command:

    java -cp '*' com.exalead.papi.datainteg.connectors.rscan.server.RemoteScanLauncher 
    -rscanPort <port number> -connector <connector class>=<connector name>

    where:

    • <port number> is an available port (not used by CloudView).
    • <connector class> is the name of your connector class, for example, com.customer.cloudview.Connector1
    • <connector name> is the name of your connector.
    • You can use the -connector parameter several times to launch several connectors at once.

    The following snippet shows the source code for the RemoteScanLauncher class:

    package com.exalead.papi.datainteg.connectors.rscan.server;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    
    import com.exalead.mercury.plugin.simple.SimplePluginManager;
    import com.exalead.papi.datainteg.connectors.rscan.unmanaged.Runner;
    import com.exalead.papi.framework.connectors.Connector;
    
    public class RemoteScanLauncher {
      private class ConnectorDescription {
        private String clazz;
        private String name;
    
        public ConnectorDescription(final String clazz, final String name) {
          this.clazz = clazz;
          this.name = name;
        }
    
        public String getClazz() {
          return clazz;
        }
    
        public String getName() {
          return name;
        }
      }
    
      private static final Logger logger = Logger
          .getLogger(RemoteScanLauncher.class);
    
      private int rscanPort = -1;
      private List<ConnectorDescription> connectors = new ArrayList<ConnectorDescription>();
      private void parseCommandLine(final String[] args)
          throws CommandLineParameterException {
        if (args.length > 0) {
          int i = 0;
    
          while (i < args.length) {
            final String param = args[i++];
    
            if (param.equals("-rscanPort")) {
              if (args.length < i + 1) {
                throw new CommandLineParameterException("Missing " + param + " value");
              } else {
                final String rscanPortParam = args[i++];
                this.rscanPort = Integer.parseInt(rscanPortParam);
              }
            }
    
            else if (param.equals("-connector")) {
              if (args.length < i + 1) {
                throw new CommandLineParameterException("Missing " + param + " value");
              } else {
                final String connectorParam = args[i++];
                final String[] connector = connectorParam.split("=");
                if (connector.length != 2) {
                  throw new CommandLineParameterException("Invalid " + param + " value");
                }
                final ConnectorDescription connectorDescription = new ConnectorDescription(connector[0], 
    connector[1]);
                connectors.add(connectorDescription);
              }
            }
    
            else {
              throw new CommandLineParameterException("Unknown command line parameter: " + param);
            }
          }
        }
      }
    
      private void validateCommandLineParameters()
          throws CommandLineParameterException {
        if (this.rscanPort == -1) {
          throw new CommandLineParameterException("Missing -rscanPort parameter");
        }
    
        if (this.connectors.size() == 0) {
          throw new CommandLineParameterException("Missing -connector parameter");
        }
      }
    
      private void displayHelp() {
        final String help = "Rscan connector launcher (c) Exalead\n"
            + "Usage: \n"
            + "1. Copy all .jar files from CLOUDVIEW/sdk/java-customcode/lib into your working directory\n"
            + "2. Copy all .jar files of your connector into your working directory\n"
            + "3. Into your working directory: java -cp '*' 
    com.exalead.papi.datainteg.connectors.rscan.server.RemoteScanLauncher -rscanPort <port number>
     -connector <connector class>=<connector name>\n"
            + "   You can use several -connector parameters to launch several connectors";
        logger.info(help);
      }
    
      private void run() throws Exception {
        SimplePluginManager.getCurrentInstance();
    
        // Start a RSCAN server
        final Runner rscanRunner = new Runner(this.rscanPort);
    
        try {
          // add new connectors
          for (final ConnectorDescription connector : connectors) {
            @SuppressWarnings("unchecked")
            final Class<? extends Connector> clazz = (Class<? extends Connector>) 
    Class .forName(connector.getClazz());
            final String name = connector.getName();
    
            rscanRunner.registerConnector(clazz, name);
            logger.info("Connector " + name + " is launched.");
         }
    
          Thread.sleep(Long.MAX_VALUE);
        } finally {
          rscanRunner.stop();
        }
      }
    
      public static void main(String[] args) throws Exception {
        BasicConfigurator.configure();
        Logger.getRootLogger().setLevel(Level.INFO);
    
        final RemoteScanLauncher launcher = new RemoteScanLauncher();
    
        try {
          launcher.parseCommandLine(args);
          launcher.validateCommandLineParameters();
          launcher.run();
        } catch (final CommandLineParameterException e) {
          logger.error(e);
          launcher.displayHelp();
        }
      }
    }