incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r960994 [2/2] - in /incubator/lcf/trunk/modules: ./ connectors/jcifs/ framework/ framework/core/org/apache/lcf/core/common/ framework/core/org/apache/lcf/core/interfaces/ framework/core/org/apache/lcf/core/system/ framework/crawler-ui/ fram...
Date Tue, 06 Jul 2010 19:45:54 GMT
Modified: incubator/lcf/trunk/modules/framework/jetty-runner/org/apache/lcf/jettyrunner/LCFJettyRunner.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/jetty-runner/org/apache/lcf/jettyrunner/LCFJettyRunner.java?rev=960994&r1=960993&r2=960994&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/jetty-runner/org/apache/lcf/jettyrunner/LCFJettyRunner.java
(original)
+++ incubator/lcf/trunk/modules/framework/jetty-runner/org/apache/lcf/jettyrunner/LCFJettyRunner.java
Tue Jul  6 19:45:53 2010
@@ -20,6 +20,8 @@ package org.apache.lcf.jettyrunner;
 import java.io.*;
 import org.apache.lcf.core.interfaces.*;
 import org.apache.lcf.agents.interfaces.*;
+import org.apache.lcf.crawler.interfaces.*;
+import org.apache.lcf.authorities.interfaces.*;
 import org.apache.lcf.agents.system.*;
 
 import java.io.IOException;
@@ -49,6 +51,16 @@ public class LCFJettyRunner
 
   public static final String agentShutdownSignal = org.apache.lcf.agents.AgentRun.agentShutdownSignal;
 
+  // Configuration parameters
+  public static final String connectorsConfigurationFile = "org.apache.lcf.connectorsconfigurationfile";
+  
+  // 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;
   
   public LCFJettyRunner( int port, String crawlerWarPath, String authorityServiceWarPath
)
@@ -126,26 +138,36 @@ public class LCFJettyRunner
    */
   public static void main( String[] args )
   {
-    if (args.length != 3)
+    if (args.length != 3 && args.length != 1 && args.length != 0)
     {
-      System.err.println("Usage: LCFJettyRunner <port> <crawler-war-path> <authority-service-war-path>");
+      System.err.println("Usage: LCFJettyRunner [<port> [<crawler-war-path> <authority-service-war-path>]]");
       System.exit(1);
     }
 
-    int jettyPort = 8888;
-    try
+    int jettyPort = 8345;
+    if (args.length > 0)
     {
-      jettyPort = Integer.parseInt(args[0]);
+      try
+      {
+        jettyPort = Integer.parseInt(args[0]);
+      }
+      catch (NumberFormatException e)
+      {
+        e.printStackTrace(System.err);
+        System.exit(1);
+      }
     }
-    catch (NumberFormatException e)
+    
+    String crawlerWarPath = "war/lcf-crawler-ui.war";
+    String authorityserviceWarPath = "war/lcf-authority-service.war";
+    if (args.length == 3)
     {
-      e.printStackTrace(System.err);
-      System.exit(1);
+      crawlerWarPath = args[1];
+      authorityserviceWarPath = args[2];
     }
     
     // Ready to begin in earnest...
-    
-    
+        
     try
     {
       LCF.initializeEnvironment();
@@ -155,19 +177,234 @@ public class LCFJettyRunner
       ILockManager lockManager = LockManagerFactory.make(tc);
       lockManager.clearGlobalFlag(agentShutdownSignal);
 
+      // Grab a database handle, so we can use transactions later.
+      IDBInterface database = DBInterfaceFactory.make(tc,
+        LCF.getMasterDatabaseName(),
+        LCF.getMasterDatabaseUsername(),
+        LCF.getMasterDatabasePassword());
+
       // Do the basic initialization of the database and its schema
       LCF.createSystemDatabase(tc,"","");
       LCF.installTables(tc);
-      IAgentManager mgr = AgentManagerFactory.make(tc);
-      mgr.registerAgent("org.apache.lcf.crawler.system.CrawlerAgent");
+      IAgentManager agentMgr = AgentManagerFactory.make(tc);
+      agentMgr.registerAgent("org.apache.lcf.crawler.system.CrawlerAgent");
 
-      // Other code will go here to discover and register various connectors that exist in
the classpath
-      // MHL
+      // Read connectors configuration file (to figure out what we need to register)
+      Connectors c = null;
+      File connectorConfigFile = LCF.getFileProperty(connectorsConfigurationFile);
+      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 LCFException("Couldn't find connector configuration file: "+e.getMessage(),e);
+        }
+        catch (IOException e)
+        {
+          throw new LCFException("Error reading connector configuration file: "+e.getMessage(),e);
+        }
+      }
+      
+      // Unregister all connectors.
+      
+      // 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 (LCFException 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 (LCFException e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          catch (Error e)
+          {
+            database.signalRollback();
+            throw e;
+          }
+          finally
+          {
+            database.endTransaction();
+          }
+        }
+        System.err.println("Successfully unregistered all repository connectors");
+      }
+      
+      if (c != null)
+      {
 
+        // 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 (LCFException 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 (LCFException 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 LCFException("Unrecognized connectors node type '"+cn.getType()+"'");
+        }
+      }
+      
       System.err.println("Starting jetty...");
       
       // Create a jetty instance
-      LCFJettyRunner jetty = new LCFJettyRunner(jettyPort,args[1],args[2]);
+      LCFJettyRunner jetty = new LCFJettyRunner(jettyPort,crawlerWarPath,authorityserviceWarPath);
       // This will register a shutdown hook as well.
       jetty.start();
 



Mime
View raw message