incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shinich...@apache.org
Subject svn commit: r1214014 - in /incubator/lcf/branches/CONNECTORS-313: ./ framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/
Date Wed, 14 Dec 2011 01:09:31 GMT
Author: shinichiro
Date: Wed Dec 14 01:09:30 2011
New Revision: 1214014

URL: http://svn.apache.org/viewvc?rev=1214014&view=rev
Log:
Fix for CONNECTORS-313

Added:
    incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/Connectors.java
    incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegisterAll.java
    incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegsiterConnectors.java
Removed:
    incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/Connectors.java
Modified:
    incubator/lcf/branches/CONNECTORS-313/build.xml
    incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ManifoldCFJettyRunner.java

Modified: incubator/lcf/branches/CONNECTORS-313/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-313/build.xml?rev=1214014&r1=1214013&r2=1214014&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-313/build.xml (original)
+++ incubator/lcf/branches/CONNECTORS-313/build.xml Wed Dec 14 01:09:30 2011
@@ -2020,7 +2020,20 @@
         </manifest>
         <jar destfile="dist/example/start.jar" manifest="build/example/manifest"/>
     </target>
-    
+
+    <target name="deliver-multi-process" depends="deliver-example">
+        <copy todir="dist">
+            <fileset dir="dist/example">
+                <include name="properties.xml"/>
+                <include name="connectors.xml"/>
+                <include name="logging.ini"/>
+            </fileset>
+        </copy>
+        <replace file="dist/properties.xml" token="&lt;libdir path=&quot;./connector-lib&quot;/&gt;"
value="&lt;libdir path=&quot;./lib&quot;/&gt;"/>
+        <mkdir dir="dist/mysynchdir"/>
+        <replace file="dist/properties.xml" token="&lt;!-- Any additional properties
go here --&gt;" value="&lt;!-- Any additional properties go here --&gt;&#0010;
 &lt;property name=&quot;org.apache.manifoldcf.synchdirectory&quot; value=&quot;./mysynchdir&quot;/&gt;"/>
+    </target>
+  
     <target name="calculate-filesystem-tests-condition" depends="calculate-filesystem-condition,calculate-nulloutput-condition">
       <condition property="filesystem-tests.include">
         <and>
@@ -3640,7 +3653,7 @@
     <target name="deliver-proprietary-connectors" depends="deliver-documentum-connector,deliver-filenet-connector,deliver-livelink-connector,deliver-memex-connector,deliver-meridio-connector,deliver-sharepoint-connector"/>
     <target name="deliver-proprietary-connectors-doc" depends="deliver-documentum-connector-doc,deliver-filenet-connector-doc,deliver-livelink-connector-doc,deliver-memex-connector-doc,deliver-meridio-connector-doc,deliver-sharepoint-connector-doc"/>
 
-    <target name="build-dev" depends="deliver-framework,deliver-open-connectors,deliver-output-connectors,deliver-lgpl-connectors,deliver-proprietary-connectors,deliver-example"/>
+    <target name="build-dev" depends="deliver-framework,deliver-open-connectors,deliver-output-connectors,deliver-lgpl-connectors,deliver-proprietary-connectors,deliver-example,deliver-multi-process"/>
     <target name="build" depends="build-dev,cleanup-afterbuild"/>
     <target name="javadoc" depends="deliver-framework-doc,deliver-open-connectors-doc,deliver-output-connectors-doc,deliver-lgpl-connectors-doc,deliver-proprietary-connectors-doc"/>
     <target name="doc" depends="deliver-site-doc"/>

Modified: incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ManifoldCFJettyRunner.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ManifoldCFJettyRunner.java?rev=1214014&r1=1214013&r2=1214014&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ManifoldCFJettyRunner.java
(original)
+++ incubator/lcf/branches/CONNECTORS-313/framework/jetty-runner/src/main/java/org/apache/manifoldcf/jettyrunner/ManifoldCFJettyRunner.java
Wed Dec 14 01:09:30 2011
@@ -19,10 +19,8 @@ package org.apache.manifoldcf.jettyrunne
 
 import java.io.*;
 import org.apache.manifoldcf.core.interfaces.*;
-import org.apache.manifoldcf.agents.interfaces.*;
-import org.apache.manifoldcf.crawler.interfaces.*;
-import org.apache.manifoldcf.authorities.interfaces.*;
 import org.apache.manifoldcf.agents.system.*;
+import org.apache.manifoldcf.crawler.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -50,18 +48,6 @@ public class ManifoldCFJettyRunner
   public static final String _rcsid = "@(#)$Id: ManifoldCFJettyRunner.java 989983 2010-08-27
00:10:12Z kwright $";
 
   public static final String agentShutdownSignal = org.apache.manifoldcf.agents.AgentRun.agentShutdownSignal;
-
-  // Configuration parameters
-  public static final String connectorsConfigurationFile = "org.apache.manifoldcf.connectorsconfigurationfile";
-  public static final String databaseSuperuserName = "org.apache.manifoldcf.dbsuperusername";
-  public static final String databaseSuperuserPassword = "org.apache.manifoldcf.dbsuperuserpassword";
-  
-  // Connectors configuration file
-  public static final String NODE_OUTPUTCONNECTOR = "outputconnector";
-  public static final String NODE_AUTHORITYCONNECTOR = "authorityconnector";
-  public static final String NODE_REPOSITORYCONNECTOR = "repositoryconnector";
-  public static final String ATTRIBUTE_NAME = "name";
-  public static final String ATTRIBUTE_CLASS = "class";
   
   protected Server server;
   
@@ -138,270 +124,6 @@ public class ManifoldCFJettyRunner
     return conns[0].getLocalPort();
   }
 
-  /** Clear the agents shutdown signal */
-  public static void clearShutdownSignal(IThreadContext tc)
-    throws ManifoldCFException
-  {
-    // Clear the agents shutdown signal.
-    ILockManager lockManager = LockManagerFactory.make(tc);
-    lockManager.clearGlobalFlag(agentShutdownSignal);
-  }
-
-  /** Create the database and the schema */
-  public static void createDatabaseAndSchema(IThreadContext tc, String superuserName, String
superuserPassword)
-    throws ManifoldCFException
-  {
-    ManifoldCF.createSystemDatabase(tc,superuserName,superuserPassword);
-    ManifoldCF.installTables(tc);
-  }
-  
-  /** Register the agents */
-  public static void registerAgents(IThreadContext tc)
-    throws ManifoldCFException
-  {
-    // Register 
-    IAgentManager agentMgr = AgentManagerFactory.make(tc);
-    agentMgr.registerAgent("org.apache.manifoldcf.crawler.system.CrawlerAgent");
-  }
-
-  /** Read connectors configuration file.
-  */
-  public static Connectors readConnectorDeclarations(File connectorConfigFile)
-    throws ManifoldCFException
-  {
-    Connectors c = null;
-    if (connectorConfigFile != null)
-    {
-      try
-      {
-        // Open the file, read it, and attempt to do the connector registrations
-        InputStream is = new FileInputStream(connectorConfigFile);
-        try
-        {
-          c = new Connectors(is);
-        }
-        finally
-        {
-          is.close();
-        }
-      }
-      catch (FileNotFoundException e)
-      {
-        throw new ManifoldCFException("Couldn't find connector configuration file: "+e.getMessage(),e);
-      }
-      catch (IOException e)
-      {
-        throw new ManifoldCFException("Error reading connector configuration file: "+e.getMessage(),e);
-      }
-    }
-    return c;
-  }
-
-  /** Unregister all connectors.
-  */
-  public static void unregisterAllConnectors(IThreadContext tc)
-    throws ManifoldCFException
-  {
-    // Grab a database handle, so we can use transactions later.
-    IDBInterface database = DBInterfaceFactory.make(tc,
-      ManifoldCF.getMasterDatabaseName(),
-      ManifoldCF.getMasterDatabaseUsername(),
-      ManifoldCF.getMasterDatabasePassword());
-
-    // Output connectors...
-    {
-      IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
-      IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
-      IResultSet classNames = mgr.getConnectors();
-      int i = 0;
-      while (i < classNames.getRowCount())
-      {
-        IResultRow row = classNames.getRow(i++);
-        String className = (String)row.getValue("classname");
-        // Deregistration should be done in a transaction
-        database.beginTransaction();
-        try
-        {
-          // Find the connection names that come with this class
-          String[] connectionNames = connManager.findConnectionsForConnector(className);
-          // For all connection names, notify all agents of the deregistration
-          AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
-          // Now that all jobs have been placed into an appropriate state, actually do the
deregistration itself.
-          mgr.unregisterConnector(className);
-        }
-        catch (ManifoldCFException e)
-        {
-          database.signalRollback();
-          throw e;
-        }
-        catch (Error e)
-        {
-          database.signalRollback();
-          throw e;
-        }
-        finally
-        {
-          database.endTransaction();
-        }
-      }
-      System.err.println("Successfully unregistered all output connectors");
-    }
-      
-    // Authority connectors...
-    {
-      IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
-      IResultSet classNames = mgr.getConnectors();
-      int i = 0;
-      while (i < classNames.getRowCount())
-      {
-        IResultRow row = classNames.getRow(i++);
-        mgr.unregisterConnector((String)row.getValue("classname"));
-      }
-      System.err.println("Successfully unregistered all authority connectors");
-    }
-      
-    // Repository connectors...
-    {
-      IConnectorManager mgr = ConnectorManagerFactory.make(tc);
-      IJobManager jobManager = JobManagerFactory.make(tc);
-      IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
-      IResultSet classNames = mgr.getConnectors();
-      int i = 0;
-      while (i < classNames.getRowCount())
-      {
-        IResultRow row = classNames.getRow(i++);
-        String className = (String)row.getValue("classname");
-        // Deregistration should be done in a transaction
-        database.beginTransaction();
-        try
-        {
-          // Find the connection names that come with this class
-          String[] connectionNames = connManager.findConnectionsForConnector(className);
-          // For each connection name, modify the jobs to note that the connector is no longer
installed
-          jobManager.noteConnectorDeregistration(connectionNames);
-          // Now that all jobs have been placed into an appropriate state, actually do the
deregistration itself.
-          mgr.unregisterConnector(className);
-        }
-        catch (ManifoldCFException e)
-        {
-          database.signalRollback();
-          throw e;
-        }
-        catch (Error e)
-        {
-          database.signalRollback();
-          throw e;
-        }
-        finally
-        {
-          database.endTransaction();
-        }
-      }
-      System.err.println("Successfully unregistered all repository connectors");
-    }
-  }
-
-  /** Register all connectors as specified by a Connectors structure, usually read from the
connectors.xml file.
-  */
-  public static void registerConnectors(IThreadContext tc, Connectors c)
-    throws ManifoldCFException
-  {
-    if (c != null)
-    {
-      // Grab a database handle, so we can use transactions later.
-      IDBInterface database = DBInterfaceFactory.make(tc,
-        ManifoldCF.getMasterDatabaseName(),
-        ManifoldCF.getMasterDatabaseUsername(),
-        ManifoldCF.getMasterDatabasePassword());
-        
-      // Other code will go here to discover and register various connectors that exist in
the classpath
-      int i = 0;
-      while (i < c.getChildCount())
-      {
-        ConfigurationNode cn = c.findChild(i++);
-        if (cn.getType().equals(NODE_OUTPUTCONNECTOR))
-        {
-          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
-          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
-          IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
-          IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
-          // Registration should be done in a transaction
-          database.beginTransaction();
-          try
-          {
-            // First, register connector
-            mgr.registerConnector(name,className);
-            // Then, signal to all jobs that might depend on this connector that they can
switch state
-            // Find the connection names that come with this class
-            String[] connectionNames = connManager.findConnectionsForConnector(className);
-            // For all connection names, notify all agents of the registration
-            AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
-          }
-          catch (ManifoldCFException e)
-          {
-            database.signalRollback();
-            throw e;
-          }
-          catch (Error e)
-          {
-            database.signalRollback();
-            throw e;
-          }
-          finally
-          {
-            database.endTransaction();
-          }
-          System.err.println("Successfully registered output connector '"+className+"'");
-        }
-        else if (cn.getType().equals(NODE_AUTHORITYCONNECTOR))
-        {
-          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
-          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
-          IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
-          mgr.registerConnector(name,className);
-          System.err.println("Successfully registered authority connector '"+className+"'");
-        }
-        else if (cn.getType().equals(NODE_REPOSITORYCONNECTOR))
-        {
-          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
-          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
-          IConnectorManager mgr = ConnectorManagerFactory.make(tc);
-          IJobManager jobManager = JobManagerFactory.make(tc);
-          IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
-          // Deregistration should be done in a transaction
-          database.beginTransaction();
-          try
-          {
-            // First, register connector
-            mgr.registerConnector(name,className);
-            // Then, signal to all jobs that might depend on this connector that they can
switch state
-            // Find the connection names that come with this class
-            String[] connectionNames = connManager.findConnectionsForConnector(className);
-            // For each connection name, modify the jobs to note that the connector is now
installed
-            jobManager.noteConnectorRegistration(connectionNames);
-          }
-          catch (ManifoldCFException e)
-          {
-            database.signalRollback();
-            throw e;
-          }
-          catch (Error e)
-          {
-            database.signalRollback();
-            throw e;
-          }
-          finally
-          {
-            database.endTransaction();
-          }
-          System.err.println("Successfully registered repository connector '"+className+"'");
-        }
-        else
-          throw new ManifoldCFException("Unrecognized connectors node type '"+cn.getType()+"'");
-      }
-    }
-  }
-
   /** Run the agents process.  This method will not return unless the agents process is shut
down.
   */
   public static void runAgents(IThreadContext tc)
@@ -473,29 +195,29 @@ public class ManifoldCFJettyRunner
       IThreadContext tc = ThreadContextFactory.make();
 
       // Clear the shutdown signal
-      clearShutdownSignal(tc);
+      RegsiterConnectors.clearShutdownSignal(tc);
       
       // Get the specified superuser name and password, in case this isn't Derby we're using
-      String superuserName = ManifoldCF.getProperty(databaseSuperuserName);
+      String superuserName = ManifoldCF.getProperty(RegsiterConnectors.databaseSuperuserName);
       if (superuserName == null)
         superuserName = "";
-      String superuserPassword = ManifoldCF.getProperty(databaseSuperuserPassword);
+      String superuserPassword = ManifoldCF.getProperty(RegsiterConnectors.databaseSuperuserPassword);
       if (superuserPassword == null)
         superuserPassword = "";
       
       // Do the basic initialization of the database and its schema
-      createDatabaseAndSchema(tc,superuserName,superuserPassword);
-      registerAgents(tc);
+      RegsiterConnectors.createDatabaseAndSchema(tc,superuserName,superuserPassword);
+      RegsiterConnectors.registerAgents(tc);
       
         // Read connectors configuration file (to figure out what we need to register)
-      File connectorConfigFile = ManifoldCF.getFileProperty(connectorsConfigurationFile);
-      Connectors c = readConnectorDeclarations(connectorConfigFile);
+      File connectorConfigFile = ManifoldCF.getFileProperty(RegsiterConnectors.connectorsConfigurationFile);
+      Connectors c = RegsiterConnectors.readConnectorDeclarations(connectorConfigFile);
       
       // Unregister all connectors.
-      unregisterAllConnectors(tc);
+      RegsiterConnectors.unregisterAllConnectors(tc);
 
       // Register connections specified by connectors.xml
-      registerConnectors(tc,c);
+      RegsiterConnectors.registerConnectors(tc,c);
       
       System.err.println("Starting jetty...");
       

Added: incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/Connectors.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/Connectors.java?rev=1214014&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/Connectors.java
(added)
+++ incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/Connectors.java
Wed Dec 14 01:09:30 2011
@@ -0,0 +1,56 @@
+/* $Id: Connectors.java 988245 2010-08-23 18:39:35Z kwright $ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.crawler;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import java.util.*;
+import java.io.*;
+
+/** This class represents the configuration data read from the 'connectors.xml' file, which
+* describes all the individual connector classes and their pretty names.
+*/
+public class Connectors extends Configuration
+{
+  public static final String _rcsid = "@(#)$Id: Connectors.java 988245 2010-08-23 18:39:35Z
kwright $";
+
+  /** Constructor.
+  */
+  public Connectors()
+  {
+    super("connectors");
+  }
+
+  /** Construct from XML.
+  *@param xmlStream is the input XML stream.
+  */
+  public Connectors(InputStream xmlStream)
+    throws ManifoldCFException
+  {
+    super("connectors");
+    fromXML(xmlStream);
+  }
+
+  /** Create a new object of the appropriate class.
+  */
+  protected Configuration createNew()
+  {
+    return new Connectors();
+  }
+  
+}

Added: incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegisterAll.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegisterAll.java?rev=1214014&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegisterAll.java
(added)
+++ incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegisterAll.java
Wed Dec 14 01:09:30 2011
@@ -0,0 +1,64 @@
+package org.apache.manifoldcf.crawler;
+
+import java.io.File;
+
+import org.apache.manifoldcf.agents.system.ManifoldCF;
+import org.apache.manifoldcf.core.interfaces.*;
+
+public class RegisterAll extends TransactionalCrawlerInitializationCommand
+{
+    public static final String _rcsid = "@(#)$Id: RegisterAll.java 988245 2010-08-23 18:39:35Z
kwright $";
+
+    private RegisterAll()
+    {
+    }
+    
+    @Override
+    protected void doExecute(IThreadContext tc) throws ManifoldCFException 
+    {
+      ManifoldCF.initializeEnvironment();
+
+      // Clear the shutdown signal
+      RegsiterConnectors.clearShutdownSignal(tc);
+      
+      // Get the specified superuser name and password, in case this isn't Derby we're using
+      String superuserName = ManifoldCF.getProperty(RegsiterConnectors.databaseSuperuserName);
+      if (superuserName == null)
+        superuserName = "";
+        String superuserPassword = ManifoldCF.getProperty(RegsiterConnectors.databaseSuperuserPassword);
+      if (superuserPassword == null)
+	superuserPassword = "";
+	      
+      // Do the basic initialization of the database and its schema
+      RegsiterConnectors.createDatabaseAndSchema(tc,superuserName,superuserPassword);
+      RegsiterConnectors.registerAgents(tc);
+	      
+      // Read connectors configuration file (to figure out what we need to register)
+      File connectorConfigFile = ManifoldCF.getFileProperty(RegsiterConnectors.connectorsConfigurationFile);
+      Connectors c = RegsiterConnectors.readConnectorDeclarations(connectorConfigFile);
+
+      // Register connections specified by connectors.xml
+      RegsiterConnectors.registerConnectors(tc,c);	
+    }
+    
+    public static void main(String[] args)
+    {
+      if (args.length > 0)
+      {
+        System.err.println("Usage: RegisterAll");
+        System.exit(1);
+      }
+
+      try
+      {
+        RegisterAll register = new RegisterAll();
+        register.execute();
+        System.err.println("Successfully registered all");
+      }
+      catch (ManifoldCFException e)
+      {
+        e.printStackTrace();
+        System.exit(1);
+      }
+    }
+}

Added: incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegsiterConnectors.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegsiterConnectors.java?rev=1214014&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegsiterConnectors.java
(added)
+++ incubator/lcf/branches/CONNECTORS-313/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/RegsiterConnectors.java
Wed Dec 14 01:09:30 2011
@@ -0,0 +1,324 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.manifoldcf.crawler;
+
+import java.io.*;
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.crawler.interfaces.*;
+import org.apache.manifoldcf.authorities.interfaces.*;
+import org.apache.manifoldcf.agents.system.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Resister connectors.
+ * 
+ */
+public class RegsiterConnectors
+{
+
+  public static final String _rcsid = "@(#)$Id: RegsiterConnectors.java 989983 2010-08-27
00:10:12Z kwright $";
+
+  public static final String agentShutdownSignal = org.apache.manifoldcf.agents.AgentRun.agentShutdownSignal;
+
+  // Configuration parameters
+  public static final String connectorsConfigurationFile = "org.apache.manifoldcf.connectorsconfigurationfile";
+  public static final String databaseSuperuserName = "org.apache.manifoldcf.dbsuperusername";
+  public static final String databaseSuperuserPassword = "org.apache.manifoldcf.dbsuperuserpassword";
+  
+  // Connectors configuration file
+  public static final String NODE_OUTPUTCONNECTOR = "outputconnector";
+  public static final String NODE_AUTHORITYCONNECTOR = "authorityconnector";
+  public static final String NODE_REPOSITORYCONNECTOR = "repositoryconnector";
+  public static final String ATTRIBUTE_NAME = "name";
+  public static final String ATTRIBUTE_CLASS = "class";
+  
+  
+  public RegsiterConnectors()
+  {
+  }
+
+  /** Clear the agents shutdown signal */
+  public static void clearShutdownSignal(IThreadContext tc)
+    throws ManifoldCFException
+  {
+    // Clear the agents shutdown signal.
+    ILockManager lockManager = LockManagerFactory.make(tc);
+    lockManager.clearGlobalFlag(agentShutdownSignal);
+  }
+
+  /** Create the database and the schema */
+  public static void createDatabaseAndSchema(IThreadContext tc, String superuserName, String
superuserPassword)
+    throws ManifoldCFException
+  {
+    ManifoldCF.createSystemDatabase(tc,superuserName,superuserPassword);
+    ManifoldCF.installTables(tc);
+  }
+  
+  /** Register the agents */
+  public static void registerAgents(IThreadContext tc)
+    throws ManifoldCFException
+  {
+    // Register 
+    IAgentManager agentMgr = AgentManagerFactory.make(tc);
+    agentMgr.registerAgent("org.apache.manifoldcf.crawler.system.CrawlerAgent");
+  }
+
+  /** Read connectors configuration file.
+  */
+  public static Connectors readConnectorDeclarations(File connectorConfigFile)
+    throws ManifoldCFException
+  {
+    Connectors c = null;
+    if (connectorConfigFile != null)
+    {
+      try
+      {
+        // Open the file, read it, and attempt to do the connector registrations
+        InputStream is = new FileInputStream(connectorConfigFile);
+        try
+        {
+          c = new Connectors(is);
+        }
+        finally
+        {
+          is.close();
+        }
+      }
+      catch (FileNotFoundException e)
+      {
+        throw new ManifoldCFException("Couldn't find connector configuration file: "+e.getMessage(),e);
+      }
+      catch (IOException e)
+      {
+        throw new ManifoldCFException("Error reading connector configuration file: "+e.getMessage(),e);
+      }
+    }
+    return c;
+  }
+
+  /** Unregister all connectors.
+  */
+  public static void unregisterAllConnectors(IThreadContext tc)
+    throws ManifoldCFException
+  {
+    // Grab a database handle, so we can use transactions later.
+    IDBInterface database = DBInterfaceFactory.make(tc,
+      ManifoldCF.getMasterDatabaseName(),
+      ManifoldCF.getMasterDatabaseUsername(),
+      ManifoldCF.getMasterDatabasePassword());
+
+    // Output connectors...
+    {
+      IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+      IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+      IResultSet classNames = mgr.getConnectors();
+      int i = 0;
+      while (i < classNames.getRowCount())
+      {
+        IResultRow row = classNames.getRow(i++);
+        String className = (String)row.getValue("classname");
+        // Deregistration should be done in a transaction
+        database.beginTransaction();
+        try
+        {
+          // Find the connection names that come with this class
+          String[] connectionNames = connManager.findConnectionsForConnector(className);
+          // For all connection names, notify all agents of the deregistration
+          AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+          // Now that all jobs have been placed into an appropriate state, actually do the
deregistration itself.
+          mgr.unregisterConnector(className);
+        }
+        catch (ManifoldCFException e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        catch (Error e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        finally
+        {
+          database.endTransaction();
+        }
+      }
+      System.err.println("Successfully unregistered all output connectors");
+    }
+      
+    // Authority connectors...
+    {
+      IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
+      IResultSet classNames = mgr.getConnectors();
+      int i = 0;
+      while (i < classNames.getRowCount())
+      {
+        IResultRow row = classNames.getRow(i++);
+        mgr.unregisterConnector((String)row.getValue("classname"));
+      }
+      System.err.println("Successfully unregistered all authority connectors");
+    }
+      
+    // Repository connectors...
+    {
+      IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+      IJobManager jobManager = JobManagerFactory.make(tc);
+      IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+      IResultSet classNames = mgr.getConnectors();
+      int i = 0;
+      while (i < classNames.getRowCount())
+      {
+        IResultRow row = classNames.getRow(i++);
+        String className = (String)row.getValue("classname");
+        // Deregistration should be done in a transaction
+        database.beginTransaction();
+        try
+        {
+          // Find the connection names that come with this class
+          String[] connectionNames = connManager.findConnectionsForConnector(className);
+          // For each connection name, modify the jobs to note that the connector is no longer
installed
+          jobManager.noteConnectorDeregistration(connectionNames);
+          // Now that all jobs have been placed into an appropriate state, actually do the
deregistration itself.
+          mgr.unregisterConnector(className);
+        }
+        catch (ManifoldCFException e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        catch (Error e)
+        {
+          database.signalRollback();
+          throw e;
+        }
+        finally
+        {
+          database.endTransaction();
+        }
+      }
+      System.err.println("Successfully unregistered all repository connectors");
+    }
+  }
+
+  /** Register all connectors as specified by a Connectors structure, usually read from the
connectors.xml file.
+  */
+  public static void registerConnectors(IThreadContext tc, Connectors c)
+    throws ManifoldCFException
+  {
+    if (c != null)
+    {
+      // Grab a database handle, so we can use transactions later.
+      IDBInterface database = DBInterfaceFactory.make(tc,
+        ManifoldCF.getMasterDatabaseName(),
+        ManifoldCF.getMasterDatabaseUsername(),
+        ManifoldCF.getMasterDatabasePassword());
+        
+      // Other code will go here to discover and register various connectors that exist in
the classpath
+      int i = 0;
+      while (i < c.getChildCount())
+      {
+        ConfigurationNode cn = c.findChild(i++);
+        if (cn.getType().equals(NODE_OUTPUTCONNECTOR))
+        {
+          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
+          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
+          IOutputConnectorManager mgr = OutputConnectorManagerFactory.make(tc);
+          IOutputConnectionManager connManager = OutputConnectionManagerFactory.make(tc);
+          // Registration should be done in a transaction
+          database.beginTransaction();
+          try
+          {
+            // First, register connector
+            mgr.registerConnector(name,className);
+            // Then, signal to all jobs that might depend on this connector that they can
switch state
+            // Find the connection names that come with this class
+            String[] connectionNames = connManager.findConnectionsForConnector(className);
+            // For all connection names, notify all agents of the registration
+            AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
+          }
+          catch (ManifoldCFException e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          catch (Error e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          finally
+          {
+            database.endTransaction();
+          }
+          System.err.println("Successfully registered output connector '"+className+"'");
+        }
+        else if (cn.getType().equals(NODE_AUTHORITYCONNECTOR))
+        {
+          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
+          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
+          IAuthorityConnectorManager mgr = AuthorityConnectorManagerFactory.make(tc);
+          mgr.registerConnector(name,className);
+          System.err.println("Successfully registered authority connector '"+className+"'");
+        }
+        else if (cn.getType().equals(NODE_REPOSITORYCONNECTOR))
+        {
+          String name = cn.getAttributeValue(ATTRIBUTE_NAME);
+          String className = cn.getAttributeValue(ATTRIBUTE_CLASS);
+          IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+          IJobManager jobManager = JobManagerFactory.make(tc);
+          IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+          // Deregistration should be done in a transaction
+          database.beginTransaction();
+          try
+          {
+            // First, register connector
+            mgr.registerConnector(name,className);
+            // Then, signal to all jobs that might depend on this connector that they can
switch state
+            // Find the connection names that come with this class
+            String[] connectionNames = connManager.findConnectionsForConnector(className);
+            // For each connection name, modify the jobs to note that the connector is now
installed
+            jobManager.noteConnectorRegistration(connectionNames);
+          }
+          catch (ManifoldCFException e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          catch (Error e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          finally
+          {
+            database.endTransaction();
+          }
+          System.err.println("Successfully registered repository connector '"+className+"'");
+        }
+        else
+          throw new ManifoldCFException("Unrecognized connectors node type '"+cn.getType()+"'");
+      }
+    }
+  }
+  
+}
+
+



Mime
View raw message