Skip to content

Commit

Permalink
fix case sensitive node ids not working, enable running api without neo
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesamcl committed Dec 7, 2024
1 parent c6489df commit 43edf21
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
54 changes: 41 additions & 13 deletions webapp/grebi_api/src/main/java/uk/ac/ebi/grebi/GrebiApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> rocksDbSubgraphs = null;
Set<String> solrSubgraphs = null;
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -78,7 +102,7 @@ static void run(
final Set<String> subgraphs
) {

var stats = neo.getStats();
var stats = neo != null ? neo.getStats() : null;

Gson gson = new Gson();

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 43edf21

Please sign in to comment.