diff --git a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/GrebiApi.java b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/GrebiApi.java index c7b4fd7..51efffc 100644 --- a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/GrebiApi.java +++ b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/GrebiApi.java @@ -27,9 +27,9 @@ public class GrebiApi { public static void main(String[] args) throws ParseException, org.apache.commons.cli.ParseException, IOException { - GrebiNeoRepo neo; - GrebiSolrRepo solr; - GrebiSummaryRepo summary; + GrebiNeoRepo neo = null; + GrebiSolrRepo solr = null; + GrebiSummaryRepo summary= null; Set rocksDbSubgraphs = null; Set solrSubgraphs = null; @@ -38,24 +38,20 @@ public static void main(String[] args) throws ParseException, org.apache.commons while(true) { try { - neo = new GrebiNeoRepo(); solr = new GrebiSolrRepo(); summary = new GrebiSummaryRepo(); - neo = new GrebiNeoRepo(); rocksDbSubgraphs = (new ResolverClient()).getSubgraphs(); solrSubgraphs = solr.getSubgraphs(); summarySubgraphs = summary.getSubgraphs(); - neoSubgraphs = neo.getSubgraphs(); - if(new HashSet<>(List.of(rocksDbSubgraphs, solrSubgraphs, summarySubgraphs, neoSubgraphs)).size() != 1) { - throw new RuntimeException("RocksDB/Solr/the summary jsons/Neo4j do not seem to contain the same subgraphs. Found: " + if(new HashSet<>(List.of(rocksDbSubgraphs, solrSubgraphs, summarySubgraphs)).size() != 1) { + throw new RuntimeException("RocksDB/Solr/the summary jsons do not seem to contain the same subgraphs. Found: " + String.join(",", rocksDbSubgraphs) + " for RocksDB (from resolver service) and " + String.join(",", solrSubgraphs) + " for Solr (from list of solr cores) and " - + String.join(",", summarySubgraphs) + " for the summary jsons (from summary server) and" - + String.join(",", neoSubgraphs) + " for Neo4j (from all neo4j hosts)" + + String.join(",", summarySubgraphs) + " for the summary jsons (from summary server)" ); } break; - } catch(Exception e) { + } catch(Throwable e) { System.out.println("Could not get subgraphs from one of the services. Retrying in 10 seconds..."); e.printStackTrace(); try { @@ -66,6 +62,34 @@ public static void main(String[] args) throws ParseException, org.apache.commons } } + for(int i = 0; i < 5; ++ i) { + try { + neo = new GrebiNeoRepo(); + neoSubgraphs = neo.getSubgraphs(); + if(new HashSet<>(List.of(rocksDbSubgraphs, solrSubgraphs, summarySubgraphs)).size() != 1) { + neo = null; + throw new RuntimeException("RocksDB/Solr/the summary jsons/neo4j do not seem to contain the same subgraphs. Found: " + + String.join(",", rocksDbSubgraphs) + " for RocksDB (from resolver service) and " + + String.join(",", solrSubgraphs) + " for Solr (from list of solr cores) and " + + String.join(",", summarySubgraphs) + " for the summary jsons (from summary server) and " + + String.join(",", neoSubgraphs) + " for neo4j" + ); + } + } catch (Throwable e) { + System.out.println("Could not get subgraphs from Neo4j. Retrying in 10 seconds ("+ (4-i) + " attempts left)"); + e.printStackTrace(); + try { + Thread.sleep(10000); + } catch (InterruptedException interruptedException) { + interruptedException.printStackTrace(); + } + } + } + + if(neo == null) { + System.out.println("Neo4j is unavailable; some graph query API endpoints will be disabled"); + } + System.out.println("Found subgraphs: " + String.join(",", solrSubgraphs)); run(neo, solr, summary, solrSubgraphs); @@ -78,7 +102,7 @@ static void run( final Set subgraphs ) { - var stats = neo.getStats(); + var stats = neo != null ? neo.getStats() : null; Gson gson = new Gson(); @@ -93,7 +117,11 @@ static void run( }) .get("/api/v1/stats", ctx -> { ctx.contentType("application/json"); - ctx.result(gson.toJson(stats)); + if(stats != null) { + ctx.result(gson.toJson(stats)); + } else { + ctx.result("{\"error\":\"neo4j is not available\"}"); + } }) .get("/api/v1/subgraphs", ctx -> { ctx.contentType("application/json"); diff --git a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrClient.java b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrClient.java index 4022127..4d47655 100644 --- a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrClient.java +++ b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrClient.java @@ -130,6 +130,7 @@ public QueryResponse runSolrQuery(String coreName, SolrQuery query, Pageable pag try { qr = mySolrClient.query(query); logger.info("solr query had {} result(s).", qr.getResults().getNumFound()); + } catch (SolrServerException e) { throw new RuntimeException(e); } catch (IOException e) { diff --git a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrQuery.java b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrQuery.java index 0e98765..520ec5d 100644 --- a/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrQuery.java +++ b/webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/db/GrebiSolrQuery.java @@ -206,7 +206,7 @@ private String getSolrPropertyName(String propertyName, SearchType searchType) { private String getSolrPropertyValue(String propertyValue, SearchType searchType) { switch(searchType) { case CASE_INSENSITIVE_TOKENS: - return propertyValue.toLowerCase(); + return propertyValue; case WHOLE_FIELD: return propertyValue; default: