You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2017/08/10 05:32:59 UTC

[1/6] oodt git commit: - add default blankX struct methods - safeguard against loss of connection to File Manager in FileManagerUtils - safeguard against PCS services FM going down

Repository: oodt
Updated Branches:
  refs/heads/feature/zookeeper-config 1d70bd559 -> 905bb87c7


- add default blankX struct methods
- safeguard against loss of connection to File Manager in
FileManagerUtils
- safeguard against PCS services FM going down

Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/4af396fe
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/4af396fe
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/4af396fe

Branch: refs/heads/feature/zookeeper-config
Commit: 4af396fe9834f0e86242cf2f9023061a307d7261
Parents: 1e1fc1a
Author: Chris Mattmann <ma...@apache.org>
Authored: Fri Jul 28 21:55:01 2017 -0700
Committer: Chris Mattmann <ma...@apache.org>
Committed: Fri Jul 28 21:55:01 2017 -0700

----------------------------------------------------------------------
 .../oodt/cas/filemgr/structs/Element.java       | 10 ++
 .../oodt/cas/filemgr/structs/ProductType.java   | 14 +++
 .../apache/oodt/pcs/util/FileManagerUtils.java  | 98 ++++++++++++++------
 3 files changed, 94 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/4af396fe/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/Element.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/Element.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/Element.java
index d4e3838..520e0f3 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/Element.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/Element.java
@@ -138,5 +138,15 @@ public class Element {
     public void setDescription(String description) {
         this.description = description;
     }  
+    
+    public static Element blankElement(){
+      Element e = new Element();
+      e.setDCElement("");
+      e.setDescription("blank");
+      e.setElementId("");
+      e.setElementName("blank");
+      return e;
+      
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/oodt/blob/4af396fe/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/ProductType.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/ProductType.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/ProductType.java
index 88eb9dc..4458fba 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/ProductType.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/ProductType.java
@@ -17,6 +17,7 @@
 
 package org.apache.oodt.cas.filemgr.structs;
 
+import java.util.Collections;
 //JDK imports
 import java.util.List;
 import java.util.Vector;
@@ -200,6 +201,19 @@ public class ProductType {
     public String toString() {
         return this.name;
     }
+    
+    public static ProductType blankProductType(){
+      ProductType type = new ProductType();
+      type.setDescription("blank");
+      type.setExtractors(Collections.EMPTY_LIST);
+      type.setHandlers(Collections.EMPTY_LIST);
+      type.setName("blank");
+      type.setProductRepositoryPath("");
+      type.setProductTypeId("");
+      type.setTypeMetadata(new Metadata());
+      type.setVersioner("");
+      return type;
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/oodt/blob/4af396fe/pcs/core/src/main/java/org/apache/oodt/pcs/util/FileManagerUtils.java
----------------------------------------------------------------------
diff --git a/pcs/core/src/main/java/org/apache/oodt/pcs/util/FileManagerUtils.java b/pcs/core/src/main/java/org/apache/oodt/pcs/util/FileManagerUtils.java
index aecefb7..4388855 100644
--- a/pcs/core/src/main/java/org/apache/oodt/pcs/util/FileManagerUtils.java
+++ b/pcs/core/src/main/java/org/apache/oodt/pcs/util/FileManagerUtils.java
@@ -39,6 +39,7 @@ import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Collections;
 import java.util.List;
 import java.util.Vector;
 import java.util.logging.Level;
@@ -66,8 +67,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
     try {
       fmgrClient = new XmlRpcFileManagerClient(fileMgrUrl);
     } catch (ConnectionException e) {
-      LOG.log(Level.SEVERE, "Unable to connect to file manager: ["
-          + fileMgrUrl.toString() + "]");
+      LOG.log(Level.SEVERE,
+          "Unable to connect to file manager: [" + fileMgrUrl.toString() + "]");
       fmgrClient = null;
     }
 
@@ -83,6 +84,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public List safeGetTopNProducts(int n) {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     try {
       return this.fmgrClient.getTopNProducts(n);
     } catch (Exception e) {
@@ -92,7 +95,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
     }
   }
 
-  public Product getLatestProductByName(String prodName, String productTypeName) {
+  public Product getLatestProductByName(String prodName,
+      String productTypeName) {
     return getLatestProductByName(prodName,
         safeGetProductTypeByName(productTypeName));
   }
@@ -163,7 +167,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
     if (productTypes != null && productTypes.size() > 0) {
       for (Object productType : productTypes) {
         ProductType type = (ProductType) productType;
-        if (excludeTypeList != null && excludeTypeList.contains(type.getName())) {
+        if (excludeTypeList != null
+            && excludeTypeList.contains(type.getName())) {
           continue;
         }
 
@@ -196,14 +201,18 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public List safeIssueQuery(Query query, ProductType type) {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     List retProds = null;
 
     try {
       retProds = this.fmgrClient.query(query, type);
     } catch (Exception e) {
-      LOG.log(Level.WARNING, "Exception issuing query: [" + query
-          + "] to file manager at: [" + this.fmgrClient.getFileManagerUrl()
-          + "]: Message: " + e.getMessage(), e);
+      LOG.log(Level.WARNING,
+          "Exception issuing query: [" + query + "] to file manager at: ["
+              + this.fmgrClient.getFileManagerUrl() + "]: Message: "
+              + e.getMessage(),
+          e);
     }
 
     return retProds;
@@ -211,6 +220,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public Element safeGetElementByName(String elemName) {
+    if (!isConnected())
+      return Element.blankElement();
     Element element = null;
 
     try {
@@ -225,6 +236,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public ProductType safeGetProductTypeByName(String productTypeName) {
+    if (!isConnected())
+      return ProductType.blankProductType();
     ProductType type = null;
 
     try {
@@ -238,6 +251,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public ProductType safeGetProductTypeById(String productTypeId) {
+    if (!isConnected())
+      return ProductType.blankProductType();
     ProductType type = null;
 
     try {
@@ -251,20 +266,24 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public List safeGetProductReferences(Product product) {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     List refs = null;
 
     try {
       refs = fmgrClient.getProductReferences(product);
     } catch (Exception e) {
-      LOG.log(Level.WARNING, "Exception obtaining product references"
-          + "for product: [" + product.getProductName() + "]: Message: "
-          + e.getMessage());
+      LOG.log(Level.WARNING,
+          "Exception obtaining product references" + "for product: ["
+              + product.getProductName() + "]: Message: " + e.getMessage());
     }
 
     return refs;
   }
 
   public Metadata safeGetMetadata(Product product) {
+    if (!isConnected())
+      return new Metadata();
     Metadata metadata = null;
 
     try {
@@ -279,6 +298,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public List safeGetProductTypes() {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     List types = null;
 
     try {
@@ -293,6 +314,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public Product getLatestProduct(Query query, ProductType type) {
+    if (!isConnected())
+      return Product.getDefaultFlatProduct("", "");
     List products;
 
     try {
@@ -312,6 +335,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public Product safeGetProductByName(String prodName) {
+    if (!isConnected())
+      return Product.getDefaultFlatProduct("", "");
     Product p = null;
 
     try {
@@ -323,34 +348,39 @@ public class FileManagerUtils implements PCSConfigMetadata {
 
     return p;
   }
-  
 
   /**
    * Gets the number of products for the given type.
-   * @param type The given type.
+   * 
+   * @param type
+   *          The given type.
    * @return The number of products.
    */
-  public int safeGetNumProducts(ProductType type){
+  public int safeGetNumProducts(ProductType type) {
+    if (!isConnected())
+      return -1;
     int numProducts = -1;
-    try{
+    try {
       numProducts = this.fmgrClient.getNumProducts(type);
-    }
-    catch(Exception e){
+    } catch (Exception e) {
       e.printStackTrace();
-      LOG.warning("Exception getting num products by type: ["+type.getName()+"]: "
-          + "Message: "+e.getLocalizedMessage());
+      LOG.warning("Exception getting num products by type: [" + type.getName()
+          + "]: " + "Message: " + e.getLocalizedMessage());
     }
-    
+
     return numProducts;
   }
 
-  
   /**
    * Get a first page of Products using the pagination API.
-   * @param type Gets the first page of products for this type.
+   * 
+   * @param type
+   *          Gets the first page of products for this type.
    * @return The first page of products for this type.
    */
   public ProductPage safeFirstPage(ProductType type) {
+    if (!isConnected())
+      return ProductPage.blankPage();
     ProductPage page = null;
     try {
       page = this.fmgrClient.getFirstPage(type);
@@ -361,13 +391,15 @@ public class FileManagerUtils implements PCSConfigMetadata {
   }
 
   public String getFilePath(Product prod) {
+    if (!isConnected())
+      return "N/A";
     if (prod.getProductReferences() == null) {
       prod.setProductReferences(safeGetProductReferences(prod));
     }
 
     if (prod.getProductReferences() == null
-        || (prod.getProductReferences() != null && prod.getProductReferences()
-            .size() == 0)) {
+        || (prod.getProductReferences() != null
+            && prod.getProductReferences().size() == 0)) {
       return "N/A";
     }
 
@@ -457,7 +489,8 @@ public class FileManagerUtils implements PCSConfigMetadata {
   public static String getDirProductFilePath(Product p, String prodName) {
     return FileManagerUtils.safeGetFileFromUri(
         FileManagerUtils.getRootReference(prodName, p.getProductReferences())
-            .getOrigReference()).getAbsolutePath();
+            .getOrigReference())
+        .getAbsolutePath();
   }
 
   public static Reference getRootReference(String productName, List refs) {
@@ -478,12 +511,21 @@ public class FileManagerUtils implements PCSConfigMetadata {
       return false;
     } else {
       String referenceURI = r.getOrigReference();
-      int lastFolderInPathStartIdx = referenceURI.substring(0,
-          referenceURI.length() - 1).lastIndexOf("/") + 1;
-      String lastFolderInPath = referenceURI.substring(
-          lastFolderInPathStartIdx, referenceURI.length() - 1);
+      int lastFolderInPathStartIdx = referenceURI
+          .substring(0, referenceURI.length() - 1).lastIndexOf("/") + 1;
+      String lastFolderInPath = referenceURI.substring(lastFolderInPathStartIdx,
+          referenceURI.length() - 1);
       return lastFolderInPath.startsWith(prodName);
     }
   }
 
+  private boolean isConnected() {
+    if (this.fmgrClient == null) {
+      LOG.warning(
+          "Not connected to File Manager: Default Products, References, Metadata and other objects will be returned.");
+      return false;
+    } else
+      return true;
+  }
+
 }


[5/6] oodt git commit: - getElementsByProductType needs to use XmlRpc compat Hashtable in its IF method (fixes NoSuchMethod error)

Posted by ma...@apache.org.
- getElementsByProductType needs to use XmlRpc compat Hashtable in its
IF method (fixes NoSuchMethod error)

Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/a721243e
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/a721243e
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/a721243e

Branch: refs/heads/feature/zookeeper-config
Commit: a721243ebebba749fe18c414e3d3d5fd6c27f12a
Parents: 5f1a8e8
Author: Chris Mattmann <ma...@apache.org>
Authored: Sat Jul 29 13:52:54 2017 -0700
Committer: Chris Mattmann <ma...@apache.org>
Committed: Sat Jul 29 13:52:54 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/a721243e/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
index beba420..4e17327 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
@@ -617,7 +617,7 @@ public class XmlRpcFileManager {
   }
 
   public List<Map<String, Object>> getElementsByProductType(
-      Map<String, Object> productTypeHash)
+      Hashtable<String, Object> productTypeHash)
       throws ValidationLayerException {
     ProductType type = XmlRpcStructFactory
         .getProductTypeFromXmlRpc(productTypeHash);


[2/6] oodt git commit: safeguard against loss of Connection to FM and NPEs

Posted by ma...@apache.org.
safeguard against loss of Connection to FM and NPEs

Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/f415976d
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/f415976d
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/f415976d

Branch: refs/heads/feature/zookeeper-config
Commit: f415976da06334dce5500d8ac77355a5d90b9344
Parents: 4af396f
Author: Chris Mattmann <ma...@apache.org>
Authored: Fri Jul 28 22:04:15 2017 -0700
Committer: Chris Mattmann <ma...@apache.org>
Committed: Fri Jul 28 22:04:15 2017 -0700

----------------------------------------------------------------------
 .../webcomponents/filemgr/FileManagerConn.java  | 42 +++++++++++++++-----
 1 file changed, 32 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/f415976d/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java
----------------------------------------------------------------------
diff --git a/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java b/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java
index cdcf4c7..41c757a 100644
--- a/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java
+++ b/webapp/components/src/main/java/org/apache/oodt/cas/webcomponents/filemgr/FileManagerConn.java
@@ -28,6 +28,7 @@ import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
 import org.apache.oodt.cas.metadata.Metadata;
 
 import java.net.URL;
+import java.util.Collections;
 import java.util.List;
 import java.util.Vector;
 import java.util.logging.Level;
@@ -45,8 +46,8 @@ public class FileManagerConn {
 
   private XmlRpcFileManagerClient fm;
 
-  private static final Logger LOG = Logger.getLogger(FileManagerConn.class
-      .getName());
+  private static final Logger LOG = Logger
+      .getLogger(FileManagerConn.class.getName());
 
   public FileManagerConn(String fmUrlStr) {
     this.initFm(fmUrlStr);
@@ -54,13 +55,15 @@ public class FileManagerConn {
 
   public String getProdReceivedTime(Product p) {
     Metadata met = getMetadata(p);
-    String prodReceivedTime = met.getMetadata("CAS."
-        + CoreMetKeys.PRODUCT_RECEVIED_TIME);
-    return prodReceivedTime != null && !prodReceivedTime.equals("") ? prodReceivedTime
-        : "UNKNOWN";
+    String prodReceivedTime = met
+        .getMetadata("CAS." + CoreMetKeys.PRODUCT_RECEVIED_TIME);
+    return prodReceivedTime != null && !prodReceivedTime.equals("")
+        ? prodReceivedTime : "UNKNOWN";
   }
 
   public List<Reference> getProductReferences(Product p) {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     List<Reference> refs = new Vector<Reference>();
     try {
       refs = fm.getProductReferences(p);
@@ -73,6 +76,8 @@ public class FileManagerConn {
   }
 
   public ProductType safeGetProductTypeByName(String name) {
+    if (!isConnected())
+      return ProductType.blankProductType();
     try {
       return fm.getProductTypeByName(name);
     } catch (Exception e) {
@@ -83,6 +88,8 @@ public class FileManagerConn {
   }
 
   public Product safeGetProductById(String id) {
+    if (!isConnected())
+      return Product.getDefaultFlatProduct("", "");
     try {
       return fm.getProductById(id);
     } catch (Exception e) {
@@ -93,6 +100,8 @@ public class FileManagerConn {
   }
 
   public Metadata getMetadata(Product p) {
+    if (!isConnected())
+      return new Metadata();
     Metadata met = null;
     try {
       met = fm.getMetadata(p);
@@ -106,6 +115,8 @@ public class FileManagerConn {
   }
 
   public List<Element> safeGetElementsForProductType(ProductType type) {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     try {
       return fm.getElementsByProductType(type);
     } catch (Exception e) {
@@ -116,13 +127,15 @@ public class FileManagerConn {
   }
 
   public List<ProductType> safeGetProductTypes() {
+    if (!isConnected())
+      return Collections.EMPTY_LIST;
     List<ProductType> types = new Vector<ProductType>();
     try {
       types = this.fm.getProductTypes();
     } catch (RepositoryManagerException e) {
       LOG.log(Level.SEVERE, e.getMessage());
-      LOG.log(Level.WARNING, "Unable to obtain product types: Reason: ["
-          + e.getMessage() + "]");
+      LOG.log(Level.WARNING,
+          "Unable to obtain product types: Reason: [" + e.getMessage() + "]");
     }
     return types;
   }
@@ -135,10 +148,19 @@ public class FileManagerConn {
     try {
       this.fm = new XmlRpcFileManagerClient(new URL(urlStr));
     } catch (Exception e) {
-      LOG.log(Level.WARNING, "Unable to connect to the file manager at: ["
-          + urlStr + "]");
+      LOG.log(Level.WARNING,
+          "Unable to connect to the file manager at: [" + urlStr + "]");
       this.fm = null;
     }
   }
 
+  private boolean isConnected() {
+    if (this.fm == null) {
+      LOG.warning(
+          "File Manager Connection is null: Default objects for Products, Product Types, References, etc., will be returned.");
+      return false;
+    } else
+      return true;
+  }
+
 }


[4/6] oodt git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/oodt

Posted by ma...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/oodt


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/5f1a8e8e
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/5f1a8e8e
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/5f1a8e8e

Branch: refs/heads/feature/zookeeper-config
Commit: 5f1a8e8e3f3045c1a30b52e3d18305e0f7fb9bc2
Parents: e3d5d03 f415976
Author: Tom Barber <to...@analytical-labs.com>
Authored: Sat Jul 29 19:24:39 2017 +0100
Committer: Tom Barber <to...@analytical-labs.com>
Committed: Sat Jul 29 19:24:39 2017 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 agility/setup.py                                |  2 +-
 core/pom.xml                                    |  2 +-
 .../oodt/cas/filemgr/structs/Element.java       | 10 ++
 .../oodt/cas/filemgr/structs/ProductType.java   | 14 +++
 .../apache/oodt/pcs/util/FileManagerUtils.java  | 98 ++++++++++++++------
 .../webcomponents/filemgr/FileManagerConn.java  | 42 +++++++--
 7 files changed, 130 insertions(+), 40 deletions(-)
----------------------------------------------------------------------



[6/6] oodt git commit: Merge branch 'master' into feature/zookeeper-config

Posted by ma...@apache.org.
Merge branch 'master' into feature/zookeeper-config


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/905bb87c
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/905bb87c
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/905bb87c

Branch: refs/heads/feature/zookeeper-config
Commit: 905bb87c7df008d3784e5733f269a302680810e0
Parents: 1d70bd5 a721243
Author: Chris Mattmann <ma...@apache.org>
Authored: Wed Aug 9 22:32:41 2017 -0700
Committer: Chris Mattmann <ma...@apache.org>
Committed: Wed Aug 9 22:32:41 2017 -0700

----------------------------------------------------------------------
 .../oodt/cas/filemgr/catalog/LuceneCatalog.java | 120 ++++++++++---------
 .../oodt/cas/filemgr/structs/Element.java       |  10 ++
 .../oodt/cas/filemgr/structs/ProductType.java   |  14 +++
 .../cas/filemgr/system/XmlRpcFileManager.java   |   2 +-
 .../apache/oodt/pcs/util/FileManagerUtils.java  |  98 ++++++++++-----
 .../webcomponents/filemgr/FileManagerConn.java  |  42 +++++--
 6 files changed, 191 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/905bb87c/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/XmlRpcFileManager.java
----------------------------------------------------------------------


[3/6] oodt git commit: Fix numHits error in Lucene Catalog

Posted by ma...@apache.org.
Fix numHits error in Lucene Catalog


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/e3d5d03a
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/e3d5d03a
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/e3d5d03a

Branch: refs/heads/feature/zookeeper-config
Commit: e3d5d03a4761b1ae0ee8daaeb55173c937275fbe
Parents: f04b88e
Author: Tom Barber <to...@analytical-labs.com>
Authored: Sat Jul 29 19:24:21 2017 +0100
Committer: Tom Barber <to...@analytical-labs.com>
Committed: Sat Jul 29 19:24:21 2017 +0100

----------------------------------------------------------------------
 .../oodt/cas/filemgr/catalog/LuceneCatalog.java | 120 ++++++++++---------
 1 file changed, 64 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/e3d5d03a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
index ae218d8..59ded25 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
@@ -526,25 +526,26 @@ public class LuceneCatalog implements Catalog {
                     SortField.Type.STRING, true));
             //TODO FIX NUMBER OF RECORDS
             TopDocs check = searcher.search(query, 1, sort);
-            TopDocs topDocs = searcher.search(query, check.totalHits, sort);
+            if(check.totalHits>0) {
+                TopDocs topDocs = searcher.search(query, check.totalHits, sort);
 
-            ScoreDoc[] hits = topDocs.scoreDocs;
+                ScoreDoc[] hits = topDocs.scoreDocs;
 
-            // should be > 0 hits
-            if (hits.length > 0) {
-                products = new Vector<Product>(hits.length);
-                for (ScoreDoc hit : hits) {
-                    Document productDoc = searcher.doc(hit.doc);
-                    CompleteProduct prod = toCompleteProduct(productDoc,
+                // should be > 0 hits
+                if (hits.length > 0) {
+                    products = new Vector<Product>(hits.length);
+                    for (ScoreDoc hit : hits) {
+                        Document productDoc = searcher.doc(hit.doc);
+                        CompleteProduct prod = toCompleteProduct(productDoc,
                             getRefs, false);
-                    products.add(prod.getProduct());
-                }
-            } else {
-                LOG.log(Level.FINEST,
+                        products.add(prod.getProduct());
+                    }
+                } else {
+                    LOG.log(Level.FINEST,
                         "Request for products returned no results");
-                return null;
+                    return null;
+                }
             }
-
         } catch (IOException e) {
             LOG.log(Level.WARNING,
                     "IOException when opening index directory: ["
@@ -592,23 +593,25 @@ public class LuceneCatalog implements Catalog {
                     SortField.Type.STRING, true));
             //TODO FIX NUMBER OF RECORDS
             TopDocs check = searcher.search(query, 1, sort);
-            TopDocs topDocs = searcher.search(query, check.totalHits, sort);
+            if(check.totalHits>0) {
+                TopDocs topDocs = searcher.search(query, check.totalHits, sort);
 
-            ScoreDoc[] hits = topDocs.scoreDocs;
+                ScoreDoc[] hits = topDocs.scoreDocs;
 
-            // should be > 0 hits
-            if (hits.length > 0) {
-                products = new Vector<Product>(hits.length);
-                for (ScoreDoc hit : hits) {
-                    Document productDoc = searcher.doc(hit.doc);
-                    CompleteProduct prod = toCompleteProduct(productDoc,
+                // should be > 0 hits
+                if (hits.length > 0) {
+                    products = new Vector<Product>(hits.length);
+                    for (ScoreDoc hit : hits) {
+                        Document productDoc = searcher.doc(hit.doc);
+                        CompleteProduct prod = toCompleteProduct(productDoc,
                             getRefs, false);
-                    products.add(prod.getProduct());
-                }
-            } else {
-                LOG.log(Level.FINEST, "Request for products by type: ["
+                        products.add(prod.getProduct());
+                    }
+                } else {
+                    LOG.log(Level.FINEST, "Request for products by type: ["
                         + type.getProductTypeId() + "] returned no results");
-                return null;
+                    return null;
+                }
             }
 
         } catch (IOException e) {
@@ -796,7 +799,9 @@ public class LuceneCatalog implements Catalog {
 
         for (int pageNum = 1; pageNum < numPages + 1; pageNum++) {
             List<Product> pageProducts = paginateQuery(query, type, pageNum, null);
+            if(pageProducts!=null) {
                 products.addAll(pageProducts);
+            }
         }
 
         if(n<=products.size()) {
@@ -1374,59 +1379,61 @@ public class LuceneCatalog implements Catalog {
             TermQuery prodTypeTermQuery = new TermQuery(new Term(
                     "product_type_id", type.getProductTypeId()));
             booleanQuery.add(prodTypeTermQuery, BooleanClause.Occur.MUST);
-            
+
             //convert filemgr query into a lucene query
             for (QueryCriteria queryCriteria : query.getCriteria()) {
                 booleanQuery.add(this.getQuery(queryCriteria), BooleanClause.Occur.MUST);
             }
-            
+
             Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                     SortField.Type.STRING, true));
             LOG.log(Level.FINE, "Querying LuceneCatalog: q: [" + booleanQuery
                     + "]");
             //TODO FIX NUMBER OF RECORDS
             TopDocs check = searcher.search(booleanQuery.build(),1, sort);
-            TopDocs topDocs = searcher.search(booleanQuery.build(),check.totalHits, sort);
+            if(check.totalHits>0) {
+                TopDocs topDocs = searcher.search(booleanQuery.build(), check.totalHits, sort);
 
-            // Calculate page size and set it while we have the results
-            if (page != null) {
-            	page.setTotalPages(PaginationUtils.getTotalPage(topDocs.totalHits, pageSize));
-            }
+                // Calculate page size and set it while we have the results
+                if (page != null) {
+                    page.setTotalPages(PaginationUtils.getTotalPage(topDocs.totalHits, pageSize));
+                }
 
-            ScoreDoc[] hits = topDocs.scoreDocs;
+                ScoreDoc[] hits = topDocs.scoreDocs;
 
-            if (hits.length > 0) {
+                if (hits.length > 0) {
 
-                int startNum = (pageNum - 1) * pageSize;
-                if (doSkip) {
-                    if (startNum > hits.length) {
-                        startNum = 0;
-                    }
+                    int startNum = (pageNum - 1) * pageSize;
+                    if (doSkip) {
+                        if (startNum > hits.length) {
+                            startNum = 0;
+                        }
 
-                    products = new Vector<Product>(pageSize);
+                        products = new Vector<Product>(pageSize);
 
-                    for (int i = startNum; i < Math.min(hits.length,
+                        for (int i = startNum; i < Math.min(hits.length,
                             (startNum + pageSize)); i++) {
-                        Document productDoc = searcher.doc(hits[i].doc);
+                            Document productDoc = searcher.doc(hits[i].doc);
 
-                        CompleteProduct prod = toCompleteProduct(productDoc,
+                            CompleteProduct prod = toCompleteProduct(productDoc,
                                 false, false);
-                        products.add(prod.getProduct());
-                    }
-                } else {
-                    products = new Vector<Product>(hits.length);
-                    for (int i = 0; i < hits.length; i++) {
-                        Document productDoc = searcher.doc(hits[i].doc);
+                            products.add(prod.getProduct());
+                        }
+                    } else {
+                        products = new Vector<Product>(hits.length);
+                        for (int i = 0; i < hits.length; i++) {
+                            Document productDoc = searcher.doc(hits[i].doc);
 
-                        CompleteProduct prod = toCompleteProduct(productDoc,
+                            CompleteProduct prod = toCompleteProduct(productDoc,
                                 false, false);
-                        products.add(prod.getProduct());
+                            products.add(prod.getProduct());
+                        }
                     }
-                }
-            } else {
-                LOG.log(Level.WARNING, "Query: [" + query
+                } else {
+                    LOG.log(Level.WARNING, "Query: [" + query
                         + "] for Product Type: [" + type.getProductTypeId()
                         + "] returned no results");
+                }
             }
 
         } catch (Exception e) {
@@ -1446,6 +1453,7 @@ public class LuceneCatalog implements Catalog {
         }
 
         return products;
+
     }
 
     private org.apache.lucene.search.Query getQuery(QueryCriteria queryCriteria) throws CatalogException {