From ea32f96c01fa5e786c2b23e38dfb5bde3a220e0d Mon Sep 17 00:00:00 2001 From: jzonthemtn Date: Wed, 25 Sep 2024 07:04:04 -0400 Subject: [PATCH] #9 Updating for change in Phileas to let each pheye filter have its own endpoint configuration. --- distribution/philter.properties | 1 - distribution/policies/default.json | 3 + docker-compose.yaml | 2 - .../api/controllers/AbstractController.java | 55 ------------------- .../api/controllers/StatusApiController.java | 13 +---- pom.xml | 2 +- 6 files changed, 5 insertions(+), 71 deletions(-) diff --git a/distribution/philter.properties b/distribution/philter.properties index eb565e1..2bc41de 100644 --- a/distribution/philter.properties +++ b/distribution/philter.properties @@ -1,7 +1,6 @@ # General configuration server.port=8080 logging.level.root=INFO -ner.endpoint=http://ph-eye:18080 # Span Disambiguation span.disambiguation.enabled=false diff --git a/distribution/policies/default.json b/distribution/policies/default.json index 7105617..599f2bf 100644 --- a/distribution/policies/default.json +++ b/distribution/policies/default.json @@ -4,6 +4,9 @@ "identifiers": { "dictionaries": [], "person": { + "phEyeConfiguration": { + "endpoint": "http://localhost:5000" + }, "personFilterStrategies": [{ "strategy": "REDACT", "redactionFormat": "{{{REDACTED-%t}}}" diff --git a/docker-compose.yaml b/docker-compose.yaml index d8ca5fe..059a8ab 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -11,8 +11,6 @@ services: depends_on: - ph-eye image: philterd/philter:2.5.0 - environment: - ner.endpoint: http://ph-eye:18080/ ports: - "8080:8080" networks: diff --git a/philter-api/src/main/java/ai/philterd/philter/api/controllers/AbstractController.java b/philter-api/src/main/java/ai/philterd/philter/api/controllers/AbstractController.java index b69a852..7522bd2 100644 --- a/philter-api/src/main/java/ai/philterd/philter/api/controllers/AbstractController.java +++ b/philter-api/src/main/java/ai/philterd/philter/api/controllers/AbstractController.java @@ -1,65 +1,10 @@ package ai.philterd.philter.api.controllers; -import ai.philterd.phileas.model.exceptions.api.ServiceUnavailableException; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.net.URL; - public abstract class AbstractController { private static final Logger LOGGER = LogManager.getLogger(AbstractController.class); - protected String getPythonRESTServiceStatus(String philterNerEndpoint) { - - LOGGER.trace("Retrieving ph-eye status."); - - final HttpClient client = HttpClientBuilder.create().build(); - - try { - - final URL url = new URL(philterNerEndpoint); - final String protocol = url.getProtocol(); - final String host = url.getHost(); - final int port = url.getPort(); - - final HttpHost target = new HttpHost(host, port, protocol); - - // specify the get request - final HttpGet getRequest = new HttpGet("/status"); - - final HttpResponse httpResponse = client.execute(target, getRequest); - final HttpEntity entity = httpResponse.getEntity(); - - if (entity != null) { - - final String response = EntityUtils.toString(entity); - LOGGER.debug("ph-eye status response: {}", response); - return response; - - } else { - - LOGGER.debug("Received empty response from ph-eye status."); - - } - - } catch (Exception ex) { - - LOGGER.warn("Unable to successfully determine status: {}", ex.getMessage()); - throw new ServiceUnavailableException("Philter is still initializing. If message persists refer to Philter's log file."); - - } - - return "Unhealthy"; - - } - } \ No newline at end of file diff --git a/philter-api/src/main/java/ai/philterd/philter/api/controllers/StatusApiController.java b/philter-api/src/main/java/ai/philterd/philter/api/controllers/StatusApiController.java index c18c123..5135c00 100644 --- a/philter-api/src/main/java/ai/philterd/philter/api/controllers/StatusApiController.java +++ b/philter-api/src/main/java/ai/philterd/philter/api/controllers/StatusApiController.java @@ -31,19 +31,8 @@ public StatusApiController(PhileasConfiguration phileasConfiguration) { @RequestMapping(value="/api/status", method=RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity status() throws IOException { - final String health = getPythonRESTServiceStatus(phileasConfiguration.nerEndpoint()); + return new ResponseEntity<>("healthy: " + getVersion(), HttpStatus.OK); - LOGGER.info("ph-eye status is: {}", health); - - if(health.startsWith("healthy:")) { - - return new ResponseEntity<>(health + ": " + getVersion(), HttpStatus.OK); - - } else { - - return new ResponseEntity<>(NER_UNHEALTHY_OR_INITIALIZING, HttpStatus.SERVICE_UNAVAILABLE); - - } } diff --git a/pom.xml b/pom.xml index fced6d4..39fddf4 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ 4.13.2 1.13.3 1.10.19 - 2.7.0 + 2.8.0-SNAPSHOT 1.4.0 3.3.1 6.1.10