diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9ad8b36fee4af524a7d7cf9f8124bdd68d5f31f8..d2a0e989290c0fe43eb3aec75f5f0ef2bbc27631 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,6 @@ +variables: + IMAGE_NAME: ${CODE_REGISTRY_IMAGE}/${CI_PROJECT_NAME}:${ENVIRONMENT}-${CI_COMMIT_SHORT_SHA} + # Do not run for merge requests workflow: rules: @@ -12,6 +15,7 @@ include: stages: - init - build + - trigger #### # Templates @@ -43,8 +47,8 @@ Build Image Haz: DOCKER_BUILD_ARGS: | BUILD_IMAGE=${DEVOPS_REGISTRY}usgs/java:11 FROM_IMAGE=${DEVOPS_REGISTRY}usgs/java:11 - ci_job_token=${CI_JOB_TOKEN} - UPSTREAM_PATH: ghsc/nshmp/nshmp-haz-v2 + CI_JOB_TOKEN=${CI_JOB_TOKEN} + UPSTREAM_PATH: ghsc/nshmp/nshmp-haz Build Image WS: extends: @@ -54,15 +58,15 @@ Build Image WS: DOCKER_BUILD_ARGS: | BUILD_IMAGE=${DEVOPS_REGISTRY}usgs/java:11 FROM_IMAGE=${DEVOPS_REGISTRY}usgs/java:11 - ci_job_token=${CI_JOB_TOKEN} + CI_JOB_TOKEN=${CI_JOB_TOKEN} DOCKERFILE: ws.Dockerfile - UPSTREAM_PATH: ghsc/nshmp/nshmp-haz-v2 + UPSTREAM_PATH: ghsc/nshmp/nshmp-haz Build Lambda: artifacts: expire_in: 1 yr paths: - - build/libs/nshmp-haz-v2.jar + - build/libs/nshmp-haz.jar - build/libs/nshmp-haz-dependencies.zip extends: - .gradle @@ -137,3 +141,38 @@ Unit Tests: script: - ./gradlew check - cat ${JACOCO_HTML_DIR}/index.html + +#### +# Stage: trigger +#### + +Trigger nshmp-haz-ws CDK: + needs: + - Build Image WS + rules: + - + if: !reference [.development-env, if] + variables: !reference [.development-env, variables] + when: manual + allow_failure: true + - !reference [.staging-env] + - !reference [.production-env] + script: + - apk add curl + - | + if [ "${ENVIRONMENT}" == 'production' ]; then + REF="production"; + fi + - | + curl --request POST \ + --form token=${NSHMP_HAZ_WS_CDK_TRIGGER_TOKEN} \ + --form ref=${REF} \ + --form "variables[description]=Triggered by nshmp-haz" \ + --form "variables[ENVIRONMENT]=${ENVIRONMENT}" \ + --form "variables[NSHMP_HAZ_WS_IMAGE]=${IMAGE_NAME}" \ + --form "variables[TRIGGER_PASSCODE]=${NSHMP_HAZ_WS_CDK_TRIGGER_TOKEN}" \ + "https://${PRIVATE_GITLAB}/api/v4/projects/${NSHMP_HAZ_WS_CDK_PROJECT_ID}/trigger/pipeline" + stage: trigger + variables: + REF: main + UPSTREAM_PATH: ghsc/nshmp/nshmp-haz diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eaac6832b8df55ff25170b0b1517b8162cfeb516..58cb309d74c891e6e0aef8864ff9c792b14e89b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,6 @@ If you have direct contributions you would like considered for incorporation into the project you can [fork this repository][2] and [submit a merge request][3] for review. -[1]: https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/issues +[1]: https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/issues [2]: https://docs.gitlab.com/ee/gitlab-basics/fork-project.html [3]: https://docs.gitlab.com/ee/gitlab-basics/add-merge-request.html diff --git a/Dockerfile b/Dockerfile index 8fe300315d5f2fc1cd21dd23013a3af787d7c2cf..3a5e5a678a771ac174282fc00fad13727cec4ca9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,14 @@ # Run hazard jar file. # # Running Hazard: -# docker pull code.chs.usgs.gov:5001/ghsc/nshmp/images/nshmp-haz-v2; +# docker pull code.chs.usgs.gov:5001/ghsc/nshmp/images/nshmp-haz; # docker run \ # -e PROGRAM=<deagg | deagg-epsilon | deagg-iml | hazard | hazard-2018 | rate> \ # -e MODEL=<WUS_20[08|14|18] | CEUS_20[08|14|18] | COUS_20[08|14|18] | AK_2007 | HI_2020> \ # -v /absolute/path/to/sites/file:/app/sites.<geojson | csv> \ # -v /absolute/path/to/config/file:/app/config.json \ # -v /absolute/path/to/output:/app/output \ -# code.chs.usgs.gov:5001/ghsc/nshmp/images/nshmp-haz-v2; +# code.chs.usgs.gov:5001/ghsc/nshmp/images/nshmp-haz; # # Build locally: # docker build @@ -20,7 +20,7 @@ ARG BUILD_IMAGE=usgs/java:11 ARG FROM_IMAGE=usgs/java:11 -ARG project=nshmp-haz-v2 +ARG project=nshmp-haz ARG builder_workdir=/app/${project} ARG libs_dir=${builder_workdir}/build/libs @@ -31,15 +31,16 @@ FROM ${BUILD_IMAGE} as builder ARG builder_workdir ARG libs_dir + +# TODO +# Remove once nshmp-lib is public ARG git_username ARG git_password -ARG gitlab_token=null -ARG ci_job_token=null +ARG GITLAB_TOKEN=null +ARG CI_JOB_TOKEN=null ENV GIT_NSHMP_USERNAME ${git_username} ENV GIT_NSHMP_PASSWORD ${git_password} -ENV GITLAB_TOKEN ${gitlab_token} -ENV CI_JOB_TOKEN ${ci_job_token} WORKDIR ${builder_workdir} diff --git a/build.gradle b/build.gradle index e220de132a60e946360cb97cce86e81d61f89305..cf42f93f77e99cb7fa99a5aa61fd76f14545ec18 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ * Then build the JAR file: ./gradlew assemble * * One can then specify the model to run in the services: - * java -jar build/libs/nshmp-haz-v2.jar --models=/path/to/models + * java -jar build/libs/nshmp-haz.jar --models=/path/to/models * * Where <MODEL> is one of the model enums in nshmp.www.Model */ diff --git a/code.json b/code.json index 900a2a7d22e4a3bfd0d422b58564243f6efb311d..ba79cd17229e5b108ff37671089c4e128bd7a0ab 100644 --- a/code.json +++ b/code.json @@ -1,6 +1,6 @@ [ { - "name": "nshmp-haz-v2", + "name": "nshmp-haz", "organization": "U.S. Geological Survey", "description": "National Seismic Hazard Mapping Project (NSHMP) software stack", "version": "#.#.#", @@ -12,15 +12,15 @@ "licenses": [ { "name": "Public Domain, CC0-1.0", - "URL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/blob/master/LICENSE.md" + "URL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/blob/master/LICENSE.md" } ] }, - "repositoryURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/", - "homepageURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/tree/master/docs", - "downloadURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/releases/tag/v#.#.#", - "disclaimerURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/blob/master/DISCLAIMER.md", + "repositoryURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz/", + "homepageURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/tree/master/docs", + "downloadURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/releases/tag/v#.#.#", + "disclaimerURL": "https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/blob/master/DISCLAIMER.md", "vcs": "git", "laborHours": 1200, diff --git a/etc/matlab/gmmBatchExample.m b/etc/matlab/gmmBatchExample.m index 344532d117f10f6d0c5cdee459d2969e6372294f..e61fff510598179fff04eba3900568b3f4c4229e 100644 --- a/etc/matlab/gmmBatchExample.m +++ b/etc/matlab/gmmBatchExample.m @@ -1,4 +1,4 @@ -%% nshmp-haz-v2 Ground Motion Model (GMM) batch processing example script +%% nshmp-haz Ground Motion Model (GMM) batch processing example script clear; @@ -31,7 +31,7 @@ inputs = fileread('gmm-inputs.csv'); % All GMM services are available to call for batch processing. host = 'http://localhost:8080'; -service = '/nshmp-haz-v2/gmm/spectra'; +service = '/nshmp-haz/gmm/spectra'; query = 'gmm=AB_06_PRIME&gmm=CAMPBELL_03&gmm=FRANKEL_96'; diff --git a/etc/python/gmmBatchExample.py b/etc/python/gmmBatchExample.py index 130267fba754696938c5fd1471f473761f6d08bd..ff5c3dd4da960ec7f53da49b9cd1071f2c60dbaa 100644 --- a/etc/python/gmmBatchExample.py +++ b/etc/python/gmmBatchExample.py @@ -1,4 +1,4 @@ -## nshmp-haz-v2 Ground Motion Model (GMM) batch processing example script +## nshmp-haz Ground Motion Model (GMM) batch processing example script import requests @@ -35,7 +35,7 @@ file.close() # All GMM services are available to call for batch processing. host = 'http://localhost:8080' -service = '/nshmp-haz-v2/gmm/spectra' +service = '/nshmp-haz/gmm/spectra' url = host + service diff --git a/gradle.properties b/gradle.properties index 52e9cd3a8988f24d29c387b9e685c6a41c932572..05bbb8d30359538c9280b621f542f5af0487916f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ junitVersion = 5.5.2 micronautVersion = 2.4.1 mnPluginVersion = 1.4.2 nodeVersion = 3.0.1 -nshmpLibVersion = 0.5.0 +nshmpLibVersion = 0.5.1 nshmpWsUtilsVersion = 0.1.2 shadowVersion = 5.2.0 spotbugsVersion = 4.2.4 diff --git a/gradle/ext.gradle b/gradle/ext.gradle index 62ff007397def4b95746bfd70258df4dacf1b501..ddd9896f6c4e2672b3386794d48bcbe606e2bbc4 100644 --- a/gradle/ext.gradle +++ b/gradle/ext.gradle @@ -2,7 +2,7 @@ * Extra properties config. */ ext { - projectName = 'nshmp-haz-v2' + projectName = 'nshmp-haz' propsPath = '/classes/java/main/service.properties' diff --git a/scripts/docker-config.inc.sh b/scripts/docker-config.inc.sh index 2f104260682543b4492318e930a3636b802b9e06..e8cba087878b452c6801999f075281c6f38db485 100644 --- a/scripts/docker-config.inc.sh +++ b/scripts/docker-config.inc.sh @@ -19,7 +19,7 @@ readonly CONTEXT_PATH="${CONTEXT_PATH:-/}"; readonly JAVA_XMX="${JAVA_XMX:-8g}"; readonly MODEL=$(echo "${MODEL:-CONUS_2008}" | awk \{'print toupper($0)'\}); readonly NSHM_VERSION="${NSHM_VERSION:-master}"; -readonly PROJECT="${PROJECT:-nshmp-haz-v2}"; +readonly PROJECT="${PROJECT:-nshmp-haz}"; readonly PROGRAM=$(echo "${PROGRAM:-hazard}" | awk \{'print tolower($0)'\}); readonly WUS="Western US"; readonly VERSION_2014B="v4.1.1"; diff --git a/settings.gradle b/settings.gradle index 61152b0cbe312d8bd4f310a755d22bcb8f7ed045..21a2225684e38abe85a5b87abe8ef9ce4a23c51b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ plugins { id "com.alexvasilkov.git-dependencies" version "2.0.1" } -rootProject.name = "nshmp-haz-v2" +rootProject.name = "nshmp-haz" /** * Download default model, nshm-conus-2018. diff --git a/src/main/java/gov/usgs/earthquake/nshmp/DeaggEpsilon.java b/src/main/java/gov/usgs/earthquake/nshmp/DeaggEpsilon.java index c8a5e293b3184cd27093e8f6de92ddada244eb1e..562a384a158a1aabf79778d1c102ce4ff7014eae 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/DeaggEpsilon.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/DeaggEpsilon.java @@ -217,7 +217,7 @@ public class DeaggEpsilon { Disaggregation disagg = Disaggregation.atImls(hazard, spectrum, exec); List<Response> responses = new ArrayList<>(spectrum.size()); - for (Imt imt : config.hazard.imts) { + for (Imt imt : spectrum.keySet()) { ResponseData imtMetadata = new ResponseData( ImmutableList.of(), site, diff --git a/src/main/java/gov/usgs/earthquake/nshmp/HazardCalc.java b/src/main/java/gov/usgs/earthquake/nshmp/HazardCalc.java index 4e788b9a865ef4fc260eaa3f72d230a4235fc144..dec96fb7781d59e970a839048ccb596ed16a3697 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/HazardCalc.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/HazardCalc.java @@ -54,15 +54,15 @@ public class HazardCalc { * argument. * * <p>Refer to the nshmp-haz <a - * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/wikis" + * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/wikis" * target="_top">wiki</a> for comprehensive descriptions of source models, * configuration files, site files, and hazard calculations. * * @see <a - * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/wikis/Building-&-Running" + * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/wikis/Building-&-Running" * target="_top"> nshmp-haz wiki</a> * @see <a - * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/tree/master/etc/examples" + * href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/tree/master/etc/examples" * target="_top"> example calculations</a> */ public static void main(String[] args) { diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/ContextPathCookie.java b/src/main/java/gov/usgs/earthquake/nshmp/www/ContextPathCookie.java deleted file mode 100644 index dcdf890cbee25489ebd82b2a897498ad7ca8498d..0000000000000000000000000000000000000000 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/ContextPathCookie.java +++ /dev/null @@ -1,39 +0,0 @@ -package gov.usgs.earthquake.nshmp.www; - -import java.time.Duration; - -import org.reactivestreams.Publisher; - -import io.micronaut.context.annotation.Requires; -import io.micronaut.context.annotation.Value; -import io.micronaut.core.async.publisher.Publishers; -import io.micronaut.http.HttpMethod; -import io.micronaut.http.HttpRequest; -import io.micronaut.http.MutableHttpResponse; -import io.micronaut.http.annotation.Filter; -import io.micronaut.http.cookie.Cookie; -import io.micronaut.http.filter.HttpServerFilter; -import io.micronaut.http.filter.ServerFilterChain; - -/** - * Add context path as a cookie for Swagger to use. - * - * @author U.S. Geological Survey - */ -@Requires(property = "micronaut.server.context-path") -@Filter(methods = { HttpMethod.GET, HttpMethod.HEAD }, - patterns = { "/**" }) -public class ContextPathCookie implements HttpServerFilter { - private final Cookie contextPathCookie; - - ContextPathCookie(@Value("${micronaut.server.context-path}") String contextPath) { - this.contextPathCookie = Cookie.of("contextPath", contextPath).maxAge(Duration.ofMinutes(2L)); - } - - @Override - public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, - ServerFilterChain chain) { - return Publishers.map(chain.proceed(request), response -> response.cookie(contextPathCookie)); - } - -} diff --git a/src/main/java/gov/usgs/earthquake/nshmp/www/SourceController.java b/src/main/java/gov/usgs/earthquake/nshmp/www/SourceController.java index d60708d38e657c42c66715f0b582141480e25bd0..b5713e6d59e1658338acb17c1c6437c2a00b8d4a 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/www/SourceController.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/www/SourceController.java @@ -20,7 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; * default model used * * <p> To run the Micronaut jar file with a model: java -jar - * path/to/nshmp-haz-v2.jar -model=<{@code Model}> + * path/to/nshmp-haz.jar -model=<{@code Model}> * * * @author U.S. Geological Survey diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fc040527b56725fe553b5344a3d4d9887fb209ef..d875d42d0166e8ad2674aaf6453f196f2e8f2be4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,11 +14,11 @@ nshmp-haz: ## # The basin service url # To specify the url to use: - # java -jar build/libs/nshmp-haz-v2.jar --basin-service-url= + # java -jar build/libs/nshmp-haz.jar --basin-service-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: - # java -jar build/libs/nshmp-haz-v2.jar --models=<path/to/models> + # java -jar build/libs/nshmp-haz.jar --models=<path/to/models> model-path: ${models:libs/nshmp-haz-dep--nshm-conus-2018} diff --git a/src/main/resources/swagger/index.html b/src/main/resources/swagger/index.html index bf2ed5ab0c78a0dd41d8e3c2b8d653f4c57fd9dd..8a4003d3a8a88c3fc3ec0d151715f68af8e5acbc 100644 --- a/src/main/resources/swagger/index.html +++ b/src/main/resources/swagger/index.html @@ -39,11 +39,11 @@ <div id="swagger-ui"></div> <footer class="nshmp-template-footer"> - <a href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/blob/master/LICENSE.md"> + <a href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/blob/master/LICENSE.md"> License </a> - <a href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz-v2/-/blob/master/DISCLAIMER.md"> + <a href="https://code.usgs.gov/ghsc/nshmp/nshmp-haz/-/blob/master/DISCLAIMER.md"> Disclaimer </a> diff --git a/src/main/resources/swagger/index.js b/src/main/resources/swagger/index.js index f9288b53567722b966a326280bb6cf541549057b..06e5a1326e3df94485c3d6879f3d3d773b4dcecf 100644 --- a/src/main/resources/swagger/index.js +++ b/src/main/resources/swagger/index.js @@ -1,24 +1,38 @@ window.onload = function() { - const extract = function(v) { - return decodeURIComponent( - v.replace( - /(?:(?:^|.*;\s*)contextPath\s*\=\s*([^;]*).*$)|^.*$/, - '$1' - ) - ); - }; - - const contextPath = extract(document.cookie); + let contextPath = window.location.pathname; + contextPath = contextPath.endsWith('/') ? contextPath.slice(0, -1) : contextPath; const ui = SwaggerUIBundle({ - url: `${contextPath}/swagger`, + url: `./swagger`, dom_id: '#swagger-ui', tagsSorter: 'alpha', presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset], - plugins: [SwaggerUIBundle.plugins.DownloadUrl], + plugins: [SwaggerUIBundle.plugins.DownloadUrl, updateContextPath(contextPath)], validatorUrl: null, deepLinking: true }); window.ui = ui; }; + +function updateContextPath(contextPath) { + return { + statePlugins: { + spec: { + wrapActions: { + updateJsonSpec: (oriAction) => (...args) => { + const [spec] = args; + if (spec && spec.paths) { + const newPaths = {}; + Object.entries(spec.paths).forEach( + ([path, value]) => (newPaths[contextPath + path] = value) + ); + spec.paths = newPaths; + } + oriAction(...args); + }, + }, + }, + }, + }; +} diff --git a/ws.Dockerfile b/ws.Dockerfile index 2fca9f0bf1833baf223a708cf2cc38ec945ae3b5..e19925ebf02f46da6a7ea5f147dc3971b7ba89f9 100644 --- a/ws.Dockerfile +++ b/ws.Dockerfile @@ -16,11 +16,6 @@ ARG BUILD_IMAGE=usgs/java:11 ARG FROM_IMAGE=usgs/java:11 -ARG project=nshmp-haz-v2 -ARG builder_workdir=/app/${project} -ARG libs_dir=${builder_workdir}/build/libs -ARG jar_file=${libs_dir}/${project}.jar - #### # Builder image: Build jar file. #### @@ -30,12 +25,10 @@ ARG builder_workdir # TODO # Remove once nshmp-lib is public -ARG gitlab_token=null -ARG ci_job_token=null -ENV GITLAB_TOKEN ${gitlab_token} -ENV CI_JOB_TOKEN ${ci_job_token} +ARG GITLAB_TOKEN=null +ARG CI_JOB_TOKEN=null -WORKDIR ${builder_workdir} +WORKDIR /app COPY . . @@ -48,27 +41,23 @@ FROM ${FROM_IMAGE} LABEL maintainer="Peter Powers <pmpowers@usgs.gov>, Brandon Clayton <bclayton@usgs.gov>" -ARG libs_dir -ARG builder_workdir -ARG project - -ENV PROJECT ${project} -ENV CONTEXT_PATH "/" -ENV BASIN_SERVICE_URL "https://staging-earthquake.usgs.gov/nshmp/ws/data/basin" -ENV JAVA_XMS="2g" -ENV JAVA_XMX="8g" +ENV CONTEXT_PATH="/" +ENV BASIN_SERVICE_URL="https://earthquake.usgs.gov/nshmp/ws/data/basin" +ENV JAVA_OPTS="-Xms2g -Xmx8g" +ENV MODELS_DIRECTORY="/models" WORKDIR /app -COPY --from=builder ${libs_dir}/* ./ +COPY --from=builder /app/build/libs/nshmp-haz.jar . -VOLUME [ "/models" ] +VOLUME [ "${MODELS_DIRECTORY}" ] EXPOSE 8080 -ENTRYPOINT java -jar "${PROJECT}.jar" \ - "-Xms${JAVA_XMS}" \ - "-Xmx${JAVA_XMX}" \ +ENTRYPOINT java \ + ${JAVA_OPTS} \ + -jar \ + nshmp-haz.jar \ "-Dmicronaut.server.context-path=${CONTEXT_PATH}" \ --basin-service-url="${BASIN_SERVICE_URL}" \ - --models="/models"; + --models="${MODELS_DIRECTORY}";