Skip to content

Commit 9349a45

Browse files
authored
Merge pull request #593 from boozallen/591-improve-arch-test
#591 improve archetype test
2 parents 4c5e02d + dab1912 commit 9349a45

4 files changed

+112
-163
lines changed

foundation/foundation-archetype/extensions-to-add-to-archetype_test-generator-deploy_pom.xml

-133
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<plugin>
2+
<groupId>com.boozallen.aissemble</groupId>
3+
<artifactId>mda-maven-plugin</artifactId>
4+
<executions>
5+
<execution>
6+
<id>copy-spark-application</id>
7+
<phase>prepare-package</phase>
8+
<goals>
9+
<goal>copy-pipeline-artifacts</goal>
10+
</goals>
11+
<configuration>
12+
<targetPipelineTypes>
13+
<targetPipelineType>data-flow</targetPipelineType>
14+
</targetPipelineTypes>
15+
<targetArtifactTypes>
16+
<targetArtifactType>VALUES_FILES</targetArtifactType>
17+
</targetArtifactTypes>
18+
<outputDirectory>${project.basedir}/src/main/resources/apps/pipeline-invocation-service/target/</outputDirectory>
19+
</configuration>
20+
</execution>
21+
</executions>
22+
<configuration>
23+
<groupId>${project.groupId}</groupId>
24+
<modelsArtifactId>${project.parent.artifactId}-pipeline-models</modelsArtifactId>
25+
<pipelinesDirectory>${project.parent.basedir}/${project.parent.artifactId}-pipelines/</pipelinesDirectory>
26+
<habushuArtifactVersion>${version.habushu.dist.artifact}</habushuArtifactVersion>
27+
</configuration>
28+
<dependencies>
29+
<dependency>
30+
<groupId>${project.groupId}</groupId>
31+
<artifactId>${project.parent.artifactId}-pipeline-models</artifactId>
32+
<version>${project.version}</version>
33+
</dependency>
34+
</dependencies>
35+
</plugin>

foundation/foundation-archetype/test-project-archetype.sh

+69-30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# #L%
1111
###
1212

13+
set -o pipefail
1314
echo -e "\n\n **** TESTING ARCHETYPE GENERATION **** \n\n"
1415

1516
if [ $# -ne 1 ]; then
@@ -21,27 +22,73 @@ fi
2122
mkdir -p target/temp
2223
cd target/temp
2324

25+
#---
26+
## Replacement for `sed -i` that formats the command correctly for MacOS and Linux
27+
##
28+
## @args: $1 and $2 are passed in unchanged to `sed`
29+
#---
30+
function sub {
31+
if [[ $OSTYPE == "darwin"* ]]; then
32+
sed -i '' "$1" "$2" || exit 1
33+
else
34+
sed -i "$1" "$2" || exit 1
35+
fi
36+
}
37+
38+
#---
39+
## Escapes the contents of a stdin for use with a `sed` substitution command. Namely ensures dollar signs, new lines
40+
## and backslashes are escaped.
41+
##
42+
## @stdin: the content to escape
43+
## @stdout: the input with '$', '\', and '\n' escaped
44+
#---
45+
function esc {
46+
# sed is used for a straightforward substitution of \ and $
47+
# awk is used to escape newlines. Essentially, replaces the newlines between lines of input with a backslash and newline.
48+
# Hence ORS (output record sep) is `\\\n`. However, because trailing newlines are always chomped in pipes, the last
49+
# newline in the input must not be escaped. Therfore, input is buffered by one line in the `last` var so we can turn set
50+
# the ORS to blank for the final line.
51+
sed 's/\([\/\$]\)/\\\1/g' | awk 'NR > 1 {ORS="\\\n"} END {ORS=""; print last} {print last} {last=$0}' ORS=''
52+
}
53+
2454
function updatePomBasedOnChildDirs {
2555
# The 'TODO' text line that we're going to replace in the file
2656
# should be passed in as the first param to this method. i.e.
2757
# updatePomBasedOnChildDirs '<!-- TODO: this is where manual actions go -->'
2858
todoText=$1
29-
30-
modules=""
59+
modules=""
3160
for d in */ ; do
3261
if [ $d != "target/" ]; then
3362
# Drop / from the end of the directory
3463
d="${d/\//}"
35-
modules+="<module>$d</module>"
64+
modules+="<module>$d</module>"$'\n '
3665
fi
3766
done
3867

3968
echo -e "\nINFO: Adding \n\t$modules\n\tto $PWD/pom.xml\n"
40-
fileContents=`cat pom.xml`
41-
fileContents="${fileContents/$todoText/$modules}"
69+
# command substitution trims trailing newlines so add it back
70+
sub "s/$todoText/$(esc <<< "$modules")/" pom.xml
71+
}
4272

43-
# NOTE - the formatting get's all messed up
44-
echo -e $fileContents > pom.xml
73+
#---
74+
## Runs maven build and captures any manual actions for adding Fermenter executions to the deploy POM, then updates the
75+
## deploy POM based on the detected manual actions.
76+
#---
77+
function runBuildAndUpdateDeploy {
78+
deployInsert="<!-- Add executions for each deployment module -->"
79+
outputstart='executions to test-generator-deploy'
80+
outputend='\[WARNING\]'
81+
# $outputstart match at end ensures the match line isn't captured. NF ensures blank lines aren't captured.
82+
execs=$(./mvnw clean install | tee /dev/tty | \
83+
awk "BEGIN {output=0} /$outputend/ {output=0} NF && output {print} /$outputstart/ {output=1}")\
84+
|| { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
85+
if [ -n "$execs" ]; then
86+
#re-adding insert comment allows for subsequent insertions
87+
execs=$deployInsert$'\n'$execs
88+
execs=$(esc <<< "$execs")
89+
echo -e "\n INFO: Adding execution profiles to deploy POM: \n$execs"
90+
sub "s/$deployInsert/$execs/" test-generator-deploy/pom.xml
91+
fi
4592
}
4693

4794
package='com.bah.aiops'
@@ -61,7 +108,7 @@ mvn archetype:generate -B \
61108
-DmavenRepositoryUrl=https://repo1.maven.org/maven2 \
62109
-DmavenSnapshotRepositoryUrl=https://s01.oss.sonatype.org/content/repositories/snapshots
63110

64-
cd test-generator/
111+
cd test-generator/ || exit
65112

66113
# Add pipelines files necessary for testing.
67114

@@ -201,49 +248,41 @@ echo "{
201248
echo -e "\n# maven-suppress-warnings" >> Tiltfile
202249

203250
echo -e "\nINFO: Running full build to generate project structure\n"
204-
./mvnw clean install || { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
251+
runBuildAndUpdateDeploy
205252

206-
207-
cd test-generator-shared/
253+
cd test-generator-shared/ || exit
208254
updatePomBasedOnChildDirs "<!-- TODO: replace with your project-specific modules here -->"
209255

210-
cd ../test-generator-docker/
256+
cd ../test-generator-docker/ || exit
211257
updatePomBasedOnChildDirs "<!-- TODO: Add docker modules here -->"
212258

213-
cd ../test-generator-pipelines/
259+
cd ../test-generator-pipelines/ || exit
214260
updatePomBasedOnChildDirs "<!-- TODO: replace with your pipeline-specific modules here -->"
215261

216262
cd ..
217263

218264
echo -e "\nINFO: Generating project structure for pipelines and data records\n"
219-
./mvnw clean install || { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
265+
runBuildAndUpdateDeploy
220266

221-
cd test-generator-pipelines/example-machine-learning-pipeline/
267+
cd test-generator-pipelines/example-machine-learning-pipeline/ || exit
222268
updatePomBasedOnChildDirs "<!-- TODO: replace with your step-specific modules here -->"
223269

224270
cd ../..
225271

226272
echo -e "\nINFO: Generating project structure for ml pipelines\n"
227-
./mvnw clean install || { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
228-
229-
230-
echo -e "\nINFO: updating the test-generator-deploy/pom.xml based on static code as it's hard to predict without folder structure\n"
231-
executions=`cat ../../../extensions-to-add-to-archetype_test-generator-deploy_pom.xml`
232-
233-
fileContents=`cat test-generator-deploy/pom.xml`
234-
todoText="<!-- Add executions for each deployment module -->"
235-
fileContents="${fileContents/$todoText/$executions}"
236-
echo -e $fileContents > test-generator-deploy/pom.xml
237-
273+
runBuildAndUpdateDeploy
238274

275+
echo -e "\nINFO: updating the test-generator-deploy/pom.xml based on static code as it's hard to predict\n"
276+
plugins=$(esc < ../../../plugins-to-add-to-archetype_test-generator-deploy_pom.xml)
277+
sub "s/ *<\/plugins>/$plugins <\/plugins>/" test-generator-deploy/pom.xml
239278

240279
echo -e "\nINFO: Running full build to check that the build passes w/o any manual actions needed\n"
241-
./mvnw clean install || { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; } > maven-build.log
242-
buildLog=`cat maven-build.log`
243-
if [[ $buildLog == *"MANUAL ACTION NEEDED"* ]]; then
280+
# NOTE: because fermenter results are cached, the build-cache will hide remaining manual actions that were missed in previous steps
281+
./mvnw clean install -Dmaven.build.cache.skipCache -Dfermenter.display.message.keys=true | tee /dev/tty | awk '/WARNING/ {print}' > maven-build.log \
282+
|| { echo -e '\n\n\t**** MAVEN BUILD FAILED ****\n\n' ; exit 1; }
283+
if grep -iq 'Manual action' maven-build.log; then
244284
echo -e "\n\n **** ERROR: Manual action still found in build **** \n Look at **archetype/target/temp/test-generator/maven-build.log** to see what the problem was. \n\n"
245285
exit 1
246286
else
247287
echo -e "\n\n **** SUCCESS: Completed the full build successfully ****\n\n"
248288
fi
249-

foundation/foundation-mda/src/main/resources/templates/pipeline.microprofile-config.properties.vm

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ mp.messaging.outgoing.metadata-ingest.topic=metadata-ingest
1414
mp.messaging.outgoing.metadata-ingest.value.serializer=com.boozallen.aissemble.core.metadata.producer.MetadataSerializer
1515
#end
1616

17+
#if (${pipeline.isAlertingSupportNeeded()})
18+
$header Alert Producer configs $header
19+
mp.messaging.outgoing.alerts.connector=smallrye-kafka
20+
mp.messaging.outgoing.alerts.topic=alerts
21+
##TODO: StringSerializer actually throws an exception. We need an AlertSerializer in alerting-core
22+
mp.messaging.outgoing.alerts.value.serializer=org.apache.kafka.common.serialization.StringSerializer
23+
#end
24+
1725
#if (${pipeline.getDataLineage()})
1826
$header Data Lineage Emitter configs $header
1927
$comment By default, uses in-memory transport and logs events to console.

0 commit comments

Comments
 (0)