From 837883bdfd06bea177e2b0140f0c6c794001ab17 Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Mon, 25 Jan 2021 16:33:13 -0700 Subject: [PATCH] use Micronaut arg for basin url --- .../nshmp/www/DeaggEpsilonController.java | 7 ----- .../www/services/DeaggEpsilonService.java | 28 ++----------------- src/main/resources/application.yml | 6 ++++ 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/DeaggEpsilonController.java b/src/main/java/gov/usgs/earthquake/nshmp/www/DeaggEpsilonController.java index ab2976d4e..478f8087a 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/DeaggEpsilonController.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/www/DeaggEpsilonController.java @@ -11,7 +11,6 @@ import gov.usgs.earthquake.nshmp.www.services.DeaggEpsilonService; import gov.usgs.earthquake.nshmp.www.services.DeaggEpsilonService.Query; import gov.usgs.earthquake.nshmp.www.services.HazardService; -import io.micronaut.context.event.StartupEvent; import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpResponse; import io.micronaut.http.MediaType; @@ -19,7 +18,6 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.PathVariable; import io.micronaut.http.annotation.QueryValue; -import io.micronaut.runtime.event.annotation.EventListener; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -32,11 +30,6 @@ public class DeaggEpsilonController { @Inject private NshmpMicronautServlet servlet; - @EventListener - public void init(StartupEvent event) { - DeaggEpsilonService.init(); - } - @Get(uri = "/usage", produces = MediaType.APPLICATION_JSON) public HttpResponse<String> doGetUsage(HttpRequest<?> request) { var urlHelper = servlet.urlHelper(request); diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/services/DeaggEpsilonService.java b/src/main/java/gov/usgs/earthquake/nshmp/www/services/DeaggEpsilonService.java index 2f744fe86..02cb1f53b 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/services/DeaggEpsilonService.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/www/services/DeaggEpsilonService.java @@ -1,19 +1,13 @@ package gov.usgs.earthquake.nshmp.www.services; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.util.EnumMap; import java.util.List; -import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.function.Function; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableList; -import com.google.common.io.Resources; import gov.usgs.earthquake.nshmp.calc.CalcConfig; import gov.usgs.earthquake.nshmp.calc.Deaggregation; @@ -30,6 +24,7 @@ import gov.usgs.earthquake.nshmp.www.meta.Metadata; import gov.usgs.earthquake.nshmp.www.services.ServicesUtil.Key; import gov.usgs.earthquake.nshmp.www.services.SourceServices.SourceModel; +import io.micronaut.context.annotation.Value; import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpResponse; @@ -43,26 +38,9 @@ public final class DeaggEpsilonService { /* Developer notes: See HazardService. */ private static final String NAME = "Epsilon Deaggregation"; - private static URL basinUrl; - public static void init() { - try (InputStream config = Resources.getResource("config.properties").openStream()) { - checkNotNull(config, "Missing config.properties"); - - Properties props = new Properties(); - props.load(config); - if (props.containsKey("basin_host")) { - /* - * TODO Site builder tests if service is working, which may be - * inefficient for single call services. - */ - var url = new URL(props.getProperty("basin_host") + "/nshmp/ws/data/basin"); - basinUrl = url; - } - } catch (IOException | NullPointerException e) { - throw new RuntimeException(e); - } - } + @Value("${nshmp-haz.basin-service-url}") + private static URL basinUrl; /** * Handler for {@link DeaggEpsilonController#doGetDeaggEpsilon}. Returns the diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 864c3d0da..46d39c2cf 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,6 +15,12 @@ micronaut: mapping: /** nshmp-haz: + ## + # The basin service url + # To specify the url to use: + # java -jar build/libs/nshmp-haz-v2.jar --basin-url= + basin-service-url: ${basin-service-url:https://staging-earthquake.usgs.gov/nshmp/ws/data/basin} + ## # The path to the models. # To specify the model to use: -- GitLab