-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cached statistics and all ontologies for ontologies tab and cleaned u…
…p logging on backend.
- Loading branch information
1 parent
e5c4a2e
commit 09d8251
Showing
10 changed files
with
173 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...d/src/main/java/uk/ac/ebi/spot/ols/controller/api/v2/cache/V2OntologyCacheController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package uk.ac.ebi.spot.ols.controller.api.v2.cache; | ||
|
||
import com.google.gson.Gson; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.rest.webmvc.ResourceNotFoundException; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import uk.ac.ebi.spot.ols.controller.api.v2.helpers.DynamicQueryHelper; | ||
import uk.ac.ebi.spot.ols.controller.api.v2.responses.V2PagedAndFacetedResponse; | ||
import uk.ac.ebi.spot.ols.model.v2.V2Entity; | ||
import uk.ac.ebi.spot.ols.repository.v2.V2OntologyRepository; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This controller caches all ontologies for use in the ontologies tab. | ||
* This is done to address OLS slowness as backend, solr and neo4j pods all located on different nodes. See | ||
* https://overcast.blog/minimizing-inter-node-communication-in-kubernetes-dc53a8e28212. | ||
* | ||
*/ | ||
@Controller | ||
@RequestMapping("/api/v2/cache/ontologies") | ||
public class V2OntologyCacheController { | ||
|
||
private Gson gson = new Gson(); | ||
|
||
@Autowired | ||
V2OntologyRepository ontologyRepository; | ||
|
||
private static ResponseEntity allOntologiesResponse = null; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(V2OntologyCacheController.class); | ||
|
||
@RequestMapping(path = "", produces = {MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.GET) | ||
public HttpEntity<V2PagedAndFacetedResponse<V2Entity>> getAllOntologies( | ||
) throws ResourceNotFoundException, IOException { | ||
|
||
if (allOntologiesResponse == null) { | ||
logger.debug("getAllOntologies from Solr"); | ||
Map<String, Collection<String>> properties = new HashMap<>(); | ||
properties.put("isObsolete", List.of("false")); | ||
|
||
Pageable pageable = PageRequest.of(0, 1000); | ||
allOntologiesResponse = new ResponseEntity<>( | ||
new V2PagedAndFacetedResponse<>( | ||
ontologyRepository.find(pageable, "en", null, null, null, false, DynamicQueryHelper.filterProperties(properties)) | ||
), | ||
HttpStatus.OK); | ||
logger.trace("allOntologiesResponse = {}", allOntologiesResponse); | ||
} else { | ||
logger.debug("getAllOntologies from cache"); | ||
} | ||
return allOntologiesResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.