From 5392d31e514c9f93d6150e8740a8f43cd5f4d0ba Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Tue, 26 Sep 2023 13:34:41 -0500 Subject: [PATCH] Resolve #2 This commit resolves #2 but also suppresses the numerous stack traces from Solr communication. The end result is a Solr `.xml` file which can be loaded with `registry-mgr-legacy`. --- .../registry/client/RegistryClientSolr.java | 92 +++++++++++++++---- .../gov/nasa/pds/citool/search/DocWriter.java | 2 + 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/main/java/gov/nasa/pds/citool/registry/client/RegistryClientSolr.java b/src/main/java/gov/nasa/pds/citool/registry/client/RegistryClientSolr.java index fd2bfa5a..597b3774 100644 --- a/src/main/java/gov/nasa/pds/citool/registry/client/RegistryClientSolr.java +++ b/src/main/java/gov/nasa/pds/citool/registry/client/RegistryClientSolr.java @@ -70,14 +70,32 @@ public boolean publishFile(FileInfo fi) throws Exception ContentStreamUpdateRequest req = new ContentStreamUpdateRequest(endPoint); req.addFile(file, "application/octet-stream"); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); - NamedList resp = solrClient.request(req); - - Object error = resp.get("error"); - if(error != null) + + try { - log.warning("Blob: " + blobName + ": " + error.toString()); - } - + NamedList resp = solrClient.request(req); + Object error = resp.get("error"); + if(error != null) + { + log.warning("Blob: " + blobName + ": " + error.toString()); + } + } + catch (HttpSolrClient.RemoteSolrException ex) + { + // For some reason, RemoteSolrException is a sublcass of RuntimeException, even though + // that's typically for unchecked exceptions of failures in the JVM itself, hence a + // separate `catch` here. + return false; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + return false; + } + return true; } @@ -94,18 +112,37 @@ public List getResourceIds(String dataSetId) throws Exception query.add("fl", "identifier"); query.add("rows", "100"); - QueryResponse resp = solrClient.query(PDS_COLLECTION, query); - SolrDocumentList res = resp.getResults(); - - for(SolrDocument doc: res) + try { - Object obj = doc.getFirstValue("identifier"); - if(obj != null) + QueryResponse resp = solrClient.query(PDS_COLLECTION, query); + SolrDocumentList res = resp.getResults(); + + for(SolrDocument doc: res) { - ids.add(obj.toString()); + Object obj = doc.getFirstValue("identifier"); + if(obj != null) + { + ids.add(obj.toString()); + } } + } - + catch (HttpSolrClient.RemoteSolrException ex) + { + // For some reason, RemoteSolrException is a sublcass of RuntimeException, even though + // that's typically for unchecked exceptions of failures in the JVM itself, hence a + // separate `catch` here. + return ids; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + // Ignore + } + return ids; } @@ -117,9 +154,28 @@ private boolean md5Exists(FileInfo fi) throws Exception String md5 = fi.md5.startsWith("0") ? fi.md5.substring(1) : fi.md5; SolrQuery query = new SolrQuery("md5:\"" + md5 + "\""); - QueryResponse resp = solrClient.query(FILE_COLLECTION, query); - SolrDocumentList res = resp.getResults(); - return res.getNumFound() > 0; + try + { + QueryResponse resp = solrClient.query(FILE_COLLECTION, query); + SolrDocumentList res = resp.getResults(); + return res.getNumFound() > 0; + } + catch (HttpSolrClient.RemoteSolrException ex) + { + // For some reason, RemoteSolrException is a sublcass of RuntimeException, even though + // that's typically for unchecked exceptions of failures in the JVM itself, hence a + // separate `catch` here. + return false; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + // Ignore + } + return false; } diff --git a/src/main/java/gov/nasa/pds/citool/search/DocWriter.java b/src/main/java/gov/nasa/pds/citool/search/DocWriter.java index 9cbf7529..d83c1be2 100644 --- a/src/main/java/gov/nasa/pds/citool/search/DocWriter.java +++ b/src/main/java/gov/nasa/pds/citool/search/DocWriter.java @@ -17,6 +17,7 @@ import java.io.FileWriter; import java.util.List; import java.util.Map; +import java.util.UUID; import org.apache.commons.lang.StringEscapeUtils; @@ -44,6 +45,7 @@ public void close() throws Exception public void write(Map> fields) throws Exception { writer.write("\n"); + writer.write("" + UUID.randomUUID().toString() + "\n"); for(Map.Entry> field: fields.entrySet()) {