Skip to content

Commit

Permalink
adding test case for the coolstore application
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley committed Aug 13, 2024
1 parent 4ba6010 commit edb0349
Show file tree
Hide file tree
Showing 345 changed files with 237,678 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/apis/recognizer/language_recognizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func AnalyzeFile(configFile string, targetLanguage string) (model.Language, erro

func isStaticFileExtension(path string) bool {
staticDirs := [4]string{"static/", "templates/", "META-INF/resources/", "public/"}
//staticDirs := [4]string{"static/", "templates/"}
for _, dir := range staticDirs {
if strings.Contains(path, dir) {
return true
Expand Down
6 changes: 6 additions & 0 deletions resources/projects/coolstore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target

.classpath
.idea
.settings
.vscode
182 changes: 182 additions & 0 deletions resources/projects/coolstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# CoolStore Monolith

This repository has the complete coolstore monolith built as a Java EE 7 application. To deploy it on JBoss 7.4 follow the instructions below


## Pre requisite

* JBoss 7.4 zip installation
* Keycloak v20.0.5 zip installation
* podman or docker, tested with podman version 4.3.1
* maven, tested with maven version 3.8.5
* OpenJDK, tested with version 17.0.5

## Start a postgreSQL database

```
podman run --name myPostgresDb \
-p 5432:5432 \
-e POSTGRES_USER=postgresUser \
-e POSTGRES_PASSWORD=postgresPW \
-e POSTGRES_DB=postgresDB \
-d postgres
```

## Start keycloak

Extract keycloak-20.0.5.zip

```cd keycloak-20.0.5```

Start keycloak in dev mode listening on port 8081

``` ./bin/kc.sh start-dev --http-port=8081 ```

Open http://127.0.0.1:8081 in your browser


Set an administrator username and password, then login to keycloak using these credentials

Click on the "Master" dropdown, and select "Create Realm"

Click on "Browse" and locate the file realm-export.json in this repo.

Click on "Create" to create the "eap" realm

Click on "Users" and "Create new user"

Enter a username, e.g. "user1" and click on "Create"

From the next form, click on the "Credentials" tab and "Set password"

Set a password and password confirmation, and unselect "Temporary"

Click on "Save" to store the password.

Keycloak is now configured correctly

## Configure JBoss 7.4

Unzip jboss-eap-7.4.0.zip

``` cd jboss-eap-7.4/jboss-eap-7.4 ```

Create the folder modules/org/postgresql/main

``` mkdir -p modules/org/postgresql/main ```


Download the postgres jdbc driver from https://jdbc.postgresql.org/download/ e.g. https://jdbc.postgresql.org/download/postgresql-42.5.4.jar

Copy postgres jar file to modules/org/postgresql/main

create module.xml -- ensure the filename matches the filename downloaded in the previous step

```
cat <<EOF > modules/org/postgresql/main/module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.5.4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
EOF
```


Start JBoss EAP 7.4 in full high availability mode

From the jboss-eap-7.4 folder run:

```./jboss-eap-7.4-2/bin/standalone.sh -c standalone-full-ha.xml -Djboss.node.name=node1 ```

In another terminal, start the jboss cli, from the jboss7.4 installation folder run

``` ./bin/jboss-cli.sh --connect ```

Run the following commands:

```
/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql)
```

```
data-source add --name=CoolstoreDS --jndi-name=java:jboss/datasources/CoolstoreDS --driver-name=postgresql --connection-url=jdbc:postgresql://127.0.0.1:5432/postgresDB --user-name=postgresUser --password=postgresPW
```

```
jms-topic add --topic-address=topic.orders --entries=topic/orders
/subsystem=messaging-activemq/server=default:write-attribute(name=cluster-password, value=password)
```

## Build and deploy the application

From the root of this repo, run:

`mvn package`

Set the JBOSS_HOME env variable e.g.

`export JBOSS_HOME=~/jboss-eap-7.4/jboss-eap-7.4`

Run the jboss cli:

` $JBOSS_HOME/bin/jboss-cli.sh`

Run the following command to deploy the application:

`deploy ./target/ROOT.war`

Navigate to http://127.0.0.1:8080

![coolstore](assets/coolstore.png "coolstore")

From the coostore, click on "Sign in" in the top right

Login with the user credentials created on Keycloak, e.g. user1

You should now be able to complete the checkout process.

## Start a second instance.

Make a copy of the jboss-eap-7.4/jboss-eap-7.4 e.g jboss-eap-7.4/jboss-eap-7.4-2

Within the jboss-eap-7.4 folder you should now see jboss-eap-7.4 and jboss-eap-7.4-2

In the jboss-eap-7.4-2, remove the contents of standalone/data/activemq

From the jboss-eap-7.4 folder run:

`./jboss-eap-7.4-2/bin/standalone.sh -c standalone-full-ha.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=node2`

## Monitor the logs

Open up two terminals in the jboss-eap-7.4 folder

Run:

`tail -f jboss-eap-7.4/standalone/log/server.log`

in one terminal and

`tail -f jboss-eap-7.4-2/standalone/log/server.log`

in the other

## Testing clustering

If you perform a test checkout of an item, you should see both nodes processing the messages in the logs e.g.

```
2023-03-02 14:41:23,131 INFO [stdout] (Thread-3 (ActiveMQ-client-global-threads))
2023-03-02 14:41:23,131 INFO [stdout] (Thread-3 (ActiveMQ-client-global-threads)) Message recd !
2023-03-02 14:41:23,131 INFO [stdout] (Thread-3 (ActiveMQ-client-global-threads)) Received order: {"orderValue":10.49,"customerName":"Karl Svensson","customerEmail":"[email protected]","retailPrice":10.0,"discount":-2.5,"shippingFee":2.99,"shippingDiscount":0.0,"items":[{"productSku":"329299","quantity":1}]}
2023-03-02 14:41:23,132 INFO [stdout] (Thread-3 (ActiveMQ-client-global-threads)) Order object is Order [orderId=0, customerName=Karl Svensson, [email protected], orderValue=10.49, retailPrice=10.0, discount=-2.5, shippingFee=2.99, shippingDiscount=0.0, itemList=[OrderItem [productId=329299, quantity=1]]]
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
labels:
app: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: docker.io/library/postgres:15
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: coolstore
- name: POSTGRES_USER
value: quarkus
- name: POSTGRES_PASSWORD
value: quarkus
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-storage
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
type: NodePort
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
nodePort: 30007
3 changes: 3 additions & 0 deletions resources/projects/coolstore/deploy/kubernetes/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
postgresqlUsername: quarkus
postgresqlPassword: quarkus
postgresqlDatabase: coolstore
Loading

0 comments on commit edb0349

Please sign in to comment.