Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java service #16

Merged
merged 10 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
25 changes: 25 additions & 0 deletions src/services/examples/backend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "java",
"endpoints": {
"http": {
"/cart/checkout": ["sleep,1000", "sql://backend-db/?query=SELECT * from carts", ["http://ext-payment-1/pay", "http://ext-payment-2/pay"]],
"/cart/add": ["sql://backend-db/?query=SELECT * from carts"],
"error": [{"call": "error,500,Cart not found", "probability": 0.5}],
"/data": ["sleep,50", "log,warn,do some logging", "log,more logging", {
"call": "data",
"id": "price",
"type": "double",
"value": [1,2,3]
}, {
"call": "data",
"id": "randomThingy",
"chance": "integer,min:5,max:13"
}, {
"call": "data",
"id": "stuff",
"chance": "letter,casing:upper"
}]
}
},
"name": "backend"
}
1 change: 1 addition & 0 deletions src/services/examples/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"mysql","databases":{"shop":{"carts":["id","name","value"],"customers":["id","name","email"]}},"name":"backend-db"}
41 changes: 41 additions & 0 deletions src/services/examples/frontend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"type": "nodejs",
"options": {
"connectionDelay": 500,
"httpLibrary": "request-promise"
},
"endpoints": {
"http": {
"/logo.png": ["sleep,1000"],
"/script.js": ["sleep,5000"],
"/checkout": ["http://backend/cart/checkout", "image,logo.png", "script,script.js","ajax,cache"],
"/addtocart": ["http://backend/cart/add", "slow,1500"],
"/cache": [["sleep,5000","sleep,5"], "cache,1024"],
"/schedule": ["sleep,50", {
"call": "error,500,oops",
"schedule": "0-30 * * * * * *"
}],
"/test": [{
"call": "http://localhost:9876/cache",
"catchExceptions": false,
"remoteTimeout": 2000
}],
"/data": ["sleep,50", "log,warn,do some logging", "log,more logging", {
"call": "data",
"id": "price",
"type": "double",
"value": [1,2,3]
}, {
"call": "data",
"id": "randomThingy",
"chance": "integer,min:5,max:13"
}, {
"call": "data",
"id": "stuff",
"chance": "letter,casing:upper"
}],
"/script": ["code,sample.js"]
}
},
"name": "frontend"
}
7 changes: 7 additions & 0 deletions src/services/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
*.class
target/maven-*
extras/*.jar
target/
node.log
javanode.iml
15 changes: 15 additions & 0 deletions src/services/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM maven:3-jdk-11 AS build
WORKDIR /home/app
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package

FROM openjdk:11-jre
RUN mkdir -p /app/dependency-jars
WORKDIR /app
COPY --from=build /home/app/target /app/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypointk8s.sh
COPY extras/* /app/
EXPOSE 8080
CMD ["/entrypoint.sh"]
4 changes: 4 additions & 0 deletions src/services/java/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo java -jar "javanode-1.0-SNAPSHOT.jar" 8080
APP_CONFIG="$(</config.json)" java -jar "javanode-1.0-SNAPSHOT.jar" 8080

Empty file.
2 changes: 2 additions & 0 deletions src/services/java/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
mvn package
134 changes: 134 additions & 0 deletions src/services/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cisco.open.appsimulator.java</groupId>
<artifactId>javanode</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javanode</name>
<properties>
<jettyVersion>11.0.0.beta3</jettyVersion>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.cisco.open.appsimulator.JavaNode</mainClass>
<arguments>
<argument>8080</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.cisco.open.appsimulator.JavaNode</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Copy project dependency -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
2 changes: 2 additions & 0 deletions src/services/java/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
env APP_CONFIG="$(<../examples/backend.json)" mvn -e compile exec:java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.cisco.open.appsimulator;

import java.io.IOException;

public class HttpException extends IOException
{
protected int code;

public HttpException(int code, String message) {
super(message);
this.code = code;
}

public int getCode() {
return this.code;
}
}
Loading
Loading