Skip to content

Commit

Permalink
Merge pull request #4 from transcom/B-19835-B-19836-TRDM-Tests
Browse files Browse the repository at this point in the history
B-19835 and B-19836 TRDM tests
  • Loading branch information
TevinAdams authored May 14, 2024
2 parents 1e9293e + b821e27 commit f392359
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
auth:
password: $DOCKER_PASSWORD
username: $DOCKER_USERNAME
environment:
TEST_DB_HOST: localhost
TEST_DB_NAME: test_db
TEST_DB_USER: postgres
TEST_DB_PORT: 5433
TEST_DB_PASSWORD: mysecretpassword
TEST_DB_URL: jdbc:postgresql://localhost:5433/test_db?user=postgres&password=mysecretpassword

steps:
- checkout
- run:
Expand Down
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# DO NOT WRITE SECRETS IN HERE

## milmove-db-test variables
export TEST_DB_HOST="localhost"
export TEST_DB_NAME="test_db"
export TEST_DB_USER="postgres"
export TEST_DB_PORT="5433"
export TEST_DB_PASSWORD="mysecretpassword"
export TEST_DB_URL="jdbc:postgresql://${TEST_DB_HOST}:${TEST_DB_PORT}/${TEST_DB_NAME}?user=${TEST_DB_USER}&password=${TEST_DB_PASSWORD}"

# Apache variables
export PROVIDER="org.apache.ws.security.components.crypto.Merlin"
export CLIENT_PROPS_FILE_PATH="src/main/resources/client_sign.properties"
Expand Down
90 changes: 47 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
# Table of Contents
- [Table of Contents](#table-of-contents)
- [Disabled RESTful to SOAP Conversion Capabilities](#disabled-restful-to-soap-conversion-capabilities)
- [API Gateway](#api-gateway)
- [TRDM](#trdm)
- [Pre-Requisites](#pre-requisites)
- [Running tests](#running-tests)
- [How to Deploy](#how-to-deploy)
- [History](#history)
- [Disabled RESTful to SOAP Conversion Capabilities](#disabled-restful-to-soap-conversion-capabilities)
- [Deprecated API Gateway](#deprecated-api-gateway)
- [TRDM](#trdm)
- [Whitelisted tables](#whitelisted-tables)
- [Apache CXF Code Generation](#apache-cxf-code-generation)
- [Apache CXF Code Generation](#apache-cxf-code-generation)
- [Plugin](#plugin)
- [Known Issue](#known-issue)
- [trdm-lambda](#trdm-lambda)
- [Pre-Requisites](#pre-requisites)
- [Build](#build)
- [Run Application Locally](#run-application-locally)
- [Deploy](#deploy)
- [ENV variables](#env-variables)
- [CI/CD Known Issue](#cicd-known-issue)
- [trdm-lambda](#trdm-lambda)
- [ENV variables](#env-variables)
- [Environment Specific Yaml files](#environment-specific-yaml-files)
- [Application Information](#application-information)
- [Application Information](#application-information)
- [Meta Annotations](#meta-annotations)
- [Controller Advice](#controller-advice)
- [Custom Properties](#custom-properties)
- [Endpoints](#endpoints)
- [Deprecated Endpoints](#deprecated-endpoints)
- [lastTableUpdate](#lasttableupdate)
- [getTable](#gettable)

# Disabled RESTful to SOAP Conversion Capabilities
# Pre-Requisites
* OpenJDK 17
* Maven (No specific version)
* [MyMove PreReqs](https://transcom.github.io/mymove-docs/docs/getting-started/application-setup/prerequisites)

# Running tests
This repository relies on the Transcom [mymove repository](https://github.com/transcom/mymove). This means that tests require a connection to that repositories docker containers. Please see the following steps:
1. Have two open terminal windows, one for this repository and another for the mymove repository
2. `cd` into the mymove repository in your second window
1. If you haven't already, run `direnv allow`
2. Run `make server_test_setup` to configure your docker container
3. For more documentation on this, please see mymove docs [here](https://transcom.github.io/mymove-docs/docs/getting-started/development/testing)
3. Open Docker Desktop and confirm that the `milmove-db-test` container is up and running
4. Change back to your first terminal window for this repository
5. Run `mvn test`

# How to Deploy

To deploy the application to AWS, download the latest release, upload it into the bucket under lambda builds -> trdm-soap-proxy -> Make a new version folder -> upload with proper encryption keys set.

After it has been uploaded into the bucket please update the `trdm_soap_proxy_version` variable in terraform [here](https://github.com/transcom/terraform-aws-app-environment) under `variables.tf`.

# History
This section of the README is dedicated to the past history of this repository. It will provide a high-level of the previous version of this repository which was to serve as an API gateway from Transcom's MyMove to Transcom Relational Database Management's (TRDM) servers. This approach was abandoned and switched to a cron job for the sake of time sensitivity and a vastly already out-of-scope feature approach. It can be previewed via the git history prior to release `v1.0.0.0`. The release and its changelog can be found [here](https://github.com/transcom/trdm-lambda/releases/tag/v1.0.0.0). There are still some deprecated files remaining within this repository.

## Disabled RESTful to SOAP Conversion Capabilities
This lambda function as of version 1 received an overhaul to function as a cron based lambda function invoked via a timer.

It has the complete capability of providing a REST to SOAP conversion service. This can be of use in the future when other services may need to interface through us. It currently is running as spring boot application which is not necessarily needed for a cron job, but due to time sensitivity it was not phased out when overhauling. It does still offer the future ability to turn back on the RESTful aspects to provide said conversion service, but as of right now it is disabled.

# API Gateway
## Deprecated API Gateway
Please see documentation [here](https://dp3.atlassian.net/wiki/spaces/MT/pages/2275573761/TRDM+Soap+Proxy+API+Gateway+Lambda+Function).

# TRDM
## TRDM
We are leveraging the `ReturnTableV7` WSDL provided by TRDM. This file has been verified to be unclassified in its entirety, holding no sensitive information and cleared to release into our open source repository by their administrators.

Please refer to the [code generation](#apache-cxf-code-generation) section as to how this WSDL is so important for our function.
Expand All @@ -40,7 +65,7 @@ Read about which tables we are allowed to access [here](https://dp3.atlassian.ne

See information about the truststore [here](https://dp3.atlassian.net/wiki/spaces/MT/pages/2290483201/Updating+TRDM+Lambda+Function+Trust+Store).

# Apache CXF Code Generation
## Apache CXF Code Generation
It is very important to understand the backbone of the SOAP envelope generation. By using the `cxf-codegen-plugin` we can provide a WSDL and it will auto generate us code under `target` that can be used to generate SOAP envelopes.

## Plugin
Expand Down Expand Up @@ -70,7 +95,7 @@ It is very important to understand the backbone of the SOAP envelope generation.
</plugin>
```

## Known Issue
## CI/CD Known Issue
We have found that CI/CD does not work well when using Apache CXF code generation. The plugin generates code at build time, and since CircleCI handles our actual build and release this means that it will be generated within CircleCI. This is normally not a problem and actually a good thing; however, this plugin makes hard coded file references to the file system directories it was built inside of. So, when CircleCI builds it and releases it the code will have hard coded *file* references to the WSDL such as (Exaggeration) `CircleCI/resources/`, meaning when deployed in AWS it will always fail. So, the way around that is to generate it locally, modify it as necessary, and store it within GitHub. This is why you can find the ReturnTableV7 code generated with that plugin added to our src manually [here](src/main/java/cxf).

After the code was generated and plugged into `src`, we had to manually modify the WSDL references. See examples when you search that directory and sub directories for `classpath:ReturnTableV7.wsdl` - before these were class paths they were file references with hard coded CircleCI values - hence why when it was hosted into AWS Lambda it couldn't find the CircleCI directories.
Expand All @@ -96,31 +121,10 @@ static {
Instead of relying on the target that gets auto generated with the plugin.


# trdm-lambda
## trdm-lambda
Provides a serverless Java application to host an internal RESTful interface. This Java application will handle SOAP-based requests toward TRDM on behalf of our Go MilMove server. It will be hosted as an AWS Lambda function for MilMove API requests to TRDM via SOAP.

## Pre-Requisites

The first step is to download and install [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and then [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html).

Let’s run AWS SAM CLI on the path where the template.yaml is located and execute the command:
### Build

To build the application run `sam build` from the root directory or in the same directory as the `template.yml` file.

### Run Application Locally

To run the application locally run `sam local start-api`. It will require AWS credentials to turn on, so either you need `/.aws/credentials` or if using
aws-vault to manage your credentials you need to wrap your start command like so: `aws-vault exec transcom-gov-dev -- sam local start-api`.

## Deploy

To deploy the application to AWS, download the latest release, upload it into the bucket under lambda builds -> trdm-soap-proxy -> Make a new version folder -> upload with proper encryption keys set.

After it has been uploaded into the bucket please update the `trdm_soap_proxy_version` variable in terraform [here](https://github.com/transcom/terraform-aws-app-environment) under `variables.tf`.


## ENV variables
### ENV variables

The `application.yml` can store configurations for your env variables. Which includes both secrets and configs.

Expand All @@ -142,7 +146,7 @@ If each env requires a different configuration create a new yaml file following

[Spring documentation](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.properties-and-configuration).

## Application Information
### Application Information

This application utilizes several core Spring Features.
1. Custom Validation for a request body using `Meta Annotations`
Expand Down Expand Up @@ -174,7 +178,7 @@ When adding custom properties to the application you can add them directly the t

Then if you plan on reading them into the application create a `CustomPropProps.java` class to handle the custom props you are loading in.

## Endpoints
## Deprecated Endpoints

### lastTableUpdate
[Go here](docs/lastTableUpdate.md)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.milmove.trdmlambda</groupId>
<artifactId>trdm-lambda</artifactId>
<version>1.0.3.2</version>
<version>1.0.3.3</version>
<name>trdm java spring interface</name>
<description>Project for deploying a Java TRDM interfacer for TGET data.</description>
<properties>
Expand Down
4 changes: 3 additions & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ set -eu -o pipefail
echo "Packaging..."

# Build via sam
sam build
# Tests have been disabled during the build because more work needs to be completed to automate the pipelines for trdm
# sam build // This should be reinstated in B-20145 under E-05306
MAVEN_OPTS="-DskipTests=true" sam build

# Zip requires `cd` because if not it will compile the relative paths
# which means it will also zip .aws-sam/build/, breaking the deployment.
Expand Down
Loading

0 comments on commit f392359

Please sign in to comment.