[Bedework-commit] indexer r98 - in trunk/src/org/bedework/indexer: . crawler

svnadmin at bedework.org svnadmin at bedework.org
Fri Apr 27 16:36:21 EDT 2012


Author: douglm
Date: 2012-04-27 16:36:20 -0400 (Fri, 27 Apr 2012)
New Revision: 98

Modified:
   trunk/src/org/bedework/indexer/BwIndexer.java
   trunk/src/org/bedework/indexer/crawler/Crawl.java
   trunk/src/org/bedework/indexer/crawler/ProcessorBase.java
Log:
Further solr related updates

Modified: trunk/src/org/bedework/indexer/BwIndexer.java
===================================================================
--- trunk/src/org/bedework/indexer/BwIndexer.java	2012-03-13 15:36:55 UTC (rev 97)
+++ trunk/src/org/bedework/indexer/BwIndexer.java	2012-04-27 20:36:20 UTC (rev 98)
@@ -6,9 +6,9 @@
     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
@@ -18,9 +18,12 @@
 */
 package org.bedework.indexer;
 
-import org.bedework.indexer.BwIndexerMBean;
 import org.bedework.indexer.crawler.Crawl.CrawlResult;
 
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -28,9 +31,21 @@
  * @author douglm
  *
  */
-public class BwIndexer extends BwIndexApp implements BwIndexerMBean {
+public class BwIndexer extends BwIndexApp implements BwIndexerMBean, GBeanLifecycle {
   private boolean running;
 
+  /** Geronimo gbean info
+   */
+  public static final GBeanInfo GBEAN_INFO;
+  static {
+    GBeanInfoBuilder infoB =
+        GBeanInfoBuilder.createStatic("Bedework-Indexer", BwIndexer.class);
+    infoB.addAttribute("account", String.class, true);
+    infoB.addAttribute("skipPaths", String.class, true);
+
+    GBEAN_INFO = infoB.getBeanInfo();
+  }
+
   private class ProcessorThread extends Thread {
     boolean showedTrace;
 
@@ -63,6 +78,7 @@
 
   private ProcessorThread processor;
 
+  @Override
   public String getName() {
     /* This apparently must be the same as the name attribute in the
      * jboss service definition
@@ -86,6 +102,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#rebuildIndex()
    */
+  @Override
   public List<String> rebuildIndex() {
     try {
       setIndexBuildLocationPrefix(System.getProperty("org.bedework.data.dir"));
@@ -109,6 +126,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#isStarted()
    */
+  @Override
   public boolean isStarted() {
     return (processor != null) && processor.isAlive();
   }
@@ -116,6 +134,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#start()
    */
+  @Override
   public synchronized void start() {
     if (processor != null) {
       error("Already started");
@@ -135,6 +154,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#stop()
    */
+  @Override
   public synchronized void stop() {
     if (processor == null) {
       error("Already stopped");
@@ -166,6 +186,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#setSkipPaths(java.lang.String)
    */
+  @Override
   public void setSkipPaths(final String val) {
     String[] paths = val.split(":");
 
@@ -179,6 +200,7 @@
   /* (non-Javadoc)
    * @see org.bedework.indexer.BwIndexerMBean#getSkipPaths()
    */
+  @Override
   public String getSkipPaths() {
     String delim = "";
     StringBuilder sb = new StringBuilder();
@@ -192,4 +214,30 @@
 
     return sb.toString();
   }
+
+  /* ========================================================================
+   * Geronimo lifecycle methods
+   * ======================================================================== */
+
+  /**
+   * @return gbean info
+   */
+  public static GBeanInfo getGBeanInfo() {
+    return GBEAN_INFO;
+  }
+
+  @Override
+  public void doFail() {
+    stop();
+  }
+
+  @Override
+  public void doStart() throws Exception {
+    start();
+  }
+
+  @Override
+  public void doStop() throws Exception {
+    stop();
+  }
 }

Modified: trunk/src/org/bedework/indexer/crawler/Crawl.java
===================================================================
--- trunk/src/org/bedework/indexer/crawler/Crawl.java	2012-03-13 15:36:55 UTC (rev 97)
+++ trunk/src/org/bedework/indexer/crawler/Crawl.java	2012-04-27 20:36:20 UTC (rev 98)
@@ -6,9 +6,9 @@
     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
@@ -18,9 +18,12 @@
 */
 package org.bedework.indexer.crawler;
 
+import org.bedework.calfacade.BwSystem;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calsvc.indexing.BwIndexLuceneDefs;
 import org.bedework.calsvc.indexing.BwIndexer;
+import org.bedework.calsvc.indexing.BwIndexerFactory;
+import org.bedework.calsvci.CalSvcI;
 import org.bedework.indexer.CalSys;
 
 import edu.rpi.sss.util.DateTimeUtil;
@@ -55,7 +58,7 @@
 public class Crawl extends CalSys {
   private String indexBuildLocation;
 
-  private String indexBuildLocationPrefix;
+  //private String indexBuildLocationPrefix;
 
   protected long batchDelay;
   protected long entityDelay;
@@ -107,6 +110,12 @@
     public List<String> infoLines = new ArrayList<String>();
   }
 
+  static class Indexes {
+    String publicIndex;
+
+    String userIndex;
+  }
+
   /**
    * @return CrawlResult
    * @throws CalFacadeException
@@ -114,20 +123,8 @@
   public CrawlResult crawl() throws CalFacadeException {
     CrawlResult cr = new CrawlResult();
 
-    /* First set up a new directory - see if new exists - if so delete */
-    String newPath = getPath(indexBuildLocation,
-                             BwIndexLuceneDefs.newIndexname);
+    Indexes idxs = newIndexes(cr);
 
-    boolean newExisted = exists(newPath);
-
-    outInfo(cr, "About to build directories at " + newPath);
-
-    if (newExisted) {
-      remove(newPath);
-    }
-
-    create(newPath);
-
     /* Now we can reindex into the new directory */
 
     UserProcessor uproc = new UserProcessor("User",
@@ -135,7 +132,7 @@
                                             2000,   // batchDelay,
                                             100,    // entityDelay,
                                             skipPaths,
-                                            newPath,
+                                            idxs.userIndex,
                                             userThreads,
                                             maxUserThreads);
     uproc.start("/" + getUserCalendarRoot());
@@ -145,7 +142,7 @@
                                                 2000,   // batchDelay,
                                                 100,    // entityDelay,
                                                 skipPaths,
-                                                newPath,
+                                                idxs.publicIndex,
                                                 publicThreads,
                                                 maxPublicThreads);
     pproc.start("/" + getPublicCalendarRoot());
@@ -156,6 +153,57 @@
     cr.infoLines.addAll(uproc.getStats().statsList());
     cr.infoLines.addAll(pproc.getStats().statsList());
 
+    endIndexing(cr, idxs);
+
+    return cr;
+  }
+
+  private Indexes newIndexes(final CrawlResult cr) throws CalFacadeException {
+    Indexes idxs = new Indexes();
+
+    /* First set up a new directory - see if new exists - if so delete */
+    idxs.userIndex = getPath(indexBuildLocation,
+                             BwIndexLuceneDefs.newIndexname);
+
+    boolean newExisted = exists(idxs.userIndex);
+
+    outInfo(cr, "About to build directories at " + idxs.userIndex);
+
+    if (newExisted) {
+      remove(idxs.userIndex);
+    }
+
+    create(idxs.userIndex);
+
+    CalSvcI svci = getAdminSvci();
+
+    BwSystem sys = svci.getSysparsHandler().get();
+
+    if (!sys.getUseSolr()) {
+      idxs.publicIndex = idxs.userIndex;
+      return idxs;
+    }
+
+    // Switch public indexes.
+
+    String defName = sys.getSolrDefaultCore();
+
+    idxs.publicIndex = defName + "-" + DateTimeUtil.isoDateTime();
+
+    BwIndexer idx = BwIndexerFactory.getIndexer(true, adminAccount, true, sys,
+                                                idxs.publicIndex,
+                                                sys.getSolrCoreAdmin());
+
+    idx.newIndex(idxs.publicIndex);
+
+    return idxs;
+  }
+
+  private void endIndexing(final CrawlResult cr,
+                           final Indexes idxs) throws CalFacadeException {
+    /* If it's lucene both public and user are the same.
+     */
+
     /* Rename directories */
     String oldPath = getPath(indexBuildLocation,
                              BwIndexLuceneDefs.oldIndexname);
@@ -179,15 +227,15 @@
         outErr(cr, "Unable to rename current index at " + currentPath +
                    "  to " + oldPath);
 
-        return cr;
+        return;
       }
     }
 
-    outInfo(cr, "About to rename directories from " + newPath +
+    outInfo(cr, "About to rename directories from " + idxs.userIndex +
                 "  to " + currentPath);
 
-    if (!rename(newPath, currentPath)) {
-      outErr(cr, "Unable to rename new index at " + newPath +
+    if (!rename(idxs.userIndex, currentPath)) {
+      outErr(cr, "Unable to rename new index at " + idxs.userIndex +
                  "  to " + currentPath +
                  " attempting to rename old back to current");
       if (!rename(oldPath, currentPath)) {
@@ -196,11 +244,25 @@
                    "  from " + oldPath);
       }
 
-      return cr;
+      return;
     }
 
+    CalSvcI svci = getAdminSvci();
+
+    BwSystem sys = svci.getSysparsHandler().get();
+
+    if (!sys.getUseSolr()) {
+      cr.ok = true;
+      return;
+    }
+
+    BwIndexer idx = BwIndexerFactory.getIndexer(true, adminAccount, true, sys,
+                                                idxs.publicIndex,
+                                                sys.getSolrCoreAdmin());
+
+    idx.swapIndex(idxs.publicIndex, sys.getSolrDefaultCore());
+
     cr.ok = true;
-    return cr;
   }
 
   private void outInfo(final CrawlResult cr, final String msg) {

Modified: trunk/src/org/bedework/indexer/crawler/ProcessorBase.java
===================================================================
--- trunk/src/org/bedework/indexer/crawler/ProcessorBase.java	2012-03-13 15:36:55 UTC (rev 97)
+++ trunk/src/org/bedework/indexer/crawler/ProcessorBase.java	2012-04-27 20:36:20 UTC (rev 98)
@@ -6,9 +6,9 @@
     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
@@ -27,8 +27,8 @@
 import org.bedework.indexer.CalSys;
 import org.bedework.indexer.EntityIndexerThread;
 import org.bedework.indexer.IndexStats;
+import org.bedework.indexer.IndexStats.StatType;
 import org.bedework.indexer.ThreadPool;
-import org.bedework.indexer.IndexStats.StatType;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -118,6 +118,7 @@
     return tpool;
   }
 
+  @Override
   public String getCurrentPath() throws CalFacadeException {
     return currentPath;
   }
@@ -216,7 +217,9 @@
     }
 
     return BwIndexerFactory.getIndexer(publick, principal,
-                                       true, getSyspars(), indexRootPath);
+                                       true, getSyspars(),
+                                       indexRootPath,
+                                       null);
   }
 
   @Override



More information about the Bedework-commit mailing list